aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-07-03 14:36:55 -0400
committerJack Lloyd <[email protected]>2016-07-17 10:43:41 -0400
commitcae7a66072905bc264ecf0805a8738a674ff2986 (patch)
treef10d8a79a6ce4be3992da74c6bd1e66a10709d0f /src/cli
parentee1b5c7e8513b3b97efa87720154d8ca24774eba (diff)
Revamp entropy polling
Remove Entropy_Accumulator, instead have entropy sources directly add entropy to the RNG.
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/speed.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index f1ff29af0..1299b0d19 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -6,6 +6,7 @@
*/
#include "cli.h"
+#include "../tests/test_rng.h" // FIXME
#include <sstream>
#include <iomanip>
@@ -602,30 +603,17 @@ class Speed final : public Command
output() << Timer::result_string_bps(timer);
}
- void bench_entropy_sources(const std::chrono::milliseconds runtime)
+ void bench_entropy_sources(const std::chrono::milliseconds)
{
Botan::Entropy_Sources& srcs = Botan::Entropy_Sources::global_sources();
- typedef std::chrono::system_clock clock;
-
- auto deadline = clock::now() + runtime;
-
for(auto src : srcs.enabled_sources())
{
- double entropy_bits = 0.0;
- size_t samples = 0;
- std::vector<size_t> entropy;
-
- Botan::Entropy_Accumulator accum(
- [&](const uint8_t buf[], size_t buf_len, double buf_entropy) -> bool {
- entropy.insert(entropy.end(), buf, buf + buf_len);
- entropy_bits += buf_entropy;
- samples += 1;
- return (samples > 1024 || entropy_bits > 1024 || clock::now() > deadline);
- });
+ size_t entropy_bits = 0;
+ Botan_Tests::SeedCapturing_RNG rng;
Timer timer(src, "", "bytes");
- timer.run([&] { srcs.poll_just(accum, src); });
+ timer.run([&] { entropy_bits = srcs.poll_just(rng, src); });
#if defined(BOTAN_HAS_COMPRESSION)
std::unique_ptr<Botan::Compression_Algorithm> comp(Botan::make_compressor("zlib"));
@@ -633,13 +621,13 @@ class Speed final : public Command
if(comp)
{
- compressed.assign(entropy.begin(), entropy.end());
+ compressed.assign(rng.seed_material().begin(), rng.seed_material().end());
comp->start(9);
comp->finish(compressed);
}
#endif
- output() << "Entropy source " << src << " output " << entropy.size() << " bytes"
+ output() << "Entropy source " << src << " output " << rng.seed_material().size() << " bytes"
<< " estimated entropy " << entropy_bits
<< " in " << timer.milliseconds() << " ms";
@@ -650,7 +638,7 @@ class Speed final : public Command
}
#endif
- output() << " total samples " << samples << "\n";
+ output() << " total samples " << rng.samples() << "\n";
}
}