From cae7a66072905bc264ecf0805a8738a674ff2986 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 3 Jul 2016 14:36:55 -0400 Subject: Revamp entropy polling Remove Entropy_Accumulator, instead have entropy sources directly add entropy to the RNG. --- src/lib/entropy/entropy_srcs.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/lib/entropy/entropy_srcs.cpp') diff --git a/src/lib/entropy/entropy_srcs.cpp b/src/lib/entropy/entropy_srcs.cpp index 81076b0e9..22d2e5e4b 100644 --- a/src/lib/entropy/entropy_srcs.cpp +++ b/src/lib/entropy/entropy_srcs.cpp @@ -69,7 +69,7 @@ std::unique_ptr Entropy_Source::create(const std::string& name) return std::unique_ptr(new Intel_Rdrand); #endif } - + if(name == "rdseed") { #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED) @@ -163,36 +163,30 @@ size_t Entropy_Sources::poll(RandomNumberGenerator& rng, auto deadline = clock::now() + timeout; - double bits_collected = 0; - - Entropy_Accumulator accum([&](const byte in[], size_t in_len, double entropy_estimate) { - rng.add_entropy(in, in_len); - bits_collected += entropy_estimate; - return (bits_collected >= poll_bits || clock::now() > deadline); - }); + size_t bits_collected = 0; - for(size_t i = 0; i != m_srcs.size(); ++i) + for(Entropy_Source* src : m_srcs) { - m_srcs[i]->poll(accum); - if(accum.polling_goal_achieved()) + bits_collected += src->poll(rng); + + if (bits_collected >= poll_bits || clock::now() > deadline) break; } - return static_cast(bits_collected); + return bits_collected; } -bool Entropy_Sources::poll_just(Entropy_Accumulator& accum, const std::string& the_src) +size_t Entropy_Sources::poll_just(RandomNumberGenerator& rng, const std::string& the_src) { for(size_t i = 0; i != m_srcs.size(); ++i) { if(m_srcs[i]->name() == the_src) { - m_srcs[i]->poll(accum); - return true; + return m_srcs[i]->poll(rng); } } - return false; + return 0; } Entropy_Sources::Entropy_Sources(const std::vector& sources) -- cgit v1.2.3