summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2022-12-10 15:24:06 +0100
committerJoel Klinghed <the_jk@spawned.biz>2022-12-10 15:24:56 +0100
commita2faea780f345dbd51bbea149237f659c766b64a (patch)
treebcd2e041eef8d37f1f5c3ed65a8305681565aec9 /src
parent7d1b5ec6922a0d0f437431a4fe1e694d3a7538c4 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/hash_method_openssl.cc22
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