Use internal SHA256 helpers in hash header
This commit is contained in:
+4
-11
@@ -23,7 +23,6 @@
|
|||||||
#include "crypto/sha512.h"
|
#include "crypto/sha512.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <openssl/sha.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -151,13 +150,10 @@ public:
|
|||||||
/** Compute the 256-bit hash of a std::string */
|
/** Compute the 256-bit hash of a std::string */
|
||||||
inline std::string Hash(std::string input)
|
inline std::string Hash(std::string input)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
unsigned char hash[CSHA256::OUTPUT_SIZE];
|
||||||
SHA256_CTX sha256;
|
CSHA256().Write((const unsigned char*)input.data(), input.size()).Finalize(hash);
|
||||||
SHA256_Init(&sha256);
|
|
||||||
SHA256_Update(&sha256, input.c_str(), input.size());
|
|
||||||
SHA256_Final(hash, &sha256);
|
|
||||||
stringstream ss;
|
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];
|
ss << hex << setw(2) << setfill('0') << (int)hash[i];
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
@@ -166,10 +162,7 @@ inline std::string Hash(std::string input)
|
|||||||
/** Compute the 256-bit hash of a void pointer */
|
/** Compute the 256-bit hash of a void pointer */
|
||||||
inline void Hash(void* in, unsigned int len, unsigned char* out)
|
inline void Hash(void* in, unsigned int len, unsigned char* out)
|
||||||
{
|
{
|
||||||
SHA256_CTX sha256;
|
CSHA256().Write((const unsigned char*)in, len).Finalize(out);
|
||||||
SHA256_Init(&sha256);
|
|
||||||
SHA256_Update(&sha256, in, len);
|
|
||||||
SHA256_Final(out, &sha256);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the 512-bit hash of an object. */
|
/** Compute the 512-bit hash of an object. */
|
||||||
|
|||||||
Reference in New Issue
Block a user