Skip to content

aes: do not ignore ECB return value when used in other modes - #11004

Open
rizlik wants to merge 1 commit into
wolfSSL:masterfrom
rizlik:ecb_fixes
Open

aes: do not ignore ECB return value when used in other modes#11004
rizlik wants to merge 1 commit into
wolfSSL:masterfrom
rizlik:ecb_fixes

Conversation

@rizlik

@rizlik rizlik commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

don't ignore ECB if used as building block for other modes

Copilot AI review requested due to automatic review settings July 29, 2026 16:18
@rizlik rizlik self-assigned this Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread wolfcrypt/src/aes.c
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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think the object should not be re-used in case of error

@rizlik
rizlik requested a review from SparkiDev July 29, 2026 22:35
@rizlik rizlik assigned SparkiDev and unassigned rizlik Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants