aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/speed.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-01-26 00:23:41 -0500
committerJack Lloyd <[email protected]>2016-01-26 00:23:41 -0500
commitc811650072534165ccf3c79cd4da81ffe0612cd0 (patch)
treed95c45046e1a9bffa737ccc9938a35f674588bcf /src/cli/speed.cpp
parent6adce3dcdd8572b4e7091feedcfcf435ca553ad3 (diff)
Add time tests for all RNG types
Diffstat (limited to 'src/cli/speed.cpp')
-rw-r--r--src/cli/speed.cpp79
1 files changed, 68 insertions, 11 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 79f657f98..2db8e5128 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -24,6 +24,22 @@
#include <botan/system_rng.h>
#endif
+#if defined(BOTAN_HAS_HMAC_DRBG)
+ #include <botan/hmac_drbg.h>
+#endif
+
+#if defined(BOTAN_HAS_HMAC_RNG)
+ #include <botan/hmac_rng.h>
+#endif
+
+#if defined(BOTAN_HAS_X931_RNG)
+ #include <botan/x931_rng.h>
+#endif
+
+#if defined(BOTAN_HAS_COMPRESSION)
+ #include <botan/compression.h>
+#endif
+
#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
#include <botan/pkcs8.h>
#include <botan/pubkey.h>
@@ -352,7 +368,23 @@ class Speed final : public Command
#endif
Botan::AutoSeeded_RNG auto_rng;
- bench_rng(auto_rng, "AutoSeeded_RNG", msec, buf_size);
+ bench_rng(auto_rng, "AutoSeeded_RNG (periodic reseed)", msec, buf_size);
+
+ Botan::ANSI_X931_RNG x931_rng(Botan::BlockCipher::create("AES-256").release(), new Botan::AutoSeeded_RNG);
+ bench_rng(x931_rng, x931_rng.name(), msec, buf_size);
+
+#if defined(BOTAN_HAS_HMAC_DRBG)
+ for(std::string hash : { "SHA-256", "SHA-384", "SHA-512" })
+ {
+
+ auto hmac = Botan::MessageAuthenticationCode::create("HMAC(" + hash + ")");
+ Botan::HMAC_DRBG hmac_drbg(hmac->clone());
+ bench_rng(hmac_drbg, hmac_drbg.name(), msec, buf_size);
+
+ Botan::HMAC_RNG hmac_rng(hmac->clone(), hmac->clone());
+ bench_rng(hmac_rng, hmac_rng.name(), msec, buf_size);
+ }
+#endif
}
else if(algo == "entropy")
{
@@ -511,7 +543,11 @@ class Speed final : public Command
size_t buf_size)
{
Botan::secure_vector<uint8_t> buffer(buf_size);
- Timer timer(rng_name, "", "bytes", buffer.size());
+
+ rng.add_entropy(buffer.data(), buffer.size());
+ size_t bits = rng.reseed(256);
+
+ Timer timer(rng_name, "", "generate", buffer.size());
timer.run_until_elapsed(runtime, [&] { rng.randomize(buffer.data(), buffer.size()); });
output() << Timer::result_string_bps(timer);
}
@@ -526,21 +562,43 @@ class Speed final : public Command
for(auto src : srcs.enabled_sources())
{
- size_t bytes = 0, entropy_bits = 0, samples = 0;
+ size_t entropy_bits = 0, samples = 0;
+ std::vector<size_t> entropy;
+
Botan::Entropy_Accumulator accum(
- [&](const uint8_t [], size_t buf_len, size_t buf_entropy) -> bool {
- bytes += buf_len;
- entropy_bits += buf_entropy;
+ [&](const uint8_t buf[], size_t buf_len, size_t buf_entropy) -> bool {
+ entropy.insert(entropy.end(), buf, buf + buf_len);
+ entropy_bits += buf_entropy;
samples += 1;
- return (samples > 100 || entropy_bits > 512 || clock::now() > deadline);
+ return (samples > 1024 || entropy_bits > 1024 || clock::now() > deadline);
});
Timer timer(src, "", "bytes");
timer.run([&] { srcs.poll_just(accum, src); });
- output() << "Entropy source " << src << " produced " << bytes << " bytes with "
- << entropy_bits << " estimated bits of entropy in "
- << samples << " samples in " << timer.milliseconds() << " ms\n";
+#if defined(BOTAN_HAS_COMPRESSION)
+ std::unique_ptr<Botan::Compressor_Transform> comp(Botan::make_compressor("zlib", 9));
+ Botan::secure_vector<uint8_t> compressed;
+
+ if(comp)
+ {
+ compressed.assign(entropy.begin(), entropy.end());
+ comp->start();
+ comp->finish(compressed);
+ }
+#endif
+
+ output() << "Entropy source " << src << " output " << entropy.size()
+ << " bytes in " << timer.milliseconds() << " ms";
+
+#if defined(BOTAN_HAS_COMPRESSION)
+ if(compressed.size() > 0)
+ {
+ output() << " output compressed to " << compressed.size() << " bytes";
+ }
+#endif
+
+ output() << " total samples " << samples << "\n";
}
}
@@ -815,7 +873,6 @@ class Speed final : public Command
}
#endif
-
};
BOTAN_REGISTER_COMMAND("speed", Speed);