diff options
author | lloyd <[email protected]> | 2012-02-20 21:04:50 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-02-20 21:04:50 +0000 |
commit | 018bfa3c50ec857ce93b44096fc1890dc7dd65a5 (patch) | |
tree | 39b72c034c6eb789a80f8d63bfde35f4705663c8 /src/entropy | |
parent | ec3d97c4b9cde8c017afa0f6c1dc7e69c6ac1229 (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.
Diffstat (limited to 'src/entropy')
-rw-r--r-- | src/entropy/dev_random/dev_random.cpp | 9 |
1 files changed, 6 insertions, 3 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; } } |