From f2f701b4d7aac9230424063d5f18f2abfbbeca92 Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Fri, 20 Nov 2020 16:35:58 +0900 Subject: [PATCH 1/2] Use OpeSSL EVP API instead of SHA256_Init/Update/Final --- include/tscore/SHA256.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/tscore/SHA256.h b/include/tscore/SHA256.h index 987a64cd76f..12d426c604e 100644 --- a/include/tscore/SHA256.h +++ b/include/tscore/SHA256.h @@ -26,25 +26,29 @@ #include "tscore/ink_code.h" #include "tscore/ink_defs.h" #include "tscore/CryptoHash.h" -#include +#include class SHA256Context : public ats::CryptoContextBase { protected: - SHA256_CTX _ctx; + EVP_MD_CTX *ctx; public: - SHA256Context() { SHA256_Init(&_ctx); } + SHA256Context() + { + ctx = EVP_MD_CTX_new(); + EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr); + } /// Update the hash with @a data of @a length bytes. bool update(void const *data, int length) override { - return SHA256_Update(&_ctx, data, length); + return EVP_DigestUpdate(ctx, data, length); } /// Finalize and extract the @a hash. bool finalize(CryptoHash &hash) override { - return SHA256_Final(hash.u8, &_ctx); + return EVP_DigestFinal_ex(ctx, hash.u8, nullptr); } }; From 8b736036112ce31dff4aa31d9c96aca392732bf1 Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Mon, 30 Nov 2020 16:55:41 +0900 Subject: [PATCH 2/2] Destroy MD context --- include/tscore/SHA256.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/tscore/SHA256.h b/include/tscore/SHA256.h index 12d426c604e..cbe8a590371 100644 --- a/include/tscore/SHA256.h +++ b/include/tscore/SHA256.h @@ -39,6 +39,7 @@ class SHA256Context : public ats::CryptoContextBase ctx = EVP_MD_CTX_new(); EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr); } + ~SHA256Context() { EVP_MD_CTX_free(ctx); } /// Update the hash with @a data of @a length bytes. bool update(void const *data, int length) override