aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 03:22:35 +0000
committerlloyd <[email protected]>2010-03-04 03:22:35 +0000
commit76f39cc9fe4b2a3354db22f8beaf0c3788578b79 (patch)
treec25ddaf29f22dc29786487d606d68c2344c46f22 /checks
parentda09382f398dcf27a3ffdb82dd9f916ba96567ac (diff)
Add a new constructor to each public key algorithm (only the public
keys so far, private keys not changed) that takes an AlgorithmIdentifier and a MemoryRegion<byte>&. This performs the X.509 decoding. It is not possible anymore to create uninitialized PK objects.
Diffstat (limited to 'checks')
-rw-r--r--checks/ecdh.cpp58
-rw-r--r--checks/ecdsa.cpp41
2 files changed, 2 insertions, 97 deletions
diff --git a/checks/ecdh.cpp b/checks/ecdh.cpp
index 9341f8432..cb3246ace 100644
--- a/checks/ecdh.cpp
+++ b/checks/ecdh.cpp
@@ -181,8 +181,7 @@ void test_ecdh_cp_ctor_as_op(RandomNumberGenerator& rng)
Botan::ECDH_PublicKey public_a = private_a; // Bob gets this
Botan::ECDH_PublicKey public_a2(public_a);
- Botan::ECDH_PublicKey public_a3;
- public_a3 = public_a;
+ Botan::ECDH_PublicKey public_a3 = public_a;
// Bob creates a key with a matching group
Botan::ECDH_PrivateKey private_b(rng, dom_pars); //public_a.getCurve()
@@ -206,60 +205,6 @@ void test_ecdh_cp_ctor_as_op(RandomNumberGenerator& rng)
CHECK_MESSAGE(alice_key_2 == bob_key_3, "different keys - " << "Alice's key was: " << alice_key.as_string() << ", Bob's key was: " << bob_key.as_string());
}
-/**
-* The following test tests whether ECDH keys exhibit correct behaviour when it is
-* attempted to use them in an uninitialized state
-*/
-void test_non_init_ecdh_keys(RandomNumberGenerator& rng)
- {
- std::cout << "." << std::flush;
-
- // set up dom pars
- std::string g_secp("024a96b5688ef573284664698968c38bb913cbfc82");
- Botan::SecureVector<Botan::byte> sv_g_secp = decode_hex(g_secp);
- BigInt bi_p_secp("0xffffffffffffffffffffffffffffffff7fffffff");
- BigInt bi_a_secp("0xffffffffffffffffffffffffffffffff7ffffffc");
- BigInt bi_b_secp("0x1c97befc54bd7a8b65acf89f81d4d4adc565fa45");
- BigInt order = BigInt("0x0100000000000000000001f4c8f927aed3ca752257");
- CurveGFp curve(bi_p_secp, bi_a_secp, bi_b_secp);
- BigInt cofactor = BigInt(1);
- PointGFp p_G = OS2ECP ( sv_g_secp, curve );
- Botan::EC_Domain_Params dom_pars = Botan::EC_Domain_Params(curve, p_G, order, cofactor);
-
- // alices key (a key constructed by domain parameters IS an emphemeral key!)
- Botan::ECDH_PrivateKey private_a(rng, dom_pars);
- Botan::ECDH_PrivateKey private_b(rng, dom_pars);
-
- Botan::ECDH_PublicKey public_b;
-
- Botan::ECDH_PrivateKey private_empty;
- Botan::ECDH_PublicKey public_empty;
-
- bool exc1 = false;
- try
- {
- Botan::SymmetricKey void_key = private_empty.derive_key(public_b);
- }
- catch (Botan::Exception e)
- {
- exc1 = true;
- }
-
- CHECK_MESSAGE(exc1, "there was no exception thrown when attempting to use an uninitialized ECDH key");
-
- bool exc2 = false;
- try
- {
- Botan::SymmetricKey void_key = private_a.derive_key(public_empty);
- }
- catch (Botan::Exception e)
- {
- exc2 = true;
- }
-
- CHECK_MESSAGE(exc2, "there was no exception thrown when attempting to use an uninitialized ECDH key");
- }
-
}
u32bit do_ecdh_tests(Botan::RandomNumberGenerator& rng)
@@ -270,7 +215,6 @@ u32bit do_ecdh_tests(Botan::RandomNumberGenerator& rng)
test_ecdh_some_dp(rng);
test_ecdh_der_derivation(rng);
test_ecdh_cp_ctor_as_op(rng);
- test_non_init_ecdh_keys(rng);
std::cout << std::endl;
diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp
index 5dcd90efd..64ac4be6b 100644
--- a/checks/ecdsa.cpp
+++ b/checks/ecdsa.cpp
@@ -470,8 +470,7 @@ void test_cp_and_as_ctors(RandomNumberGenerator& rng)
ECDSA_PublicKey pk_1 = cp_priv_key; // pub-key, as-op
ECDSA_PublicKey pk_2(pk_1); // pub-key, cp-ctor
- ECDSA_PublicKey pk_3;
- pk_3 = pk_2; // pub-key, as-op
+ ECDSA_PublicKey pk_3 = pk_2;
bool ver_success_1 = pk_1.verify(sv_message.begin(), sv_message.size(), signature_1.begin(), signature_1.size());
@@ -482,43 +481,6 @@ void test_cp_and_as_ctors(RandomNumberGenerator& rng)
CHECK_MESSAGE((ver_success_1 && ver_success_2 && ver_success_3), "different results for copied keys");
}
-/**
-* The following test tests whether ECDSA keys exhibit correct behaviour when it is
-* attempted to use them in an uninitialized state
-*/
-void test_non_init_ecdsa_keys(RandomNumberGenerator& rng)
- {
- std::cout << "." << std::flush;
-
- std::auto_ptr<PKCS8_PrivateKey> loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng));
-
- std::string str_message = ("12345678901234567890abcdef12");
- ECDSA_PrivateKey empty_priv;
- ECDSA_PublicKey empty_pub;
- SecureVector<byte> sv_message = decode_hex(str_message);
- bool exc1 = false;
- try
- {
- SecureVector<byte> signature_1 = empty_priv.sign(sv_message.begin(), sv_message.size(), rng);
- }
- catch (std::exception e)
- {
- exc1 = true;
- }
- CHECK_MESSAGE(exc1, "there was no exception thrown when attempting to use an uninitialized ECDSA key");
-
- bool exc2 = false;
- try
- {
- empty_pub.verify(sv_message.begin(), sv_message.size(), sv_message.begin(), sv_message.size());
- }
- catch (std::exception e)
- {
- exc2 = true;
- }
- CHECK_MESSAGE(exc2, "there was no exception thrown when attempting to use an uninitialized ECDSA key");
- }
-
}
u32bit do_ecdsa_tests(Botan::RandomNumberGenerator& rng)
@@ -537,7 +499,6 @@ u32bit do_ecdsa_tests(Botan::RandomNumberGenerator& rng)
test_curve_registry(rng);
test_read_pkcs8(rng);
test_cp_and_as_ctors(rng);
- test_non_init_ecdsa_keys(rng);
std::cout << std::endl;