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 /checks | |
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 'checks')
-rw-r--r-- | checks/cvc_tests.cpp | 1 | ||||
-rw-r--r-- | checks/ecdh.cpp | 26 | ||||
-rw-r--r-- | checks/ecdsa.cpp | 89 | ||||
-rw-r--r-- | checks/pk.cpp | 98 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 64 |
5 files changed, 139 insertions, 139 deletions
diff --git a/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 9d7b7290b..5bd671ba6 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -23,7 +23,6 @@ #include <botan/x509cert.h> #include <botan/x509self.h> #include <botan/oids.h> -#include <botan/look_pk.h> #include <botan/cvc_self.h> #include <botan/cvc_cert.h> #include <botan/cvc_ado.h> diff --git a/checks/ecdh.cpp b/checks/ecdh.cpp index 92b2f58e8..a63742f2f 100644 --- a/checks/ecdh.cpp +++ b/checks/ecdh.cpp @@ -17,7 +17,7 @@ #include <iostream> #include <fstream> -#include <botan/look_pk.h> +#include <botan/pubkey.h> #include <botan/ecdh.h> #include <botan/x509self.h> #include <botan/der_enc.h> @@ -39,11 +39,11 @@ void test_ecdh_normal_derivation(RandomNumberGenerator& rng) ECDH_PrivateKey private_b(rng, dom_pars); //public_a.getCurve() - std::auto_ptr<PK_Key_Agreement> ka(get_pk_kas(private_a, "KDF2(SHA-1)")); - std::auto_ptr<PK_Key_Agreement> kb(get_pk_kas(private_b, "KDF2(SHA-1)")); + 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()); + 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) { @@ -70,11 +70,11 @@ void test_ecdh_some_dp(RandomNumberGenerator& rng) ECDH_PrivateKey private_a(rng, dom_pars); ECDH_PrivateKey private_b(rng, dom_pars); - std::auto_ptr<PK_Key_Agreement> ka(get_pk_kas(private_a, "KDF2(SHA-1)")); - std::auto_ptr<PK_Key_Agreement> kb(get_pk_kas(private_b, "KDF2(SHA-1)")); + 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()); + 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()); } @@ -99,11 +99,11 @@ void test_ecdh_der_derivation(RandomNumberGenerator& rng) MemoryVector<byte> key_a = private_a.public_value(); MemoryVector<byte> key_b = private_b.public_value(); - std::auto_ptr<PK_Key_Agreement> ka(get_pk_kas(private_a, "KDF2(SHA-1)")); - std::auto_ptr<PK_Key_Agreement> kb(get_pk_kas(private_b, "KDF2(SHA-1)")); + 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); + 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()); //cout << "key: " << alice_key.as_string() << endl; diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index 036cc4dd1..d46ebb25e 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -11,7 +11,7 @@ #if defined(BOTAN_HAS_ECDSA) #include <botan/botan.h> -#include <botan/look_pk.h> +#include <botan/pubkey.h> #include <botan/ecdsa.h> #include <botan/rsa.h> #include <botan/x509cert.h> @@ -70,12 +70,12 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) { format = "EMSA1_BSI(SHA-1)"; } - std::auto_ptr<PK_Signer> pk_signer(get_pk_signer(priv_key, format)); + PK_Signer pk_signer(priv_key, format); SecureVector<byte> signature; bool sig_exc = false; try { - signature = pk_signer->sign_message(message, rng); + signature = pk_signer.sign_message(message, rng); } catch(Encoding_Error e) { @@ -90,11 +90,10 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) CHECK(!sig_exc); } - if(i==0) // makes no sense to check for sha224 { - std::auto_ptr<PK_Verifier> pk_verifier(get_pk_verifier(priv_key, format)); - bool ver = pk_verifier->verify_message(message, signature); + PK_Verifier pk_verifier(priv_key, format); + bool ver = pk_verifier.verify_message(message, signature); CHECK(ver); } @@ -103,16 +102,16 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) // now check that verification alone fails // sign it with the normal EMSA1 - std::auto_ptr<PK_Signer> pk_signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); - SecureVector<byte> signature = pk_signer->sign_message(message, rng); + PK_Signer pk_signer(priv_key, "EMSA1(SHA-224)"); + SecureVector<byte> signature = pk_signer.sign_message(message, rng); - std::auto_ptr<PK_Verifier> pk_verifier(get_pk_verifier(priv_key, "EMSA1_BSI(SHA-224)")); + PK_Verifier pk_verifier(priv_key, "EMSA1_BSI(SHA-224)"); // verify against EMSA1_BSI // we make sure it doesn't fail because of the invalid signature, // but because of the Encoding_Error - if(pk_verifier->verify_message(message, signature)) + if(pk_verifier.verify_message(message, signature)) std::cout << "Corrupt ECDSA signature verified, should not have\n"; } @@ -163,20 +162,20 @@ void test_sign_then_ver(RandomNumberGenerator& rng) EC_Domain_Params dom_pars(OID("1.3.132.0.8")); ECDSA_PrivateKey ecdsa(rng, dom_pars); - std::auto_ptr<PK_Signer> signer(get_pk_signer(ecdsa, "EMSA1(SHA-1)")); + PK_Signer signer(ecdsa, "EMSA1(SHA-1)"); SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12"); - SecureVector<byte> sig = signer->sign_message(msg, rng); + SecureVector<byte> sig = signer.sign_message(msg, rng); - std::auto_ptr<PK_Verifier> verifier(get_pk_verifier(ecdsa, "EMSA1(SHA-1)")); + PK_Verifier verifier(ecdsa, "EMSA1(SHA-1)"); - bool ok = verifier->verify_message(msg, sig); + bool ok = verifier.verify_message(msg, sig); if(!ok) std::cout << "ERROR: Could not verify ECDSA signature\n"; sig[0]++; - ok = verifier->verify_message(msg, sig); + ok = verifier.verify_message(msg, sig); if(ok) std::cout << "ERROR: Bogus ECDSA signature verified anyway\n"; @@ -192,16 +191,16 @@ bool test_ec_sign(RandomNumberGenerator& rng) ECDSA_PrivateKey priv_key(rng, dom_pars); std::string pem_encoded_key = PKCS8::PEM_encode(priv_key); - std::auto_ptr<PK_Signer> signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); - std::auto_ptr<PK_Verifier> verifier(get_pk_verifier(priv_key, "EMSA1(SHA-224)")); + PK_Signer signer(priv_key, "EMSA1(SHA-224)"); + PK_Verifier verifier(priv_key, "EMSA1(SHA-224)"); for(u32bit i = 0; i != 256; ++i) - signer->update((byte)i); - SecureVector<byte> sig = signer->signature(rng); + signer.update((byte)i); + SecureVector<byte> sig = signer.signature(rng); for(u32bit i = 0; i != 256; ++i) - verifier->update((byte)i); - if(!verifier->check_signature(sig)) + verifier.update((byte)i); + if(!verifier.check_signature(sig)) { std::cout << "ECDSA self-test failed!"; return false; @@ -209,9 +208,9 @@ bool test_ec_sign(RandomNumberGenerator& rng) // now check valid signature, different input for(u32bit i = 1; i != 256; ++i) //starting from 1 - verifier->update((byte)i); + verifier.update((byte)i); - if(verifier->check_signature(sig)) + if(verifier.check_signature(sig)) { std::cout << "ECDSA with bad input passed validation"; return false; @@ -221,9 +220,9 @@ bool test_ec_sign(RandomNumberGenerator& rng) sig[sig.size()/2]++; for(u32bit i = 0; i != 256; ++i) - verifier->update((byte)i); + verifier.update((byte)i); - if(verifier->check_signature(sig)) + if(verifier.check_signature(sig)) { std::cout << "ECDSA with bad signature passed validation"; return false; @@ -363,13 +362,13 @@ void test_curve_registry(RandomNumberGenerator& rng) dom_pars.get_base_point().check_invariants(); ECDSA_PrivateKey ecdsa(rng, dom_pars); - std::auto_ptr<PK_Signer> signer(get_pk_signer(ecdsa, "EMSA1(SHA-1)")); - std::auto_ptr<PK_Verifier> verifier(get_pk_verifier(ecdsa, "EMSA1(SHA-1)")); + PK_Signer signer(ecdsa, "EMSA1(SHA-1)"); + PK_Verifier verifier(ecdsa, "EMSA1(SHA-1)"); SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12"); - SecureVector<byte> sig = signer->sign_message(msg, rng); + SecureVector<byte> sig = signer.sign_message(msg, rng); - if(!verifier->verify_message(msg, sig)) + if(!verifier.verify_message(msg, sig)) std::cout << "Failed testing ECDSA sig for curve " << oids[i] << "\n"; } catch(Invalid_Argument& e) @@ -383,35 +382,43 @@ void test_curve_registry(RandomNumberGenerator& rng) void test_read_pkcs8(RandomNumberGenerator& rng) { std::cout << "." << std::flush; + + SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12"); + try { std::auto_ptr<PKCS8_PrivateKey> loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* ecdsa = dynamic_cast<ECDSA_PrivateKey*>(loaded_key.get()); CHECK_MESSAGE(ecdsa, "the loaded key could not be converted into an ECDSA_PrivateKey"); - std::auto_ptr<PK_Signer> signer(get_pk_signer(*ecdsa, "EMSA1(SHA-1)")); - - SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12"); - SecureVector<byte> sig = signer->sign_message(msg, rng); + PK_Signer signer(*ecdsa, "EMSA1(SHA-1)"); - std::auto_ptr<PK_Verifier> verifier(get_pk_verifier(*ecdsa, "EMSA1(SHA-1)")); + SecureVector<byte> sig = signer.sign_message(msg, rng); - bool ok = verifier->verify_message(msg, sig); + PK_Verifier verifier(*ecdsa, "EMSA1(SHA-1)"); - CHECK_MESSAGE(ok, "generated sig could not be verified positively"); + CHECK_MESSAGE(verifier.verify_message(msg, sig), + "generated sig could not be verified positively"); + } + catch (std::exception& e) + { + std::cout << "Exception in test_read_pkcs8 - " << e.what() << "\n"; + } + try + { std::auto_ptr<PKCS8_PrivateKey> loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); // anew in each test with unregistered domain-parameters ECDSA_PrivateKey* ecdsa_nodp = dynamic_cast<ECDSA_PrivateKey*>(loaded_key_nodp.get()); CHECK_MESSAGE(ecdsa_nodp, "the loaded key could not be converted into an ECDSA_PrivateKey"); - signer.reset(get_pk_signer(*ecdsa_nodp, "EMSA1(SHA-1)")); - verifier.reset(get_pk_verifier(*ecdsa_nodp, "EMSA1(SHA-1)")); + PK_Signer signer(*ecdsa_nodp, "EMSA1(SHA-1)"); + PK_Verifier verifier(*ecdsa_nodp, "EMSA1(SHA-1)"); - SecureVector<byte> signature_nodp = signer->sign_message(msg, rng); + SecureVector<byte> signature_nodp = signer.sign_message(msg, rng); - ok = verifier->verify_message(msg, signature_nodp); - CHECK_MESSAGE(ok, "generated signature could not be verified positively (no_dom)"); + CHECK_MESSAGE(verifier.verify_message(msg, signature_nodp), + "generated signature could not be verified positively (no_dom)"); try { diff --git a/checks/pk.cpp b/checks/pk.cpp index 33d4da0fc..cee298f6b 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -56,7 +56,6 @@ #endif #include <botan/filters.h> -#include <botan/look_pk.h> #include <botan/numthry.h> using namespace Botan; @@ -127,22 +126,21 @@ void validate_save_and_load(const Private_Key* priv_key, } } -void validate_decryption(PK_Decryptor* d, const std::string& algo, +void validate_decryption(PK_Decryptor& d, const std::string& algo, const SecureVector<byte> ctext, const SecureVector<byte> ptext, bool& failure) { - SecureVector<byte> decrypted = d->decrypt(ctext); + SecureVector<byte> decrypted = d.decrypt(ctext); if(decrypted != ptext) { std::cout << "FAILED (decrypt): " << algo << std::endl; dump_data(decrypted, ptext); failure = true; } - delete d; } -void validate_encryption(PK_Encryptor* e, PK_Decryptor* d, +void validate_encryption(PK_Encryptor& e, PK_Decryptor& d, const std::string& algo, const std::string& input, const std::string& random, const std::string& exp, bool& failure) @@ -151,7 +149,7 @@ void validate_encryption(PK_Encryptor* e, PK_Decryptor* d, SecureVector<byte> expected = decode_hex(exp); Fixed_Output_RNG rng(decode_hex(random)); - SecureVector<byte> out = e->encrypt(message, rng); + SecureVector<byte> out = e.encrypt(message, rng); if(out != expected) { std::cout << "FAILED (encrypt): " << algo << std::endl; @@ -160,10 +158,9 @@ void validate_encryption(PK_Encryptor* e, PK_Decryptor* d, } validate_decryption(d, algo, out, message, failure); - delete e; } -void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, +void validate_signature(PK_Verifier& v, PK_Signer& s, const std::string& algo, const std::string& input, const std::string& random, const std::string& exp, bool& failure) { @@ -172,7 +169,7 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, SecureVector<byte> expected = decode_hex(exp); Fixed_Output_RNG rng(decode_hex(random)); - SecureVector<byte> sig = s->sign_message(message, message.size(), rng); + SecureVector<byte> sig = s.sign_message(message, message.size(), rng); if(sig != expected) { @@ -181,7 +178,7 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, failure = true; } - if(!v->verify_message(message, message.size(), sig, sig.size())) + if(!v.verify_message(message, message.size(), sig, sig.size())) { std::cout << "FAILED (verify): " << algo << std::endl; failure = true; @@ -190,24 +187,21 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, /* This isn't a very thorough testing method, but it will hopefully catch any really horrible errors */ sig[0]++; - if(v->verify_message(message, message.size(), sig, sig.size())) + if(v.verify_message(message, message.size(), sig, sig.size())) { std::cout << "FAILED (accepted bad sig): " << algo << std::endl; failure = true; } - - delete v; - delete s; } -void validate_kas(PK_Key_Agreement* kas, const std::string& algo, +void validate_kas(PK_Key_Agreement& kas, const std::string& algo, const SecureVector<byte>& pubkey, const std::string& output, u32bit keylen, bool& failure) { SecureVector<byte> expected = decode_hex(output); - SecureVector<byte> got = kas->derive_key(keylen, - pubkey, pubkey.size()).bits_of(); + SecureVector<byte> got = kas.derive_key(keylen, + pubkey, pubkey.size()).bits_of(); if(got != expected) { @@ -215,8 +209,6 @@ void validate_kas(PK_Key_Agreement* kas, const std::string& algo, dump_data(got, expected); failure = true; } - - delete kas; } u32bit validate_rsa_enc_pkcs8(const std::string& algo, @@ -246,8 +238,8 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo, std::string eme = algo.substr(12, std::string::npos); - PK_Encryptor* e = get_pk_encryptor(*rsapub, eme); - PK_Decryptor* d = get_pk_decryptor(*rsapriv, eme); + PK_Encryptor_MR_with_EME e(*rsapub, eme); + PK_Decryptor_MR_with_EME d(*rsapriv, eme); bool failure = false; validate_encryption(e, d, algo, str[1], str[2], str[3], failure); @@ -273,8 +265,8 @@ u32bit validate_rsa_enc(const std::string& algo, std::string eme = algo.substr(6, std::string::npos); - PK_Encryptor* e = get_pk_encryptor(pubkey, eme); - PK_Decryptor* d = get_pk_decryptor(privkey, eme); + PK_Encryptor_MR_with_EME e(pubkey, eme); + PK_Decryptor_MR_with_EME d(privkey, eme); bool failure = false; validate_encryption(e, d, algo, str[3], str[4], str[5], failure); @@ -299,12 +291,12 @@ u32bit validate_elg_enc(const std::string& algo, std::string eme = algo.substr(8, std::string::npos); - PK_Decryptor* d = get_pk_decryptor(privkey, eme); + PK_Decryptor_MR_with_EME d(privkey, eme); bool failure = false; if(str.size() == 7) { - PK_Encryptor* e = get_pk_encryptor(pubkey, eme); + PK_Encryptor_MR_with_EME e(pubkey, eme); validate_encryption(e, d, algo, str[4], str[5], str[6], failure); } else @@ -333,8 +325,8 @@ u32bit validate_rsa_sig(const std::string& algo, std::string emsa = algo.substr(7, std::string::npos); - PK_Verifier* v = get_pk_verifier(pubkey, emsa); - PK_Signer* s = get_pk_signer(privkey, emsa); + PK_Verifier v(pubkey, emsa); + PK_Signer s(privkey, emsa); bool failure = false; validate_signature(v, s, algo, str[3], str[4], str[5], failure); return (failure ? 1 : 0); @@ -354,13 +346,13 @@ u32bit validate_rsa_ver(const std::string& algo, std::string emsa = algo.substr(6, std::string::npos); - std::auto_ptr<PK_Verifier> v(get_pk_verifier(key, emsa)); + PK_Verifier v(key, emsa); SecureVector<byte> msg = decode_hex(str[2]); SecureVector<byte> sig = decode_hex(str[3]); bool passed = true; - passed = v->verify_message(msg, msg.size(), sig, sig.size()); + passed = v.verify_message(msg, msg.size(), sig, sig.size()); return (passed ? 0 : 1); #endif @@ -386,12 +378,12 @@ u32bit validate_rsa_ver_x509(const std::string& algo, std::string emsa = algo.substr(11, std::string::npos); - std::auto_ptr<PK_Verifier> v(get_pk_verifier(*rsakey, emsa)); + PK_Verifier v(*rsakey, emsa); SecureVector<byte> msg = decode_hex(str[1]); SecureVector<byte> sig = decode_hex(str[2]); - bool passed = v->verify_message(msg, msg.size(), sig, sig.size()); + bool passed = v.verify_message(msg, msg.size(), sig, sig.size()); return (passed ? 0 : 1); #endif @@ -412,13 +404,13 @@ u32bit validate_rw_ver(const std::string& algo, std::string emsa = algo.substr(5, std::string::npos); - std::auto_ptr<PK_Verifier> v(get_pk_verifier(key, emsa)); + PK_Verifier v(key, emsa); SecureVector<byte> msg = decode_hex(str[2]); SecureVector<byte> sig = decode_hex(str[3]); bool passed = true; - passed = v->verify_message(msg, msg.size(), sig, sig.size()); + passed = v.verify_message(msg, msg.size(), sig, sig.size()); return (passed ? 0 : 1); #endif @@ -440,8 +432,8 @@ u32bit validate_rw_sig(const std::string& algo, std::string emsa = algo.substr(3, std::string::npos); - PK_Verifier* v = get_pk_verifier(pubkey, emsa); - PK_Signer* s = get_pk_signer(privkey, emsa); + PK_Verifier v(pubkey, emsa); + PK_Signer s(privkey, emsa); bool failure = false; validate_signature(v, s, algo, str[3], str[4], str[5], failure); @@ -478,8 +470,8 @@ u32bit validate_dsa_sig(const std::string& algo, std::string emsa = algo.substr(4, std::string::npos); - PK_Verifier* v = get_pk_verifier(*dsapub, emsa); - PK_Signer* s = get_pk_signer(*dsapriv, emsa); + PK_Verifier v(*dsapub, emsa); + PK_Signer s(*dsapriv, emsa); bool failure = false; validate_signature(v, s, algo, str[1], str[2], str[3], failure); @@ -503,8 +495,8 @@ u32bit validate_ecdsa_sig(const std::string& algo, std::string emsa = algo.substr(6, std::string::npos); - PK_Verifier* v = get_pk_verifier(ecdsa, emsa); - PK_Signer* s = get_pk_signer(ecdsa, emsa); + PK_Verifier v(ecdsa, emsa); + PK_Signer s(ecdsa, emsa); bool failure = false; validate_signature(v, s, algo, str[2], str[3], str[4], failure); @@ -534,13 +526,13 @@ u32bit validate_dsa_ver(const std::string& algo, std::string emsa = algo.substr(7, std::string::npos); - std::auto_ptr<PK_Verifier> v(get_pk_verifier(*dsakey, emsa)); + PK_Verifier v(*dsakey, emsa); SecureVector<byte> msg = decode_hex(str[1]); SecureVector<byte> sig = decode_hex(str[2]); - v->set_input_format(DER_SEQUENCE); - bool passed = v->verify_message(msg, msg.size(), sig, sig.size()); + v.set_input_format(DER_SEQUENCE); + bool passed = v.verify_message(msg, msg.size(), sig, sig.size()); return (passed ? 0 : 1); #endif @@ -563,8 +555,8 @@ u32bit validate_nr_sig(const std::string& algo, std::string emsa = algo.substr(3, std::string::npos); - PK_Verifier* v = get_pk_verifier(pubkey, emsa); - PK_Signer* s = get_pk_signer(privkey, emsa); + PK_Verifier v(pubkey, emsa); + PK_Signer s(privkey, emsa); bool failure = false; validate_signature(v, s, algo, str[5], str[6], str[7], failure); @@ -594,7 +586,7 @@ u32bit validate_dh(const std::string& algo, if(str.size() == 6) keylen = to_u32bit(str[5]); - PK_Key_Agreement* kas = get_pk_kas(mykey, kdf); + PK_Key_Agreement kas(mykey, kdf); bool failure = false; validate_kas(kas, algo, otherkey.public_value(), @@ -628,17 +620,15 @@ u32bit validate_dlies(const std::string& algo, MessageAuthenticationCode* mac = get_mac(options[1]); u32bit mac_key_len = to_u32bit(options[2]); - PK_Decryptor* d = - new DLIES_Decryptor(to, - get_kdf(options[0]), - mac->clone(), mac_key_len); + DLIES_Encryptor e(from, + get_kdf(options[0]), + mac, mac_key_len); - DLIES_Encryptor* e = - new DLIES_Encryptor(from, - get_kdf(options[0]), - mac, mac_key_len); + DLIES_Decryptor d(to, + get_kdf(options[0]), + mac->clone(), mac_key_len); - e->set_other_key(to.public_value()); + e.set_other_key(to.public_value()); std::string empty = ""; bool failure = false; diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 56df89eb3..0cc1bea3a 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -6,7 +6,6 @@ #include <botan/pkcs8.h> #include <botan/mem_ops.h> -#include <botan/look_pk.h> #include <botan/libstate.h> #include <botan/parsing.h> @@ -215,13 +214,16 @@ void benchmark_rsa(RandomNumberGenerator& rng, while(verify_timer.seconds() < seconds || sig_timer.seconds() < seconds) { - std::auto_ptr<PK_Encryptor> enc(get_pk_encryptor(key, enc_padding)); - std::auto_ptr<PK_Decryptor> dec(get_pk_decryptor(key, enc_padding)); - benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 10000, seconds); + PK_Encryptor_MR_with_EME enc(key, enc_padding); + PK_Decryptor_MR_with_EME dec(key, enc_padding); - std::auto_ptr<PK_Signer> sig(get_pk_signer(key, sig_padding)); - std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, sig_padding)); - benchmark_sig_ver(*ver, *sig, verify_timer, + benchmark_enc_dec(enc, dec, enc_timer, dec_timer, + rng, 10000, seconds); + + PK_Signer sig(key, sig_padding); + PK_Verifier ver(key, sig_padding); + + benchmark_sig_ver(ver, sig, verify_timer, sig_timer, rng, 10000, seconds); } @@ -270,10 +272,11 @@ void benchmark_rw(RandomNumberGenerator& rng, RW_PrivateKey key(rng, keylen); keygen_timer.stop(); - std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding)); - std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, padding)); + PK_Signer sig(key, padding); + PK_Verifier ver(key, padding); - benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); + benchmark_sig_ver(ver, sig, verify_timer, sig_timer, + rng, 10000, seconds); } const std::string nm = "RW-" + to_string(keylen); @@ -325,10 +328,10 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, ECDSA_PrivateKey key(rng, params); keygen_timer.stop(); - std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding)); - std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, padding)); + PK_Signer sig(key, padding); + PK_Verifier ver(key, padding); - benchmark_sig_ver(*ver, *sig, verify_timer, + benchmark_sig_ver(ver, sig, verify_timer, sig_timer, rng, 1000, seconds); } @@ -384,10 +387,10 @@ void benchmark_gost_3410(RandomNumberGenerator& rng, GOST_3410_PrivateKey key(rng, params); keygen_timer.stop(); - std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding)); - std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, padding)); + PK_Signer sig(key, padding); + PK_Verifier ver(key, padding); - benchmark_sig_ver(*ver, *sig, verify_timer, + benchmark_sig_ver(ver, sig, verify_timer, sig_timer, rng, 1000, seconds); } @@ -435,8 +438,8 @@ void benchmark_ecdh(RandomNumberGenerator& rng, ECDH_PrivateKey ecdh2(rng, params); keygen_timer.stop(); - std::auto_ptr<PK_Key_Agreement> ka1(get_pk_kas(ecdh1, "KDF2(SHA-1)")); - std::auto_ptr<PK_Key_Agreement> ka2(get_pk_kas(ecdh2, "KDF2(SHA-1)")); + PK_Key_Agreement ka1(ecdh1, "KDF2(SHA-1)"); + PK_Key_Agreement ka2(ecdh2, "KDF2(SHA-1)"); SymmetricKey secret1, secret2; @@ -446,11 +449,11 @@ void benchmark_ecdh(RandomNumberGenerator& rng, break; kex_timer.start(); - secret1 = ka1->derive_key(32, ecdh2.public_value()); + secret1 = ka1.derive_key(32, ecdh2.public_value()); kex_timer.stop(); kex_timer.start(); - secret2 = ka2->derive_key(32, ecdh1.public_value()); + secret2 = ka2.derive_key(32, ecdh1.public_value()); kex_timer.stop(); if(secret1 != secret2) @@ -502,10 +505,10 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, algo_name = key.algo_name(); keygen_timer.stop(); - std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding)); - std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, padding)); + PK_Signer sig(key, padding); + PK_Verifier ver(key, padding); - benchmark_sig_ver(*ver, *sig, verify_timer, + benchmark_sig_ver(ver, sig, verify_timer, sig_timer, rng, 1000, seconds); } @@ -548,8 +551,8 @@ void benchmark_dh(RandomNumberGenerator& rng, DH_PrivateKey dh2(rng, group); keygen_timer.stop(); - std::auto_ptr<PK_Key_Agreement> ka1(get_pk_kas(dh1, "KDF2(SHA-1)")); - std::auto_ptr<PK_Key_Agreement> ka2(get_pk_kas(dh2, "KDF2(SHA-1)")); + PK_Key_Agreement ka1(dh1, "KDF2(SHA-1)"); + PK_Key_Agreement ka2(dh2, "KDF2(SHA-1)"); SymmetricKey secret1, secret2; @@ -559,11 +562,11 @@ void benchmark_dh(RandomNumberGenerator& rng, break; kex_timer.start(); - secret1 = ka1->derive_key(32, dh2.public_value()); + secret1 = ka1.derive_key(32, dh2.public_value()); kex_timer.stop(); kex_timer.start(); - secret2 = ka2->derive_key(32, dh1.public_value()); + secret2 = ka2.derive_key(32, dh1.public_value()); kex_timer.stop(); if(secret1 != secret2) @@ -672,10 +675,11 @@ void benchmark_elg(RandomNumberGenerator& rng, ElGamal_PrivateKey key(rng, group); keygen_timer.stop(); - std::auto_ptr<PK_Decryptor> dec(get_pk_decryptor(key, padding)); - std::auto_ptr<PK_Encryptor> enc(get_pk_encryptor(key, padding)); + PK_Decryptor_MR_with_EME dec(key, padding); + PK_Encryptor_MR_with_EME enc(key, padding); - benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds); + benchmark_enc_dec(enc, dec, enc_timer, dec_timer, + rng, 1000, seconds); } const std::string nm = algo_name + "-" + to_string(pbits); |