diff options
author | Matej Kenda <[email protected]> | 2015-11-19 16:51:27 +0100 |
---|---|---|
committer | Matej Kenda <[email protected]> | 2015-11-19 16:51:27 +0100 |
commit | fb103b7d1fe333b3d7424a36ea2f9b90df8b49ef (patch) | |
tree | 4606a4ba9cc981cc0d975f0ec7724d060424e5e1 /src/tests/test_pubkey.h | |
parent | 94d89769739ebe05e048f217b03672fb0c336fca (diff) | |
parent | 9bff61f4c577661bf4a62a860baf190d4ea8ed6a (diff) |
Merge branch 'master' of github.com:randombit/botan into fix_algo_registry_locking_windows
Diffstat (limited to 'src/tests/test_pubkey.h')
-rw-r--r-- | src/tests/test_pubkey.h | 137 |
1 files changed, 104 insertions, 33 deletions
diff --git a/src/tests/test_pubkey.h b/src/tests/test_pubkey.h index e1197a61b..a5a1c2799 100644 --- a/src/tests/test_pubkey.h +++ b/src/tests/test_pubkey.h @@ -7,40 +7,111 @@ #ifndef BOTAN_TEST_PUBKEY_H__ #define BOTAN_TEST_PUBKEY_H__ +#include "tests.h" + +#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO) + #include <botan/pubkey.h> -using namespace Botan; - -size_t validate_encryption(Botan::PK_Encryptor& e, Botan::PK_Decryptor& d, - const std::string& algo, - const std::string& input, - const std::string& random, - const std::string& expected); - -size_t validate_signature(PK_Verifier& v, PK_Signer& s, - const std::string& algo, - const std::string& input, - RandomNumberGenerator& signer_rng, - RandomNumberGenerator& test_rng, - const std::string& exp); - -size_t validate_signature(PK_Verifier& v, PK_Signer& s, - const std::string& algo, - const std::string& input, - RandomNumberGenerator& rng, - const std::string& exp); - -size_t validate_signature(PK_Verifier& v, PK_Signer& s, - const std::string& algo, - const std::string& input, - RandomNumberGenerator& rng, - const std::string& random, - const std::string& exp); - -size_t validate_kas(PK_Key_Agreement& kas, - const std::string& algo, - const std::vector<byte>& pubkey, - const std::string& output, - size_t keylen); +namespace Botan_Tests { + +class PK_Signature_Generation_Test : public Text_Based_Test + { + public: + PK_Signature_Generation_Test(const std::string& algo, + const std::string& test_src, + const std::vector<std::string>& required_keys, + const std::vector<std::string>& optional_keys = {}) : + Text_Based_Test(algo, test_src, required_keys, optional_keys) {} + + virtual std::string default_padding(const VarMap&) const + { + throw std::runtime_error("No default padding scheme set for " + algo_name()); + } + + virtual std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) = 0; + private: + Test::Result run_one_test(const std::string&, const VarMap& vars) override; + }; + +class PK_Signature_Verification_Test : public Text_Based_Test + { + public: + PK_Signature_Verification_Test(const std::string& algo, + const std::string& test_src, + const std::vector<std::string>& required_keys, + const std::vector<std::string>& optional_keys = {}) : + Text_Based_Test(algo, test_src, required_keys, optional_keys) {} + + virtual std::string default_padding(const VarMap&) const + { + throw std::runtime_error("No default padding scheme set for " + algo_name()); + } + + virtual std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) = 0; + private: + Test::Result run_one_test(const std::string& header, const VarMap& vars) override; + }; + +class PK_Encryption_Decryption_Test : public Text_Based_Test + { + public: + PK_Encryption_Decryption_Test(const std::string& algo, + const std::string& test_src, + const std::vector<std::string>& required_keys, + const std::vector<std::string>& optional_keys = {}) : + Text_Based_Test(algo, test_src, required_keys, optional_keys) {} + + virtual std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) = 0; + + virtual std::string default_padding(const VarMap&) const { return "Raw"; } + private: + Test::Result run_one_test(const std::string& header, const VarMap& vars) override; +}; + +class PK_Key_Agreement_Test : public Text_Based_Test + { + public: + PK_Key_Agreement_Test(const std::string& algo, + const std::string& test_src, + const std::vector<std::string>& required_keys, + const std::vector<std::string>& optional_keys = {}) : + Text_Based_Test(algo, test_src, required_keys, optional_keys) {} + + virtual std::unique_ptr<Botan::Private_Key> load_our_key(const VarMap& vars) = 0; + virtual std::vector<uint8_t> load_their_key(const VarMap& vars) = 0; + + virtual std::string default_kdf(const VarMap&) const { return "Raw"; } + + private: + Test::Result run_one_test(const std::string& header, const VarMap& vars) override; + }; + +class PK_Key_Generation_Test : public Test + { + protected: + std::vector<Test::Result> run() override; + + 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); + }; + +void check_invalid_signatures(Test::Result& result, + Botan::PK_Verifier& verifier, + const std::vector<uint8_t>& message, + const std::vector<uint8_t>& signature); + +void check_invalid_ciphertexts(Test::Result& result, + Botan::PK_Decryptor& decryptor, + const std::vector<uint8_t>& plaintext, + const std::vector<uint8_t>& ciphertext); + +} + +#endif #endif |