diff options
author | Jack Lloyd <[email protected]> | 2018-03-21 06:45:06 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-21 06:45:06 -0400 |
commit | 29bbabad6e833a2b0047a41fe8bed8960b8e1116 (patch) | |
tree | 915e973afebf76890333ed8c2f1a04c90f70b987 /src/tests/test_pubkey.cpp | |
parent | e7689444a0ef4ab5c252235968d84acf6685819a (diff) |
Support "mixed" OAEP hashes
Test vectors from pyca/cryptography
Fixes GH #109
Diffstat (limited to 'src/tests/test_pubkey.cpp')
-rw-r--r-- | src/tests/test_pubkey.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index 666650969..722056b2f 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -250,7 +250,7 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const Va const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); const std::string padding = choose_padding(vars, pad_hdr); - Test::Result result(algo_name() + (padding.empty() ? padding : "/" + padding) + " decryption"); + Test::Result result(algo_name() + (padding.empty() ? padding : "/" + padding) + " encryption"); std::unique_ptr<Botan::Private_Key> privkey = load_private_key(vars); @@ -344,6 +344,49 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const Va return result; } +Test::Result +PK_Decryption_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) + { + const std::vector<uint8_t> plaintext = get_req_bin(vars, "Msg"); + const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); + const std::string padding = choose_padding(vars, pad_hdr); + + Test::Result result(algo_name() + (padding.empty() ? padding : "/" + padding) + " decryption"); + + std::unique_ptr<Botan::Private_Key> privkey = load_private_key(vars); + + std::vector<std::unique_ptr<Botan::PK_Decryptor>> decryptors; + + for(auto const& dec_provider : possible_providers(algo_name())) + { + std::unique_ptr<Botan::PK_Decryptor> decryptor; + + try + { + decryptor.reset(new Botan::PK_Decryptor_EME(*privkey, Test::rng(), padding, dec_provider)); + } + catch(Botan::Lookup_Error&) + { + continue; + } + + Botan::secure_vector<uint8_t> decrypted; + try + { + decrypted = decryptor->decrypt(ciphertext); + } + catch(Botan::Exception& e) + { + result.test_failure("Failed to decrypt KAT ciphertext", e.what()); + } + + result.test_eq(dec_provider, "decryption of KAT", decrypted, plaintext); + check_invalid_ciphertexts(result, *decryptor, plaintext, ciphertext); + } + + return result; + } + Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) { const std::vector<uint8_t> K = get_req_bin(vars, "K"); |