summaryrefslogtreecommitdiff
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
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.
-rw-r--r--meson.build2
-rw-r--r--src/hash_method_openssl.cc22
2 files changed, 15 insertions, 9 deletions
diff --git a/meson.build b/meson.build
index 9f23dfc..7470152 100644
--- a/meson.build
+++ b/meson.build
@@ -242,7 +242,7 @@ travel_dep = declare_dependency(
link_with: travel_lib,
dependencies: [image_dep, mediainfo_dep, timezone_dep])
-openssl_dep = dependency('openssl', version: '>= 1.0')
+openssl_dep = dependency('openssl', version: '>= 1.1.0')
hash_methods = []
if openssl_dep.found()
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