aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-08 19:21:35 -0400
committerJack Lloyd <[email protected]>2018-04-08 19:33:34 -0400
commit0ca00cd6184a9c9e4d6a0dfc8a2488746ee22f23 (patch)
tree5374c6eca54779a3855eac05b7f909c58b649c4d /src/cli
parentc921a1bff2f267dd94f7e4aa8f30341e83d8d52f (diff)
Add BigInt::square plus a speed test for BigInt multiply
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/speed.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index afe75decc..b8397363f 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -23,6 +23,10 @@
#include <botan/internal/os_utils.h>
#include <botan/version.h>
+#if defined(BOTAN_HAS_BIGINT)
+ #include <botan/bigint.h>
+#endif
+
#if defined(BOTAN_HAS_BLOCK_CIPHER)
#include <botan/block_cipher.h>
#endif
@@ -895,6 +899,13 @@ class Speed final : public Command
}
#endif
+#if defined(BOTAN_HAS_BIGINT)
+ else if(algo == "mp_mul")
+ {
+ bench_mp_mul(msec);
+ }
+#endif
+
#if defined(BOTAN_HAS_NUMBERTHEORY)
else if(algo == "random_prime")
{
@@ -1428,6 +1439,42 @@ class Speed final : public Command
}
#endif
+#if defined(BOTAN_HAS_BIGINT)
+
+ void bench_mp_mul(const std::chrono::milliseconds runtime)
+ {
+ std::chrono::milliseconds runtime_per_size = runtime / 9;
+ for(size_t bits : { 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096 })
+ {
+ std::unique_ptr<Timer> mul_timer = make_timer("BigInt mul " + std::to_string(bits));
+ std::unique_ptr<Timer> sqr_timer = make_timer("BigInt sqr " + std::to_string(bits));
+
+ const Botan::BigInt y(rng(), bits);
+ Botan::secure_vector<Botan::word> ws;
+
+ while(mul_timer->under(runtime_per_size))
+ {
+ Botan::BigInt x(rng(), bits);
+
+ sqr_timer->start();
+ x.square(ws);
+ sqr_timer->stop();
+
+ x.mask_bits(bits);
+
+ mul_timer->start();
+ x.mul(y, ws);
+ mul_timer->stop();
+ }
+
+ record_result(mul_timer);
+ record_result(sqr_timer);
+ }
+
+ }
+
+#endif
+
#if defined(BOTAN_HAS_DL_GROUP)
void bench_modexp(const std::chrono::milliseconds runtime)