From a2faea780f345dbd51bbea149237f659c766b64a Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sat, 10 Dec 2022 15:24:06 +0100 Subject: Use modern openssl hash methods The old ones was marked as deprecated in openssl 3.0.0 but the replaments have been in openssl since 1.1.0. --- src/hash_method_openssl.cc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/hash_method_openssl.cc b/src/hash_method_openssl.cc index 08884cb..75f6b8a 100644 --- a/src/hash_method_openssl.cc +++ b/src/hash_method_openssl.cc @@ -2,29 +2,35 @@ #include "hash_method.hh" -#include +#include namespace { class Sha256HashMethod : public HashMethod { public: Sha256HashMethod() { - SHA256_Init(&ctx_); + ctx_ = EVP_MD_CTX_new(); + EVP_DigestInit_ex(ctx_, EVP_sha256(), nullptr); + } + + ~Sha256HashMethod() override { + EVP_MD_CTX_free(ctx_); } void update(void const* data, size_t count) override { - SHA256_Update(&ctx_, data, count); + EVP_DigestUpdate(ctx_, data, count); } std::string finish() override { - uint8_t out[SHA256_DIGEST_LENGTH]; - SHA256_Final(out, &ctx_); - SHA256_Init(&ctx_); - return to_string(out, sizeof(out)); + uint8_t out[EVP_MAX_MD_SIZE]; + unsigned int len; + EVP_DigestFinal_ex(ctx_, out, &len); + EVP_DigestInit_ex(ctx_, EVP_sha256(), nullptr); + return to_string(out, len); } private: - SHA256_CTX ctx_; + EVP_MD_CTX* ctx_; }; } // namespace -- cgit v1.2.3-70-g09d2