Repository navigation
aes-kw: reject empty keys and single-semiblock unwrap inputs - #103
Conversation
KW and KWP unwrap accepted an 8-byte input. With no key data the unwrap loop runs zero rounds, so the integrity check compares the input against the default IV directly and returns Ok with an empty key without using the KEK. Wrapping an empty key likewise produced just the IV. Require at least one semiblock of key data on wrap and two semiblocks (IV plus data) on unwrap, and add regression cases to the existing InvalidDataSize tests.
|
It looks like this doesn't cover Also it seems like there's a disparity between plaintexts and ciphertexts. Based on my reading of RFC3394 the minimum plaintext key size is 128-bits or two blocks. |
|
Thanks Tony, good catches on both! I pushed an update:
|
| pub fn wrap_fixed_key<N>(&self, key: &Array<u8, N>) -> KwWrappedKey<N> | ||
| where | ||
| N: ArraySize + NonZero + Add<IvLen> + Rem<IvLen>, | ||
| N: ArraySize + NonZero + Add<IvLen> + Rem<IvLen> + IsGreaterOrEqual<U16>, |
There was a problem hiding this comment.
Hmm, the bounds change is technically breaking. It may not actually matter in practice, though.
We could also just bump the minor version to v0.4.
| pub fn wrap_fixed_key<N>(&self, key: &Array<u8, N>) -> KwpWrappedKey<N> | ||
| where | ||
| N: ArraySize + Add<IvLenM1> + IsLess<KwpMaxLen>, | ||
| N: ArraySize + NonZero + Add<IvLenM1> + IsLess<KwpMaxLen>, |
There was a problem hiding this comment.
Same here re: bounds changes, though I'm not sure it matters if the thing it breaks is buggy anyway.
tarcieri
left a comment
There was a problem hiding this comment.
Going to go ahead and merge this despite the breaking changes. I think we can just bump the minor version to be safe.
KW and KWP
unwrap_keyaccept an 8-byte input. With no key data the unwrap loop runs zero rounds, so the integrity check compares the input with the default IV directly and returnsOkwith an empty key without using the KEK. Wrapping an empty key also produces just the IV.This requires at least one semiblock of key data on wrap and two semiblocks (IV plus data) on unwrap, and adds the cases to the existing
error_invalid_data_sizetests inkw_tests.rsandkwp_tests.rs. The KW test fails without the change and all aes-kw tests pass with it (cargo test --all-features), andcargo fmt --checkis clean.Reported privately as GHSA-38fr-39m3-52f8; @tarcieri said it doesn't need to stay embargoed.