diff options
author | lloyd <[email protected]> | 2010-03-08 15:36:18 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-08 15:36:18 +0000 |
commit | 8a47f6f2bbf169a2ea0853234f81b49070c770df (patch) | |
tree | 2633ed0d927faf23a067aa88d6cceb9de29f0be4 /src/pubkey | |
parent | 05f6d6c8edec9907778f362c927f368140fee6a2 (diff) |
Modify pubkey classes to take names instead of object pointers.
Remove use of look_pk from the source and examples, instead
instantiate classes directly.
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/dlies/dlies.cpp | 11 | ||||
-rw-r--r-- | src/pubkey/dlies/dlies.h | 4 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa.cpp | 8 | ||||
-rw-r--r-- | src/pubkey/elgamal/elgamal.cpp | 9 | ||||
-rw-r--r-- | src/pubkey/keypair/keypair.cpp | 30 | ||||
-rw-r--r-- | src/pubkey/keypair/keypair.h | 8 | ||||
-rw-r--r-- | src/pubkey/nr/nr.cpp | 9 | ||||
-rw-r--r-- | src/pubkey/rsa/rsa.cpp | 12 | ||||
-rw-r--r-- | src/pubkey/rw/rw.cpp | 9 |
9 files changed, 44 insertions, 56 deletions
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp index 2253f84d5..07477fd5d 100644 --- a/src/pubkey/dlies/dlies.cpp +++ b/src/pubkey/dlies/dlies.cpp @@ -6,7 +6,6 @@ */ #include <botan/dlies.h> -#include <botan/look_pk.h> #include <botan/internal/xor_buf.h> namespace Botan { @@ -18,7 +17,7 @@ DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& key, KDF* kdf_obj, MessageAuthenticationCode* mac_obj, u32bit mac_kl) : - ka(get_pk_kas(key, "Raw")), + ka(key, "Raw"), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl) @@ -28,7 +27,6 @@ DLIES_Encryptor::DLIES_Encryptor(const PK_Key_Agreement_Key& key, DLIES_Encryptor::~DLIES_Encryptor() { - delete ka; delete kdf; delete mac; } @@ -48,7 +46,7 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], u32bit length, out.copy(my_key, my_key.size()); out.copy(my_key.size(), in, length); - SecureVector<byte> vz(my_key, ka->derive_key(0, other_key).bits_of()); + SecureVector<byte> vz(my_key, ka.derive_key(0, other_key).bits_of()); const u32bit K_LENGTH = length + mac_keylen; OctetString K = kdf->derive_key(K_LENGTH, vz, vz.size()); @@ -92,7 +90,7 @@ DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& key, KDF* kdf_obj, MessageAuthenticationCode* mac_obj, u32bit mac_kl) : - ka(get_pk_kas(key, "Raw")), + ka(key, "Raw"), kdf(kdf_obj), mac(mac_obj), mac_keylen(mac_kl) @@ -102,7 +100,6 @@ DLIES_Decryptor::DLIES_Decryptor(const PK_Key_Agreement_Key& key, DLIES_Decryptor::~DLIES_Decryptor() { - delete ka; delete kdf; delete mac; } @@ -121,7 +118,7 @@ SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], u32bit length) const SecureVector<byte> C(msg + my_key.size(), CIPHER_LEN); SecureVector<byte> T(msg + my_key.size() + CIPHER_LEN, mac->OUTPUT_LENGTH); - SecureVector<byte> vz(v, ka->derive_key(0, v).bits_of()); + SecureVector<byte> vz(v, ka.derive_key(0, v).bits_of()); const u32bit K_LENGTH = C.size() + mac_keylen; OctetString K = kdf->derive_key(K_LENGTH, vz, vz.size()); diff --git a/src/pubkey/dlies/dlies.h b/src/pubkey/dlies/dlies.h index e8b87a091..fd2cefe4a 100644 --- a/src/pubkey/dlies/dlies.h +++ b/src/pubkey/dlies/dlies.h @@ -35,7 +35,7 @@ class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor SecureVector<byte> other_key, my_key; - PK_Key_Agreement* ka; + PK_Key_Agreement ka; KDF* kdf; MessageAuthenticationCode* mac; u32bit mac_keylen; @@ -59,7 +59,7 @@ class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor SecureVector<byte> my_key; - PK_Key_Agreement* ka; + PK_Key_Agreement ka; KDF* kdf; MessageAuthenticationCode* mac; u32bit mac_keylen; diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp index 1fbc2abc1..bd9641856 100644 --- a/src/pubkey/dsa/dsa.cpp +++ b/src/pubkey/dsa/dsa.cpp @@ -8,7 +8,6 @@ #include <botan/dsa.h> #include <botan/numthry.h> #include <botan/keypair.h> -#include <botan/look_pk.h> namespace Botan { @@ -65,10 +64,9 @@ bool DSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const try { - KeyPair::check_key(rng, - get_pk_signer(*this, "EMSA1(SHA-1)"), - get_pk_verifier(*this, "EMSA1(SHA-1)") - ); + PK_Signer this_signer(*this, "EMSA1(SHA-1)"); + PK_Verifier this_verifier(*this, "EMSA1(SHA-1)"); + KeyPair::check_key(rng, this_signer, this_verifier); } catch(Self_Test_Failure) { diff --git a/src/pubkey/elgamal/elgamal.cpp b/src/pubkey/elgamal/elgamal.cpp index 2abd769e5..6b919d916 100644 --- a/src/pubkey/elgamal/elgamal.cpp +++ b/src/pubkey/elgamal/elgamal.cpp @@ -8,7 +8,6 @@ #include <botan/elgamal.h> #include <botan/numthry.h> #include <botan/keypair.h> -#include <botan/look_pk.h> #include <botan/internal/workfactor.h> namespace Botan { @@ -66,10 +65,12 @@ bool ElGamal_PrivateKey::check_key(RandomNumberGenerator& rng, try { + PK_Encryptor_MR_with_EME this_encryptor(*this, "EME1(SHA-1)"); + PK_Decryptor_MR_with_EME this_decryptor(*this, "EME1(SHA-1)"); + KeyPair::check_key(rng, - get_pk_encryptor(*this, "EME1(SHA-1)"), - get_pk_decryptor(*this, "EME1(SHA-1)") - ); + this_encryptor, + this_decryptor); } catch(Self_Test_Failure) { diff --git a/src/pubkey/keypair/keypair.cpp b/src/pubkey/keypair/keypair.cpp index 486577fc5..d54d8e442 100644 --- a/src/pubkey/keypair/keypair.cpp +++ b/src/pubkey/keypair/keypair.cpp @@ -1,13 +1,11 @@ /* * Keypair Checks -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ #include <botan/keypair.h> -#include <botan/look_pk.h> -#include <memory> namespace Botan { @@ -17,22 +15,20 @@ namespace KeyPair { * Check an encryption key pair for consistency */ void check_key(RandomNumberGenerator& rng, - PK_Encryptor* encryptor, PK_Decryptor* decryptor) + PK_Encryptor& encryptor, + PK_Decryptor& decryptor) { - if(encryptor->maximum_input_size() == 0) + if(encryptor.maximum_input_size() == 0) return; - std::auto_ptr<PK_Encryptor> enc(encryptor); - std::auto_ptr<PK_Decryptor> dec(decryptor); - - SecureVector<byte> message(enc->maximum_input_size() - 1); + SecureVector<byte> message(encryptor.maximum_input_size() - 1); rng.randomize(message, message.size()); - SecureVector<byte> ciphertext = enc->encrypt(message, rng); + SecureVector<byte> ciphertext = encryptor.encrypt(message, rng); if(ciphertext == message) throw Self_Test_Failure("Encryption key pair consistency failure"); - SecureVector<byte> message2 = dec->decrypt(ciphertext); + SecureVector<byte> message2 = decryptor.decrypt(ciphertext); if(message != message2) throw Self_Test_Failure("Encryption key pair consistency failure"); } @@ -41,11 +37,9 @@ void check_key(RandomNumberGenerator& rng, * Check a signature key pair for consistency */ void check_key(RandomNumberGenerator& rng, - PK_Signer* signer, PK_Verifier* verifier) + PK_Signer& signer, + PK_Verifier& verifier) { - std::auto_ptr<PK_Signer> sig(signer); - std::auto_ptr<PK_Verifier> ver(verifier); - SecureVector<byte> message(16); rng.randomize(message, message.size()); @@ -53,18 +47,18 @@ void check_key(RandomNumberGenerator& rng, try { - signature = sig->sign_message(message, rng); + signature = signer.sign_message(message, rng); } catch(Encoding_Error) { return; } - if(!ver->verify_message(message, signature)) + if(!verifier.verify_message(message, signature)) throw Self_Test_Failure("Signature key pair consistency failure"); ++message[0]; - if(ver->verify_message(message, signature)) + if(verifier.verify_message(message, signature)) throw Self_Test_Failure("Signature key pair consistency failure"); } diff --git a/src/pubkey/keypair/keypair.h b/src/pubkey/keypair/keypair.h index b1d5c2da0..22dcca0ea 100644 --- a/src/pubkey/keypair/keypair.h +++ b/src/pubkey/keypair/keypair.h @@ -24,8 +24,8 @@ namespace KeyPair { * @throw Self_Test_Failure if the arguments are not related to each other */ BOTAN_DLL void check_key(RandomNumberGenerator& rng, - PK_Encryptor* enc, - PK_Decryptor* dec); + PK_Encryptor& enc, + PK_Decryptor& dec); /** * Tests whether the specified signer and verifier are related to each other, @@ -37,8 +37,8 @@ BOTAN_DLL void check_key(RandomNumberGenerator& rng, * @throw Self_Test_Failure if the arguments are not related to each other */ BOTAN_DLL void check_key(RandomNumberGenerator& rng, - PK_Signer* sig, - PK_Verifier* ver); + PK_Signer& sig, + PK_Verifier& ver); } diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp index 1fc8630d7..8a1b8c261 100644 --- a/src/pubkey/nr/nr.cpp +++ b/src/pubkey/nr/nr.cpp @@ -8,7 +8,6 @@ #include <botan/nr.h> #include <botan/numthry.h> #include <botan/keypair.h> -#include <botan/look_pk.h> namespace Botan { @@ -71,10 +70,12 @@ bool NR_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const try { + PK_Signer this_signer(*this, "EMSA1(SHA-1)"); + PK_Verifier this_verifier(*this, "EMSA1(SHA-1)"); + KeyPair::check_key(rng, - get_pk_signer(*this, "EMSA1(SHA-1)"), - get_pk_verifier(*this, "EMSA1(SHA-1)") - ); + this_signer, + this_verifier); } catch(Self_Test_Failure) { diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index dc182f36a..984d030ef 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -9,7 +9,6 @@ #include <botan/parsing.h> #include <botan/numthry.h> #include <botan/keypair.h> -#include <botan/look_pk.h> namespace Botan { @@ -57,15 +56,12 @@ bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const try { - KeyPair::check_key(rng, - get_pk_encryptor(*this, "EME1(SHA-1)"), - get_pk_decryptor(*this, "EME1(SHA-1)") - ); + PK_Signer this_signer(*this, "EMSA4(SHA-1)"); + PK_Verifier this_verifier(*this, "EMSA4(SHA-1)"); KeyPair::check_key(rng, - get_pk_signer(*this, "EMSA4(SHA-1)"), - get_pk_verifier(*this, "EMSA4(SHA-1)") - ); + this_signer, + this_verifier); } catch(Self_Test_Failure) { diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp index 7b87ce7df..b2bf2f916 100644 --- a/src/pubkey/rw/rw.cpp +++ b/src/pubkey/rw/rw.cpp @@ -8,7 +8,6 @@ #include <botan/rw.h> #include <botan/numthry.h> #include <botan/keypair.h> -#include <botan/look_pk.h> #include <botan/parsing.h> #include <algorithm> @@ -59,10 +58,12 @@ bool RW_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const try { + PK_Signer this_signer(*this, "EMSA2(SHA-1)"); + PK_Verifier this_verifier(*this, "EMSA2(SHA-1)"); + KeyPair::check_key(rng, - get_pk_signer(*this, "EMSA2(SHA-1)"), - get_pk_verifier(*this, "EMSA2(SHA-1)") - ); + this_signer, + this_verifier); } catch(Self_Test_Failure) { |