From f3be3404d6630cfbeb5c36549c8eaee533c8acd0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 28 Apr 2026 06:29:39 +0000 Subject: [PATCH] Use internal SHA256 helpers in hash header --- src/hash.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/hash.h b/src/hash.h index c89a316f..2295a79c 100644 --- a/src/hash.h +++ b/src/hash.h @@ -23,7 +23,6 @@ #include "crypto/sha512.h" #include -#include #include #include @@ -151,13 +150,10 @@ public: /** Compute the 256-bit hash of a std::string */ inline std::string Hash(std::string input) { - unsigned char hash[SHA256_DIGEST_LENGTH]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, input.c_str(), input.size()); - SHA256_Final(hash, &sha256); + unsigned char hash[CSHA256::OUTPUT_SIZE]; + CSHA256().Write((const unsigned char*)input.data(), input.size()).Finalize(hash); stringstream ss; - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + for (int i = 0; i < CSHA256::OUTPUT_SIZE; i++) { ss << hex << setw(2) << setfill('0') << (int)hash[i]; } return ss.str(); @@ -166,10 +162,7 @@ inline std::string Hash(std::string input) /** Compute the 256-bit hash of a void pointer */ inline void Hash(void* in, unsigned int len, unsigned char* out) { - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, in, len); - SHA256_Final(out, &sha256); + CSHA256().Write((const unsigned char*)in, len).Finalize(out); } /** Compute the 512-bit hash of an object. */