diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-05-05 11:32:06 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-05-05 11:56:24 -0700 |
commit | 33f853d8d88917b145e2793bf8eb1b4e3790e7e7 (patch) | |
tree | 65ca7a2c2d47eaa28d87ad1513a7ebc3a385d3a3 | |
parent | f544094d5e1ee627ebd34542aead7bf1241fae19 (diff) | |
download | bitcoin-33f853d8d88917b145e2793bf8eb1b4e3790e7e7.tar.xz |
Test that GetPerformanceCounter() increments
-rw-r--r-- | src/random.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/random.cpp b/src/random.cpp index 40879e8737..8107cb3105 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -17,6 +17,7 @@ #include <stdlib.h> #include <limits> #include <chrono> +#include <thread> #ifndef WIN32 #include <sys/time.h> @@ -262,6 +263,8 @@ FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false) bool Random_SanityCheck() { + uint64_t start = GetPerformanceCounter(); + /* This does not measure the quality of randomness, but it does test that * OSRandom() overwrites all 32 bytes of the output given a maximum * number of tries. @@ -288,7 +291,14 @@ bool Random_SanityCheck() tries += 1; } 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 */ + if (num_overwritten != NUM_OS_RANDOM_BYTES) return false; /* If this failed, bailed out after too many tries */ + + // Check that GetPerformanceCounter increases at least during a GetOSRand() call + 1ms sleep. + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + uint64_t stop = GetPerformanceCounter(); + if (stop == start) return false; + + return true; } FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDeterministic), bytebuf_size(0), bitbuf_size(0) |