Skip to content

Commit 551fd25

Browse files
committed
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#2244.
1 parent 50e4bdf commit 551fd25

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

openssl/src/symm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,8 @@ impl Crypter {
626626

627627
ctx.set_key_length(key.len())?;
628628

629-
if let (Some(iv), Some(iv_len)) = (iv, t.iv_len()) {
630-
if iv.len() != iv_len {
631-
ctx.set_iv_length(iv.len())?;
632-
}
629+
if let (Some(iv), Some(_iv_len)) = (iv, t.iv_len()) {
630+
ctx.set_iv_length(iv.len())?;
633631
}
634632

635633
f(&mut ctx, None, Some(key), iv)?;

0 commit comments

Comments
 (0)