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:
+3
-2
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user