aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-18 12:01:47 -0400
committerJack Lloyd <[email protected]>2018-04-18 12:01:47 -0400
commit45fa74db0a273f9ad36b1496c59b5caaaa1e6874 (patch)
tree67d570eda6fe53c3a35b00e88c91e075fc86c96a /src
parent3716327e26a9298cf4d09ed7703074ed4e4d5a37 (diff)
Add cycle counter for NIST reduction
Diffstat (limited to 'src')
-rw-r--r--src/cli/speed.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index fdd62ce11..3ec8b83e4 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -91,6 +91,7 @@
#include <botan/numthry.h>
#include <botan/pow_mod.h>
#include <botan/reducer.h>
+ #include <botan/curve_nistp.h>
#endif
#if defined(BOTAN_HAS_ECC_GROUP)
@@ -919,6 +920,10 @@ class Speed final : public Command
{
bench_bn_redc(msec);
}
+ else if(algo == "nistp_redc")
+ {
+ bench_nistp_redc(msec);
+ }
#endif
#if defined(BOTAN_HAS_FPE_FE1)
@@ -1506,6 +1511,53 @@ class Speed final : public Command
#endif
#if defined(BOTAN_HAS_NUMBERTHEORY)
+ void bench_nistp_redc(const std::chrono::milliseconds total_runtime)
+ {
+ Botan::secure_vector<Botan::word> ws;
+
+ auto runtime = total_runtime / 5;
+
+ std::unique_ptr<Timer> p192_timer = make_timer("P-192 redc");
+ while(p192_timer->under(runtime))
+ {
+ Botan::BigInt r192(rng(), 192*2 - 1);
+ p192_timer->run([&]() { Botan::redc_p192(r192, ws); });
+ }
+ record_result(p192_timer);
+
+ std::unique_ptr<Timer> p224_timer = make_timer("P-224 redc");
+ while(p224_timer->under(runtime))
+ {
+ Botan::BigInt r224(rng(), 224*2 - 1);
+ p224_timer->run([&]() { Botan::redc_p224(r224, ws); });
+ }
+ record_result(p224_timer);
+
+ std::unique_ptr<Timer> p256_timer = make_timer("P-256 redc");
+ while(p256_timer->under(runtime))
+ {
+ Botan::BigInt r256(rng(), 256*2 - 1);
+ p256_timer->run([&]() { Botan::redc_p256(r256, ws); });
+ }
+ record_result(p256_timer);
+
+ std::unique_ptr<Timer> p384_timer = make_timer("P-384 redc");
+ while(p384_timer->under(runtime))
+ {
+ Botan::BigInt r384(rng(), 384*2 - 1);
+ p384_timer->run([&]() { Botan::redc_p384(r384, ws); });
+ }
+ record_result(p384_timer);
+
+ std::unique_ptr<Timer> p521_timer = make_timer("P-521 redc");
+ while(p521_timer->under(runtime))
+ {
+ Botan::BigInt r521(rng(), 521*2 - 1);
+ p521_timer->run([&]() { Botan::redc_p521(r521, ws); });
+ }
+ record_result(p521_timer);
+ }
+
void bench_bn_redc(const std::chrono::milliseconds runtime)
{
Botan::BigInt p;