From 09e5dbfa06055498ddeaa4dcbd30a36a7dcc4462 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 29 Jul 2015 07:52:55 +0200 Subject: [PATCH] Use boost's guaranteed non-deterministic random number generator. If it compiles, it's safe. --- cmake/EthDependencies.cmake | 2 +- libdevcore/CMakeLists.txt | 1 + libdevcore/CommonData.cpp | 1 - libdevcore/FixedHash.cpp | 2 +- libdevcore/FixedHash.h | 4 ++-- libdevcore/vector_ref.h | 3 ++- libdevcrypto/Common.cpp | 1 - libethash-cl/ethash_cl_miner.cpp | 5 +++-- libethcore/Common.cpp | 1 - libethcore/Ethash.cpp | 1 - libethcore/EthashAux.cpp | 1 - libethereum/State.cpp | 1 - test/libdevcrypto/SecretStore.cpp | 1 - test/libdevcrypto/crypto.cpp | 1 - test/libdevcrypto/trie.cpp | 3 --- test/libethcore/dagger.cpp | 1 - test/libethereum/genesis.cpp | 3 --- test/libp2p/rlpx.cpp | 1 - 18 files changed, 10 insertions(+), 23 deletions(-) diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 86415f2dd..0d4a7a4bc 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -213,7 +213,7 @@ elseif (UNIX) endif() -find_package(Boost 1.54.0 REQUIRED COMPONENTS thread date_time system regex chrono filesystem unit_test_framework program_options) +find_package(Boost 1.54.0 REQUIRED COMPONENTS thread date_time system regex chrono filesystem unit_test_framework program_options random) message(" - boost header: ${Boost_INCLUDE_DIRS}") message(" - boost lib : ${Boost_LIBRARIES}") diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index 7cd236cea..41f9b023e 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -26,6 +26,7 @@ add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) +target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${DB_LIBRARIES}) diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index ef178965f..a2d4ce1e0 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -21,7 +21,6 @@ #include "CommonData.h" -#include #include "Exceptions.h" #include "Log.h" diff --git a/libdevcore/FixedHash.cpp b/libdevcore/FixedHash.cpp index 6c2a9a57e..be202b5f4 100644 --- a/libdevcore/FixedHash.cpp +++ b/libdevcore/FixedHash.cpp @@ -26,7 +26,7 @@ using namespace std; using namespace dev; -std::random_device dev::s_fixedHashEngine; +boost::random_device dev::s_fixedHashEngine; h128 dev::fromUUID(std::string const& _uuid) { diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 0de2cc825..7c612970a 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -25,8 +25,8 @@ #include #include -#include #include +#include #include "CommonData.h" namespace dev @@ -36,7 +36,7 @@ namespace dev template struct StaticLog2 { enum { result = 1 + StaticLog2::result }; }; template <> struct StaticLog2<1> { enum { result = 0 }; }; -extern std::random_device s_fixedHashEngine; +extern boost::random_device s_fixedHashEngine; /// Fixed-size raw-byte array container type, with an API optimised for storing hashes. /// Transparently converts to/from the corresponding arithmetic type; this will diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index 1932a8fda..ca5ac3753 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -6,12 +6,13 @@ #include #include #include +#include namespace dev { static unsigned char s_cleanseCounter = 0; -static std::random_device s_vectorRefEngine; +static boost::random_device s_vectorRefEngine; /** * A modifiable reference to an existing object or vector in memory. diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index 606c5794c..970443063 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -21,7 +21,6 @@ */ #include "Common.h" -#include #include #include #include diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 2183de320..7e2573303 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -29,8 +29,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -470,7 +471,7 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook m_searchKernel.setArg(argPos + 2, ~0u); unsigned buf = 0; - random_device engine; + boost::random_device engine; uint64_t start_nonce = uniform_int_distribution()(engine); for (;; start_nonce += m_globalWorkSize) { diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 343d87be1..ccbd00c77 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -20,7 +20,6 @@ */ #include "Common.h" -#include #include #include #include diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 511146b75..99fcc04cf 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 763bea417..ea4d6232c 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/libethereum/State.cpp b/libethereum/State.cpp index b8c0ce89c..9e22ef52d 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -22,7 +22,6 @@ #include "State.h" #include -#include #include #include #include diff --git a/test/libdevcrypto/SecretStore.cpp b/test/libdevcrypto/SecretStore.cpp index bff6e0720..272fa7422 100644 --- a/test/libdevcrypto/SecretStore.cpp +++ b/test/libdevcrypto/SecretStore.cpp @@ -21,7 +21,6 @@ */ #include -#include #include #include "../JsonSpiritHeaders.h" #include diff --git a/test/libdevcrypto/crypto.cpp b/test/libdevcrypto/crypto.cpp index 2d7392d7e..84f15d7b2 100644 --- a/test/libdevcrypto/crypto.cpp +++ b/test/libdevcrypto/crypto.cpp @@ -21,7 +21,6 @@ * Crypto test functions. */ -#include #if ETH_HAVE_SECP256K1 #include #endif diff --git a/test/libdevcrypto/trie.cpp b/test/libdevcrypto/trie.cpp index 720001f9c..be88c7cee 100644 --- a/test/libdevcrypto/trie.cpp +++ b/test/libdevcrypto/trie.cpp @@ -21,10 +21,7 @@ */ #include -#include - #include - #include "../JsonSpiritHeaders.h" #include #include diff --git a/test/libethcore/dagger.cpp b/test/libethcore/dagger.cpp index 0e69793e2..0473a0136 100644 --- a/test/libethcore/dagger.cpp +++ b/test/libethcore/dagger.cpp @@ -21,7 +21,6 @@ */ #include -#include #include "../JsonSpiritHeaders.h" #include #include diff --git a/test/libethereum/genesis.cpp b/test/libethereum/genesis.cpp index a8bc852f0..8d4b2878f 100644 --- a/test/libethereum/genesis.cpp +++ b/test/libethereum/genesis.cpp @@ -21,10 +21,7 @@ */ #include -#include - #include - #include "../JsonSpiritHeaders.h" #include #include diff --git a/test/libp2p/rlpx.cpp b/test/libp2p/rlpx.cpp index 82c781d7d..e03c6a296 100644 --- a/test/libp2p/rlpx.cpp +++ b/test/libp2p/rlpx.cpp @@ -20,7 +20,6 @@ * RLPx test functions. */ -#include #include #include #include