18
18
#include < stdlib.h>
19
19
#include < thread>
20
20
21
+ #include < randomenv.h>
22
+
21
23
#include < support/allocators/secure.h>
22
24
23
25
#ifndef WIN32
@@ -263,44 +265,6 @@ static void Strengthen(const unsigned char (&seed)[32], int microseconds, CSHA51
263
265
memory_cleanse (buffer, sizeof (buffer));
264
266
}
265
267
266
- static void RandAddSeedPerfmon (CSHA512& hasher)
267
- {
268
- #ifdef WIN32
269
- // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
270
- // Seed with the entire set of perfmon data
271
-
272
- // This can take up to 2 seconds, so only do it every 10 minutes
273
- static int64_t nLastPerfmon;
274
- if (GetTime () < nLastPerfmon + 10 * 60 )
275
- return ;
276
- nLastPerfmon = GetTime ();
277
-
278
- std::vector<unsigned char > vData (250000 , 0 );
279
- long ret = 0 ;
280
- unsigned long nSize = 0 ;
281
- const size_t nMaxSize = 10000000 ; // Bail out at more than 10MB of performance data
282
- while (true ) {
283
- nSize = vData.size ();
284
- ret = RegQueryValueExA (HKEY_PERFORMANCE_DATA, " Global" , nullptr , nullptr , vData.data (), &nSize);
285
- if (ret != ERROR_MORE_DATA || vData.size () >= nMaxSize)
286
- break ;
287
- vData.resize (std::max ((vData.size () * 3 ) / 2 , nMaxSize)); // Grow size of buffer exponentially
288
- }
289
- RegCloseKey (HKEY_PERFORMANCE_DATA);
290
- if (ret == ERROR_SUCCESS) {
291
- hasher.Write (vData.data (), nSize);
292
- memory_cleanse (vData.data (), nSize);
293
- } else {
294
- // Performance data is only a best-effort attempt at improving the
295
- // situation when the OS randomness (and other sources) aren't
296
- // adequate. As a result, failure to read it is isn't considered critical,
297
- // so we don't call RandFailure().
298
- // TODO: Add logging when the logger is made functional before global
299
- // constructors have been invoked.
300
- }
301
- #endif
302
- }
303
-
304
268
#ifndef WIN32
305
269
/* * Fallback: get 32 bytes of system entropy from /dev/urandom. The most
306
270
* compatible way to get cryptographic randomness on UNIX-ish platforms.
@@ -585,8 +549,8 @@ static void SeedSleep(CSHA512& hasher, RNGState& rng)
585
549
// High-precision timestamp after sleeping (as we commit to both the time before and after, this measures the delay)
586
550
SeedTimestamp (hasher);
587
551
588
- // Windows performance monitor data (once every 10 minutes)
589
- RandAddSeedPerfmon (hasher);
552
+ // Dynamic environment data (performance monitoring, ...; once every 10 minutes)
553
+ RandAddDynamicEnv (hasher);
590
554
591
555
// Strengthen every minute
592
556
SeedStrengthen (hasher, rng);
@@ -600,8 +564,11 @@ static void SeedStartup(CSHA512& hasher, RNGState& rng) noexcept
600
564
// Everything that the 'slow' seeder includes.
601
565
SeedSlow (hasher);
602
566
603
- // Windows performance monitor data.
604
- RandAddSeedPerfmon (hasher);
567
+ // Dynamic environment data
568
+ RandAddDynamicEnv (hasher);
569
+
570
+ // Static environment data
571
+ RandAddStaticEnv (hasher);
605
572
606
573
// Strengthen
607
574
SeedStrengthen (hasher, rng);
0 commit comments