aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-06 07:48:55 -0500
committerJack Lloyd <[email protected]>2018-03-06 07:48:55 -0500
commitd1c861c280d973990c25996ab8558e784283325b (patch)
tree0549e4fa6e23378eb08ef0f305097baec4deb71e
parentcdd93a156d249ba721e74ec52bc1c13afc9921b1 (diff)
Extend speed to support ratio of CPU clocks
This is to handle machines (like POWER8) where the CPU clock cycles increment at a slower rate than the actual machine clocks. GH #1460
-rw-r--r--src/cli/speed.cpp319
1 files changed, 173 insertions, 146 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 94dc08eb0..209e8d68a 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -1,5 +1,5 @@
/*
-* (C) 2009,2010,2014,2015,2017 Jack Lloyd
+* (C) 2009,2010,2014,2015,2017,2018 Jack Lloyd
* (C) 2015 Simon Warta (Kullo GmbH)
*
* Botan is released under the Simplified BSD License (see license.txt)
@@ -113,21 +113,18 @@ class Timer final
{
public:
Timer(const std::string& name,
- uint64_t event_mult = 1,
- const std::string& doing = "",
- const std::string& provider = "",
- size_t buf_size = 0)
+ const std::string& provider,
+ const std::string& doing,
+ uint64_t event_mult,
+ size_t buf_size,
+ double clock_cycle_ratio)
: m_name(name + ((provider.empty() || provider == "base") ? "" : " [" + provider + "]"))
, m_doing(doing)
, m_buf_size(buf_size)
, m_event_mult(event_mult)
+ , m_clock_cycle_ratio(clock_cycle_ratio)
{}
- Timer(const std::string& name,
- const std::string& provider,
- const std::string& doing)
- : Timer(name, 1, doing, provider, 0) {}
-
Timer(const Timer& other) = default;
static uint64_t get_system_timestamp_ns()
@@ -283,6 +280,7 @@ class Timer final
std::string m_name, m_doing;
size_t m_buf_size;
uint64_t m_event_mult;
+ double m_clock_cycle_ratio;
// set at runtime
std::string m_custom_msg;
@@ -310,7 +308,7 @@ void Timer::stop()
uint64_t cycles_taken = Timer::get_cpu_cycle_counter() - m_cpu_cycles_start;
if(cycles_taken > 0)
{
- m_cpu_cycles_used += cycles_taken;
+ m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
}
}
@@ -576,7 +574,7 @@ class Speed final : public Command
{
public:
Speed()
- : Command("speed --msec=300 --format=default --provider= --buf-size=1024 --clear-cpuid= --ecc-groups= *algos") {}
+ : Command("speed --msec=500 --format=default --ecc-groups= --provider= --buf-size=1024 --clear-cpuid= --cpu-clock-ratio=1.0 *algos") {}
std::vector<std::string> default_benchmark_list()
{
@@ -681,6 +679,18 @@ class Speed final : public Command
const std::string provider = get_arg("provider");
std::vector<std::string> ecc_groups = Botan::split_on(get_arg("ecc-groups"), ',');
const std::string format = get_arg("format");
+ const std::string clock_ratio = get_arg("cpu-clock-ratio");
+
+ m_clock_cycle_ratio = std::strtod(clock_ratio.c_str(), nullptr);
+
+ /*
+ * This argument is intended to be the ratio between the cycle counter
+ * and the actual machine cycles. It is extremely unlikely that there is
+ * any machine where the cycle counter increments faster than the actual
+ * clock.
+ */
+ if(m_clock_cycle_ratio < 0.0 || m_clock_cycle_ratio > 1.0)
+ throw CLI_Usage_Error("Unlikely CPU clock ratio of " + clock_ratio);
if(format == "table")
m_summary.reset(new Summary);
@@ -952,20 +962,21 @@ class Speed final : public Command
private:
+ double m_clock_cycle_ratio;
std::unique_ptr<Summary> m_summary;
std::unique_ptr<JSON_Output> m_json;
- void record_result(const Timer& t)
+ void record_result(const std::unique_ptr<Timer>& t)
{
if(m_json)
{
- m_json->add(t);
+ m_json->add(*t);
}
else
{
- output() << t.to_string() << std::flush;
+ output() << t->to_string() << std::flush;
if(m_summary)
- m_summary->add(t);
+ m_summary->add(*t);
}
}
@@ -996,17 +1007,33 @@ class Speed final : public Command
}
}
+ std::unique_ptr<Timer> make_timer(const std::string& name,
+ uint64_t event_mult = 1,
+ const std::string& what = "",
+ const std::string& provider = "",
+ size_t buf_size = 0)
+ {
+ return std::unique_ptr<Timer>(
+ new Timer(name, provider, what, event_mult, buf_size, m_clock_cycle_ratio));
+ }
+
+ std::unique_ptr<Timer> make_timer(const std::string& algo,
+ const std::string& provider,
+ const std::string& what)
+ {
+ return make_timer(algo, 1, what, provider, 0);
+ }
+
#if defined(BOTAN_HAS_BLOCK_CIPHER)
void bench_block_cipher(Botan::BlockCipher& cipher,
const std::string& provider,
std::chrono::milliseconds runtime,
const std::vector<size_t>& buf_sizes)
{
-
- Timer ks_timer(cipher.name(), provider, "key schedule");
+ std::unique_ptr<Timer> ks_timer = make_timer(cipher.name(), provider, "key schedule");
const Botan::SymmetricKey key(rng(), cipher.maximum_keylength());
- ks_timer.run([&]() { cipher.set_key(key); });
+ ks_timer->run([&]() { cipher.set_key(key); });
const size_t bs = cipher.block_size();
std::set<size_t> buf_sizes_in_blocks;
@@ -1022,13 +1049,13 @@ class Speed final : public Command
{
std::vector<uint8_t> buffer(buf_size);
- Timer encrypt_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
- Timer decrypt_timer(cipher.name(), buffer.size(), "decrypt", provider, buf_size);
+ std::unique_ptr<Timer> encrypt_timer = make_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
+ std::unique_ptr<Timer> decrypt_timer = make_timer(cipher.name(), buffer.size(), "decrypt", provider, buf_size);
- encrypt_timer.run_until_elapsed(runtime, [&]() { cipher.encrypt(buffer); });
+ encrypt_timer->run_until_elapsed(runtime, [&]() { cipher.encrypt(buffer); });
record_result(encrypt_timer);
- decrypt_timer.run_until_elapsed(runtime, [&]() { cipher.decrypt(buffer); });
+ decrypt_timer->run_until_elapsed(runtime, [&]() { cipher.decrypt(buffer); });
record_result(decrypt_timer);
}
}
@@ -1045,7 +1072,7 @@ class Speed final : public Command
{
Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
- Timer encrypt_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
+ std::unique_ptr<Timer> encrypt_timer = make_timer(cipher.name(), buffer.size(), "encrypt", provider, buf_size);
const Botan::SymmetricKey key(rng(), cipher.maximum_keylength());
cipher.set_key(key);
@@ -1056,9 +1083,9 @@ class Speed final : public Command
cipher.set_iv(iv.begin(), iv.size());
}
- while(encrypt_timer.under(runtime))
+ while(encrypt_timer->under(runtime))
{
- encrypt_timer.run([&]() { cipher.encipher(buffer); });
+ encrypt_timer->run([&]() { cipher.encipher(buffer); });
}
record_result(encrypt_timer);
@@ -1079,8 +1106,8 @@ class Speed final : public Command
{
Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
- Timer timer(hash.name(), buffer.size(), "hash", provider, buf_size);
- timer.run_until_elapsed(runtime, [&]() { hash.update(buffer); hash.final(output.data()); });
+ std::unique_ptr<Timer> timer = make_timer(hash.name(), buffer.size(), "hash", provider, buf_size);
+ timer->run_until_elapsed(runtime, [&]() { hash.update(buffer); hash.final(output.data()); });
record_result(timer);
}
}
@@ -1103,9 +1130,9 @@ class Speed final : public Command
mac.set_key(key);
mac.start(nullptr, 0);
- Timer timer(mac.name(), buffer.size(), "mac", provider, buf_size);
- timer.run_until_elapsed(runtime, [&]() { mac.update(buffer); });
- timer.run([&]() { mac.final(output.data()); });
+ std::unique_ptr<Timer> timer = make_timer(mac.name(), buffer.size(), "mac", provider, buf_size);
+ timer->run_until_elapsed(runtime, [&]() { mac.update(buffer); });
+ timer->run([&]() { mac.final(output.data()); });
record_result(timer);
}
}
@@ -1118,12 +1145,12 @@ class Speed final : public Command
const std::chrono::milliseconds runtime,
const std::vector<size_t>& buf_sizes)
{
- Timer ks_timer(enc.name(), enc.provider(), "key schedule");
+ std::unique_ptr<Timer> ks_timer = make_timer(enc.name(), enc.provider(), "key schedule");
const Botan::SymmetricKey key(rng(), enc.key_spec().maximum_keylength());
- ks_timer.run([&]() { enc.set_key(key); });
- ks_timer.run([&]() { dec.set_key(key); });
+ ks_timer->run([&]() { enc.set_key(key); });
+ ks_timer->run([&]() { dec.set_key(key); });
record_result(ks_timer);
@@ -1131,19 +1158,19 @@ class Speed final : public Command
{
Botan::secure_vector<uint8_t> buffer = rng().random_vec(buf_size);
- Timer encrypt_timer(enc.name(), buffer.size(), "encrypt", enc.provider(), buf_size);
- Timer decrypt_timer(dec.name(), buffer.size(), "decrypt", dec.provider(), buf_size);
+ std::unique_ptr<Timer> encrypt_timer = make_timer(enc.name(), buffer.size(), "encrypt", enc.provider(), buf_size);
+ std::unique_ptr<Timer> decrypt_timer = make_timer(dec.name(), buffer.size(), "decrypt", dec.provider(), buf_size);
Botan::secure_vector<uint8_t> iv = rng().random_vec(enc.default_nonce_length());
if(buf_size >= enc.minimum_final_size())
{
- while(encrypt_timer.under(runtime) && decrypt_timer.under(runtime))
+ while(encrypt_timer->under(runtime) && decrypt_timer->under(runtime))
{
// Must run in this order, or AEADs will reject the ciphertext
- encrypt_timer.run([&]() { enc.start(iv); enc.finish(buffer); });
+ encrypt_timer->run([&]() { enc.start(iv); enc.finish(buffer); });
- decrypt_timer.run([&]() { dec.start(iv); dec.finish(buffer); });
+ decrypt_timer->run([&]() { dec.start(iv); dec.finish(buffer); });
if(iv.size() > 0)
{
@@ -1172,8 +1199,8 @@ class Speed final : public Command
rng.reseed_from_rng(Botan::system_rng(), 256);
#endif
- Timer timer(rng_name, buffer.size(), "generate", "", buf_size);
- timer.run_until_elapsed(runtime, [&]() { rng.randomize(buffer.data(), buffer.size()); });
+ std::unique_ptr<Timer> timer = make_timer(rng_name, buffer.size(), "generate", "", buf_size);
+ timer->run_until_elapsed(runtime, [&]() { rng.randomize(buffer.data(), buffer.size()); });
record_result(timer);
}
}
@@ -1187,8 +1214,8 @@ class Speed final : public Command
size_t entropy_bits = 0;
Botan_Tests::SeedCapturing_RNG rng;
- Timer timer(src, "", "bytes");
- timer.run([&]() { entropy_bits = srcs.poll_just(rng, src); });
+ std::unique_ptr<Timer> timer = make_timer(src, "", "bytes");
+ timer->run([&]() { entropy_bits = srcs.poll_just(rng, src); });
size_t compressed_size = 0;
@@ -1209,7 +1236,7 @@ class Speed final : public Command
std::ostringstream msg;
msg << "Entropy source " << src << " output " << rng.seed_material().size() << " bytes"
- << " estimated entropy " << entropy_bits << " in " << timer.milliseconds() << " ms";
+ << " estimated entropy " << entropy_bits << " in " << timer->milliseconds() << " ms";
if(compressed_size > 0)
{
@@ -1218,7 +1245,7 @@ class Speed final : public Command
msg << " total samples " << rng.samples() << "\n";
- timer.set_custom_msg(msg.str());
+ timer->set_custom_msg(msg.str());
record_result(timer);
}
@@ -1231,8 +1258,8 @@ class Speed final : public Command
{
const Botan::EC_Group group(group_name);
- Timer mult_timer(group_name + " scalar mult");
- Timer blinded_mult_timer(group_name + " blinded scalar mult");
+ std::unique_ptr<Timer> mult_timer = make_timer(group_name + " scalar mult");
+ std::unique_ptr<Timer> blinded_mult_timer = make_timer(group_name + " blinded scalar mult");
const Botan::BigInt scalar(rng(), group.get_p_bits());
const Botan::PointGFp& base_point = group.get_base_point();
@@ -1241,11 +1268,11 @@ class Speed final : public Command
std::vector<Botan::BigInt> ws;
- while(blinded_mult_timer.under(runtime))
+ while(blinded_mult_timer->under(runtime))
{
- const Botan::PointGFp r1 = mult_timer.run([&]() { return base_point * scalar; });
+ const Botan::PointGFp r1 = mult_timer->run([&]() { return base_point * scalar; });
- const Botan::PointGFp r2 = blinded_mult_timer.run(
+ const Botan::PointGFp r2 = blinded_mult_timer->run(
[&]() { return scalar_mult.mul(scalar, group.get_order(), rng(), ws); });
BOTAN_ASSERT_EQUAL(r1, r2, "Same point computed by both methods");
@@ -1258,22 +1285,22 @@ class Speed final : public Command
void bench_os2ecp(const std::vector<std::string>& groups, const std::chrono::milliseconds runtime)
{
- Timer uncmp_timer("OS2ECP uncompressed");
- Timer cmp_timer("OS2ECP compressed");
+ std::unique_ptr<Timer> uncmp_timer = make_timer("OS2ECP uncompressed");
+ std::unique_ptr<Timer> cmp_timer = make_timer("OS2ECP compressed");
for(std::string group_name : groups)
{
const Botan::EC_Group group(group_name);
- while(uncmp_timer.under(runtime) && cmp_timer.under(runtime))
+ while(uncmp_timer->under(runtime) && cmp_timer->under(runtime))
{
const Botan::BigInt k(rng(), 256);
const Botan::PointGFp p = group.get_base_point() * k;
const Botan::secure_vector<uint8_t> os_cmp = Botan::EC2OSP(p, Botan::PointGFp::COMPRESSED);
const Botan::secure_vector<uint8_t> os_uncmp = Botan::EC2OSP(p, Botan::PointGFp::UNCOMPRESSED);
- uncmp_timer.run([&]() { group.OS2ECP(os_uncmp); });
- cmp_timer.run([&]() { group.OS2ECP(os_cmp); });
+ uncmp_timer->run([&]() { group.OS2ECP(os_uncmp); });
+ cmp_timer->run([&]() { group.OS2ECP(os_cmp); });
}
record_result(uncmp_timer);
@@ -1289,8 +1316,8 @@ class Speed final : public Command
{
const Botan::BigInt n = 1000000000000000;
- Timer enc_timer("FPE_FE1 encrypt");
- Timer dec_timer("FPE_FE1 decrypt");
+ std::unique_ptr<Timer> enc_timer = make_timer("FPE_FE1 encrypt");
+ std::unique_ptr<Timer> dec_timer = make_timer("FPE_FE1 decrypt");
const Botan::SymmetricKey key(rng(), 32);
const std::vector<uint8_t> tweak(8); // 8 zeros
@@ -1300,18 +1327,18 @@ class Speed final : public Command
Botan::FPE_FE1 fpe_fe1(n, 3, "HMAC(SHA-256)");
fpe_fe1.set_key(key);
- while(enc_timer.under(runtime))
+ while(enc_timer->under(runtime))
{
- enc_timer.start();
+ enc_timer->start();
x = fpe_fe1.encrypt(x, tweak.data(), tweak.size());
- enc_timer.stop();
+ enc_timer->stop();
}
- for(size_t i = 0; i != enc_timer.events(); ++i)
+ for(size_t i = 0; i != enc_timer->events(); ++i)
{
- dec_timer.start();
+ dec_timer->start();
x = fpe_fe1.decrypt(x, tweak.data(), tweak.size());
- dec_timer.stop();
+ dec_timer->stop();
}
BOTAN_ASSERT(x == 1, "FPE works");
@@ -1325,21 +1352,21 @@ class Speed final : public Command
void bench_rfc3394(const std::chrono::milliseconds runtime)
{
- Timer wrap_timer("RFC3394 AES-256 key wrap");
- Timer unwrap_timer("RFC3394 AES-256 key unwrap");
+ std::unique_ptr<Timer> wrap_timer = make_timer("RFC3394 AES-256 key wrap");
+ std::unique_ptr<Timer> unwrap_timer = make_timer("RFC3394 AES-256 key unwrap");
const Botan::SymmetricKey kek(rng(), 32);
Botan::secure_vector<uint8_t> key(64, 0);
- while(wrap_timer.under(runtime))
+ while(wrap_timer->under(runtime))
{
- wrap_timer.start();
+ wrap_timer->start();
key = Botan::rfc3394_keywrap(key, kek);
- wrap_timer.stop();
+ wrap_timer->stop();
- unwrap_timer.start();
+ unwrap_timer->start();
key = Botan::rfc3394_keyunwrap(key, kek);
- unwrap_timer.stop();
+ unwrap_timer->stop();
key[0] += 1;
}
@@ -1364,13 +1391,13 @@ class Speed final : public Command
const Botan::BigInt random_e(rng(), e_bits);
const Botan::BigInt random_f(rng(), f_bits);
- Timer e_timer(group_bits_str + " short exponent", "", "modexp");
- Timer f_timer(group_bits_str + " full exponent", "", "modexp");
+ std::unique_ptr<Timer> e_timer = make_timer(group_bits_str + " short exponent", "", "modexp");
+ std::unique_ptr<Timer> f_timer = make_timer(group_bits_str + " full exponent", "", "modexp");
- while(f_timer.under(runtime))
+ while(f_timer->under(runtime))
{
- e_timer.run([&]() { Botan::power_mod(group.get_g(), random_e, group.get_p()); });
- f_timer.run([&]() { Botan::power_mod(group.get_g(), random_f, group.get_p()); });
+ e_timer->run([&]() { Botan::power_mod(group.get_g(), random_e, group.get_p()); });
+ f_timer->run([&]() { Botan::power_mod(group.get_g(), random_f, group.get_p()); });
}
record_result(e_timer);
@@ -1386,18 +1413,18 @@ class Speed final : public Command
p.set_bit(521);
p--;
- Timer barrett_timer("Barrett");
- Timer schoolbook_timer("Schoolbook");
+ std::unique_ptr<Timer> barrett_timer = make_timer("Barrett");
+ std::unique_ptr<Timer> schoolbook_timer = make_timer("Schoolbook");
Botan::Modular_Reducer mod_p(p);
- while(schoolbook_timer.under(runtime))
+ while(schoolbook_timer->under(runtime))
{
const Botan::BigInt x(rng(), p.bits() * 2 - 2);
- const Botan::BigInt r1 = barrett_timer.run(
+ const Botan::BigInt r1 = barrett_timer->run(
[&] { return mod_p.reduce(x); });
- const Botan::BigInt r2 = schoolbook_timer.run(
+ const Botan::BigInt r2 = schoolbook_timer->run(
[&] { return x % p; });
BOTAN_ASSERT(r1 == r2, "Computed different results");
@@ -1413,33 +1440,33 @@ class Speed final : public Command
p.set_bit(521);
p--;
- Timer invmod_timer("inverse_euclid");
- Timer monty_timer("montgomery_inverse");
- Timer ct_invmod_timer("ct_inverse_mod");
- Timer powm_timer("exponentiation");
+ std::unique_ptr<Timer> invmod_timer = make_timer("inverse_euclid");
+ std::unique_ptr<Timer> monty_timer = make_timer("montgomery_inverse");
+ std::unique_ptr<Timer> ct_invmod_timer = make_timer("ct_inverse_mod");
+ std::unique_ptr<Timer> powm_timer = make_timer("exponentiation");
Botan::Fixed_Exponent_Power_Mod powm_p(p - 2, p);
- while(invmod_timer.under(runtime))
+ while(invmod_timer->under(runtime))
{
const Botan::BigInt x(rng(), p.bits() - 1);
- const Botan::BigInt x_inv1 = invmod_timer.run([&]
+ const Botan::BigInt x_inv1 = invmod_timer->run([&]
{
return Botan::inverse_euclid(x + p, p);
});
- const Botan::BigInt x_inv2 = monty_timer.run([&]
+ const Botan::BigInt x_inv2 = monty_timer->run([&]
{
return Botan::normalized_montgomery_inverse(x, p);
});
- const Botan::BigInt x_inv3 = ct_invmod_timer.run([&]
+ const Botan::BigInt x_inv3 = ct_invmod_timer->run([&]
{
return Botan::ct_inverse_mod_odd_modulus(x, p);
});
- const Botan::BigInt x_inv4 = powm_timer.run([&]
+ const Botan::BigInt x_inv4 = powm_timer->run([&]
{
return powm_p(x);
});
@@ -1461,17 +1488,17 @@ class Speed final : public Command
for(size_t bits : { 1024, 1536 })
{
- Timer genprime_timer("random_prime " + std::to_string(bits));
- Timer is_prime_timer("is_prime " + std::to_string(bits));
+ std::unique_ptr<Timer> genprime_timer = make_timer("random_prime " + std::to_string(bits));
+ std::unique_ptr<Timer> is_prime_timer = make_timer("is_prime " + std::to_string(bits));
- while(genprime_timer.under(runtime) && is_prime_timer.under(runtime))
+ while(genprime_timer->under(runtime) && is_prime_timer->under(runtime))
{
- const Botan::BigInt p = genprime_timer.run([&]
+ const Botan::BigInt p = genprime_timer->run([&]
{
return Botan::random_prime(rng(), bits, coprime);
});
- const bool ok = is_prime_timer.run([&]
+ const bool ok = is_prime_timer->run([&]
{
return Botan::is_prime(p, rng(), 64, true);
});
@@ -1485,7 +1512,7 @@ class Speed final : public Command
// Now test p+2, p+4, ... which may or may not be prime
for(size_t i = 2; i != 64; i += 2)
{
- is_prime_timer.run([&]() { Botan::is_prime(p, rng(), 64, true); });
+ is_prime_timer->run([&]() { Botan::is_prime(p, rng(), 64, true); });
}
}
@@ -1508,21 +1535,21 @@ class Speed final : public Command
Botan::PK_Encryptor_EME enc(key, rng(), padding, provider);
Botan::PK_Decryptor_EME dec(key, rng(), padding, provider);
- Timer enc_timer(nm + " " + padding, provider, "encrypt");
- Timer dec_timer(nm + " " + padding, provider, "decrypt");
+ std::unique_ptr<Timer> enc_timer = make_timer(nm + " " + padding, provider, "encrypt");
+ std::unique_ptr<Timer> dec_timer = make_timer(nm + " " + padding, provider, "decrypt");
- while(enc_timer.under(msec) || dec_timer.under(msec))
+ while(enc_timer->under(msec) || dec_timer->under(msec))
{
// Generate a new random ciphertext to decrypt
- if(ciphertext.empty() || enc_timer.under(msec))
+ if(ciphertext.empty() || enc_timer->under(msec))
{
plaintext = unlock(rng().random_vec(enc.maximum_input_size()));
- ciphertext = enc_timer.run([&]() { return enc.encrypt(plaintext, rng()); });
+ ciphertext = enc_timer->run([&]() { return enc.encrypt(plaintext, rng()); });
}
- if(dec_timer.under(msec))
+ if(dec_timer->under(msec))
{
- auto dec_pt = dec_timer.run([&]() { return dec.decrypt(ciphertext); });
+ auto dec_pt = dec_timer->run([&]() { return dec.decrypt(ciphertext); });
if(dec_pt != plaintext) // sanity check
{
@@ -1543,13 +1570,13 @@ class Speed final : public Command
{
const std::string kdf = "KDF2(SHA-256)"; // arbitrary choice
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key1(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key1(keygen_timer->run([&]
{
return Botan::create_private_key(algo, rng(), params);
}));
- std::unique_ptr<Botan::Private_Key> key2(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key2(keygen_timer->run([&]
{
return Botan::create_private_key(algo, rng(), params);
}));
@@ -1565,12 +1592,12 @@ class Speed final : public Command
const std::vector<uint8_t> ka1_pub = ka_key1.public_value();
const std::vector<uint8_t> ka2_pub = ka_key2.public_value();
- Timer ka_timer(nm, provider, "key agreements");
+ std::unique_ptr<Timer> ka_timer = make_timer(nm, provider, "key agreements");
- while(ka_timer.under(msec))
+ while(ka_timer->under(msec))
{
- Botan::SymmetricKey symkey1 = ka_timer.run([&]() { return ka1.derive_key(32, ka2_pub); });
- Botan::SymmetricKey symkey2 = ka_timer.run([&]() { return ka2.derive_key(32, ka1_pub); });
+ Botan::SymmetricKey symkey1 = ka_timer->run([&]() { return ka1.derive_key(32, ka2_pub); });
+ Botan::SymmetricKey symkey2 = ka_timer->run([&]() { return ka2.derive_key(32, ka1_pub); });
if(symkey1 != symkey2)
{
@@ -1590,21 +1617,21 @@ class Speed final : public Command
Botan::PK_KEM_Decryptor dec(key, rng(), kdf, provider);
Botan::PK_KEM_Encryptor enc(key, rng(), kdf, provider);
- Timer kem_enc_timer(nm, provider, "KEM encrypt");
- Timer kem_dec_timer(nm, provider, "KEM decrypt");
+ std::unique_ptr<Timer> kem_enc_timer = make_timer(nm, provider, "KEM encrypt");
+ std::unique_ptr<Timer> kem_dec_timer = make_timer(nm, provider, "KEM decrypt");
- while(kem_enc_timer.under(msec) && kem_dec_timer.under(msec))
+ while(kem_enc_timer->under(msec) && kem_dec_timer->under(msec))
{
Botan::secure_vector<uint8_t> encap_key, enc_shared_key;
Botan::secure_vector<uint8_t> salt = rng().random_vec(16);
- kem_enc_timer.start();
+ kem_enc_timer->start();
enc.encrypt(encap_key, enc_shared_key, 64, rng(), salt);
- kem_enc_timer.stop();
+ kem_enc_timer->stop();
- kem_dec_timer.start();
+ kem_dec_timer->start();
Botan::secure_vector<uint8_t> dec_shared_key = dec.decrypt(encap_key, 64, salt);
- kem_dec_timer.stop();
+ kem_dec_timer->stop();
if(enc_shared_key != dec_shared_key)
{
@@ -1626,9 +1653,9 @@ class Speed final : public Command
{
const std::string nm = grp.empty() ? algo : (algo + "-" + grp);
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return Botan::create_private_key(algo, rng(), grp);
}));
@@ -1649,12 +1676,12 @@ class Speed final : public Command
Botan::PK_Signer sig(key, rng(), padding, Botan::IEEE_1363, provider);
Botan::PK_Verifier ver(key, padding, Botan::IEEE_1363, provider);
- Timer sig_timer(nm + " " + padding, provider, "sign");
- Timer ver_timer(nm + " " + padding, provider, "verify");
+ std::unique_ptr<Timer> sig_timer = make_timer(nm + " " + padding, provider, "sign");
+ std::unique_ptr<Timer> ver_timer = make_timer(nm + " " + padding, provider, "verify");
- while(ver_timer.under(msec) || sig_timer.under(msec))
+ while(ver_timer->under(msec) || sig_timer->under(msec))
{
- if(signature.empty() || sig_timer.under(msec))
+ if(signature.empty() || sig_timer->under(msec))
{
/*
Length here is kind of arbitrary, but 48 bytes fits into a single
@@ -1662,15 +1689,15 @@ class Speed final : public Command
*/
message = unlock(rng().random_vec(48));
- signature = sig_timer.run([&]() { return sig.sign_message(message, rng()); });
+ signature = sig_timer->run([&]() { return sig.sign_message(message, rng()); });
bad_signature = signature;
bad_signature[rng().next_byte() % bad_signature.size()] ^= rng().next_nonzero_byte();
}
- if(ver_timer.under(msec))
+ if(ver_timer->under(msec))
{
- const bool verified = ver_timer.run([&]
+ const bool verified = ver_timer->run([&]
{
return ver.verify_message(message, signature);
});
@@ -1680,7 +1707,7 @@ class Speed final : public Command
error_output() << "Correct signature rejected in PK signature bench\n";
}
- const bool verified_bad = ver_timer.run([&]
+ const bool verified_bad = ver_timer->run([&]
{
return ver.verify_message(message, bad_signature);
});
@@ -1705,9 +1732,9 @@ class Speed final : public Command
{
const std::string nm = "RSA-" + std::to_string(keylen);
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return Botan::create_private_key("RSA", rng(), std::to_string(keylen));
}));
@@ -1792,9 +1819,9 @@ class Speed final : public Command
const std::string params =
(bits == 1024) ? "dsa/jce/1024" : ("dsa/botan/" + std::to_string(bits));
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return Botan::create_private_key("DSA", rng(), params);
}));
@@ -1815,9 +1842,9 @@ class Speed final : public Command
const std::string params = "modp/ietf/" + std::to_string(keylen);
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return Botan::create_private_key("ElGamal", rng(), params);
}));
@@ -1879,9 +1906,9 @@ class Speed final : public Command
const std::string nm = "McEliece-" + std::to_string(n) + "," + std::to_string(t) +
" (WF=" + std::to_string(Botan::mceliece_work_factor(n, t)) + ")";
- Timer keygen_timer(nm, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return new Botan::McEliece_PrivateKey(rng(), n, t);
}));
@@ -1907,9 +1934,9 @@ class Speed final : public Command
for(std::string params : xmss_params)
{
- Timer keygen_timer(params, provider, "keygen");
+ std::unique_ptr<Timer> keygen_timer = make_timer(params, provider, "keygen");
- std::unique_ptr<Botan::Private_Key> key(keygen_timer.run([&]
+ std::unique_ptr<Botan::Private_Key> key(keygen_timer->run([&]
{
return Botan::create_private_key("XMSS", rng(), params);
}));
@@ -1927,30 +1954,30 @@ class Speed final : public Command
{
const std::string nm = "NEWHOPE";
- Timer keygen_timer(nm, "", "keygen");
- Timer shareda_timer(nm, "", "shareda");
- Timer sharedb_timer(nm, "", "sharedb");
+ std::unique_ptr<Timer> keygen_timer = make_timer(nm, "", "keygen");
+ std::unique_ptr<Timer> shareda_timer = make_timer(nm, "", "shareda");
+ std::unique_ptr<Timer> sharedb_timer = make_timer(nm, "", "sharedb");
Botan::ChaCha_RNG nh_rng(Botan::secure_vector<uint8_t>(32));
- while(sharedb_timer.under(msec))
+ while(sharedb_timer->under(msec))
{
std::vector<uint8_t> send_a(Botan::NEWHOPE_SENDABYTES), send_b(Botan::NEWHOPE_SENDBBYTES);
std::vector<uint8_t> shared_a(32), shared_b(32);
Botan::newhope_poly sk_a;
- keygen_timer.start();
+ keygen_timer->start();
Botan::newhope_keygen(send_a.data(), &sk_a, nh_rng);
- keygen_timer.stop();
+ keygen_timer->stop();
- sharedb_timer.start();
+ sharedb_timer->start();
Botan::newhope_sharedb(shared_b.data(), send_b.data(), send_a.data(), nh_rng);
- sharedb_timer.stop();
+ sharedb_timer->stop();
- shareda_timer.start();
+ shareda_timer->start();
Botan::newhope_shareda(shared_a.data(), &sk_a, send_b.data());
- shareda_timer.stop();
+ shareda_timer->stop();
BOTAN_ASSERT(shared_a == shared_b, "Same derived key");
}