Updated hashing algorithm.

This commit is contained in:
Ravin Perera
2019-10-30 18:35:08 +05:30
parent 2ba739c984
commit 93d4abfd2a
4 changed files with 8 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -80,7 +80,7 @@ struct hash_buffer
stringtohash.append(buffer);
stringtohash.append(timestr);
hash = crypto::sha_512_hash(stringtohash);
hash = crypto::get_hash(stringtohash);
}
};