From 551fd25010e482d33dbc766ce28fde2d16bbfda2 Mon Sep 17 00:00:00 2001 From: Love Westlund Date: Mon, 27 May 2024 21:48:56 +0200 Subject: [PATCH] Always set IV length for ciphers that use an IV 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/rust-openssl#2244. --- openssl/src/symm.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openssl/src/symm.rs b/openssl/src/symm.rs index af010569e..dd523adac 100644 --- a/openssl/src/symm.rs +++ b/openssl/src/symm.rs @@ -626,10 +626,8 @@ impl Crypter { ctx.set_key_length(key.len())?; - if let (Some(iv), Some(iv_len)) = (iv, t.iv_len()) { - if iv.len() != iv_len { - ctx.set_iv_length(iv.len())?; - } + if let (Some(iv), Some(_iv_len)) = (iv, t.iv_len()) { + ctx.set_iv_length(iv.len())?; } f(&mut ctx, None, Some(key), iv)?;