aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-03-06 11:25:43 -0500
committerJack Lloyd <[email protected]>2020-03-06 11:25:43 -0500
commit9b52b57c51692ba962029010001e1538864fcc47 (patch)
treea4e7c5a380906f8a18dd1286a927b545271cea0f /src/cli
parentb79272e7c9c2ec4a6d4444c4c5ef004f80a20430 (diff)
parentfa79464a2640dc51d34fa2a42751a27356e08ecc (diff)
Merge GH #2298 Clean up prime generation logic
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/speed.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 06c1e6ab9..e81ddd24b 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -1598,26 +1598,37 @@ class Speed final : public Command
{
const size_t coprime = 65537; // simulates RSA key gen
- for(size_t bits : { 1024, 1536 })
+ for(size_t bits : { 256, 384, 512, 768, 1024, 1536 })
{
std::unique_ptr<Timer> genprime_timer = make_timer("random_prime " + std::to_string(bits));
+ std::unique_ptr<Timer> gensafe_timer = make_timer("random_safe_prime " + std::to_string(bits));
std::unique_ptr<Timer> is_prime_timer = make_timer("is_prime " + std::to_string(bits));
- while(genprime_timer->under(runtime) && is_prime_timer->under(runtime))
+ while(gensafe_timer->under(runtime))
{
const Botan::BigInt p = genprime_timer->run([&]
{
return Botan::random_prime(rng(), bits, coprime);
});
- const bool ok = is_prime_timer->run([&]
+ if(!is_prime_timer->run([&] { return Botan::is_prime(p, rng(), 64, true); }))
{
- return Botan::is_prime(p, rng(), 64, true);
+ error_output() << "Generated prime " << p << " which failed a primality test";
+ }
+
+ const Botan::BigInt sg = gensafe_timer->run([&]
+ {
+ return Botan::random_safe_prime(rng(), bits);
});
- if(!ok)
+ if(!is_prime_timer->run([&] { return Botan::is_prime(sg, rng(), 64, true); }))
{
- error_output() << "Generated prime " << p << " which failed a primality test";
+ error_output() << "Generated safe prime " << sg << " which failed a primality test";
+ }
+
+ if(!is_prime_timer->run([&] { return Botan::is_prime(sg / 2, rng(), 64, true); }))
+ {
+ error_output() << "Generated prime " << sg/2 << " which failed a primality test";
}
// Now test p+2, p+4, ... which may or may not be prime
@@ -1628,6 +1639,7 @@ class Speed final : public Command
}
record_result(genprime_timer);
+ record_result(gensafe_timer);
record_result(is_prime_timer);
}
}