| 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 |
32 #define WS_SHA1_DIGEST_LENGTH 20 |
| 33 #define WS_SHA256_DIGEST_LENGTH 32 |
33 #define WS_SHA256_DIGEST_LENGTH 32 |
| |
34 #define WS_SHA512_DIGEST_LENGTH 32 |
| 34 |
35 |
| 35 #ifdef __APPLE__ |
36 #ifdef __APPLE__ |
| 36 /* macos */ |
37 /* macos */ |
| 37 |
38 |
| 38 #define WS_CRYPTO_COMMON_CRYPTO |
39 #define WS_CRYPTO_COMMON_CRYPTO |
| 39 |
40 |
| 40 #define WS_AES_CTX CCCryptorRef |
41 #define WS_AES_CTX CCCryptorRef |
| 41 #define WS_SHA1_CTX CC_SHA1_CTX |
42 #define WS_SHA1_CTX CC_SHA1_CTX |
| 42 #define WS_SHA_CTX CC_SHA256_CTX |
43 #define WS_SHA256_CTX CC_SHA256_CTX |
| |
44 #define WS_SHA512_CTX CC_SHA512_CTX |
| 43 |
45 |
| 44 #include <CommonCrypto/CommonCrypto.h> |
46 #include <CommonCrypto/CommonCrypto.h> |
| 45 #include <CommonCrypto/CommonDigest.h> |
47 #include <CommonCrypto/CommonDigest.h> |
| 46 |
48 |
| 47 #elif defined(_WIN32) |
49 #elif defined(_WIN32) |
| 80 #define WS_USE_OPENSSL |
83 #define WS_USE_OPENSSL |
| 81 |
84 |
| 82 #if OPENSSL_VERSION_NUMBER < 0x30000000L |
85 #if OPENSSL_VERSION_NUMBER < 0x30000000L |
| 83 #define WS_SHA256_CTX SHA1_CTX |
86 #define WS_SHA256_CTX SHA1_CTX |
| 84 #define WS_SHA256_CTX SHA256_CTX |
87 #define WS_SHA256_CTX SHA256_CTX |
| |
88 #define WS_SHA512_CTX SHA512_CTX |
| 85 #else |
89 #else |
| 86 #define WS_SHA1_CTX EVP_MD_CTX* |
90 #define WS_SHA1_CTX EVP_MD_CTX* |
| 87 #define WS_SHA256_CTX EVP_MD_CTX* |
91 #define WS_SHA256_CTX EVP_MD_CTX* |
| |
92 #define WS_SHA512_CTX EVP_MD_CTX* |
| 88 #endif |
93 #endif |
| 89 |
94 |
| 90 |
95 |
| 91 #if defined(__sun) && defined(__SunOS_5_10) |
96 #if defined(__sun) && defined(__SunOS_5_10) |
| 92 #include <sha2.h> |
97 #include <sha2.h> |
| 95 #define SHA_Final SHAFinal |
100 #define SHA_Final SHAFinal |
| 96 |
101 |
| 97 #define SHA256_Init SHA256Init |
102 #define SHA256_Init SHA256Init |
| 98 #define SHA256_Update SHA256Update |
103 #define SHA256_Update SHA256Update |
| 99 #define SHA256_Final SHA256Final |
104 #define SHA256_Final SHA256Final |
| |
105 |
| |
106 #define SHA512_Init SHA512Init |
| |
107 #define SHA512_Update SHA512Update |
| |
108 #define SHA512_Final SHA512Final |
| 100 #else |
109 #else |
| 101 #include <openssl/sha.h> |
110 #include <openssl/sha.h> |
| 102 #endif |
111 #endif |
| 103 |
112 |
| 104 #endif |
113 #endif |
| 111 int ws_sha256_init(WS_SHA256_CTX *ctx); |
120 int ws_sha256_init(WS_SHA256_CTX *ctx); |
| 112 WS_SHA256_CTX* ws_sha256_create(void); |
121 WS_SHA256_CTX* ws_sha256_create(void); |
| 113 void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t len); |
122 void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t len); |
| 114 void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *buf); |
123 void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *buf); |
| 115 |
124 |
| |
125 int ws_sha512_init(WS_SHA512_CTX *ctx); |
| |
126 WS_SHA512_CTX* ws_sha512_create(void); |
| |
127 void ws_sha512_update(WS_SHA512_CTX *ctx, const char *data, size_t len); |
| |
128 void ws_sha512_final(WS_SHA512_CTX *ctx, unsigned char *buf); |
| |
129 |
| 116 |
130 |
| 117 #ifdef __cplusplus |
131 #ifdef __cplusplus |
| 118 } |
132 } |
| 119 #endif |
133 #endif |
| 120 |
134 |