aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/speed.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/speed.cpp')
-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);
}
}