diff options
author | Jack Lloyd <[email protected]> | 2016-05-23 11:38:01 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-05-23 11:38:01 -0400 |
commit | e4829225d91fd712ad70bb61f291b268f8d0d0d0 (patch) | |
tree | 60cc4d3b00739c170cec84697d09be2120bbb97e | |
parent | 585a9056166c32d1d6537c163b8960b2106e3e21 (diff) |
Add FPE_FE1 runtime metrics
-rw-r--r-- | src/cli/speed.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index 595b4bd20..c6149bf68 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -6,6 +6,7 @@ */ #include "cli.h" + #include <sstream> #include <iomanip> #include <chrono> @@ -36,6 +37,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,6 +403,13 @@ 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") { Botan::AutoSeeded_RNG auto_rng; @@ -639,6 +651,41 @@ class Speed final : public Command } } +#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) |