diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/main.cpp | 18 | ||||
-rw-r--r-- | src/tests/test_c25519.cpp | 21 | ||||
-rw-r--r-- | src/tests/test_certstor.cpp | 3 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_mceliece.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_name_constraint.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_ocb.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_ocsp.cpp | 2 | ||||
-rw-r--r-- | src/tests/test_otp.cpp | 9 | ||||
-rw-r--r-- | src/tests/test_pubkey.cpp | 58 | ||||
-rw-r--r-- | src/tests/test_rng.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_srp6.cpp | 3 | ||||
-rw-r--r-- | src/tests/test_x509_path.cpp | 2 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 4 | ||||
-rw-r--r-- | src/tests/unit_x509.cpp | 6 |
15 files changed, 121 insertions, 28 deletions
diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 0ddd28dc2..352b74b75 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -52,7 +52,7 @@ class Test_Runner final : public Botan_CLI::Command { std::unique_ptr<Botan::RandomNumberGenerator> rng; -#if defined(BOTAN_HAS_HMAC_DRBG) && defined(BOTAN_HAS_SHA2_64) +#if defined(BOTAN_HAS_HMAC_DRBG) && defined(BOTAN_AUTO_RNG_HMAC) std::vector<uint8_t> seed = Botan::hex_decode(drbg_seed); if(seed.empty()) @@ -62,15 +62,17 @@ class Test_Runner final : public Botan_CLI::Command Botan::store_be(ts, seed.data()); } - output() << " rng:HMAC_DRBG with seed '" << Botan::hex_encode(seed) << "'\n"; + output() << " rng:HMAC_DRBG(" << BOTAN_AUTO_RNG_HMAC << ") with seed '" << Botan::hex_encode(seed) << "'\n"; - // Expand out the seed to 512 bits to make the DRBG happy - std::unique_ptr<Botan::HashFunction> sha512(Botan::HashFunction::create("SHA-512")); - sha512->update(seed); - seed.resize(sha512->output_length()); - sha512->final(seed.data()); + // Expand out the seed with a hash to make the DRBG happy + std::unique_ptr<Botan::MessageAuthenticationCode> mac = + Botan::MessageAuthenticationCode::create(BOTAN_AUTO_RNG_HMAC); - std::unique_ptr<Botan::HMAC_DRBG> drbg(new Botan::HMAC_DRBG("SHA-384")); + mac->set_key(seed); + seed.resize(mac->output_length()); + mac->final(seed.data()); + + std::unique_ptr<Botan::HMAC_DRBG> drbg(new Botan::HMAC_DRBG(std::move(mac))); drbg->initialize_with(seed.data(), seed.size()); #if defined(BOTAN_TARGET_OS_HAS_THREADS) diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp index ccc84a4b0..2c7003e1d 100644 --- a/src/tests/test_c25519.cpp +++ b/src/tests/test_c25519.cpp @@ -38,6 +38,7 @@ class Curve25519_Sclarmult_Tests final : public Text_Based_Test return result; } }; +BOTAN_REGISTER_TEST("curve25519_scalar", Curve25519_Sclarmult_Tests); class Curve25519_Roundtrip_Test final : public Test { @@ -57,6 +58,7 @@ class Curve25519_Roundtrip_Test final : public Test const std::string b_pass = "bob pass"; // Then serialize to encrypted storage +#if defined(BOTAN_HAS_AES) && defined(BOTAN_HAS_GCM) const auto pbe_time = std::chrono::milliseconds(10); const std::string a_priv_pem = Botan::PKCS8::PEM_encode(a_priv_gen, Test::rng(), a_pass, pbe_time); const std::string b_priv_pem = Botan::PKCS8::PEM_encode(b_priv_gen, Test::rng(), b_pass, pbe_time); @@ -67,6 +69,17 @@ class Curve25519_Roundtrip_Test final : public Test std::unique_ptr<Botan::Private_Key> a_priv(Botan::PKCS8::load_key(a_priv_ds, Test::rng(), [a_pass]() { return a_pass; })); std::unique_ptr<Botan::Private_Key> b_priv(Botan::PKCS8::load_key(b_priv_ds, Test::rng(), b_pass)); +#else + const std::string a_priv_pem = Botan::PKCS8::PEM_encode(a_priv_gen); + const std::string b_priv_pem = Botan::PKCS8::PEM_encode(b_priv_gen); + + // Reload back into memory + Botan::DataSource_Memory a_priv_ds(a_priv_pem); + Botan::DataSource_Memory b_priv_ds(b_priv_pem); + + std::unique_ptr<Botan::Private_Key> a_priv(Botan::PKCS8::load_key(a_priv_ds, Test::rng())); + std::unique_ptr<Botan::Private_Key> b_priv(Botan::PKCS8::load_key(b_priv_ds, Test::rng())); +#endif // Export public keys as PEM const std::string a_pub_pem = Botan::X509::PEM_encode(*a_priv); @@ -83,8 +96,8 @@ class Curve25519_Roundtrip_Test final : public Test if(a_pub_key && b_pub_key) { - Botan::PK_Key_Agreement a_ka(*a_priv, Test::rng(), "KDF2(SHA-256)"); - Botan::PK_Key_Agreement b_ka(*b_priv, Test::rng(), "KDF2(SHA-256)"); + Botan::PK_Key_Agreement a_ka(*a_priv, Test::rng(), "Raw"); + Botan::PK_Key_Agreement b_ka(*b_priv, Test::rng(), "Raw"); const std::string context = "shared context value"; Botan::SymmetricKey a_key = a_ka.derive_key(32, b_pub_key->public_value(), context); @@ -108,6 +121,8 @@ class Curve25519_Roundtrip_Test final : public Test } }; +BOTAN_REGISTER_TEST("curve25519_rt", Curve25519_Roundtrip_Test); + class Curve25519_Keygen_Tests final : public PK_Key_Generation_Test { public: @@ -121,8 +136,6 @@ class Curve25519_Keygen_Tests final : public PK_Key_Generation_Test } }; -BOTAN_REGISTER_TEST("curve25519_scalar", Curve25519_Sclarmult_Tests); -BOTAN_REGISTER_TEST("curve25519_rt", Curve25519_Roundtrip_Test); BOTAN_REGISTER_TEST("curve25519_keygen", Curve25519_Keygen_Tests); #endif diff --git a/src/tests/test_certstor.cpp b/src/tests/test_certstor.cpp index 24b905cfd..1bdf28a60 100644 --- a/src/tests/test_certstor.cpp +++ b/src/tests/test_certstor.cpp @@ -21,7 +21,8 @@ namespace Botan_Tests { namespace { -#if defined(BOTAN_HAS_CERTSTOR_SQL) +#if defined(BOTAN_HAS_CERTSTOR_SQL) && defined(BOTAN_HAS_RSA) + struct CertificateAndKey { const Botan::X509_Certificate certificate; diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 34127893d..b639a95b2 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -233,6 +233,7 @@ class FFI_Unit_Tests final : public Test result.test_note("PBKDF timed 10 ms " + std::to_string(iters_10ms) + " iterations " + "100 ms " + std::to_string(iters_100ms) + " iterations"); +#if defined(BOTAN_HAS_KDF2) const std::vector<uint8_t> kdf_secret = Botan::hex_decode("92167440112E"); const std::vector<uint8_t> kdf_salt = Botan::hex_decode("45A9BEDED69163123D0348F5185F61ABFB1BF18D6AEA454F"); const size_t kdf_out_len = 18; @@ -248,6 +249,7 @@ class FFI_Unit_Tests final : public Test { result.test_eq("KDF output", outbuf, "3A5DC9AA1C872B4744515AC2702D6396FC2A"); } +#endif size_t out_len = 64; outstr.resize(out_len); @@ -263,6 +265,7 @@ class FFI_Unit_Tests final : public Test TEST_FFI_FAIL("bad password", botan_bcrypt_is_valid, ("nope", outstr.data())); } +#if defined(BOTAN_HAS_ECDSA) // x509 cert test botan_x509_cert_t cert; if(TEST_FFI_OK(botan_x509_cert_load_file, (&cert, Test::data_file("ecc/CSCA.CSCA.csca-germany.1.crt").c_str()))) @@ -358,6 +361,7 @@ class FFI_Unit_Tests final : public Test TEST_FFI_OK(botan_x509_cert_destroy, (cert)); } +#endif std::vector<Test::Result> results; results.push_back(ffi_test_errors()); diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp index 7f27e844b..bcc467344 100644 --- a/src/tests/test_mceliece.cpp +++ b/src/tests/test_mceliece.cpp @@ -32,7 +32,7 @@ namespace { #if defined(BOTAN_HAS_MCELIECE) -#if defined(BOTAN_HAS_HMAC_DRBG) +#if defined(BOTAN_HAS_HMAC_DRBG) && defined(BOTAN_HAS_SHA2_32) && defined(BOTAN_HASH_SHA2_64) class McEliece_Keygen_Encrypt_Test final : public Text_Based_Test { public: @@ -117,6 +117,9 @@ class McEliece_Keygen_Encrypt_Test final : public Text_Based_Test BOTAN_REGISTER_TEST("mce_keygen", McEliece_Keygen_Encrypt_Test); #endif + +#if defined(BOTAN_HAS_SHA2_32) + class McEliece_Tests final : public Test { public: @@ -190,7 +193,9 @@ class McEliece_Tests final : public Test results.push_back(result); +#if defined(BOTAN_HAS_KDF2) results.push_back(test_kem(sk, pk)); +#endif #if defined(BOTAN_HAS_MCEIES) results.push_back(test_mceies(sk, pk)); @@ -280,6 +285,8 @@ BOTAN_REGISTER_TEST("mceliece", McEliece_Tests); #endif +#endif + } } diff --git a/src/tests/test_name_constraint.cpp b/src/tests/test_name_constraint.cpp index 46ebaa466..62c014fde 100644 --- a/src/tests/test_name_constraint.cpp +++ b/src/tests/test_name_constraint.cpp @@ -17,7 +17,7 @@ namespace Botan_Tests { namespace { -#if defined(BOTAN_HAS_X509_CERTIFICATES) +#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_HAS_RSA) class Name_Constraint_Tests final : public Test { diff --git a/src/tests/test_ocb.cpp b/src/tests/test_ocb.cpp index 177365409..8fc41c6c6 100644 --- a/src/tests/test_ocb.cpp +++ b/src/tests/test_ocb.cpp @@ -166,8 +166,12 @@ class OCB_Wide_Long_KAT_Tests final : public Text_Based_Test if(algo == "SHACAL2") { +#if defined(BOTAN_HAS_SHACAL2) cipher = Botan::BlockCipher::create_or_throw("SHACAL2"); bs = 32; +#else + return {result}; +#endif } else { diff --git a/src/tests/test_ocsp.cpp b/src/tests/test_ocsp.cpp index 542b4b575..bcf0e517d 100644 --- a/src/tests/test_ocsp.cpp +++ b/src/tests/test_ocsp.cpp @@ -15,7 +15,7 @@ namespace Botan_Tests { -#if defined(BOTAN_HAS_OCSP) +#if defined(BOTAN_HAS_OCSP) && defined(BOTAN_HAS_RSA) class OCSP_Tests final : public Test { diff --git a/src/tests/test_otp.cpp b/src/tests/test_otp.cpp index dfe01aa93..9bd4c0f18 100644 --- a/src/tests/test_otp.cpp +++ b/src/tests/test_otp.cpp @@ -6,6 +6,7 @@ */ #include "tests.h" +#include <botan/hash.h> #if defined(BOTAN_HAS_HOTP) #include <botan/parsing.h> @@ -34,6 +35,10 @@ class HOTP_KAT_Tests final : public Text_Based_Test { Test::Result result("HOTP " + hash_algo); + std::unique_ptr<Botan::HashFunction> hash_test = Botan::HashFunction::create(hash_algo); + if(!hash_test) + return {result}; + const std::vector<uint8_t> key = get_req_bin(vars, "Key"); const size_t otp = get_req_sz(vars, "OTP"); const uint64_t counter = get_req_sz(vars, "Counter"); @@ -85,6 +90,10 @@ class TOTP_KAT_Tests final : public Text_Based_Test { Test::Result result("TOTP " + hash_algo); + std::unique_ptr<Botan::HashFunction> hash_test = Botan::HashFunction::create(hash_algo); + if(!hash_test) + return {result}; + const std::vector<uint8_t> key = get_req_bin(vars, "Key"); const size_t otp = get_req_sz(vars, "OTP"); const size_t digits = get_req_sz(vars, "Digits"); diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index 3859fcf8f..b3038ca0c 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -454,7 +454,11 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() const Botan::Private_Key& key = *key_p; - result.confirm("Key passes self tests", key.check_key(Test::rng(), true)); + try + { + result.confirm("Key passes self tests", key.check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} result.test_gte("Key has reasonable estimated strength (lower)", key.estimated_strength(), 64); result.test_lt("Key has reasonable estimated strength (upper)", key.estimated_strength(), 512); @@ -467,7 +471,12 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() 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); + + try + { + result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { @@ -482,7 +491,12 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() 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); + + try + { + result.confirm("public key passes self tests", loaded->check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { @@ -498,7 +512,12 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() 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); + + try + { + result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { @@ -512,27 +531,39 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() 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); + try + { + result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip BER private key", e.what()); } +#if defined(BOTAN_HAS_PKCS5_PBE2) && defined(BOTAN_HAS_AES) && defined(BOTAN_HAS_SHA2_32) + + const std::string pbe_algo = "PBE-PKCS5v20(AES-128,SHA-256)"; 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))); + std::chrono::milliseconds(10), + pbe_algo)); 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); + try + { + result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { @@ -543,21 +574,28 @@ std::vector<Test::Result> PK_Key_Generation_Test::run() { Botan::DataSource_Memory data_src( Botan::PKCS8::BER_encode(key, Test::rng(), passphrase, - std::chrono::milliseconds(10))); + std::chrono::milliseconds(10), + pbe_algo)); 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); + + try + { + result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); + } + catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip encrypted BER private key", e.what()); } - +#endif } + result.end_timer(); results.push_back(result); diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 51d636693..e018349c0 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -8,6 +8,10 @@ #include "tests.h" #include "test_rng.h" +#if defined(BOTAN_HAS_STATEFUL_RNG) + #include <botan/stateful_rng.h> +#endif + #if defined(BOTAN_HAS_HMAC_DRBG) #include <botan/hmac_drbg.h> #endif diff --git a/src/tests/test_srp6.cpp b/src/tests/test_srp6.cpp index 741e9ef46..831df1b82 100644 --- a/src/tests/test_srp6.cpp +++ b/src/tests/test_srp6.cpp @@ -14,7 +14,8 @@ namespace Botan_Tests { namespace { -#if defined(BOTAN_HAS_SRP6) +#if defined(BOTAN_HAS_SRP6) && defined(BOTAN_HAS_SHA2_32) + class SRP6_Unit_Tests final : public Test { public: diff --git a/src/tests/test_x509_path.cpp b/src/tests/test_x509_path.cpp index e805a29b3..e31d3265c 100644 --- a/src/tests/test_x509_path.cpp +++ b/src/tests/test_x509_path.cpp @@ -23,7 +23,7 @@ namespace Botan_Tests { namespace { -#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) +#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_HAS_RSA) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) std::map<std::string, std::string> read_results(const std::string& results_file) { diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index f46b94295..212a19dc4 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -860,6 +860,8 @@ class ECC_Unit_Tests final : public Test BOTAN_REGISTER_TEST("ecc_unit", ECC_Unit_Tests); +#if defined(BOTAN_HAS_ECDSA) + class ECC_Invalid_Key_Tests final : public Text_Based_Test { public: @@ -890,6 +892,8 @@ BOTAN_REGISTER_TEST("ecc_invalid", ECC_Invalid_Key_Tests); #endif +#endif + } } diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index bf17fda3f..b9aa1709e 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -996,6 +996,12 @@ Test::Result test_hashes(const std::string& algo, const std::string& hash_fn = " const std::unique_ptr<Botan::Private_Key> key(make_a_private_key(algo)); + if(!key) + { + result.test_note("Skipping due to missing signature algorithm: " + algo); + return result; + } + struct TestData { const std::string issuer, subject, issuer_hash, subject_hash; |