Skip to content

Commit

Permalink
Always set IV length for AES CCM ciphers
Browse files Browse the repository at this point in the history
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 #2244.
  • Loading branch information
lwestlund committed Jun 7, 2024
1 parent 50e4bdf commit 542b783
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion openssl/src/symm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,12 @@ impl Crypter {
ctx.set_key_length(key.len())?;

if let (Some(iv), Some(iv_len)) = (iv, t.iv_len()) {
if iv.len() != iv_len {
if iv.len() != iv_len
|| matches!(
t.nid(),
Nid::AES_128_CCM | Nid::AES_192_CCM | Nid::AES_256_CCM
)
{
ctx.set_iv_length(iv.len())?;
}
}
Expand Down

0 comments on commit 542b783

Please sign in to comment.