From e4829225d91fd712ad70bb61f291b268f8d0d0d0 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Mon, 23 May 2016 11:38:01 -0400 Subject: Add FPE_FE1 runtime metrics --- src/cli/speed.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/cli/speed.cpp') 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 #include #include @@ -36,6 +37,10 @@ #include #endif +#if defined(BOTAN_HAS_FPE_FE1) + #include +#endif + #if defined(BOTAN_HAS_COMPRESSION) #include #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 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) -- cgit v1.2.3