aboutsummaryrefslogtreecommitdiffstats
path: root/checks/ecdh.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 00:46:02 +0000
committerlloyd <[email protected]>2014-01-01 00:46:02 +0000
commit22062aa7636e844621243d582ae4e2938d5a1f93 (patch)
treeb15536fc1922f5136e01e84042a0f83551af35b4 /checks/ecdh.cpp
parent0b11408316f7df4901535bb665631172d2d42fb0 (diff)
Testier
Diffstat (limited to 'checks/ecdh.cpp')
-rw-r--r--checks/ecdh.cpp134
1 files changed, 0 insertions, 134 deletions
diff --git a/checks/ecdh.cpp b/checks/ecdh.cpp
deleted file mode 100644
index 30139b27e..000000000
--- a/checks/ecdh.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
-* ECDH tests
-*
-* (C) 2007 Manuel Hartl ([email protected])
-* 2008 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include "tests.h"
-
-#include "common.h"
-
-#include <iostream>
-#include <fstream>
-
-#include <botan/auto_rng.h>
-#include <botan/pubkey.h>
-#include <botan/ecdh.h>
-#include <botan/x509self.h>
-#include <botan/der_enc.h>
-
-using namespace Botan;
-
-#define CHECK_MESSAGE(expr, print) try { if(!(expr)) { ++fails; std::cout << print << "\n"; } } catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; }
-#define CHECK(expr) try { if(!(expr)) { ++fails; std::cout << #expr << "\n"; } } catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; }
-
-namespace {
-
-size_t test_ecdh_normal_derivation(RandomNumberGenerator& rng)
- {
- size_t fails = 0;
-
- EC_Group dom_pars(OID("1.3.132.0.8"));
-
- ECDH_PrivateKey private_a(rng, dom_pars);
-
- ECDH_PrivateKey private_b(rng, dom_pars); //public_a.getCurve()
-
- PK_Key_Agreement ka(private_a, "KDF2(SHA-1)");
- PK_Key_Agreement kb(private_b, "KDF2(SHA-1)");
-
- SymmetricKey alice_key = ka.derive_key(32, private_b.public_value());
- SymmetricKey bob_key = kb.derive_key(32, private_a.public_value());
-
- if(alice_key != bob_key)
- {
- std::cout << "The two keys didn't match!\n";
- std::cout << "Alice's key was: " << alice_key.as_string() << "\n";
- std::cout << "Bob's key was: " << bob_key.as_string() << "\n";
- ++fails;
- }
-
- return fails;
- }
-
-size_t test_ecdh_some_dp(RandomNumberGenerator& rng)
- {
- size_t fails = 0;
-
- std::vector<std::string> oids;
- oids.push_back("1.2.840.10045.3.1.7");
- oids.push_back("1.3.132.0.8");
- oids.push_back("1.2.840.10045.3.1.1");
-
- for(u32bit i = 0; i< oids.size(); i++)
- {
- OID oid(oids[i]);
- EC_Group dom_pars(oid);
-
- ECDH_PrivateKey private_a(rng, dom_pars);
- ECDH_PrivateKey private_b(rng, dom_pars);
-
- PK_Key_Agreement ka(private_a, "KDF2(SHA-1)");
- PK_Key_Agreement kb(private_b, "KDF2(SHA-1)");
-
- SymmetricKey alice_key = ka.derive_key(32, private_b.public_value());
- SymmetricKey bob_key = kb.derive_key(32, private_a.public_value());
-
- CHECK_MESSAGE(alice_key == bob_key, "different keys - " << "Alice's key was: " << alice_key.as_string() << ", Bob's key was: " << bob_key.as_string());
- }
-
- return fails;
- }
-
-size_t test_ecdh_der_derivation(RandomNumberGenerator& rng)
- {
- size_t fails = 0;
-
- std::vector<std::string> oids;
- oids.push_back("1.2.840.10045.3.1.7");
- oids.push_back("1.3.132.0.8");
- oids.push_back("1.2.840.10045.3.1.1");
-
- for(u32bit i = 0; i< oids.size(); i++)
- {
- OID oid(oids[i]);
- EC_Group dom_pars(oid);
-
- ECDH_PrivateKey private_a(rng, dom_pars);
- ECDH_PrivateKey private_b(rng, dom_pars);
-
- std::vector<byte> key_a = private_a.public_value();
- std::vector<byte> key_b = private_b.public_value();
-
- PK_Key_Agreement ka(private_a, "KDF2(SHA-1)");
- PK_Key_Agreement kb(private_b, "KDF2(SHA-1)");
-
- SymmetricKey alice_key = ka.derive_key(32, key_b);
- SymmetricKey bob_key = kb.derive_key(32, key_a);
-
- CHECK_MESSAGE(alice_key == bob_key, "different keys - " << "Alice's key was: " << alice_key.as_string() << ", Bob's key was: " << bob_key.as_string());
-
- }
-
- return fails;
- }
-
-}
-
-size_t test_ecdh()
- {
- size_t fails = 0;
-
- AutoSeeded_RNG rng;
-
- fails += test_ecdh_normal_derivation(rng);
- fails += test_ecdh_some_dp(rng);
- fails += test_ecdh_der_derivation(rng);
-
- test_report("ECDH", 3, fails);
-
- return fails;
- }