aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-09-05 13:29:06 -0400
committerJack Lloyd <[email protected]>2016-09-05 13:29:06 -0400
commitfd39528f76a03b1308afb99bb4f77f722e212246 (patch)
tree456908c3223777577e382350e8251f12c9cf3e4b /src/cli
parent590365ee98bdbd10d1de990a5044cece45308208 (diff)
parent6b2e3aa24fa29bf7e449372f61a709ab94c0ced5 (diff)
Merge GH #613 NewHope R-LWE key exchange
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/speed.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index c1f3a91e8..f1c193ba6 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -83,6 +83,11 @@
#include <botan/mceliece.h>
#endif
+#if defined(BOTAN_HAS_NEWHOPE) && defined(BOTAN_HAS_CHACHA)
+ #include <botan/newhope.h>
+ #include <botan/chacha.h>
+#endif
+
namespace Botan_CLI {
namespace {
@@ -306,6 +311,7 @@ std::vector<std::string> default_benchmark_list()
"ECDSA",
"Curve25519",
"McEliece",
+ "NEWHOPE"
};
}
@@ -396,6 +402,12 @@ class Speed final : public Command
bench_mceliece(provider, msec);
}
#endif
+#if defined(BOTAN_HAS_NEWHOPE) && defined(BOTAN_HAS_CHACHA)
+ else if(algo == "NEWHOPE")
+ {
+ bench_newhope(provider, msec);
+ }
+#endif
#if defined(BOTAN_HAS_NUMBERTHEORY)
else if(algo == "random_prime")
@@ -1079,6 +1091,71 @@ class Speed final : public Command
}
#endif
+#if defined(BOTAN_HAS_NEWHOPE) && defined(BOTAN_HAS_CHACHA)
+ void bench_newhope(const std::string& provider,
+ std::chrono::milliseconds msec)
+ {
+ const std::string nm = "NEWHOPE";
+
+ Timer keygen_timer(nm, "", "keygen");
+ Timer shareda_timer(nm, "", "shareda");
+ Timer sharedb_timer(nm, "", "sharedb");
+
+ class ChaCha20_RNG : public Botan::RandomNumberGenerator
+ {
+ public:
+ std::string name() const override { return "ChaCha20_RNG"; }
+ void clear() override { /* ignored */ }
+
+ void randomize(uint8_t out[], size_t len) override
+ {
+ Botan::clear_mem(out, len);
+ m_chacha.cipher1(out, len);
+ }
+
+ bool is_seeded() const override { return true; }
+
+ void add_entropy(const uint8_t[], size_t) override { /* ignored */ }
+
+ ChaCha20_RNG(const Botan::secure_vector<uint8_t>& seed)
+ {
+ m_chacha.set_key(seed);
+ }
+
+ private:
+ Botan::ChaCha m_chacha;
+ };
+
+ ChaCha20_RNG nh_rng(rng().random_vec(32));
+
+ while(sharedb_timer.under(msec))
+ {
+ std::vector<uint8_t> send_a(NEWHOPE_SENDABYTES), send_b(NEWHOPE_SENDBBYTES);
+ std::vector<uint8_t> shared_a(32), shared_b(32);
+
+ Botan::newhope_poly sk_a;
+
+ keygen_timer.start();
+ Botan::newhope_keygen(send_a.data(), &sk_a, nh_rng);
+ keygen_timer.stop();
+
+ sharedb_timer.start();
+ Botan::newhope_sharedb(shared_b.data(), send_b.data(), send_a.data(), nh_rng);
+ sharedb_timer.stop();
+
+ shareda_timer.start();
+ Botan::newhope_shareda(shared_a.data(), &sk_a, send_b.data());
+ shareda_timer.stop();
+
+ BOTAN_ASSERT(shared_a == shared_b, "Same derived key");
+ }
+
+ output() << Timer::result_string_ops(keygen_timer);
+ output() << Timer::result_string_ops(shareda_timer);
+ output() << Timer::result_string_ops(sharedb_timer);
+ }
+#endif
+
};
BOTAN_REGISTER_COMMAND("speed", Speed);