aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/speed.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/speed.cpp')
-rw-r--r--src/cli/speed.cpp98
1 files changed, 71 insertions, 27 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 595b4bd20..222a98d3f 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -6,6 +6,8 @@
*/
#include "cli.h"
+#include "../tests/test_rng.h" // FIXME
+
#include <sstream>
#include <iomanip>
#include <chrono>
@@ -17,9 +19,12 @@
#include <botan/hash.h>
#include <botan/mac.h>
#include <botan/cipher_mode.h>
-#include <botan/auto_rng.h>
#include <botan/entropy_src.h>
+#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
+ #include <botan/auto_rng.h>
+#endif
+
#if defined(BOTAN_HAS_SYSTEM_RNG)
#include <botan/system_rng.h>
#endif
@@ -36,6 +41,10 @@
#include <botan/x931_rng.h>
#endif
+#if defined(BOTAN_HAS_FPE_FE1)
+ #include <botan/fpe_fe1.h>
+#endif
+
#if defined(BOTAN_HAS_COMPRESSION)
#include <botan/compression.h>
#endif
@@ -398,10 +407,19 @@ class Speed final : public Command
bench_inverse_mod(msec);
}
#endif
+
+#if defined(BOTAN_HAS_FPE_FE1)
+ else if(algo == "fpe_fe1")
+ {
+ bench_fpe_fe1(msec);
+ }
+#endif
else if(algo == "RNG")
{
+#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
Botan::AutoSeeded_RNG auto_rng;
bench_rng(auto_rng, "AutoSeeded_RNG (periodic reseed)", msec, buf_size);
+#endif
#if defined(BOTAN_HAS_SYSTEM_RNG)
bench_rng(Botan::system_rng(), "System_RNG", msec, buf_size);
@@ -415,12 +433,15 @@ class Speed final : public Command
#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());
+ Botan::HMAC_DRBG hmac_drbg(hash);
bench_rng(hmac_drbg, hmac_drbg.name(), msec, buf_size);
+ }
+#endif
- Botan::HMAC_RNG hmac_rng(hmac->clone(), hmac->clone());
+#if defined(BOTAN_HAS_HMAC_RNG)
+ for(std::string hash : { "SHA-256", "SHA-384", "SHA-512" })
+ {
+ Botan::HMAC_RNG hmac_rng(Botan::MessageAuthenticationCode::create("HMAC(" + hash + ")"));
bench_rng(hmac_rng, hmac_rng.name(), msec, buf_size);
}
#endif
@@ -579,38 +600,26 @@ class Speed final : public Command
{
Botan::secure_vector<uint8_t> buffer(buf_size);
- rng.add_entropy(buffer.data(), buffer.size());
- rng.reseed(256);
+#if defined(BOTAN_HAS_SYSTEM_RNG)
+ rng.reseed_from_rng(Botan::system_rng(), 256);
+#endif
Timer timer(rng_name, "", "generate", buffer.size());
timer.run_until_elapsed(runtime, [&] { rng.randomize(buffer.data(), buffer.size()); });
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"));
@@ -618,13 +627,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";
@@ -635,10 +644,45 @@ class Speed final : public Command
}
#endif
- output() << " total samples " << samples << "\n";
+ output() << " total samples " << rng.samples() << "\n";
}
}
+#if defined(BOTAN_HAS_FPE_FE1)
+
+ void bench_fpe_fe1(const std::chrono::milliseconds runtime)
+ {
+ const Botan::BigInt n = 1000000000000000;
+
+ Timer enc_timer("FPE_FE1 encrypt");
+ Timer dec_timer("FPE_FE1 decrypt");
+
+ const Botan::SymmetricKey key(rng(), 32);
+ const std::vector<uint8_t> tweak(8); // 8 zeros
+
+ Botan::BigInt x = 1;
+
+ while(enc_timer.under(runtime))
+ {
+ enc_timer.start();
+ x = Botan::FPE::fe1_encrypt(n, x, key, tweak);
+ enc_timer.stop();
+ }
+
+ for(size_t i = 0; i != enc_timer.events(); ++i)
+ {
+ dec_timer.start();
+ x = Botan::FPE::fe1_decrypt(n, x, key, tweak);
+ dec_timer.stop();
+ }
+
+ BOTAN_ASSERT(x == 1, "FPE works");
+
+ output() << Timer::result_string_ops(enc_timer);
+ output() << Timer::result_string_ops(dec_timer);
+ }
+#endif
+
#if defined(BOTAN_HAS_NUMBERTHEORY)
void bench_inverse_mod(const std::chrono::milliseconds runtime)