Use internal SHA256 helpers in hash header

This commit is contained in:
root
2026-04-28 06:29:39 +00:00
parent bd4b484374
commit f3be3404d6
+4 -11
View File
@@ -23,7 +23,6 @@
#include "crypto/sha512.h"
#include <iomanip>
#include <openssl/sha.h>
#include <sstream>
#include <vector>
@@ -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. */