Repository: randombit/botan
Pull request #2124 (2019-09-28 11:53:42)

Add poly_dbl speed util


Patch:
diff --git a/doc/dev_ref/todo.rst b/doc/dev_ref/todo.rst
index e8bf89183..e8e4b7fbc 100644
--- a/doc/dev_ref/todo.rst
+++ b/doc/dev_ref/todo.rst
@@ -200,6 +200,7 @@ CLI
 
 * Add a ``--completion`` option to dump autocomplete info, write
   support for autocompletion in bash/zsh.
+* Refactor ``speed``
 * Change `tls_server` to be a tty<->socket app, like `tls_client` is,
   instead of a bogus echo server.
 * `encrypt` / `decrypt` tools providing password based file encryption
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index d5a23f08c..6c74f8ec3 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -81,6 +81,10 @@
    #include <botan/compression.h>
 #endif
 
+#if defined(BOTAN_HAS_POLY_DBL)
+   #include <botan/internal/poly_dbl.h>
+#endif
+
 #if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
    #include <botan/pkcs8.h>
    #include <botan/pubkey.h>
@@ -668,6 +672,12 @@ class Speed final : public Command
                bench_passhash9();
                }
 #endif
+#if defined(BOTAN_HAS_POLY_DBL)
+            else if(algo == "poly_dbl")
+               {
+               bench_poly_dbl(msec);
+               }
+#endif
 
 #if defined(BOTAN_HAS_DL_GROUP)
             else if(algo == "modexp")
@@ -2111,6 +2121,26 @@ class Speed final : public Command
          }
 #endif
 
+#if defined(BOTAN_HAS_POLY_DBL)
+      void bench_poly_dbl(std::chrono::milliseconds msec)
+         {
+         for(size_t sz : { 8, 16, 24, 32, 64, 128 })
+            {
+            std::unique_ptr<Timer> be_timer = make_timer("poly_dbl_be_" + std::to_string(sz));
+            std::unique_ptr<Timer> le_timer = make_timer("poly_dbl_le_" + std::to_string(sz));
+
+            std::vector<uint8_t> buf(sz);
+            rng().randomize(buf.data(), sz);
+
+            be_timer->run_until_elapsed(msec, [&]() { Botan::poly_double_n(buf.data(), buf.data(), sz); });
+            le_timer->run_until_elapsed(msec, [&]() { Botan::poly_double_n_le(buf.data(), buf.data(), sz); });
+
+            record_result(be_timer);
+            record_result(le_timer);
+            }
+         }
+#endif
+
 #if defined(BOTAN_HAS_BCRYPT)
 
       void bench_bcrypt()
diff --git a/src/lib/utils/poly_dbl/poly_dbl.h b/src/lib/utils/poly_dbl/poly_dbl.h
index 931b4873e..7d9f52331 100644
--- a/src/lib/utils/poly_dbl/poly_dbl.h
+++ b/src/lib/utils/poly_dbl/poly_dbl.h
@@ -14,7 +14,7 @@ namespace Botan {
 /**
 * Polynomial doubling in GF(2^n)
 */
-void BOTAN_PUBLIC_API(2,3) poly_double_n(uint8_t out[], const uint8_t in[], size_t n);
+void BOTAN_TEST_API poly_double_n(uint8_t out[], const uint8_t in[], size_t n);
 
 /**
 * Returns true iff poly_double_n is implemented for this size.
@@ -32,7 +32,7 @@ inline void poly_double_n(uint8_t buf[], size_t n)
 /*
 * Little endian convention - used for XTS
 */
-void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n);
+void BOTAN_TEST_API poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n);
 
 }
 


Test patch:
diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py
index df5e8b9b7..e449bb74f 100755
--- a/src/scripts/test_cli.py
+++ b/src/scripts/test_cli.py
@@ -994,7 +994,7 @@ def cli_speed_tests(_tmp_dir):
 
     # these all have a common output format
     math_ops = ['mp_mul', 'mp_div', 'mp_div10', 'modexp', 'random_prime', 'inverse_mod',
-                'rfc3394', 'fpe_fe1', 'ecdsa_recovery', 'ecc_init',
+                'rfc3394', 'fpe_fe1', 'ecdsa_recovery', 'ecc_init', 'poly_dbl',
                 'bn_redc', 'nistp_redc', 'ecc_mult', 'ecc_ops', 'os2ecp', 'primality_test',
                 'bcrypt', 'passhash9', 'argon2']