diff options
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/dlies/dlies.cpp | 16 | ||||
-rw-r--r-- | src/lib/pubkey/ecies/ecies.cpp | 16 |
2 files changed, 14 insertions, 18 deletions
diff --git a/src/lib/pubkey/dlies/dlies.cpp b/src/lib/pubkey/dlies/dlies.cpp index d24542d0e..4aee3ffb3 100644 --- a/src/lib/pubkey/dlies/dlies.cpp +++ b/src/lib/pubkey/dlies/dlies.cpp @@ -69,11 +69,9 @@ std::vector<uint8_t> DLIES_Encryptor::enc(const uint8_t in[], size_t length, SymmetricKey enc_key(secret_keys.data(), cipher_key_len); m_cipher->set_key(enc_key); - if(m_iv.size()) - { - m_cipher->start(m_iv.bits_of()); - } - + if(m_iv.size() == 0 && !m_cipher->valid_nonce_length(m_iv.size())) + throw Invalid_Argument("DLIES with " + m_cipher->name() + " requires an IV be set"); + m_cipher->start(m_iv.bits_of()); m_cipher->finish(ciphertext); } else @@ -194,11 +192,9 @@ secure_vector<uint8_t> DLIES_Decryptor::do_decrypt(uint8_t& valid_mask, // the decryption can fail: // e.g. Invalid_Authentication_Tag is thrown if GCM is used and the message does not have a valid tag - if(m_iv.size()) - { - m_cipher->start(m_iv.bits_of()); - } - + if(m_iv.size() == 0 && !m_cipher->valid_nonce_length(m_iv.size())) + throw Invalid_Argument("DLIES with " + m_cipher->name() + " requires an IV be set"); + m_cipher->start(m_iv.bits_of()); m_cipher->finish(ciphertext); } catch(...) diff --git a/src/lib/pubkey/ecies/ecies.cpp b/src/lib/pubkey/ecies/ecies.cpp index 1c8ca45b6..a8c277b3a 100644 --- a/src/lib/pubkey/ecies/ecies.cpp +++ b/src/lib/pubkey/ecies/ecies.cpp @@ -287,10 +287,11 @@ std::vector<uint8_t> 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->start(m_iv.bits_of()); - } + 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<uint8_t> encrypted_data(data, data + length); m_cipher->finish(encrypted_data); @@ -391,10 +392,9 @@ secure_vector<uint8_t> 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->start(m_iv.bits_of()); - } + 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 { |