-
-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encrypt AES 256 CCM with 12 byte IV silently uses 7 byte IV #2244
Comments
I vaguely remember set_iv_length returning an error when used with ciphers that don't support IV length changes. If that's not the case, your proposed solution seems fine to me. What a bizarre decision on the OpenSSL side of things... |
lwestlund
added a commit
to lwestlund/rust-openssl
that referenced
this issue
May 27, 2024
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.
lwestlund
added a commit
to lwestlund/rust-openssl
that referenced
this issue
Jun 7, 2024
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been trying to use an IV of length 12 for encryption with AES 256 CCM but the result is as if I had used an IV of length 7. I suspect that this might be an issue for other ciphers that use an IV as well but I haven't tested.
This is observed using https://docs.rs/openssl/0.10.64/openssl/index.html (latest at time of writing) and OpenSSL 3.3.0.
The problem appears to be that the AES 256 CCM cipher defines the default IV length as 12, but OpenSSL still defaults to 7, causing the last 5 bytes in a 12 byte IV to be ignored.
Minimal reproducible example to show that 7 and 12 byte IV gives the same result:
Details
From my testing, removing the inner length comparison of
rust-openssl/openssl/src/symm.rs
Lines 629 to 633 in 5095d7d
and unconditionally setting the IV length fixes the issue.
I think that this might be an appropriate solution for the problem and would be happy to submit a PR for it!
The text was updated successfully, but these errors were encountered: