diff options
author | Jack Lloyd <[email protected]> | 2017-12-22 09:46:08 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-22 09:46:08 -0500 |
commit | b237575f35d3cbffb4c4f91b0a379c45b7b0003c (patch) | |
tree | 3a4a017b9eea1d26ea9805b5d7c2796ff3469803 /src | |
parent | bf0f89a52bbe67cd892ba1a8d6790ff30d7fc8d1 (diff) |
Break out of Win32 entropy poll as soon as entropy goal is reached.
Rather than running over the entire heap list which may be long.
Fixes #1369
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/entropy/win32_stats/es_win32.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/entropy/win32_stats/es_win32.cpp b/src/lib/entropy/win32_stats/es_win32.cpp index 0e7056550..86d1f2caf 100644 --- a/src/lib/entropy/win32_stats/es_win32.cpp +++ b/src/lib/entropy/win32_stats/es_win32.cpp @@ -19,6 +19,10 @@ namespace Botan { */ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) { + const size_t POLL_TARGET = 128; + const size_t EST_ENTROPY_HEAP_INFO = 4; + const size_t EST_ENTROPY_THREAD_INFO = 2; + /* First query a bunch of basic statistical stuff */ @@ -51,10 +55,10 @@ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) */ HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); - size_t bits = 0; + size_t collected = 0; #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \ - if(bits < 256) \ + if(collected < POLL_TARGET) \ { \ DATA_TYPE info; \ info.dwSize = sizeof(DATA_TYPE); \ @@ -63,7 +67,9 @@ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) do \ { \ rng.add_entropy_T(info); \ - bits += 4; \ + collected += EST_ENTROPY_THREAD_INFO; \ + if(collected >= POLL_TARGET) \ + break; \ } while(FUNC_NEXT(snapshot, &info)); \ } \ } @@ -74,7 +80,7 @@ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) #undef TOOLHELP32_ITER - if(bits <= 256) + if(collected < POLL_TARGET) { HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); @@ -94,11 +100,13 @@ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) do { rng.add_entropy_T(heap_entry); - bits += 4; + collected += EST_ENTROPY_HEAP_INFO; + if(collected >= POLL_TARGET) + break; } while(::Heap32Next(&heap_entry)); } - if(bits >= 256) + if(collected >= POLL_TARGET) break; } while(::Heap32ListNext(snapshot, &heap_list)); @@ -107,7 +115,7 @@ size_t Win32_EntropySource::poll(RandomNumberGenerator& rng) ::CloseHandle(snapshot); - return bits; + return collected; } } |