diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_c25519.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_dh.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_dsa.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_ecdh.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_ecdsa.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_ecgdsa.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_eckcdsa.cpp | 8 | ||||
-rw-r--r-- | src/tests/test_elg.cpp | 10 | ||||
-rw-r--r-- | src/tests/test_gost_3410.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_pubkey.cpp | 185 | ||||
-rw-r--r-- | src/tests/test_pubkey.h | 5 | ||||
-rw-r--r-- | src/tests/test_rsa.cpp | 9 |
12 files changed, 106 insertions, 174 deletions
diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp index fcf63a0be..48fd52b8b 100644 --- a/src/tests/test_c25519.cpp +++ b/src/tests/test_c25519.cpp @@ -112,14 +112,7 @@ class Curve25519_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string&) const override - { - std::unique_ptr<Botan::Private_Key> key(new Botan::Curve25519_PrivateKey(rng)); - return key; - } - + std::string algo_name() const override { return "Curve25519"; } }; BOTAN_REGISTER_TEST("curve25519_scalar", Curve25519_Sclarmult_Tests); diff --git a/src/tests/test_dh.cpp b/src/tests/test_dh.cpp index 8724d92fb..486e6dfe0 100644 --- a/src/tests/test_dh.cpp +++ b/src/tests/test_dh.cpp @@ -91,14 +91,7 @@ class Diffie_Hellman_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "modp/ietf/1024", "modp/ietf/2048" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const override - { - Botan::DL_Group group(param); - std::unique_ptr<Botan::Private_Key> key(new Botan::DH_PrivateKey(rng, group)); - return key; - } + std::string algo_name() const override { return "DH"; } }; diff --git a/src/tests/test_dsa.cpp b/src/tests/test_dsa.cpp index 015a588b3..851665db2 100644 --- a/src/tests/test_dsa.cpp +++ b/src/tests/test_dsa.cpp @@ -56,14 +56,7 @@ class DSA_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "dsa/jce/1024", "dsa/botan/2048" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const override - { - Botan::DL_Group group(param); - std::unique_ptr<Botan::Private_Key> key(new Botan::DSA_PrivateKey(rng, group)); - return key; - } + std::string algo_name() const override { return "DSA"; } }; BOTAN_REGISTER_TEST("dsa_sign", DSA_KAT_Tests); diff --git a/src/tests/test_ecdh.cpp b/src/tests/test_ecdh.cpp index 1ab2c4801..5bdce4144 100644 --- a/src/tests/test_ecdh.cpp +++ b/src/tests/test_ecdh.cpp @@ -53,14 +53,7 @@ class ECDH_Keygen_Tests : public PK_Key_Generation_Test return { "secp256r1", "secp384r1", "secp521r1", "brainpool256r1", "brainpool384r1", "brainpool512r1", "frp256v1" }; } - - 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; - } + std::string algo_name() const override { return "ECDH"; } }; diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp index b668659b4..d8695e37f 100644 --- a/src/tests/test_ecdsa.cpp +++ b/src/tests/test_ecdsa.cpp @@ -65,14 +65,7 @@ class ECDSA_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "secp256r1", "secp384r1", "secp521r1", "frp256v1" }; } - - 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::ECDSA_PrivateKey(rng, group)); - return key; - } + std::string algo_name() const override { return "ECDSA"; } }; BOTAN_REGISTER_TEST("ecdsa_sign", ECDSA_Signature_KAT_Tests); diff --git a/src/tests/test_ecgdsa.cpp b/src/tests/test_ecgdsa.cpp index e566bf045..08c3777b4 100644 --- a/src/tests/test_ecgdsa.cpp +++ b/src/tests/test_ecgdsa.cpp @@ -58,14 +58,7 @@ class ECGDSA_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "secp256r1", "secp384r1", "secp521r1" }; } - - 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::ECGDSA_PrivateKey(rng, group)); - return key; - } + std::string algo_name() const override { return "ECGDSA"; } }; BOTAN_REGISTER_TEST("ecgdsa_sign", ECGDSA_Signature_KAT_Tests); diff --git a/src/tests/test_eckcdsa.cpp b/src/tests/test_eckcdsa.cpp index 5e9978096..c2c391c2f 100644 --- a/src/tests/test_eckcdsa.cpp +++ b/src/tests/test_eckcdsa.cpp @@ -58,13 +58,7 @@ class ECKCDSA_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "secp256r1", "secp384r1", "secp521r1" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const override - { - Botan::EC_Group group(param); - return std::unique_ptr<Botan::Private_Key>(new Botan::ECKCDSA_PrivateKey(rng, group)); - } + std::string algo_name() const override { return "ECKCDSA"; } }; BOTAN_REGISTER_TEST("eckcdsa_sign", ECKCDSA_Signature_KAT_Tests); diff --git a/src/tests/test_elg.cpp b/src/tests/test_elg.cpp index 9c7b95ff7..f740be7f6 100644 --- a/src/tests/test_elg.cpp +++ b/src/tests/test_elg.cpp @@ -44,15 +44,7 @@ class ElGamal_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "modp/ietf/1024", "modp/ietf/2048" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const override - { - Botan::DL_Group group(param); - std::unique_ptr<Botan::Private_Key> key(new Botan::ElGamal_PrivateKey(rng, group)); - return key; - } - + std::string algo_name() const override { return "ElGamal"; } }; BOTAN_REGISTER_TEST("elgamal_encrypt", ElGamal_KAT_Tests); diff --git a/src/tests/test_gost_3410.cpp b/src/tests/test_gost_3410.cpp index 4daa7189e..dffe53d46 100644 --- a/src/tests/test_gost_3410.cpp +++ b/src/tests/test_gost_3410.cpp @@ -47,14 +47,7 @@ class GOST_3410_2001_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "gost_256A", "secp256r1" }; } - - 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::GOST_3410_PrivateKey(rng, group)); - return key; - } + std::string algo_name() const override { return "GOST-34.10"; } }; BOTAN_REGISTER_TEST("gost_3410_verify", GOST_3410_2001_Verification_Tests); diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index 8552e1e51..699a7f2df 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -11,6 +11,7 @@ #include "test_rng.h" #include <botan/pubkey.h> +#include <botan/pk_algs.h> #include <botan/x509_key.h> #include <botan/pkcs8.h> #include <botan/oids.h> @@ -368,116 +369,120 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() for(auto&& param : keygen_params()) { - std::unique_ptr<Botan::Private_Key> key = make_key(Test::rng(), param); + const std::string report_name = algo_name() + (param.empty() ? param : " " + param); - const std::string report_name = key->algo_name() + (param.empty() ? param : " " + param); + Test::Result result(report_name + " keygen"); - results.push_back(test_key(report_name, *key)); - } - return results; - } + result.start_timer(); + std::unique_ptr<Botan::Private_Key> key_p = + Botan::create_private_key(algo_name(), Test::rng(), param); -Test::Result -PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_Key& key) - { - Test::Result result(algo + " keygen"); + const Botan::Private_Key& key = *key_p; - try - { - Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key)); - std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); + // Test PEM public key round trips OK + try + { + Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key)); + std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); - result.confirm("recovered public key from private", loaded.get() != nullptr); - result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip PEM public key", e.what()); - } + result.confirm("recovered public key from private", loaded.get() != nullptr); + result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip PEM public key", e.what()); + } - try - { - Botan::DataSource_Memory data_src(Botan::X509::BER_encode(key)); - std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); + // Test DER public key round trips OK + try + { + Botan::DataSource_Memory data_src(Botan::X509::BER_encode(key)); + std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); - result.confirm("recovered public key from private", loaded.get() != nullptr); - result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip BER public key", e.what()); - } + result.confirm("recovered public key from private", loaded.get() != nullptr); + result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip BER public key", e.what()); + } - try - { - Botan::DataSource_Memory data_src(Botan::PKCS8::PEM_encode(key)); - std::unique_ptr<Botan::Private_Key> loaded( - Botan::PKCS8::load_key(data_src, Test::rng())); + // Test PEM private key round trips OK + try + { + Botan::DataSource_Memory data_src(Botan::PKCS8::PEM_encode(key)); + std::unique_ptr<Botan::Private_Key> loaded( + Botan::PKCS8::load_key(data_src, Test::rng())); - result.confirm("recovered private key from PEM blob", loaded.get() != nullptr); - result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip PEM private key", e.what()); - } + result.confirm("recovered private key from PEM blob", loaded.get() != nullptr); + result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip PEM private key", e.what()); + } - try - { - Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key)); - std::unique_ptr<Botan::Public_Key> loaded(Botan::PKCS8::load_key(data_src, Test::rng())); + try + { + Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key)); + std::unique_ptr<Botan::Public_Key> loaded(Botan::PKCS8::load_key(data_src, Test::rng())); - result.confirm("recovered public key from private", loaded.get() != nullptr); - result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip BER private key", e.what()); - } + result.confirm("recovered public key from private", loaded.get() != nullptr); + result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip BER private key", e.what()); + } - const std::string passphrase = Test::random_password(); + const std::string passphrase = Test::random_password(); - try - { - Botan::DataSource_Memory data_src( - Botan::PKCS8::PEM_encode(key, Test::rng(), passphrase, - std::chrono::milliseconds(10))); + try + { + Botan::DataSource_Memory data_src( + Botan::PKCS8::PEM_encode(key, Test::rng(), passphrase, + std::chrono::milliseconds(10))); - std::unique_ptr<Botan::Private_Key> loaded( - Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); + std::unique_ptr<Botan::Private_Key> loaded( + Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); - result.confirm("recovered private key from encrypted blob", loaded.get() != nullptr); - result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip encrypted PEM private key", e.what()); - } + result.confirm("recovered private key from encrypted blob", loaded.get() != nullptr); + result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip encrypted PEM private key", e.what()); + } - try - { - Botan::DataSource_Memory data_src( - Botan::PKCS8::BER_encode(key, Test::rng(), passphrase, - std::chrono::milliseconds(10))); + try + { + Botan::DataSource_Memory data_src( + Botan::PKCS8::BER_encode(key, Test::rng(), passphrase, + std::chrono::milliseconds(10))); - std::unique_ptr<Botan::Private_Key> loaded( - Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); + std::unique_ptr<Botan::Private_Key> loaded( + Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); - result.confirm("recovered private key from BER blob", loaded.get() != nullptr); - result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); - result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); - } - catch(std::exception& e) - { - result.test_failure("roundtrip encrypted BER private key", e.what()); + result.confirm("recovered private key from BER blob", loaded.get() != nullptr); + result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); + result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(std::exception& e) + { + result.test_failure("roundtrip encrypted BER private key", e.what()); + } + + result.end_timer(); + + results.push_back(result); } - return result; + return results; } } diff --git a/src/tests/test_pubkey.h b/src/tests/test_pubkey.h index b5a79bf55..35457f67a 100644 --- a/src/tests/test_pubkey.h +++ b/src/tests/test_pubkey.h @@ -121,10 +121,7 @@ class PK_Key_Generation_Test : public Test virtual std::vector<std::string> keygen_params() const = 0; - virtual std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const = 0; - private: - Test::Result test_key(const std::string& algo, const Botan::Private_Key& key); + virtual std::string algo_name() const = 0; }; void check_invalid_signatures(Test::Result& result, diff --git a/src/tests/test_rsa.cpp b/src/tests/test_rsa.cpp index 6c89a5b29..0d50193f2 100644 --- a/src/tests/test_rsa.cpp +++ b/src/tests/test_rsa.cpp @@ -106,14 +106,7 @@ class RSA_Keygen_Tests : public PK_Key_Generation_Test { public: std::vector<std::string> keygen_params() const override { return { "1024", "1280" }; } - - std::unique_ptr<Botan::Private_Key> make_key(Botan::RandomNumberGenerator& rng, - const std::string& param) const override - { - size_t bits = Botan::to_u32bit(param); - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(rng, bits)); - return key; - } + std::string algo_name() const override { return "RSA"; } }; BOTAN_REGISTER_TEST("rsa_encrypt", RSA_ES_KAT_Tests); |