diff options
author | lloyd <[email protected]> | 2014-12-08 06:51:10 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-08 06:51:10 +0000 |
commit | 1b7dbd5ca22f83ac8011dc209d92d2562562c816 (patch) | |
tree | 1258dd5cebd6d399b93df09085e2656422ee5c8d /src | |
parent | 42a34f672bfd4737e66d8813d024b6f73fdfcad4 (diff) |
Add a basic speed test for McEliece
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/speed_pk.cpp | 71 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mce_kem.h | 10 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/cmd/speed_pk.cpp b/src/cmd/speed_pk.cpp index 6ebb366c5..141248d7d 100644 --- a/src/cmd/speed_pk.cpp +++ b/src/cmd/speed_pk.cpp @@ -12,6 +12,7 @@ #include <botan/parsing.h> #include <botan/oids.h> #include <map> +#include <sstream> #if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO) #include <botan/x509_key.h> @@ -62,6 +63,11 @@ #include <botan/gost_3410.h> #endif +#if defined(BOTAN_HAS_MCELIECE) + #include <botan/mceliece.h> + #include <botan/mce_kem.h> +#endif + using namespace Botan; #include <iostream> @@ -670,6 +676,66 @@ void benchmark_elg(RandomNumberGenerator& rng, } #endif +#if defined(BOTAN_HAS_MCELIECE) +void benchmark_mce(RandomNumberGenerator& rng, + double seconds, + Benchmark_Report& report) + { + const std::vector<std::pair<size_t, size_t>> params = { + { 256, 15 }, + { 512, 33 }, + { 1024, 35 }, + { 2048, 50 }, + { 2960, 56 }, + { 6624, 115 } + }; + + const std::string algo_name = "McEliece"; + const std::string padding = "Raw"; + + for(auto& param : params) + { + Timer keygen_timer("keygen"); + Timer enc_timer(padding + " encrypt"); + Timer dec_timer(padding + " decrypt"); + + keygen_timer.start(); + McEliece_PrivateKey priv_key(rng, param.first, param.second); + McEliece_PublicKey pub_key(priv_key.x509_subject_public_key()); + keygen_timer.stop(); + + McEliece_KEM_Encryptor enc_kem(pub_key); + McEliece_KEM_Decryptor dec_kem(priv_key); + + while(enc_timer.seconds() < seconds || + dec_timer.seconds() < seconds) + { + enc_timer.start(); + auto enc_pair = enc_kem.encrypt(rng); + enc_timer.stop(); + + dec_timer.start(); + auto dec_key = dec_kem.decrypt_vec(enc_pair.first); + dec_timer.stop(); + + BOTAN_ASSERT_EQUAL(enc_pair.second, dec_key, "KEM result matches"); + } + + const std::string nm = algo_name + "-" + + std::to_string(param.first) + "," + + std::to_string(param.second); + + std::ostringstream keysize_report; + keysize_report << "(size " << pub_key.x509_subject_public_key().size() << " pub " + << priv_key.pkcs8_private_key().size() << " priv)"; + + report.report(nm + " " + keysize_report.str(), keygen_timer); + report.report(nm, enc_timer); + report.report(nm, dec_timer); + } + } +#endif + } void bench_pk(RandomNumberGenerator& rng, @@ -752,4 +818,9 @@ void bench_pk(RandomNumberGenerator& rng, if(algo == "All" || algo == "RW") benchmark_rw(rng, seconds, report); #endif + +#if defined(BOTAN_HAS_MCELIECE) + if(algo == "All" || algo == "McEliece") + benchmark_mce(rng, seconds, report); +#endif } diff --git a/src/lib/pubkey/mce/mce_kem.h b/src/lib/pubkey/mce/mce_kem.h index 4e46a0fab..2bb1edba5 100644 --- a/src/lib/pubkey/mce/mce_kem.h +++ b/src/lib/pubkey/mce/mce_kem.h @@ -37,6 +37,16 @@ class BOTAN_DLL McEliece_KEM_Decryptor * returns the derived 512-bit symmetric key */ secure_vector<Botan::byte> decrypt(const byte msg[], size_t msg_len); + + /** + * returns the derived 512-bit symmetric key + */ + template<typename Alloc> + secure_vector<Botan::byte> decrypt_vec(const std::vector<byte, Alloc>& v) + { + return decrypt(&v[0], v.size()); + + } private: McEliece_Private_Operation m_raw_priv_op; }; |