@@ -511,40 +511,28 @@ static void SeedSlow(CSHA512& hasher) noexcept
511
511
}
512
512
513
513
/* * Extract entropy from rng, strengthen it, and feed it into hasher. */
514
- static void SeedStrengthen (CSHA512& hasher, RNGState& rng) noexcept
514
+ static void SeedStrengthen (CSHA512& hasher, RNGState& rng, int microseconds ) noexcept
515
515
{
516
- static std::atomic<int64_t > last_strengthen{0 };
517
- int64_t last_time = last_strengthen.load ();
518
- int64_t current_time = GetTimeMicros ();
519
- if (current_time > last_time + 60000000 ) { // Only run once a minute
520
- // Generate 32 bytes of entropy from the RNG, and a copy of the entropy already in hasher.
521
- unsigned char strengthen_seed[32 ];
522
- rng.MixExtract (strengthen_seed, sizeof (strengthen_seed), CSHA512 (hasher), false );
523
- // Strengthen it for 10ms (100ms on first run), and feed it into hasher.
524
- Strengthen (strengthen_seed, last_time == 0 ? 100000 : 10000 , hasher);
525
- last_strengthen = current_time;
526
- }
516
+ // Generate 32 bytes of entropy from the RNG, and a copy of the entropy already in hasher.
517
+ unsigned char strengthen_seed[32 ];
518
+ rng.MixExtract (strengthen_seed, sizeof (strengthen_seed), CSHA512 (hasher), false );
519
+ // Strengthen the seed, and feed it into hasher.
520
+ Strengthen (strengthen_seed, microseconds, hasher);
527
521
}
528
522
529
- static void SeedSleep (CSHA512& hasher, RNGState& rng)
523
+ static void SeedPeriodic (CSHA512& hasher, RNGState& rng)
530
524
{
531
525
// Everything that the 'fast' seeder includes
532
526
SeedFast (hasher);
533
527
534
528
// High-precision timestamp
535
529
SeedTimestamp (hasher);
536
530
537
- // Sleep for 1ms
538
- MilliSleep (1 );
539
-
540
- // High-precision timestamp after sleeping (as we commit to both the time before and after, this measures the delay)
541
- SeedTimestamp (hasher);
542
-
543
- // Dynamic environment data (performance monitoring, ...; once every 10 minutes)
531
+ // Dynamic environment data (performance monitoring, ...)
544
532
RandAddDynamicEnv (hasher);
545
533
546
- // Strengthen every minute
547
- SeedStrengthen (hasher, rng);
534
+ // Strengthen for 10 ms
535
+ SeedStrengthen (hasher, rng, 10000 );
548
536
}
549
537
550
538
static void SeedStartup (CSHA512& hasher, RNGState& rng) noexcept
@@ -555,20 +543,20 @@ static void SeedStartup(CSHA512& hasher, RNGState& rng) noexcept
555
543
// Everything that the 'slow' seeder includes.
556
544
SeedSlow (hasher);
557
545
558
- // Dynamic environment data
546
+ // Dynamic environment data (performance monitoring, ...)
559
547
RandAddDynamicEnv (hasher);
560
548
561
549
// Static environment data
562
550
RandAddStaticEnv (hasher);
563
551
564
- // Strengthen
565
- SeedStrengthen (hasher, rng);
552
+ // Strengthen for 100 ms
553
+ SeedStrengthen (hasher, rng, 100000 );
566
554
}
567
555
568
556
enum class RNGLevel {
569
557
FAST, // !< Automatically called by GetRandBytes
570
558
SLOW, // !< Automatically called by GetStrongRandBytes
571
- SLEEP , // !< Called by RandAddSeedSleep ()
559
+ PERIODIC , // !< Called by RandAddPeriodic ()
572
560
};
573
561
574
562
static void ProcRand (unsigned char * out, int num, RNGLevel level)
@@ -586,8 +574,8 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level)
586
574
case RNGLevel::SLOW:
587
575
SeedSlow (hasher);
588
576
break ;
589
- case RNGLevel::SLEEP :
590
- SeedSleep (hasher, rng);
577
+ case RNGLevel::PERIODIC :
578
+ SeedPeriodic (hasher, rng);
591
579
break ;
592
580
}
593
581
@@ -610,7 +598,7 @@ static void ProcRand(unsigned char* out, int num, RNGLevel level)
610
598
611
599
void GetRandBytes (unsigned char * buf, int num) noexcept { ProcRand (buf, num, RNGLevel::FAST); }
612
600
void GetStrongRandBytes (unsigned char * buf, int num) noexcept { ProcRand (buf, num, RNGLevel::SLOW); }
613
- void RandAddSeedSleep () { ProcRand (nullptr , 0 , RNGLevel::SLEEP ); }
601
+ void RandAddPeriodic () { ProcRand (nullptr , 0 , RNGLevel::PERIODIC ); }
614
602
615
603
bool g_mock_deterministic_tests{false };
616
604
0 commit comments