diff options
Diffstat (limited to 'src/hash_method_openssl.cc')
| -rw-r--r-- | src/hash_method_openssl.cc | 22 |
1 files changed, 14 insertions, 8 deletions
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 <openssl/sha.h> +#include <openssl/evp.h> 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 |
