diff options
author | Jack Lloyd <[email protected]> | 2021-05-19 19:16:46 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-05-19 19:16:46 -0400 |
commit | 47e9c2fc7070b5944863796df7084533ae89093e (patch) | |
tree | c6e426c774d6ab2bccc64ac70e5532127ed3177b /src/cli | |
parent | 88e2be0c18b53891b56444368dc335bfa9c33b05 (diff) |
Add gcd results to speed cli
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/speed.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index 17d1d7cad..55e544b26 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -1570,8 +1570,9 @@ class Speed final : public Command const std::string bit_str = std::to_string(bits); auto timer = make_timer("inverse_mod-" + bit_str); + auto gcd_timer = make_timer("gcd-" + bit_str); - while(timer->under(runtime)) + while(timer->under(runtime) && gcd_timer->under(runtime)) { const Botan::BigInt x(rng(), bits - 1); Botan::BigInt mod(rng(), bits); @@ -1579,19 +1580,22 @@ class Speed final : public Command const Botan::BigInt x_inv = timer->run( [&] { return Botan::inverse_mod(x, mod); }); + const Botan::BigInt g = gcd_timer->run([&] { return gcd(x, mod); }); + if(x_inv == 0) { - const Botan::BigInt g = gcd(x, mod); BOTAN_ASSERT(g != 1, "Inversion only fails if gcd(x, mod) > 1"); } else { + BOTAN_ASSERT(g == 1, "Inversion succeeds only if gcd != 1"); const Botan::BigInt check = (x_inv*x) % mod; BOTAN_ASSERT_EQUAL(check, 1, "Const time inversion correct"); } } record_result(timer); + record_result(gcd_timer); } } |