Skip to content

Commit 542b783

Browse files
committed
Always set IV length for AES CCM ciphers
This fixes an issue where the IV length would not be set if the length was equal to the recommended length. The issue shows up at least when an IV of length 12 (which is returned by `t.iv_len()`) is used with the AES256 CCM cipher, as OpenSSL defaults the IV length to 7 bytes [^1] and it would not be correctly set to 12. [^1]: https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption Closes sfackler#2244.
1 parent 50e4bdf commit 542b783

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

openssl/src/symm.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,12 @@ impl Crypter {
627627
ctx.set_key_length(key.len())?;
628628

629629
if let (Some(iv), Some(iv_len)) = (iv, t.iv_len()) {
630-
if iv.len() != iv_len {
630+
if iv.len() != iv_len
631+
|| matches!(
632+
t.nid(),
633+
Nid::AES_128_CCM | Nid::AES_192_CCM | Nid::AES_256_CCM
634+
)
635+
{
631636
ctx.set_iv_length(iv.len())?;
632637
}
633638
}

0 commit comments

Comments
 (0)