src/server/util/hashing.h

changeset 587
c94800af0490
parent 586
9861e8ceaf96
child 589
70ad04769cbf
equal deleted inserted replaced
586:9861e8ceaf96 587:c94800af0490
27 */ 27 */
28 28
29 #ifndef HASHING_H 29 #ifndef HASHING_H
30 #define HASHING_H 30 #define HASHING_H
31 31
32 #define WS_SHA1_DIGEST_LENGTH 20
33 #define WS_SHA256_DIGEST_LENGTH 32
32 34
33 #ifdef __APPLE__ 35 #ifdef __APPLE__
34 /* macos */ 36 /* macos */
35 37
36 #define WS_CRYPTO_COMMON_CRYPTO 38 #define WS_CRYPTO_COMMON_CRYPTO
37 39
38 #define WS_AES_CTX CCCryptorRef 40 #define WS_AES_CTX CCCryptorRef
41 #define WS_SHA1_CTX CC_SHA1_CTX
39 #define WS_SHA_CTX CC_SHA256_CTX 42 #define WS_SHA_CTX CC_SHA256_CTX
40 #define WS_SHA256_DIGEST_LENGTH 32
41 43
42 #include <CommonCrypto/CommonCrypto.h> 44 #include <CommonCrypto/CommonCrypto.h>
43 #include <CommonCrypto/CommonDigest.h> 45 #include <CommonCrypto/CommonDigest.h>
44 46
45 #elif defined(_WIN32) 47 #elif defined(_WIN32)
64 BCRYPT_HASH_HANDLE hHash; 66 BCRYPT_HASH_HANDLE hHash;
65 void *pbHashObject; 67 void *pbHashObject;
66 } WinBCryptSHACTX; 68 } WinBCryptSHACTX;
67 69
68 #define WS_AES_CTX WinBCryptCTX 70 #define WS_AES_CTX WinBCryptCTX
69 #define WS_SHA_CTX WinBCryptSHACTX 71 #define WS_SHA1_CTX WinBCryptSHACTX
70 #define WS_SHA256_DIGEST_LENGTH 32 72 #define WS_SHA256_CTX WinBCryptSHACTX
71 73
72 #else 74 #else
73 /* unix/linux */ 75 /* unix/linux */
74 76
75 #include <openssl/evp.h> 77 #include <openssl/evp.h>
76 #include <openssl/rand.h> 78 #include <openssl/rand.h>
77 79
78 #define WS_USE_OPENSSL 80 #define WS_USE_OPENSSL
79 81
80 #define WS_AES_CTX EVP_CIPHER_CTX*
81
82 #if OPENSSL_VERSION_NUMBER < 0x30000000L 82 #if OPENSSL_VERSION_NUMBER < 0x30000000L
83 #define WS_SHA_CTX SHA256_CTX 83 #define WS_SHA256_CTX SHA1_CTX
84 #define WS_SHA256_CTX SHA256_CTX
84 #else 85 #else
85 #define WS_SHA_CTX EVP_MD_CTX* 86 #define WS_SHA1_CTX EVP_MD_CTX*
87 #define WS_SHA256_CTX EVP_MD_CTX*
86 #endif 88 #endif
87 #define WS_SHA256_DIGEST_LENGTH 32
88 89
89 90
90 #if defined(__sun) && defined(__SunOS_5_10) 91 #if defined(__sun) && defined(__SunOS_5_10)
91 #include <sha2.h> 92 #include <sha2.h>
93 #define SHA_Init SHAInit
94 #define SHA_Update SHAUpdate
95 #define SHA_Final SHAFinal
96
92 #define SHA256_Init SHA256Init 97 #define SHA256_Init SHA256Init
93 #define SHA256_Update SHA256Update 98 #define SHA256_Update SHA256Update
94 #define SHA256_Final SHA256Final 99 #define SHA256_Final SHA256Final
95 #else 100 #else
96 #include <openssl/sha.h> 101 #include <openssl/sha.h>
97 #endif 102 #endif
98 103
99 #endif 104 #endif
100 105
106 int ws_sha1_init(WS_SHA1_CTX *ctx);
107 WS_SHA1_CTX* ws_sha1_create(void);
108 void ws_sha1_update(WS_SHA1_CTX *ctx, const char *data, size_t len);
109 void ws_sha1_final(WS_SHA1_CTX *ctx, unsigned char *buf);
101 110
102 void ws_sha256_init(WS_SHA_CTX *ctx); 111 int ws_sha256_init(WS_SHA256_CTX *ctx);
103 WS_SHA_CTX* ws_sha256_create(void); 112 WS_SHA256_CTX* ws_sha256_create(void);
104 void ws_sha256_update(WS_SHA_CTX *ctx, const char *data, size_t len); 113 void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t len);
105 void ws_sha256_final(WS_SHA_CTX *ctx, unsigned char *buf); 114 void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *buf);
106 115
107 116
108 #ifdef __cplusplus 117 #ifdef __cplusplus
109 } 118 }
110 #endif 119 #endif

mercurial