From ef22f0773c4e0b43f8f0855fe8f52f673d079aa2 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 13 Oct 2019 14:00:18 -0400 Subject: Update DLIES in the same way GH #2050 --- src/lib/pubkey/dlies/dlies.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/lib') 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 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 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(...) -- cgit v1.2.3