diff options
author | Jack Lloyd <[email protected]> | 2018-06-20 11:38:29 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-06-20 11:38:29 -0400 |
commit | ed1c39cee69f935fb03d76e888dffd0a8083d287 (patch) | |
tree | 28fa5dda18ffaa739ccc07305aac9806c7cf4ffd /src/cli | |
parent | 661173d1f8a70133ae2e5bfacefa9d4892aadd94 (diff) |
Avoid a small timing channel in Barrett reduction
No known exploit for this but no point taking chances.
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/speed.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index d549253a7..ebf0fe466 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -1603,29 +1603,31 @@ class Speed final : public Command void bench_bn_redc(const std::chrono::milliseconds runtime) { - Botan::BigInt p; - p.set_bit(521); - p--; + for(size_t bitsize : { 512, 1024, 2048, 4096 }) + { + Botan::BigInt p(rng(), bitsize); - std::unique_ptr<Timer> barrett_timer = make_timer("Barrett"); - std::unique_ptr<Timer> schoolbook_timer = make_timer("Schoolbook"); + std::string bit_str = std::to_string(bitsize); + std::unique_ptr<Timer> barrett_timer = make_timer("Barrett-" + bit_str); + std::unique_ptr<Timer> schoolbook_timer = make_timer("Schoolbook-" + bit_str); - Botan::Modular_Reducer mod_p(p); + Botan::Modular_Reducer mod_p(p); - while(schoolbook_timer->under(runtime)) - { - const Botan::BigInt x(rng(), p.bits() * 2 - 2); + while(schoolbook_timer->under(runtime)) + { + const Botan::BigInt x(rng(), p.bits() * 2 - 2); - const Botan::BigInt r1 = barrett_timer->run( - [&] { return mod_p.reduce(x); }); - const Botan::BigInt r2 = schoolbook_timer->run( - [&] { return x % p; }); + const Botan::BigInt r1 = barrett_timer->run( + [&] { return mod_p.reduce(x); }); + const Botan::BigInt r2 = schoolbook_timer->run( + [&] { return x % p; }); - BOTAN_ASSERT(r1 == r2, "Computed different results"); - } + BOTAN_ASSERT(r1 == r2, "Computed different results"); + } - record_result(barrett_timer); - record_result(schoolbook_timer); + record_result(barrett_timer); + record_result(schoolbook_timer); + } } void bench_inverse_mod(const std::chrono::milliseconds runtime) |