Validate key_to_wrap length in aes_key_wrap_with_padding#14665
Merged
reaperhulk merged 1 commit intopyca:mainfrom Apr 15, 2026
Merged
Validate key_to_wrap length in aes_key_wrap_with_padding#14665reaperhulk merged 1 commit intopyca:mainfrom
key_to_wrap length in aes_key_wrap_with_padding#14665reaperhulk merged 1 commit intopyca:mainfrom
Conversation
1b1da40 to
97c6f47
Compare
|
Can you add a direct unit test for this as well? (Sent from my $work github) |
RFC 5649 specifies that the plaintext must be between 1 and 2^32 octets. Previously, passing an empty key_to_wrap would cause _wrap_core to be called with r=[], which skips all AES operations and returns an invalid wrapped key.
97c6f47 to
33397a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
this PR resolves #14664:
RFC 5649 specifies that the plaintext must be between 1 and 2^32 octets. Previously, passing an empty key_to_wrap would cause _wrap_core to be called with r=[], which skips all AES operations and just returns an invalid wrapped key.
Wycheproof has a test for this that is marked as "invalid":
https://github.com/C2SP/wycheproof/blob/75ede73a39b8517b2a06c8115dfbcd364479796c/testvectors_v1/aes_kwp_test.json#L839-L849
I've updated the testing harness to allow
aes_key_wrap_with_paddingto return an error in this case. The initial CI run failed in that case. Unfortunately there doesn't seem to be a way to tell if unwrapping or wrapping the key should fail, which is why this wasn't caught by the wycheproof test and why the new logic is somewhat sloppy.Thanks!