aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-12-08 06:51:10 +0000
committerlloyd <[email protected]>2014-12-08 06:51:10 +0000
commit1b7dbd5ca22f83ac8011dc209d92d2562562c816 (patch)
tree1258dd5cebd6d399b93df09085e2656422ee5c8d
parent42a34f672bfd4737e66d8813d024b6f73fdfcad4 (diff)
Add a basic speed test for McEliece
-rw-r--r--doc/relnotes/1_11_10.rst15
-rw-r--r--src/cmd/speed_pk.cpp71
-rw-r--r--src/lib/pubkey/mce/mce_kem.h10
3 files changed, 89 insertions, 7 deletions
diff --git a/doc/relnotes/1_11_10.rst b/doc/relnotes/1_11_10.rst
index cef271e2a..75c6cbade 100644
--- a/doc/relnotes/1_11_10.rst
+++ b/doc/relnotes/1_11_10.rst
@@ -2,13 +2,14 @@ Version 1.11.10, Not Yet Released
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* An implementation of McEliece code-based public key encryption based
- on INRIA's HyMES was contributed by cryptosource GmbH. The original
- version is LGPL but cryptosource has secured permission to release
- an adaptation under a BSD license. A CCA2-secure KEM scheme is also
- included.
-
- The implementations is further described in
- `http://www.cryptosource.de/docs/mceliece_in_botan.pdf`_.
+ on INRIA's HyMES and secured against a variety of side-channels was
+ contributed by cryptosource GmbH. The original version is LGPL but
+ cryptosource has secured permission to release an adaptation under a
+ BSD license. A CCA2-secure KEM scheme is also included.
+
+ The implementation is further described in
+ http://www.cryptosource.de/docs/mceliece_in_botan.pdf and
+ http://cryptosource.de/news_mce_in_botan_en.html
* Add support for TLS fallback signaling (draft-ietf-tls-downgrade-scsv-00).
Clients will send a fallback SCSV if the version passed to the Client
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;
};