aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_ecdh.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-01-03 14:15:15 -0500
committerJack Lloyd <[email protected]>2016-01-03 14:15:15 -0500
commit4658f3094d652a012c29837910aef89788654b55 (patch)
treef7b680f22394656921c9826cca36333628cd44fe /src/tests/test_ecdh.cpp
parenta1deceb37da0375c62abeca2411f5e0670a553e8 (diff)
Add ECDH tests
Only has vectors for NIST curves (data taken from NIST CAVS file)
Diffstat (limited to 'src/tests/test_ecdh.cpp')
-rw-r--r--src/tests/test_ecdh.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tests/test_ecdh.cpp b/src/tests/test_ecdh.cpp
new file mode 100644
index 000000000..a6a77fabf
--- /dev/null
+++ b/src/tests/test_ecdh.cpp
@@ -0,0 +1,74 @@
+/*
+* (C) 2015,2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+
+#if defined(BOTAN_HAS_ECDH)
+ #include "test_pubkey.h"
+ #include <botan/pubkey.h>
+ #include <botan/ecdh.h>
+#endif
+
+namespace Botan_Tests {
+
+namespace {
+
+#if defined(BOTAN_HAS_ECDH)
+
+class ECDH_KAT_Tests : public PK_Key_Agreement_Test
+ {
+ public:
+ ECDH_KAT_Tests() : PK_Key_Agreement_Test(
+ "ECDH",
+ "pubkey/ecdh.vec",
+ {"Group", "Secret", "CounterKey", "K"},
+ {"KDF"})
+ {}
+
+ std::string default_kdf(const VarMap&) const override { return "Raw"; }
+
+ std::unique_ptr<Botan::Private_Key> load_our_key(const std::string& group_id,
+ const VarMap& vars) override
+ {
+ Botan::EC_Group group(group_id);
+ const Botan::BigInt secret = get_req_bn(vars, "Secret");
+ std::unique_ptr<Botan::Private_Key> key(new Botan::ECDH_PrivateKey(Test::rng(), group, secret));
+ return key;
+ }
+
+ std::vector<uint8_t> load_their_key(const std::string&, const VarMap& vars) override
+ {
+ return get_req_bin(vars, "CounterKey");
+ }
+ };
+
+class ECDH_Keygen_Tests : public PK_Key_Generation_Test
+ {
+ public:
+ std::vector<std::string> keygen_params() const override
+ {
+ return { "secp256r1", "secp384r1", "secp521r1",
+ "brainpool256r1", "brainpool384r1", "brainpool512r1" };
+ }
+
+ std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng,
+ const std::string& param) const override
+ {
+ Botan::EC_Group group(param);
+ std::unique_ptr<Botan::Private_Key> key(new Botan::ECDH_PrivateKey(rng, group));
+ return key;
+ }
+ };
+
+
+BOTAN_REGISTER_TEST("ecdh_kat", ECDH_KAT_Tests);
+BOTAN_REGISTER_TEST("ecdh_keygen", ECDH_Keygen_Tests);
+
+#endif
+
+}
+
+}