Skip to content

Fix/update disk aes ctr iv carry - #1020

Open
night1rider wants to merge 2 commits into
wolfSSL:masterfrom
night1rider:fix/update-disk-aes-ctr-iv-carry
Open

night1rider wants to merge 2 commits into
wolfSSL:masterfrom
night1rider:fix/update-disk-aes-ctr-iv-carry

Conversation

@night1rider

Copy link
Copy Markdown
Contributor

Found this when reviewing #1015

disk_crypto_set_iv() in src/update_disk.c previously added block_offset only to the last 4 bytes (iv[12..15]) of the 16-byte AES-CTR IV without carrying into iv[0..11].
Because tools/keytools/sign.c (wc_AesCtrEncrypt()) and src/libwolfboot.c (aes_set_iv()) increment the full 128-bit big-endian counter, any IV whose low 32-bit word wraps across the header decrypts the payload with the wrong counter and fails verification.
Commit 1 (71568105) adds unit-update-disk-aes-iv-carry (wired into tools/unit-tests/Makefile and .github/workflows/test-units.yml) reproducing the failure with real AES-256-CTR (fails 3/4 before the fix).
Commit 2 (1d811020) propagates the carry branch-free across all four 32-bit big-endian words of the IV in disk_crypto_set_iv() (4/4 passing, along with all existing unit-update-disk* suites).

How to run the test

make -C tools/unit-tests unit-update-disk-aes-iv-carry
WOLFBOOT_SECTOR_SIZE=0x400 ./tools/unit-tests/unit-update-disk-aes-iv-carry

Reproduce the 32-bit IV carry drop in disk_crypto_set_iv() with real
AES-256-CTR and wire the test into tools/unit-tests/Makefile.
Propagate carry branch-free across all 16 bytes of the big-endian
AES-CTR IV in disk_crypto_set_iv(), matching aes_set_iv().
@night1rider night1rider self-assigned this Dec 2, 2026
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot December 2, 2026 19:07

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.

🟢 Approval recommended

There are no active review issues for the AES-CTR counter carry fix.

No open issues 🎉

What changed in this PR

Fixes disk-boot AES-CTR counter handling so payload decryption matches the signing tool when the IV’s low 32-bit word overflows.

Changes:

  • Propagates carry across the full 128-bit counter.
  • Adds AES-256-CTR regression tests for normal counters, multiword carry, and full wraparound.
  • Registers the test target and ignores its generated binary.
File Description
tools/​unit-tests/​unit-update-disk-aes-iv-carry.c Adds real AES-CTR carry regression tests.
tools/​unit-tests/​Makefile Registers and builds the new test.
src/​update_disk.c Implements full 128-bit IV carry propagation.
.gitignore Ignores the new test binary.

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1020

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .gitignore, tools/unit-tests/Makefile
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

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.

4 participants