Replace xxHash with blake2b (#1919)
* Replace xxHash with blake2b * Delete xxhash submodule & folder * Update random_64 initialization * Using ledger constants to generate random 128 bit union * Protect random_128 () with mutex * Don't call random_128 () twice * Use static mutex for random_128 * Update endpoint_hash_raw functions * Naming * Functions order & static random_constants
This commit is contained in:
		
					parent
					
						
							
								06a93517d1
							
						
					
				
			
			
				commit
				
					
						8ce0b7c426
					
				
			
		
					 9 changed files with 23 additions and 43 deletions
				
			
		
							
								
								
									
										3
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -11,9 +11,6 @@
 | 
				
			||||||
[submodule "crypto/phc-winner-argon2"]
 | 
					[submodule "crypto/phc-winner-argon2"]
 | 
				
			||||||
	path = crypto/phc-winner-argon2
 | 
						path = crypto/phc-winner-argon2
 | 
				
			||||||
	url = https://github.com/nanocurrency/phc-winner-argon2.git
 | 
						url = https://github.com/nanocurrency/phc-winner-argon2.git
 | 
				
			||||||
[submodule "crypto/xxhash"]
 | 
					 | 
				
			||||||
	path = crypto/xxhash
 | 
					 | 
				
			||||||
	url = https://github.com/Cyan4973/xxHash.git
 | 
					 | 
				
			||||||
[submodule "gtest"]
 | 
					[submodule "gtest"]
 | 
				
			||||||
	path = gtest
 | 
						path = gtest
 | 
				
			||||||
	url = https://github.com/google/googletest.git
 | 
						url = https://github.com/google/googletest.git
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,10 +264,6 @@ target_include_directories(argon2 PUBLIC crypto/phc-winner-argon2/include)
 | 
				
			||||||
target_include_directories(argon2 PUBLIC crypto/phc-winner-argon2/src)
 | 
					target_include_directories(argon2 PUBLIC crypto/phc-winner-argon2/src)
 | 
				
			||||||
target_include_directories(argon2 PUBLIC crypto/blake2)
 | 
					target_include_directories(argon2 PUBLIC crypto/blake2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_library (xxhash
 | 
					 | 
				
			||||||
	crypto/xxhash/xxhash.c
 | 
					 | 
				
			||||||
	crypto/xxhash/xxhash.h)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
add_library (lmdb
 | 
					add_library (lmdb
 | 
				
			||||||
	lmdb/libraries/liblmdb/lmdb.h
 | 
						lmdb/libraries/liblmdb/lmdb.h
 | 
				
			||||||
	lmdb/libraries/liblmdb/mdb.c
 | 
						lmdb/libraries/liblmdb/mdb.c
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +0,0 @@
 | 
				
			||||||
Subproject commit 0f2dd4a1cb103e3fc8c55c855b821eb24c6d82c3
 | 
					 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,6 @@ add_library (nano_lib
 | 
				
			||||||
	work.cpp)
 | 
						work.cpp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
target_link_libraries (nano_lib
 | 
					target_link_libraries (nano_lib
 | 
				
			||||||
	xxhash
 | 
					 | 
				
			||||||
	ed25519
 | 
						ed25519
 | 
				
			||||||
	crypto_lib
 | 
						crypto_lib
 | 
				
			||||||
	blake2
 | 
						blake2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <boost/endian/conversion.hpp>
 | 
					#include <boost/endian/conversion.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <crypto/xxhash/xxhash.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** Compare blocks, first by type, then content. This is an optimization over dynamic_cast, which is very slow on some platforms. */
 | 
					/** Compare blocks, first by type, then content. This is an optimization over dynamic_cast, which is very slow on some platforms. */
 | 
				
			||||||
namespace
 | 
					namespace
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,5 @@
 | 
				
			||||||
#include <nano/lib/interface.h>
 | 
					#include <nano/lib/interface.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <crypto/xxhash/xxhash.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <crypto/ed25519-donna/ed25519.h>
 | 
					#include <crypto/ed25519-donna/ed25519.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <boost/property_tree/json_parser.hpp>
 | 
					#include <boost/property_tree/json_parser.hpp>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <nano/crypto_lib/random_pool.hpp>
 | 
				
			||||||
#include <nano/lib/config.hpp>
 | 
					#include <nano/lib/config.hpp>
 | 
				
			||||||
#include <nano/lib/interface.h>
 | 
					#include <nano/lib/interface.h>
 | 
				
			||||||
#include <nano/secure/common.hpp>
 | 
					#include <nano/secure/common.hpp>
 | 
				
			||||||
| 
						 | 
					@ -8,8 +9,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <bitset>
 | 
					#include <bitset>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <crypto/xxhash/xxhash.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace nano
 | 
					namespace nano
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
using endpoint = boost::asio::ip::udp::endpoint;
 | 
					using endpoint = boost::asio::ip::udp::endpoint;
 | 
				
			||||||
| 
						 | 
					@ -22,40 +21,32 @@ bool parse_tcp_endpoint (std::string const &, nano::tcp_endpoint &);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace
 | 
					namespace
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					uint64_t ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint16_t port = 0)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static nano::random_constants constants;
 | 
				
			||||||
 | 
						assert (ip_a.is_v6 ());
 | 
				
			||||||
 | 
						uint64_t result;
 | 
				
			||||||
 | 
						nano::uint128_union address;
 | 
				
			||||||
 | 
						address.bytes = ip_a.to_v6 ().to_bytes ();
 | 
				
			||||||
 | 
						blake2b_state state;
 | 
				
			||||||
 | 
						blake2b_init (&state, sizeof (result));
 | 
				
			||||||
 | 
						blake2b_update (&state, constants.random_128.bytes.data (), constants.random_128.bytes.size ());
 | 
				
			||||||
 | 
						if (port != 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							blake2b_update (&state, &port, sizeof (port));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						blake2b_update (&state, address.bytes.data (), address.bytes.size ());
 | 
				
			||||||
 | 
						blake2b_final (&state, &result, sizeof (result));
 | 
				
			||||||
 | 
						return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a)
 | 
					uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	assert (endpoint_a.address ().is_v6 ());
 | 
						uint64_t result (ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ()));
 | 
				
			||||||
	nano::uint128_union address;
 | 
					 | 
				
			||||||
	address.bytes = endpoint_a.address ().to_v6 ().to_bytes ();
 | 
					 | 
				
			||||||
	XXH64_state_t * const state = XXH64_createState ();
 | 
					 | 
				
			||||||
	XXH64_reset (state, 0);
 | 
					 | 
				
			||||||
	XXH64_update (state, address.bytes.data (), address.bytes.size ());
 | 
					 | 
				
			||||||
	auto port (endpoint_a.port ());
 | 
					 | 
				
			||||||
	XXH64_update (state, &port, sizeof (port));
 | 
					 | 
				
			||||||
	auto result (XXH64_digest (state));
 | 
					 | 
				
			||||||
	XXH64_freeState (state);
 | 
					 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
uint64_t endpoint_hash_raw (nano::tcp_endpoint const & endpoint_a)
 | 
					uint64_t endpoint_hash_raw (nano::tcp_endpoint const & endpoint_a)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	assert (endpoint_a.address ().is_v6 ());
 | 
						uint64_t result (ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ()));
 | 
				
			||||||
	nano::uint128_union address;
 | 
					 | 
				
			||||||
	address.bytes = endpoint_a.address ().to_v6 ().to_bytes ();
 | 
					 | 
				
			||||||
	XXH64_state_t * const state = XXH64_createState ();
 | 
					 | 
				
			||||||
	XXH64_reset (state, 0);
 | 
					 | 
				
			||||||
	XXH64_update (state, address.bytes.data (), address.bytes.size ());
 | 
					 | 
				
			||||||
	auto port (endpoint_a.port ());
 | 
					 | 
				
			||||||
	XXH64_update (state, &port, sizeof (port));
 | 
					 | 
				
			||||||
	auto result (XXH64_digest (state));
 | 
					 | 
				
			||||||
	XXH64_freeState (state);
 | 
					 | 
				
			||||||
	return result;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
uint64_t ip_address_hash_raw (boost::asio::ip::address const & ip_a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	assert (ip_a.is_v6 ());
 | 
					 | 
				
			||||||
	nano::uint128_union bytes;
 | 
					 | 
				
			||||||
	bytes.bytes = ip_a.to_v6 ().to_bytes ();
 | 
					 | 
				
			||||||
	auto result (XXH64 (bytes.bytes.data (), bytes.bytes.size (), 0));
 | 
					 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -99,6 +99,7 @@ burn_account (0)
 | 
				
			||||||
nano::random_constants::random_constants ()
 | 
					nano::random_constants::random_constants ()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	nano::random_pool::generate_block (not_an_account.bytes.data (), not_an_account.bytes.size ());
 | 
						nano::random_pool::generate_block (not_an_account.bytes.data (), not_an_account.bytes.size ());
 | 
				
			||||||
 | 
						nano::random_pool::generate_block (random_128.bytes.data (), random_128.bytes.size ());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
nano::node_constants::node_constants (nano::network_constants & network_constants)
 | 
					nano::node_constants::node_constants (nano::network_constants & network_constants)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -339,6 +339,7 @@ class random_constants
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	random_constants ();
 | 
						random_constants ();
 | 
				
			||||||
	nano::account not_an_account;
 | 
						nano::account not_an_account;
 | 
				
			||||||
 | 
						nano::uint128_union random_128;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Node related constants whose value depends on the active network */
 | 
					/** Node related constants whose value depends on the active network */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue