@@ -221,14 +221,14 @@ static void SeedHardwareSlow(CSHA512& hasher) noexcept {
221
221
}
222
222
223
223
/* * Use repeated SHA512 to strengthen the randomness in seed32, and feed into hasher. */
224
- static void Strengthen (const unsigned char (&seed)[32], int microseconds , CSHA512& hasher) noexcept
224
+ static void Strengthen (const unsigned char (&seed)[32], SteadyClock::duration dur , CSHA512& hasher) noexcept
225
225
{
226
226
CSHA512 inner_hasher;
227
227
inner_hasher.Write (seed, sizeof (seed));
228
228
229
229
// Hash loop
230
230
unsigned char buffer[64 ];
231
- int64_t stop = GetTimeMicros () + microseconds ;
231
+ const auto stop{ SteadyClock::now () + dur} ;
232
232
do {
233
233
for (int i = 0 ; i < 1000 ; ++i) {
234
234
inner_hasher.Finalize (buffer);
@@ -238,7 +238,7 @@ static void Strengthen(const unsigned char (&seed)[32], int microseconds, CSHA51
238
238
// Benchmark operation and feed it into outer hasher.
239
239
int64_t perf = GetPerformanceCounter ();
240
240
hasher.Write ((const unsigned char *)&perf, sizeof (perf));
241
- } while (GetTimeMicros () < stop);
241
+ } while (SteadyClock::now () < stop);
242
242
243
243
// Produce output from inner state and feed it to outer hasher.
244
244
inner_hasher.Finalize (buffer);
@@ -492,13 +492,13 @@ static void SeedSlow(CSHA512& hasher, RNGState& rng) noexcept
492
492
}
493
493
494
494
/* * Extract entropy from rng, strengthen it, and feed it into hasher. */
495
- static void SeedStrengthen (CSHA512& hasher, RNGState& rng, int microseconds ) noexcept
495
+ static void SeedStrengthen (CSHA512& hasher, RNGState& rng, SteadyClock::duration dur ) noexcept
496
496
{
497
497
// Generate 32 bytes of entropy from the RNG, and a copy of the entropy already in hasher.
498
498
unsigned char strengthen_seed[32 ];
499
499
rng.MixExtract (strengthen_seed, sizeof (strengthen_seed), CSHA512 (hasher), false );
500
500
// Strengthen the seed, and feed it into hasher.
501
- Strengthen (strengthen_seed, microseconds , hasher);
501
+ Strengthen (strengthen_seed, dur , hasher);
502
502
}
503
503
504
504
static void SeedPeriodic (CSHA512& hasher, RNGState& rng) noexcept
@@ -518,7 +518,7 @@ static void SeedPeriodic(CSHA512& hasher, RNGState& rng) noexcept
518
518
LogPrint (BCLog::RAND, " Feeding %i bytes of dynamic environment data into RNG\n " , hasher.Size () - old_size);
519
519
520
520
// Strengthen for 10 ms
521
- SeedStrengthen (hasher, rng, 10000 );
521
+ SeedStrengthen (hasher, rng, 10ms );
522
522
}
523
523
524
524
static void SeedStartup (CSHA512& hasher, RNGState& rng) noexcept
@@ -538,7 +538,7 @@ static void SeedStartup(CSHA512& hasher, RNGState& rng) noexcept
538
538
LogPrint (BCLog::RAND, " Feeding %i bytes of environment data into RNG\n " , hasher.Size () - old_size);
539
539
540
540
// Strengthen for 100 ms
541
- SeedStrengthen (hasher, rng, 100000 );
541
+ SeedStrengthen (hasher, rng, 100ms );
542
542
}
543
543
544
544
enum class RNGLevel {
0 commit comments