From ad3df365428e95b10a4a6d683e3973860baa76a1 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 May 2022 12:21:59 +0200 Subject: Core/Crypto: Fixed EVP_PKEY reference counting for copied objects Closes #27943 (cherry picked from commit aa6a0f24312ce6132e55a9aed677362a3b1dc8a9) --- src/common/Cryptography/CryptoHash.h | 2 +- src/common/Cryptography/HMAC.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h index 38f2047c30d..01b488cb4dd 100644 --- a/src/common/Cryptography/CryptoHash.h +++ b/src/common/Cryptography/CryptoHash.h @@ -96,7 +96,7 @@ namespace Trinity::Impl if (this == &right) return *this; - int result = EVP_MD_CTX_copy(_ctx, right._ctx); + int result = EVP_MD_CTX_copy_ex(_ctx, right._ctx); ASSERT(result == 1); _digest = right._digest; return *this; diff --git a/src/common/Cryptography/HMAC.h b/src/common/Cryptography/HMAC.h index b8db59a1ae9..1c3e3c2a3a6 100644 --- a/src/common/Cryptography/HMAC.h +++ b/src/common/Cryptography/HMAC.h @@ -86,9 +86,10 @@ namespace Trinity::Impl if (this == &right) return *this; - int result = EVP_MD_CTX_copy(_ctx, right._ctx); + int result = EVP_MD_CTX_copy_ex(_ctx, right._ctx); ASSERT(result == 1); - _key = right._key; // EVP_PKEY uses reference counting internally, just copy the pointer + _key = right._key; // EVP_PKEY uses reference counting internally, just copy the pointer + EVP_PKEY_up_ref(_key); // Bump reference count for PKEY, as every instance of this class holds two references to PKEY and destructor decrements it twice _digest = right._digest; return *this; } -- cgit v1.2.3