From 1c393ac67187deb03e87da8de0b740fb16ffffdf Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 13 Oct 2019 13:10:47 -0400 Subject: Add a more explicit exception to catch cases where app doesn't set IV --- src/lib/pubkey/ecies/ecies.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/pubkey/ecies/ecies.cpp b/src/lib/pubkey/ecies/ecies.cpp index cda3a8f55..a8c277b3a 100644 --- a/src/lib/pubkey/ecies/ecies.cpp +++ b/src/lib/pubkey/ecies/ecies.cpp @@ -287,6 +287,9 @@ std::vector ECIES_Encryptor::enc(const uint8_t data[], size_t length, R // encryption m_cipher->set_key(SymmetricKey(secret_key.begin(), m_params.dem_keylen())); + if(m_iv.size() == 0 && !m_cipher->valid_nonce_length(m_iv.size())) + throw Invalid_Argument("ECIES with " + m_cipher->name() + " requires an IV be set"); + m_cipher->start(m_iv.bits_of()); secure_vector encrypted_data(data, data + length); @@ -389,6 +392,8 @@ secure_vector ECIES_Decryptor::do_decrypt(uint8_t& valid_mask, const ui // decrypt data m_cipher->set_key(SymmetricKey(secret_key.begin(), m_params.dem_keylen())); + if(m_iv.size() == 0 && !m_cipher->valid_nonce_length(m_iv.size())) + throw Invalid_Argument("ECIES with " + m_cipher->name() + " requires an IV be set"); m_cipher->start(m_iv.bits_of()); try -- cgit v1.2.3