mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Updated hashing algorithm.
This commit is contained in:
@@ -133,15 +133,15 @@ int verify_hex(std::string_view msg, std::string_view sighex, std::string_view p
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate SHA 512 hash for message prepend with prefix before hashing.
|
||||
* Generate hash for message prepend with prefix before hashing.
|
||||
*
|
||||
* @param data String to hash.
|
||||
* @return SHA 512 hash.
|
||||
* @return The hash of the given string.
|
||||
*/
|
||||
std::string sha_512_hash(std::string_view data)
|
||||
std::string get_hash(std::string_view data)
|
||||
{
|
||||
unsigned char hashchars[crypto_hash_sha512_BYTES];
|
||||
crypto_hash_sha512(hashchars, (unsigned char *)data.data(), data.length());
|
||||
unsigned char hashchars[crypto_generichash_BYTES];
|
||||
crypto_generichash(hashchars, sizeof hashchars, (unsigned char *)data.data(), data.length(), NULL, 0);
|
||||
return std::string(reinterpret_cast<char *>(hashchars), crypto_hash_sha512_BYTES);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ int verify(std::string_view msg, std::string_view sig, std::string_view pubkey);
|
||||
|
||||
int verify_hex(std::string_view msg, std::string_view sighex, std::string_view pubkeyhex);
|
||||
|
||||
std::string sha_512_hash(std::string_view data);
|
||||
std::string get_hash(std::string_view data);
|
||||
|
||||
} // namespace crypto
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ void peer_connection_watchdog()
|
||||
bool is_message_duplicate(std::string_view message)
|
||||
{
|
||||
// Get message hash and see whether message is already recieved -> abandon if duplicate.
|
||||
std::string hash = crypto::sha_512_hash(message);
|
||||
std::string hash = crypto::get_hash(message);
|
||||
|
||||
auto itr = recent_peermsg_hashes.find(hash);
|
||||
if (itr == recent_peermsg_hashes.end()) // Not found
|
||||
|
||||
@@ -80,7 +80,7 @@ struct hash_buffer
|
||||
stringtohash.append(buffer);
|
||||
stringtohash.append(timestr);
|
||||
|
||||
hash = crypto::sha_512_hash(stringtohash);
|
||||
hash = crypto::get_hash(stringtohash);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user