Skip to content

Fix ML-KEM inverse NTT overflow - #12273

Merged
SparkiDev merged 3 commits into
wolfSSL:masterfrom
ageprocpp:fix/fenrir-19076
Nov 27, 2026
Merged

SparkiDev merged 3 commits into
wolfSSL:masterfrom
ageprocpp:fix/fenrir-19076

Conversation

@ageprocpp

@ageprocpp ageprocpp commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Barrett-reduce the four-input sums after the len=4 inverse NTT layer. This keeps the following len=8 additions and subtractions within the signed 16-bit range for ML-KEM-1024.

Apply the same reduction to the WOLFSSL_MLKEM_INVNTT_UNROLL path and regenerate the AArch64, Arm32, and Thumb-2 assembly implementations with the equivalent reduction.

Add a fixed ML-KEM-1024 public API regression vector that previously produced different encapsulation and decapsulation shared secrets.

Testing

  • make -j4 wolfcrypt/test/testwolfcrypt
  • ./wolfcrypt/test/testwolfcrypt
  • ./configure --enable-mlkem --enable-armasm --disable-sha --disable-shared --disable-examples
  • Verified the AArch64 assembly-enabled wolfCrypt test passes.
  • Verified the regression test fails when the reductions are reverted.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 20:26

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ageprocpp
ageprocpp marked this pull request as ready for review November 25, 2026 21:01
@github-actions

Copy link
Copy Markdown

retest this please

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 318,448 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 319,280 B / 1,048,576 B, total: 30% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,832 B (+4.9%, 296,412 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@ageprocpp
ageprocpp marked this pull request as draft November 25, 2026 21:10
@ageprocpp
ageprocpp marked this pull request as ready for review November 25, 2026 21:25
@github-actions

Copy link
Copy Markdown

retest this please

1 similar comment
@ageprocpp

Copy link
Copy Markdown
Contributor Author

retest this please

@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 #12273

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): wolfcrypt/src/port/arm/armv8-32-mlkem-asm.S, wolfcrypt/src/port/arm/armv8-32-mlkem-asm_c.c, wolfcrypt/src/port/arm/armv8-mlkem-asm.S, wolfcrypt/src/port/arm/armv8-mlkem-asm.asm, wolfcrypt/src/port/arm/armv8-mlkem-asm_c.c, wolfcrypt/src/port/arm/thumb2-mlkem-asm.S, wolfcrypt/src/port/arm/thumb2-mlkem-asm_c.c
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

@ageprocpp ageprocpp assigned wolfSSL-Bot and unassigned ageprocpp Nov 25, 2026
@SparkiDev

Copy link
Copy Markdown
Contributor

The assembly code is generated from scripts.
Did you modify the scripts to create the code changes in this PR?
Put up a PR for scripts that generates the modified assembly code and put a comment in this PR with a link to the scripts PR.

@ageprocpp

ageprocpp commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

The corresponding assembly generator changes are in wolfSSL/scripts#728

@SparkiDev
SparkiDev merged commit 81505fc into wolfSSL:master Nov 27, 2026
848 of 871 checks passed
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.

5 participants