Skip to content

Fix 2k reduction selection for even moduli - #12081

Merged
JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
ageprocpp:fix/fenrir-17457
Nov 11, 2026
Merged

JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
ageprocpp:fix/fenrir-17457

Conversation

@ageprocpp

@ageprocpp ageprocpp commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes Fenrir #17457

For heap math, mp_exptmod can select single-digit 2k reduction for an even modulus such as 2^DIGIT_BIT. Its setup value is 2^DIGIT_BIT, which does not fit in one digit, so the operation returns MP_VAL. Reject multi-digit moduli with a zero low digit in mp_reduce_is_2k, allowing the existing Barrett path to handle them when available.

Testing

  • Built with --enable-heapmath --disable-shared --enable-static and CFLAGS='-O0 -DWOLFSSL_PUBLIC_MP'.
  • Ran ./tests/unit.test --api -test_mp_exptmod_even_2k. The test checks 2^DIGIT_BIT, 3 * 2^DIGIT_BIT, and the adjacent valid 2k modulus, using (p - 1)^2 mod p = 1.
  • Confirmed that the regression test fails against the unmodified mp_reduce_is_2k.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copilot AI balanced review requested due to automatic review settings November 10, 2026 16:29

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 10, 2026 16:30
@github-actions

Copy link
Copy Markdown

retest this please

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata -8 B, text +3,872 B (+1.4%, 286,336 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.

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

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_wolfmath.h
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

This comment was marked as duplicate.

@ageprocpp

Copy link
Copy Markdown
Contributor Author

retest this please

@ageprocpp ageprocpp assigned wolfSSL-Bot and unassigned ageprocpp Nov 10, 2026
@JacobBarthelmeh
JacobBarthelmeh merged commit 6198282 into wolfSSL:master Nov 11, 2026
444 of 445 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