aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_mceliece.cpp23
-rw-r--r--src/tests/test_pubkey.cpp40
2 files changed, 44 insertions, 19 deletions
diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp
index 36ecd660e..455c50a8d 100644
--- a/src/tests/test_mceliece.cpp
+++ b/src/tests/test_mceliece.cpp
@@ -80,17 +80,24 @@ class McEliece_Keygen_Encrypt_Test : public Text_Based_Test
rng.clear();
rng.add_entropy(encrypt_seed.data(), encrypt_seed.size());
- Botan::PK_KEM_Encryptor kem_enc(mce_priv, "KDF1(SHA-512)");
- Botan::PK_KEM_Decryptor kem_dec(mce_priv, "KDF1(SHA-512)");
+ try
+ {
+ Botan::PK_KEM_Encryptor kem_enc(mce_priv, "KDF1(SHA-512)");
+ Botan::PK_KEM_Decryptor kem_dec(mce_priv, "KDF1(SHA-512)");
+
+ Botan::secure_vector<byte> encap_key, prod_shared_key;
+ kem_enc.encrypt(encap_key, prod_shared_key, 64, rng);
- Botan::secure_vector<byte> encap_key, prod_shared_key;
- kem_enc.encrypt(encap_key, prod_shared_key, 64, rng);
+ Botan::secure_vector<byte> dec_shared_key = kem_dec.decrypt(encap_key.data(), encap_key.size(), 64);
- Botan::secure_vector<byte> dec_shared_key = kem_dec.decrypt(encap_key.data(), encap_key.size(), 64);
+ result.test_eq("ciphertext", encap_key, ciphertext);
+ result.test_eq("encrypt shared", prod_shared_key, shared_key);
+ result.test_eq("decrypt shared", dec_shared_key, shared_key);
+ }
+ catch(Botan::Lookup_Error&)
+ {
+ }
- result.test_eq("ciphertext", encap_key, ciphertext);
- result.test_eq("encrypt shared", prod_shared_key, shared_key);
- result.test_eq("decrypt shared", dec_shared_key, shared_key);
return result;
}
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index faa27f322..025628636 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -260,29 +260,47 @@ Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars)
std::unique_ptr<Botan::Private_Key> privkey = load_private_key(vars);
+ const Botan::Public_Key& pubkey = *privkey;
+
const size_t desired_key_len = K.size();
- Botan::PK_KEM_Encryptor enc(*privkey, kdf);
+ std::unique_ptr<Botan::PK_KEM_Encryptor> enc;
+ try
+ {
+ enc.reset(new Botan::PK_KEM_Encryptor(pubkey, kdf));
+ }
+ catch(Botan::Lookup_Error&)
+ {
+ return result;
+ }
Fixed_Output_RNG fixed_output_rng(get_req_bin(vars, "R"));
Botan::secure_vector<byte> produced_encap_key, shared_key;
- enc.encrypt(produced_encap_key,
- shared_key,
- desired_key_len,
- fixed_output_rng,
- salt);
+ enc->encrypt(produced_encap_key,
+ shared_key,
+ desired_key_len,
+ fixed_output_rng,
+ salt);
result.test_eq("C0 matches", produced_encap_key, C0);
result.test_eq("K matches", shared_key, K);
- Botan::PK_KEM_Decryptor dec(*privkey, kdf);
+ std::unique_ptr<Botan::PK_KEM_Decryptor> dec;
+ try
+ {
+ dec.reset(new Botan::PK_KEM_Decryptor(*privkey, kdf));
+ }
+ catch(Botan::Lookup_Error&)
+ {
+ return result;
+ }
const Botan::secure_vector<uint8_t> decr_shared_key =
- dec.decrypt(C0.data(), C0.size(),
- desired_key_len,
- salt.data(),
- salt.size());
+ dec->decrypt(C0.data(), C0.size(),
+ desired_key_len,
+ salt.data(),
+ salt.size());
result.test_eq("decrypted K matches", decr_shared_key, K);