-
Notifications
You must be signed in to change notification settings - Fork 27
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
Cipher: IV must not be set in case ECB mode of operation is used #105
Comments
See this conversation as well - it's somewhat frustrating because:
I think it's possible to just add The other option that I could think of, similar to what I suggested in the conversation linked above, would be to add a new method, something like |
Perhaps an alternative would be that we implement an enum for those cases:
(I know the variant names are fugly, couldn't think of something nicer off the top of my head) |
I think the last suggestion makes sense and covers the cases mentioned above. |
@egrimley-arm - as a follow-up from our conversation on your PR, would you find the option with the enum above reasonable? |
Yes, it seems reasonable, but I'd suggest these names for the enum: (Does |
... ok, this sounds like something the Rust type system should really be able to help with, so we don't have to ever deal with the possibility of a wrong IV size in the functions. How about: struct UnauthenticatedCipher {
cipher: Cipher,
iv: Some([u8; 32]), // or whatever the maximum possible size of the IV is
iv_len: usize,
}
impl UnauthenticatedCipher {
// checks the provided IV length against expected size
pub fn new_with_iv(cipher: Cipher, iv: &[u8]) -> Result<Self> {...}
// either sets the IV to `None`, or generates N random bytes of IV and uses that
pub fn new_without_iv(cipher: Cipher) -> Result<Self> {...}
} And in the functions we only take this new |
In cipher.rs
psa_crypto_sys::psa_cipher_set_iv is called without checking if the operation requires setting IV or not.
In case ECB operations this function
psa_crypto_sys::psa_cipher_set_iv
should not be called.Available approaches:
if the user misused it then the function will propagate the error.
The text was updated successfully, but these errors were encountered: