1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-06 09:33:12 +02:00

Make SHA256 30% faster when used for cloaking and other very small inputs,

simply by re-using the context.

The slowdown happened due to commit a541b8f4ad
in June 2021 when converting to OpenSSL 3+ code. Now it is basically
back to the pre-openssl-v3 speeds.
This commit is contained in:
Bram Matthys
2025-09-28 17:19:04 +02:00
parent b3fd6b9bca
commit 2ee12bf326
+3 -2
View File
@@ -1955,12 +1955,13 @@ void sha256hash_binary(char *dst, const char *src, unsigned long n)
{
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
unsigned int md_len;
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
static EVP_MD_CTX *mdctx = NULL;
if (!mdctx)
mdctx = EVP_MD_CTX_new();
if (EVP_DigestInit_ex(mdctx, sha256_function, NULL) != 1)
abort();
EVP_DigestUpdate(mdctx, src, n);
EVP_DigestFinal_ex(mdctx, dst, &md_len);
EVP_MD_CTX_free(mdctx);
#else
SHA256_CTX hash;