From 55b1b141fa08aab0da03bf605e651dfa05d682e8 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Fri, 26 Apr 2019 09:07:12 +0100 Subject: [PATCH] Make new random_constants class for not_an_account (#1928) --- nano/node/lmdb.cpp | 2 +- nano/node/node.cpp | 2 +- nano/secure/common.cpp | 12 +++--------- nano/secure/common.hpp | 11 ++++++++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/nano/node/lmdb.cpp b/nano/node/lmdb.cpp index 4de7ae85..73a05f03 100644 --- a/nano/node/lmdb.cpp +++ b/nano/node/lmdb.cpp @@ -1160,7 +1160,7 @@ void nano::mdb_store::upgrade_v12_to_v13 (nano::transaction const & transaction_ { size_t cost (0); nano::account account (0); - auto const & not_an_account (network_params.ledger.not_an_account ()); + auto const & not_an_account (network_params.random.not_an_account); while (account != not_an_account) { nano::account first (0); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 847ca362..ae7812a1 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -2549,7 +2549,7 @@ confirmed (false), stopped (false), announcements (0) { - last_votes.insert (std::make_pair (node.network_params.ledger.not_an_account (), nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () })); + last_votes.insert (std::make_pair (node.network_params.random.not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () })); blocks.insert (std::make_pair (block_a->hash (), block_a)); update_dependent (); } diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 90948009..2fb95a9b 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -92,19 +92,13 @@ nano_live_genesis (live_genesis_data), genesis_account (network_a == nano::nano_networks::nano_test_network ? nano_test_account : network_a == nano::nano_networks::nano_beta_network ? nano_beta_account : nano_live_account), genesis_block (network_a == nano::nano_networks::nano_test_network ? nano_test_genesis : network_a == nano::nano_networks::nano_beta_network ? nano_beta_genesis : nano_live_genesis), genesis_amount (std::numeric_limits::max ()), -burn_account (0), -not_an_account_m (0) +burn_account (0) { } -nano::account const & nano::ledger_constants::not_an_account () +nano::random_constants::random_constants () { - if (not_an_account_m.is_zero ()) - { - // Randomly generating these mean no two nodes will ever have the same sentinel values which protects against some insecure algorithms - nano::random_pool::generate_block (not_an_account_m.bytes.data (), not_an_account_m.bytes.size ()); - } - return not_an_account_m; + nano::random_pool::generate_block (not_an_account.bytes.data (), not_an_account.bytes.size ()); } nano::node_constants::node_constants (nano::network_constants & network_constants) diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 24b59e75..aabbcc6c 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -330,11 +330,15 @@ public: nano::account genesis_account; std::string genesis_block; nano::uint128_t genesis_amount; - nano::account const & not_an_account (); nano::account burn_account; +}; -private: - nano::account not_an_account_m; +/** Constants which depend on random values (this class should never be used globally due to CryptoPP globals potentially not being initialized) */ +class random_constants +{ +public: + random_constants (); + nano::account not_an_account; }; /** Node related constants whose value depends on the active network */ @@ -396,6 +400,7 @@ public: unsigned kdf_work; network_constants network; ledger_constants ledger; + random_constants random; voting_constants voting; node_constants node; portmapping_constants portmapping;