Fri, 30 May 2025 12:07:10 +0200
add common crypto hashing implementation for macOS
| src/server/util/hashing.c | file | annotate | diff | comparison | revisions | |
| src/server/util/hashing.h | file | annotate | diff | comparison | revisions |
--- a/src/server/util/hashing.c Fri May 30 11:20:12 2025 +0200 +++ b/src/server/util/hashing.c Fri May 30 12:07:10 2025 +0200 @@ -66,6 +66,8 @@ return ctx; } +#ifdef WS_USE_OPENSSL + #if OPENSSL_VERSION_NUMBER < 0x30000000L void ws_sha1_init(WS_SHA1_CTX *ctx) { @@ -163,4 +165,52 @@ EVP_DigestFinal(*ctx, md, NULL); } -#endif +#endif // OPENSSL_VERSION_NUMBER < 0x30000000L + +#endif // WS_USE_OPENSSL + + +#ifdef WS_USE_CRYPTO_COMMON + +int ws_sha1_init(WS_SHA1_CTX *ctx) { + CC_SHA1_Init(ctx); + return 0; +} + +void ws_sha1_update(WS_SHA1_CTX *ctx, const char *data, size_t len) { + CC_SHA1_Update(ctx, data, len); +} + +void ws_sha1_final(WS_SHA1_CTX *ctx, unsigned char *buf) { + CC_SHA1_Final(buf, ctx); +} + +int ws_sha256_init(WS_SHA256_CTX *ctx) { + CC_SHA256_Init(ctx); + return 0; +} + +void ws_sha256_update(WS_SHA256_CTX *ctx, const char *data, size_t len) { + CC_SHA256_Update(ctx, data, len); +} + +void ws_sha256_final(WS_SHA256_CTX *ctx, unsigned char *buf) { + CC_SHA256_Final(buf, ctx); +} + + +int ws_sha512_init(WS_SHA512_CTX *ctx) { + CC_SHA512_Init(ctx); + return 0; +} + +void ws_sha512_update(WS_SHA512_CTX *ctx, const char *data, size_t len) { + CC_SHA512_Update(ctx, data, len); +} + +void ws_sha512_final(WS_SHA512_CTX *ctx, unsigned char *buf) { + CC_SHA512_Final(buf, ctx); +} + +#endif // WS_USE_CRYPTO_COMMON +
--- a/src/server/util/hashing.h Fri May 30 11:20:12 2025 +0200 +++ b/src/server/util/hashing.h Fri May 30 12:07:10 2025 +0200 @@ -34,6 +34,7 @@ #define WS_SHA512_DIGEST_LENGTH 32 #ifdef __APPLE__ +#define WS_USE_CRYPTO_COMMON /* macos */ #define WS_CRYPTO_COMMON_CRYPTO @@ -48,7 +49,7 @@ #elif defined(_WIN32) -#define WS_CRYPTO_CNG +#define WS_USE_CRYPTO_CNG #include <windows.h> #include <bcrypt.h>