aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_pubkey.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-21 08:13:56 -0400
committerJack Lloyd <[email protected]>2018-03-21 08:13:56 -0400
commit2821d60c9c159851c3d236fcc2bdeafd2d733849 (patch)
treeea1a382c8e93f49960b85d32799579fc68b0f385 /src/tests/test_pubkey.cpp
parent9a35a05781688838b9bf951471c86363deba36cd (diff)
parent13e4658b07f95bef8b48d93c74be25f2d6afde7d (diff)
Merge GH #1503 Support mixed hashes in OAEP
Diffstat (limited to 'src/tests/test_pubkey.cpp')
-rw-r--r--src/tests/test_pubkey.cpp45
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");