From 6963af761476b20f5e5b22107ca0801d676cf868 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Fri, 8 May 2026 16:14:09 +0300 Subject: [PATCH] Do not use OSSL_PARAM_DIGEST_SIZE for blake2 in openssl --- src/3proxy_crypt.c | 36 +++++++++++++++++------------------- src/blake2_compat.h | 5 ++--- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/3proxy_crypt.c b/src/3proxy_crypt.c index 6960d47..9587583 100644 --- a/src/3proxy_crypt.c +++ b/src/3proxy_crypt.c @@ -37,16 +37,8 @@ EVP_MD *md5_hash = NULL; int blake2b_init_3p(blake2b_state *S, size_t outlen) { *S = EVP_MD_CTX_new(); if (!*S) return -1; -#if OPENSSL_VERSION_NUMBER >= 0x30000000L - size_t sz = outlen; - OSSL_PARAM params[2]; - params[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_SIZE, &sz); - params[1] = OSSL_PARAM_construct_end(); - if (!EVP_DigestInit_ex2(*S, EVP_blake2b512(), params)) { -#else (void)outlen; if (!EVP_DigestInit_ex(*S, EVP_blake2b512(), NULL)) { -#endif EVP_MD_CTX_free(*S); *S = NULL; return -1; @@ -60,19 +52,29 @@ int blake2b_update_3p(blake2b_state *S, const void *in, size_t inlen) { } int blake2b_final_3p(blake2b_state *S, void *out, size_t outlen) { -#if OPENSSL_VERSION_NUMBER >= 0x30000000L - unsigned int len = 0; - int ret = EVP_DigestFinal_ex(*S, out, &len) ? 0 : -1; -#else unsigned char tmp[64]; unsigned int len = 0; int ret = EVP_DigestFinal_ex(*S, tmp, &len) ? 0 : -1; + memset(out, 0, outlen); if (ret == 0) memcpy(out, tmp, outlen); -#endif EVP_MD_CTX_free(*S); *S = NULL; return ret; } +#else +int blake2b_final_3p(blake2b_state *S, void *out, size_t outlen) { + int res; + + if(outlen < 64){ + unsigned char tmp[64]; + res = blake2b_final(S, tmp, 64); + memcpy(out, tmp, outlen > 64? 64 : outlen); + return res; + } + res = blake2b_final(S, out, 64); + if(outlen > 64) memset(out + 64, 0, outlen - 64); + return res; +} #endif /* WITH_SSL && OPENSSL >= 1.1 */ void @@ -287,15 +289,11 @@ int main(int argc, char* argv[]){ "Performs NT crypt if no salt specified, BLAKE2 crypt with salt\n" #else "Performs BLAKE2 crypt with salt\n" -#endif - "This software uses:\n" -#ifdef WITH_SSL - " OpenSSL EVP (MD4, MD5, BLAKE2b)\n" -#else - " BLAKE2 reference implementation\n" #endif , +#ifdef WITH_SSL argv[0], +#endif argv[0]); return 1; } diff --git a/src/blake2_compat.h b/src/blake2_compat.h index 13f5719..62f5564 100644 --- a/src/blake2_compat.h +++ b/src/blake2_compat.h @@ -13,16 +13,15 @@ typedef EVP_MD_CTX *blake2b_state; int blake2b_init_3p(blake2b_state *S, size_t outlen); int blake2b_update_3p(blake2b_state *S, const void *in, size_t inlen); -int blake2b_final_3p(blake2b_state *S, void *out, size_t outlen); #else #include "libs/blake2.h" -#define blake2b_init_3p blake2b_init +#define blake2b_init_3p(A,b) blake2b_init(A,64) #define blake2b_update_3p blake2b_update -#define blake2b_final_3p blake2b_final #endif +int blake2b_final_3p(blake2b_state *S, void *out, size_t outlen); #endif /* BLAKE2_COMPAT_H */