aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/pk_crypt.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-02-28 19:25:31 -0500
committerJack Lloyd <[email protected]>2019-02-28 19:25:31 -0500
commit731f26e10a71d9749c61c71a2d997698bb55ac37 (patch)
treec8ce8f21b0f1c23df73ada12125752a9c17461d4 /src/cli/pk_crypt.cpp
parenta9d2cceb52ea93291f37c2a8da4a91bb13a4fbf6 (diff)
Split CLI utils.cpp into more parts
Add base58 encoding/decoding CLI Use decrypt_or_random in pk_decrypt
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);