diff --git a/src/common/Cryptography/HmacHash.cpp b/src/common/Cryptography/HmacHash.cpp index e52113d2e0..192610a7dc 100644 --- a/src/common/Cryptography/HmacHash.cpp +++ b/src/common/Cryptography/HmacHash.cpp @@ -20,58 +20,46 @@ #include "Errors.h" #include -#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L -HMAC_CTX* HMAC_CTX_new() -{ - HMAC_CTX *ctx = new HMAC_CTX(); - HMAC_CTX_init(ctx); - return ctx; -} - -void HMAC_CTX_free(HMAC_CTX* ctx) -{ - HMAC_CTX_cleanup(ctx); - delete ctx; -} -#endif - template -HmacHash::HmacHash(uint32 len, uint8 const* seed) : _ctx(HMAC_CTX_new()) +HmacHash::HmacHash(uint32 len, uint8 const* seed) : _ctx(EVP_MD_CTX_create()), _key(EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, nullptr, seed, len)) { - HMAC_Init_ex(_ctx, seed, len, HashCreator(), nullptr); + EVP_DigestSignInit(_ctx, nullptr, HashCreator(), nullptr, _key); memset(_digest, 0, DigestLength); } template HmacHash::~HmacHash() { - HMAC_CTX_free(_ctx); + EVP_MD_CTX_destroy(_ctx); + _ctx = nullptr; + EVP_PKEY_free(_key); + _key = nullptr; } template void HmacHash::UpdateData(std::string const& str) { - HMAC_Update(_ctx, reinterpret_cast(str.c_str()), str.length()); + EVP_DigestSignUpdate(_ctx, reinterpret_cast(str.c_str()), str.length()); } template void HmacHash::UpdateData(uint8 const* data, size_t len) { - HMAC_Update(_ctx, data, len); + EVP_DigestSignUpdate(_ctx, data, len); } template void HmacHash::Finalize() { - uint32 length = 0; - HMAC_Final(_ctx, _digest, &length); + size_t length = DigestLength; + EVP_DigestSignFinal(_ctx, _digest, &length); ASSERT(length == DigestLength); } template uint8* HmacHash::ComputeHash(BigNumber* bn) { - HMAC_Update(_ctx, bn->AsByteArray().get(), bn->GetNumBytes()); + EVP_DigestSignUpdate(_ctx, bn->AsByteArray().get(), bn->GetNumBytes()); Finalize(); return _digest; } diff --git a/src/common/Cryptography/HmacHash.h b/src/common/Cryptography/HmacHash.h index 6985e4ac59..8e8de8ae3f 100644 --- a/src/common/Cryptography/HmacHash.h +++ b/src/common/Cryptography/HmacHash.h @@ -42,7 +42,8 @@ class TC_COMMON_API HmacHash uint8* GetDigest() { return _digest; } uint32 GetLength() const { return DigestLength; } private: - HMAC_CTX* _ctx; + EVP_MD_CTX* _ctx; + EVP_PKEY* _key; uint8 _digest[DigestLength]; };