From 45fa74db0a273f9ad36b1496c59b5caaaa1e6874 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 18 Apr 2018 12:01:47 -0400 Subject: Add cycle counter for NIST reduction --- src/cli/speed.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src') 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 #include #include + #include #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 ws; + + auto runtime = total_runtime / 5; + + std::unique_ptr 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 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 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 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 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; -- cgit v1.2.3