mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #9792: FastRandomContext improvements and switch to ChaCha20
4fd2d2fAdd a FastRandomContext::randrange and use it (Pieter Wuille)1632922Switch FastRandomContext to ChaCha20 (Pieter Wuille)e04326fAdd ChaCha20 (Pieter Wuille)663fbaeFastRandom benchmark (Pieter Wuille)c21cbe6Introduce FastRandomContext::randbool() (Pieter Wuille) Tree-SHA512: 7fff61e3f6d6dc6ac846ca643d877b377db609646dd401a0e8f50b052c6b9bcd2f5fc34de6bbf28f04afd1724f6279ee163ead5f37d724fb782a00239f35db1d
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user