aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-02-20 21:04:50 +0000
committerlloyd <[email protected]>2012-02-20 21:04:50 +0000
commit018bfa3c50ec857ce93b44096fc1890dc7dd65a5 (patch)
tree39b72c034c6eb789a80f8d63bfde35f4705663c8
parentec3d97c4b9cde8c017afa0f6c1dc7e69c6ac1229 (diff)
Avoid blocking more than 100 ms in the random device reader. Scale up
how much we ask for on the basis of how many bits we're counting each byte as contributing. Change /dev/*random estimate to 7 bits per byte. Small cleanup in HMAC_RNG.
-rw-r--r--src/entropy/dev_random/dev_random.cpp9
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp3
2 files changed, 8 insertions, 4 deletions
diff --git a/src/entropy/dev_random/dev_random.cpp b/src/entropy/dev_random/dev_random.cpp
index c16f48768..9e4f0b373 100644
--- a/src/entropy/dev_random/dev_random.cpp
+++ b/src/entropy/dev_random/dev_random.cpp
@@ -105,9 +105,12 @@ Device_EntropySource::~Device_EntropySource()
*/
void Device_EntropySource::poll(Entropy_Accumulator& accum)
{
- size_t go_get = std::min<size_t>(accum.desired_remaining_bits() / 8, 48);
+ const size_t ENTROPY_BITS_PER_BYTE = 7;
- size_t read_wait_ms = std::max<size_t>(go_get, 1000);
+ const size_t go_get = std::min<size_t>(
+ accum.desired_remaining_bits() / ENTROPY_BITS_PER_BYTE, 32);
+
+ const size_t read_wait_ms = std::max<size_t>(go_get, 100);
MemoryRegion<byte>& io_buffer = accum.get_io_buffer(go_get);
for(size_t i = 0; i != devices.size(); ++i)
@@ -117,7 +120,7 @@ void Device_EntropySource::poll(Entropy_Accumulator& accum)
if(got)
{
- accum.add(&io_buffer[0], got, 6);
+ accum.add(&io_buffer[0], got, ENTROPY_BITS_PER_BYTE);
break;
}
}
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index 55503382a..74ba522a4 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -75,7 +75,8 @@ void HMAC_RNG::reseed(size_t poll_bits)
while(!accum.polling_goal_achieved() && poll_attempt < poll_bits)
{
- entropy_sources[poll_attempt % entropy_sources.size()]->poll(accum);
+ const size_t src_idx = poll_attempt % entropy_sources.size();
+ entropy_sources[src_idx]->poll(accum);
++poll_attempt;
}
}