diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/speed.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index e221b1052..ffe10844e 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -381,6 +381,12 @@ class Speed final : public Command bench_curve25519(provider, msec); } #endif +#if defined(BOTAN_HAS_MCELIECE) + else if(algo == "McEliece") + { + bench_mceliece(provider, msec); + } +#endif #if defined(BOTAN_HAS_NUMBERTHEORY) else if(algo == "random_prime") @@ -782,6 +788,41 @@ class Speed final : public Command output() << Timer::result_string_ops(ka_timer); } + void bench_pk_kem(const Botan::Private_Key& key, + const std::string& nm, + const std::string& provider, + const std::string& kdf, + std::chrono::milliseconds msec) + { + Botan::PK_KEM_Decryptor dec(key, kdf, provider); + Botan::PK_KEM_Encryptor enc(key, kdf, provider); + + Timer kem_enc_timer(nm, provider, "KEM encrypt"); + Timer kem_dec_timer(nm, provider, "KEM decrypt"); + + 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(); + enc.encrypt(encap_key, enc_shared_key, 64, rng(), salt); + kem_enc_timer.stop(); + + kem_dec_timer.start(); + Botan::secure_vector<uint8_t> dec_shared_key = dec.decrypt(encap_key, 64, salt); + kem_dec_timer.stop(); + + if(enc_shared_key != dec_shared_key) + { + error_output() << "KEM mismatch in PK bench\n"; + } + } + + output() << Timer::result_string_ops(kem_enc_timer); + output() << Timer::result_string_ops(kem_dec_timer); + } + void bench_pk_sig(const Botan::Private_Key& key, const std::string& nm, const std::string& provider, @@ -950,6 +991,47 @@ class Speed final : public Command } #endif +#if defined(BOTAN_HAS_MCELIECE) + void bench_mceliece(const std::string& provider, + std::chrono::milliseconds msec) + { + /* + SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey + SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey + SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey + SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey + SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey + SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey + */ + + const std::vector<std::pair<size_t, size_t>> mce_params = { + { 2480, 45 }, + { 2960, 57 }, + { 3408, 67 }, + { 4624, 95 }, + { 6624, 115 } + }; + + for(auto params : mce_params) + { + size_t n = params.first; + size_t t = params.second; + + 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<Botan::Private_Key> key(keygen_timer.run([&] { + return new Botan::McEliece_PrivateKey(rng(), n, t); + })); + + output() << Timer::result_string_ops(keygen_timer); + bench_pk_kem(*key, nm, provider, "KDF2(SHA-256)", msec); + } + } +#endif + }; BOTAN_REGISTER_COMMAND("speed", Speed); |