Skip to content

Commit

Permalink
Use newer evp api for sha256, because sha256.c overrides SHA256
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Nov 28, 2024
1 parent 67c07d6 commit 92072a2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/util/hashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

#include "hashing.h"

#include "debug.h"
#include "config.h"
#if USE_OPENSSL
#include <openssl/sha.h>
#include <openssl/evp.h>
#else
#include "util/sha1.h"
#include "my_sha256.h"
Expand All @@ -32,11 +34,16 @@ std::string sha1(std::string_view data)

std::string sha256(std::string_view data)
{
// same api in openssl and my_sha256.h
std::string digest(SHA256_DIGEST_SIZE, '\000');
auto src = reinterpret_cast<const uint8_t *>(data.data());
auto dst = reinterpret_cast<uint8_t *>(digest.data());
#if USE_OPENSSL
// can't call SHA256(), because it's defined by our sha256.c fallback
auto success = EVP_Digest(src, data.size(), dst, nullptr, EVP_sha256(), nullptr) == 1;
FATAL_ERROR_IF(!success, "sha256 failed");
#else
SHA256(src, data.size(), dst);
#endif
return digest;
}

Expand Down

0 comments on commit 92072a2

Please sign in to comment.