mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-16 02:24:58 +01:00
Merge #8914: Kill insecure_random and associated global state
5eaaa83 Kill insecure_random and associated global state (Wladimir J. van der Laan)
This commit is contained in:
@@ -26,7 +26,7 @@ public:
|
||||
void MakeDeterministic()
|
||||
{
|
||||
nKey.SetNull();
|
||||
seed_insecure_rand(true);
|
||||
insecure_rand = FastRandomContext(true);
|
||||
}
|
||||
|
||||
int RandomInt(int nMax)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "coins.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "script/standard.h"
|
||||
#include "uint256.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "crypto/sha512.h"
|
||||
#include "crypto/hmac_sha256.h"
|
||||
#include "crypto/hmac_sha512.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "consensus/merkle.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
void MakeDeterministic()
|
||||
{
|
||||
nKey.SetNull();
|
||||
seed_insecure_rand(true);
|
||||
insecure_rand = FastRandomContext(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "uint256.h"
|
||||
#include "arith_uint256.h"
|
||||
#include "version.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "prevector.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
@@ -27,8 +27,7 @@ class prevector_tester {
|
||||
|
||||
typedef typename pretype::size_type Size;
|
||||
bool passed = true;
|
||||
uint32_t insecure_rand_Rz_cache;
|
||||
uint32_t insecure_rand_Rw_cache;
|
||||
FastRandomContext rand_cache;
|
||||
|
||||
|
||||
template <typename A, typename B>
|
||||
@@ -171,15 +170,14 @@ public:
|
||||
test();
|
||||
}
|
||||
~prevector_tester() {
|
||||
BOOST_CHECK_MESSAGE(passed, "insecure_rand_Rz: "
|
||||
<< insecure_rand_Rz_cache
|
||||
BOOST_CHECK_MESSAGE(passed, "insecure_rand_Rz: "
|
||||
<< rand_cache.Rz
|
||||
<< ", insecure_rand_Rw: "
|
||||
<< insecure_rand_Rw_cache);
|
||||
<< rand_cache.Rw);
|
||||
}
|
||||
prevector_tester() {
|
||||
seed_insecure_rand();
|
||||
insecure_rand_Rz_cache = insecure_rand_Rz;
|
||||
insecure_rand_Rw_cache = insecure_rand_Rw;
|
||||
rand_cache = insecure_rand_ctx;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ static void MicroSleep(uint64_t n)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(manythreads)
|
||||
{
|
||||
seed_insecure_rand(false);
|
||||
|
||||
// Stress test: hundreds of microsecond-scheduled tasks,
|
||||
// serviced by 10 threads.
|
||||
//
|
||||
@@ -58,7 +56,7 @@ BOOST_AUTO_TEST_CASE(manythreads)
|
||||
|
||||
boost::mutex counterMutex[10];
|
||||
int counter[10] = { 0 };
|
||||
boost::random::mt19937 rng(insecure_rand());
|
||||
boost::random::mt19937 rng(42);
|
||||
boost::random::uniform_int_distribution<> zeroToNine(0, 9);
|
||||
boost::random::uniform_int_distribution<> randomMsec(-11, 1000);
|
||||
boost::random::uniform_int_distribution<> randomDelta(-1000, 1000);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "data/sighash.json.h"
|
||||
#include "hash.h"
|
||||
#include "main.h" // For CheckTransaction
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "script/interpreter.h"
|
||||
#include "script/script.h"
|
||||
#include "serialize.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "chain.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "util.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
std::unique_ptr<CConnman> g_connman;
|
||||
FastRandomContext insecure_rand_ctx(true);
|
||||
|
||||
extern bool fPrintToConsole;
|
||||
extern void noui_connect();
|
||||
|
||||
23
src/test/test_random.h
Normal file
23
src/test/test_random.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_RANDOM_H
|
||||
#define BITCOIN_TEST_RANDOM_H
|
||||
|
||||
#include "random.h"
|
||||
|
||||
extern FastRandomContext insecure_rand_ctx;
|
||||
|
||||
static inline void seed_insecure_rand(bool fDeterministic = false)
|
||||
{
|
||||
insecure_rand_ctx = FastRandomContext(fDeterministic);
|
||||
}
|
||||
|
||||
static inline uint32_t insecure_rand(void)
|
||||
{
|
||||
return insecure_rand_ctx.rand32();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "sync.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "utilmoneystr.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "chain.h"
|
||||
#include "random.h"
|
||||
#include "test_random.h"
|
||||
#include "versionbits.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
#include "chainparams.h"
|
||||
|
||||
Reference in New Issue
Block a user