aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/pk_crypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/pk_crypt.cpp')
-rw-r--r--src/cli/pk_crypt.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cli/pk_crypt.cpp b/src/cli/pk_crypt.cpp
index 9b7f50746..4888a742f 100644
--- a/src/cli/pk_crypt.cpp
+++ b/src/cli/pk_crypt.cpp
@@ -189,13 +189,19 @@ class PK_Decrypt final : public Command
return set_return_code(1);
}
- Botan::PK_Decryptor_EME dec(*key, rng(), "OAEP(" + oaep_hash + ")");
-
- const Botan::secure_vector<uint8_t> file_key = dec.decrypt(encrypted_key);
-
std::unique_ptr<Botan::AEAD_Mode> aead =
Botan::AEAD_Mode::create_or_throw(aead_algo, Botan::DECRYPTION);
+ const size_t expected_keylen = aead->key_spec().maximum_keylength();
+
+ Botan::PK_Decryptor_EME dec(*key, rng(), "OAEP(" + oaep_hash + ")");
+
+ const Botan::secure_vector<uint8_t> file_key =
+ dec.decrypt_or_random(encrypted_key.data(),
+ encrypted_key.size(),
+ expected_keylen,
+ rng());
+
aead->set_key(file_key);
aead->set_associated_data_vec(encrypted_key);
aead->start(nonce);