diff options
author | Jack Lloyd <[email protected]> | 2020-06-06 09:36:54 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2020-06-06 09:36:54 -0400 |
commit | 6f7b07686241fb32857a6123a2c307bcb7c2e1f0 (patch) | |
tree | 2eb018995d65c8caa7a3aaffc0404e57205de388 /src/cli | |
parent | 7d8a66de0d6b4a5aef12f0cfd21d8a6bdaa1f44d (diff) |
Minor cleanups to timing_test
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/timing_tests.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/cli/timing_tests.cpp b/src/cli/timing_tests.cpp index 01dd61596..2a07fe164 100644 --- a/src/cli/timing_tests.cpp +++ b/src/cli/timing_tests.cpp @@ -80,18 +80,19 @@ class Timing_Test size_t warmup_runs, size_t measurement_runs); - virtual std::vector<uint8_t> prepare_input(std::string input) + virtual std::vector<uint8_t> prepare_input(const std::string& input) { return Botan::hex_decode(input); } - virtual ticks measure_critical_function(std::vector<uint8_t> input) = 0; + virtual ticks measure_critical_function(const std::vector<uint8_t>& input) = 0; protected: static ticks get_ticks() { // Returns CPU counter or best approximation (monotonic clock of some kind) - return Botan::OS::get_high_resolution_clock(); + //return Botan::OS::get_high_resolution_clock(); + return Botan::OS::get_system_timestamp_ns(); } Botan::RandomNumberGenerator& timing_test_rng() @@ -114,14 +115,14 @@ class Bleichenbacker_Timing_Test final : public Timing_Test , m_enc(m_pubkey, timing_test_rng(), "Raw") , m_dec(m_privkey, timing_test_rng(), "PKCS1v15") {} - std::vector<uint8_t> prepare_input(std::string input) override + std::vector<uint8_t> prepare_input(const std::string& input) override { const std::vector<uint8_t> input_vector = Botan::hex_decode(input); const std::vector<uint8_t> encrypted = m_enc.encrypt(input_vector, timing_test_rng()); return encrypted; } - ticks measure_critical_function(std::vector<uint8_t> input) override + ticks measure_critical_function(const std::vector<uint8_t>& input) override { const ticks start = get_ticks(); m_dec.decrypt_or_random(input.data(), m_ctext_length, m_expected_content_size, timing_test_rng()); @@ -158,14 +159,14 @@ class Manger_Timing_Test final : public Timing_Test , m_enc(m_pubkey, timing_test_rng(), m_encrypt_padding) , m_dec(m_privkey, timing_test_rng(), m_decrypt_padding) {} - std::vector<uint8_t> prepare_input(std::string input) override + std::vector<uint8_t> prepare_input(const std::string& input) override { const std::vector<uint8_t> input_vector = Botan::hex_decode(input); const std::vector<uint8_t> encrypted = m_enc.encrypt(input_vector, timing_test_rng()); return encrypted; } - ticks measure_critical_function(std::vector<uint8_t> input) override + ticks measure_critical_function(const std::vector<uint8_t>& input) override { ticks start = get_ticks(); try @@ -207,8 +208,8 @@ class Lucky13_Timing_Test final : public Timing_Test Botan::MessageAuthenticationCode::create_or_throw("HMAC(" + m_mac_algo + ")"), 16, m_mac_keylen, Botan::TLS::Protocol_Version::TLS_V11, false) {} - std::vector<uint8_t> prepare_input(std::string input) override; - ticks measure_critical_function(std::vector<uint8_t> input) override; + std::vector<uint8_t> prepare_input(const std::string& input) override; + ticks measure_critical_function(const std::vector<uint8_t>& input) override; private: const std::string m_mac_algo; @@ -216,7 +217,7 @@ class Lucky13_Timing_Test final : public Timing_Test Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption m_dec; }; -std::vector<uint8_t> Lucky13_Timing_Test::prepare_input(std::string input) +std::vector<uint8_t> Lucky13_Timing_Test::prepare_input(const std::string& input) { const std::vector<uint8_t> input_vector = Botan::hex_decode(input); const std::vector<uint8_t> key(16); @@ -231,7 +232,7 @@ std::vector<uint8_t> Lucky13_Timing_Test::prepare_input(std::string input) return unlock(buf); } -ticks Lucky13_Timing_Test::measure_critical_function(std::vector<uint8_t> input) +ticks Lucky13_Timing_Test::measure_critical_function(const std::vector<uint8_t>& input) { Botan::secure_vector<uint8_t> data(input.begin(), input.end()); Botan::secure_vector<uint8_t> aad(13); @@ -263,7 +264,7 @@ class ECDSA_Timing_Test final : public Timing_Test public: ECDSA_Timing_Test(std::string ecgroup); - ticks measure_critical_function(std::vector<uint8_t> input) override; + ticks measure_critical_function(const std::vector<uint8_t>& input) override; private: const Botan::EC_Group m_group; @@ -278,7 +279,7 @@ ECDSA_Timing_Test::ECDSA_Timing_Test(std::string ecgroup) , m_x(m_privkey.private_value()) {} -ticks ECDSA_Timing_Test::measure_critical_function(std::vector<uint8_t> input) +ticks ECDSA_Timing_Test::measure_critical_function(const std::vector<uint8_t>& input) { const Botan::BigInt k(input.data(), input.size()); const Botan::BigInt msg(5); // fixed message to minimize noise @@ -310,14 +311,14 @@ class ECC_Mul_Timing_Test final : public Timing_Test m_group(ecgroup) {} - ticks measure_critical_function(std::vector<uint8_t> input) override; + ticks measure_critical_function(const std::vector<uint8_t>& input) override; private: const Botan::EC_Group m_group; std::vector<Botan::BigInt> m_ws; }; -ticks ECC_Mul_Timing_Test::measure_critical_function(std::vector<uint8_t> input) +ticks ECC_Mul_Timing_Test::measure_critical_function(const std::vector<uint8_t>& input) { const Botan::BigInt k(input.data(), input.size()); @@ -341,12 +342,12 @@ class Powmod_Timing_Test final : public Timing_Test { } - ticks measure_critical_function(std::vector<uint8_t> input) override; + ticks measure_critical_function(const std::vector<uint8_t>& input) override; private: Botan::DL_Group m_group; }; -ticks Powmod_Timing_Test::measure_critical_function(std::vector<uint8_t> input) +ticks Powmod_Timing_Test::measure_critical_function(const std::vector<uint8_t>& input) { const Botan::BigInt x(input.data(), input.size()); const size_t max_x_bits = m_group.p_bits(); @@ -372,13 +373,13 @@ class Invmod_Timing_Test final : public Timing_Test m_p = Botan::random_prime(timing_test_rng(), p_bits); } - ticks measure_critical_function(std::vector<uint8_t> input) override; + ticks measure_critical_function(const std::vector<uint8_t>& input) override; private: Botan::BigInt m_p; }; -ticks Invmod_Timing_Test::measure_critical_function(std::vector<uint8_t> input) +ticks Invmod_Timing_Test::measure_critical_function(const std::vector<uint8_t>& input) { const Botan::BigInt k(input.data(), input.size()); @@ -417,10 +418,10 @@ std::vector<std::vector<ticks>> Timing_Test::execute_evaluation( } size_t total_runs = 0; + std::vector<ticks> results(inputs.size()); + while(total_runs < (warmup_runs + measurement_runs)) { - std::vector<ticks> results(inputs.size()); - for(size_t i = 0; i != inputs.size(); ++i) { results[i] = measure_critical_function(inputs[i]); @@ -428,7 +429,7 @@ std::vector<std::vector<ticks>> Timing_Test::execute_evaluation( total_runs++; - if(total_runs >= warmup_runs) + if(total_runs > warmup_runs) { for(size_t i = 0; i != results.size(); ++i) { @@ -445,7 +446,7 @@ class Timing_Test_Command final : public Command public: Timing_Test_Command() : Command("timing_test test_type --test-data-file= --test-data-dir=src/tests/data/timing " - "--warmup-runs=1000 --measurement-runs=10000") {} + "--warmup-runs=5000 --measurement-runs=50000") {} std::string group() const override { |