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>
@@ -294,6 +295,8 @@ FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false)
294
295
295
296
bool Random_SanityCheck ()
296
297
{
298
+ uint64_t start = GetPerformanceCounter ();
299
+
297
300
/* This does not measure the quality of randomness, but it does test that
298
301
* OSRandom() overwrites all 32 bytes of the output given a maximum
299
302
* number of tries.
@@ -320,7 +323,14 @@ bool Random_SanityCheck()
320
323
321
324
tries += 1 ;
322
325
} while (num_overwritten < NUM_OS_RANDOM_BYTES && tries < MAX_TRIES);
323
- return (num_overwritten == NUM_OS_RANDOM_BYTES); /* If this failed, bailed out after too many tries */
326
+ if (num_overwritten != NUM_OS_RANDOM_BYTES) return false ; /* If this failed, bailed out after too many tries */
327
+
328
+ // Check that GetPerformanceCounter increases at least during a GetOSRand() call + 1ms sleep.
329
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
330
+ uint64_t stop = GetPerformanceCounter ();
331
+ if (stop == start) return false ;
332
+
333
+ return true ;
324
334
}
325
335
326
336
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