diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_pbkdf.cpp | 53 | ||||
-rw-r--r-- | src/tests/test_rng.cpp | 1 | ||||
-rw-r--r-- | src/tests/unit_x509.cpp | 5 |
3 files changed, 58 insertions, 1 deletions
diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp index 32144bd9b..c45cc45de 100644 --- a/src/tests/test_pbkdf.cpp +++ b/src/tests/test_pbkdf.cpp @@ -10,6 +10,10 @@ #include <botan/pbkdf.h> #endif +#if defined(BOTAN_HAS_PGP_S2K) + #include <botan/pgp_s2k.h> +#endif + namespace Botan_Tests { namespace { @@ -53,6 +57,55 @@ BOTAN_REGISTER_TEST("pbkdf", PBKDF_KAT_Tests); #endif +#if defined(BOTAN_HAS_PGP_S2K) + +class PGP_S2K_Iter_Test : public Test + { + public: + std::vector<Test::Result> run() override + { + Test::Result result("PGP_S2K iteration encoding"); + + // The maximum representable iteration count + const size_t max_iter = 65011712; + + result.test_eq("Encoding of large value accepted", + Botan::OpenPGP_S2K::encode_count(max_iter * 2), size_t(255)); + result.test_eq("Encoding of small value accepted", + Botan::OpenPGP_S2K::encode_count(0), size_t(0)); + + for(size_t c = 0; c != 256; ++c) + { + const size_t dec = Botan::OpenPGP_S2K::decode_count(c); + const size_t comp_dec = (16 + (c & 0x0F)) << ((c >> 4) + 6); + result.test_eq("Decoded value matches PGP formula", dec, comp_dec); + } + + uint8_t last_enc = 0; + + for(size_t i = 0; i <= max_iter; i += 64) + { + const uint8_t enc = Botan::OpenPGP_S2K::encode_count(i); + result.test_lte("Encoded value non-decreasing", last_enc, enc); + + /* + The iteration count as encoded may not be exactly the + value requested, but should never be less + */ + const size_t dec = Botan::OpenPGP_S2K::decode_count(enc); + result.test_gte("Decoded value is >= requested", dec, i); + + last_enc = enc; + } + + return std::vector<Test::Result>{result}; + } + }; + +BOTAN_REGISTER_TEST("pgp_s2k_iter", PGP_S2K_Iter_Test); + +#endif + } } diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 8c82b023a..899ed0050 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -598,7 +598,6 @@ BOTAN_REGISTER_TEST("chacha_rng_unit", ChaCha_RNG_Unit_Tests); #endif - #if defined(BOTAN_HAS_AUTO_RNG) class AutoSeeded_RNG_Tests : public Test diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index 89eef51d7..66cbddb36 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -60,6 +60,8 @@ Botan::X509_Cert_Options req_opts1(const std::string& algo) opts.not_before("160101200000Z"); opts.not_after("300101200000Z"); + opts.challenge = "zoom"; + if(algo == "RSA") { opts.constraints = Botan::Key_Constraints(Botan::KEY_ENCIPHERMENT); @@ -389,6 +391,9 @@ Test::Result test_x509_cert(const std::string& sig_algo, const std::string& hash hash_fn, Test::rng()); + result.test_eq("PKCS10 challenge password parsed", + user1_req.challenge_password(), "zoom"); + /* Create user #2's key and cert request */ std::unique_ptr<Botan::Private_Key> user2_key(make_a_private_key(sig_algo)); |