File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 17
17
#include < stdlib.h>
18
18
#include < limits>
19
19
#include < chrono>
20
+ #include < thread>
20
21
21
22
#ifndef WIN32
22
23
#include < sys/time.h>
@@ -262,6 +263,8 @@ FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false)
262
263
263
264
bool Random_SanityCheck ()
264
265
{
266
+ uint64_t start = GetPerformanceCounter ();
267
+
265
268
/* This does not measure the quality of randomness, but it does test that
266
269
* OSRandom() overwrites all 32 bytes of the output given a maximum
267
270
* number of tries.
@@ -288,7 +291,14 @@ bool Random_SanityCheck()
288
291
289
292
tries += 1 ;
290
293
} while (num_overwritten < NUM_OS_RANDOM_BYTES && tries < MAX_TRIES);
291
- return (num_overwritten == NUM_OS_RANDOM_BYTES); /* If this failed, bailed out after too many tries */
294
+ if (num_overwritten != NUM_OS_RANDOM_BYTES) return false ; /* If this failed, bailed out after too many tries */
295
+
296
+ // Check that GetPerformanceCounter increases at least during a GetOSRand() call + 1ms sleep.
297
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
298
+ uint64_t stop = GetPerformanceCounter ();
299
+ if (stop == start) return false ;
300
+
301
+ return true ;
292
302
}
293
303
294
304
FastRandomContext::FastRandomContext (bool fDeterministic ) : requires_seed(!fDeterministic ), bytebuf_size(0 ), bitbuf_size(0 )
You can’t perform that action at this time.
0 commit comments