aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-02-15 17:45:22 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2017-03-29 11:26:08 -0700
commit16329224e70d0525208f6b0ba00c5e1531a4f5ea (patch)
tree8decd575cf1023486f2383e125c90085ebabd17a /src/random.cpp
parente04326fe6652543dc26d90eba4a48fbdc935fd0c (diff)
downloadbitcoin-16329224e70d0525208f6b0ba00c5e1531a4f5ea.tar.xz
Switch FastRandomContext to ChaCha20
Diffstat (limited to 'src/random.cpp')
-rw-r--r--src/random.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/random.cpp b/src/random.cpp
index 8284f457c9..c1e313cbde 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -240,22 +240,16 @@ uint256 GetRandHash()
return hash;
}
-FastRandomContext::FastRandomContext(bool fDeterministic)
+void FastRandomContext::RandomSeed()
{
- // The seed values have some unlikely fixed points which we avoid.
- if (fDeterministic) {
- Rz = Rw = 11;
- } else {
- uint32_t tmp;
- do {
- GetRandBytes((unsigned char*)&tmp, 4);
- } while (tmp == 0 || tmp == 0x9068ffffU);
- Rz = tmp;
- do {
- GetRandBytes((unsigned char*)&tmp, 4);
- } while (tmp == 0 || tmp == 0x464fffffU);
- Rw = tmp;
- }
+ uint256 seed = GetRandHash();
+ rng.SetKey(seed.begin(), 32);
+ requires_seed = false;
+}
+
+FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false), bytebuf_size(0), bitbuf_size(0)
+{
+ rng.SetKey(seed.begin(), 32);
}
bool Random_SanityCheck()
@@ -288,3 +282,12 @@ bool Random_SanityCheck()
} while (num_overwritten < NUM_OS_RANDOM_BYTES && tries < MAX_TRIES);
return (num_overwritten == NUM_OS_RANDOM_BYTES); /* If this failed, bailed out after too many tries */
}
+
+FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDeterministic), bytebuf_size(0), bitbuf_size(0)
+{
+ if (!fDeterministic) {
+ return;
+ }
+ uint256 seed;
+ rng.SetKey(seed.begin(), 32);
+}