aes: do not ignore ECB return value when used in other modes - #11004
Open
rizlik wants to merge 1 commit into
Open
aes: do not ignore ECB return value when used in other modes#11004rizlik wants to merge 1 commit into
rizlik wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens AES mode implementations that internally use wc_AesEcbEncrypt() as a building block, ensuring failures from ECB encryption are not silently ignored and are propagated back to callers (with output buffers cleared on error). It also adds an API test that forces ECB failure via CryptoCb to verify error handling.
Changes:
- Check and propagate
wc_AesEcbEncrypt()return codes in CTR and GCM code paths that batch-encrypt counter blocks. - Zero relevant output buffers when ECB encryption fails in these higher-level modes.
- Add an API test (
test_wc_AesEcb_RetCodeChecked) to exercise ECB failure via CryptoCb and verify error return + zeroed output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| wolfcrypt/src/aes.c | Propagates ECB failures when ECB is used to generate keystream/counter blocks in other modes; zeros output on failure. |
| tests/api/test_aes.h | Declares and registers the new API test in the AES test group list. |
| tests/api/test_aes.c | Adds a CryptoCb-based test that forces ECB failure and asserts the calling modes return error and zero the output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
7921
to
+7925
|
|
||
| /* reset number of blocks and then do encryption */ | ||
| blocks = sz / WC_AES_BLOCK_SIZE; | ||
| wc_AesEcbEncrypt(aes, out, out, WC_AES_BLOCK_SIZE * blocks); | ||
| xorbuf(out, in, WC_AES_BLOCK_SIZE * blocks); | ||
| in += WC_AES_BLOCK_SIZE * blocks; | ||
| out += WC_AES_BLOCK_SIZE * blocks; | ||
| sz -= blocks * WC_AES_BLOCK_SIZE; | ||
| ret = wc_AesEcbEncrypt(aes, out, out, | ||
| WC_AES_BLOCK_SIZE * blocks); |
Contributor
Author
There was a problem hiding this comment.
I do think the object should not be re-used in case of error
|
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.
Description
don't ignore ECB if used as building block for other modes