diff options
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/speed.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index e876b7205..06c1e6ab9 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -1435,8 +1435,8 @@ class Speed final : public Command while(f_timer->under(runtime)) { - e_timer->run([&]() { Botan::power_mod(group.get_g(), random_e, group.get_p()); }); - f_timer->run([&]() { Botan::power_mod(group.get_g(), random_f, group.get_p()); }); + e_timer->run([&]() { group.power_g_p(random_e); }); + f_timer->run([&]() { group.power_g_p(random_f); }); } record_result(e_timer); @@ -1532,31 +1532,33 @@ class Speed final : public Command void bench_inverse_mod(const std::chrono::milliseconds runtime) { - - for(size_t bits : { 256, 384, 512 }) + for(size_t bits : { 256, 384, 512, 1024, 2048 }) { - const Botan::BigInt p = Botan::random_prime(rng(), bits); - const std::string bit_str = std::to_string(bits); - std::unique_ptr<Timer> monty_timer = make_timer("monty-" + bit_str); - std::unique_ptr<Timer> ct_invmod_timer = make_timer("ct-" + bit_str); + std::unique_ptr<Timer> timer = make_timer("inverse_mod-" + bit_str); - while(monty_timer->under(runtime)) + while(timer->under(runtime)) { - const Botan::BigInt x(rng(), p.bits() - 1); + const Botan::BigInt x(rng(), bits - 1); + Botan::BigInt mod(rng(), bits); - const Botan::BigInt x_inv1 = monty_timer->run( - [&] { return Botan::normalized_montgomery_inverse(x, p); }); + const Botan::BigInt x_inv = timer->run( + [&] { return Botan::inverse_mod(x, mod); }); - const Botan::BigInt x_inv2 = ct_invmod_timer->run( - [&] { return Botan::inverse_mod(x, p); }); - - BOTAN_ASSERT_EQUAL(x_inv1, x_inv2, "Same result"); + if(x_inv == 0) + { + const Botan::BigInt g = gcd(x, mod); + BOTAN_ASSERT(g != 1, "Inversion only fails if gcd(x, mod) > 1"); + } + else + { + const Botan::BigInt check = (x_inv*x) % mod; + BOTAN_ASSERT_EQUAL(check, 1, "Const time inversion correct"); + } } - record_result(monty_timer); - record_result(ct_invmod_timer); + record_result(timer); } } @@ -1856,6 +1858,8 @@ class Speed final : public Command std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&] { return Botan::create_private_key("RSA", rng(), std::to_string(keylen)); })); + + BOTAN_ASSERT(key->check_key(rng(), true), "Key is ok"); } record_result(keygen_timer); |