diff options
| author | Gavin Andresen <[email protected]> | 2013-02-22 08:57:38 -0800 |
|---|---|---|
| committer | Gavin Andresen <[email protected]> | 2013-02-22 08:57:38 -0800 |
| commit | aaeb443791f880351692ac020e8fdea44d2270b0 (patch) | |
| tree | c32831368135385ed93bbe737b2d441e874b6b87 /src/util.cpp | |
| parent | Merge pull request #2308 from apoelstra/safemode-privkey (diff) | |
| parent | Internal RNG for approximateBestSubset to prevent degenerate behavior. (diff) | |
| download | discoin-aaeb443791f880351692ac020e8fdea44d2270b0.tar.xz discoin-aaeb443791f880351692ac020e8fdea44d2270b0.zip | |
Merge pull request #2312 from gmaxwell/random_random
ApproximateBestSubset internal RNG to prevent degenerate behavior.
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/util.cpp b/src/util.cpp index 1f66aff60..4eff6ce71 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1281,12 +1281,26 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) } } - - - - - - +uint32_t insecure_rand_Rz = 11; +uint32_t insecure_rand_Rw = 11; +void seed_insecure_rand(bool fDeterministic) +{ + //The seed values have some unlikely fixed points which we avoid. + if(fDeterministic) + { + insecure_rand_Rz = insecure_rand_Rw = 11; + } else { + uint32_t tmp; + do{ + RAND_bytes((unsigned char*)&tmp,4); + }while(tmp==0 || tmp==0x9068ffffU); + insecure_rand_Rz=tmp; + do{ + RAND_bytes((unsigned char*)&tmp,4); + }while(tmp==0 || tmp==0x464fffffU); + insecure_rand_Rw=tmp; + } +} string FormatVersion(int nVersion) { |