Skip to content

Fix Fenrir items 16893, 16900, 16902 and 16903 - #12188

Open
kaleb-himes wants to merge 5 commits into
wolfSSL:masterfrom
kaleb-himes:kh-fenrir-ecc-curve25519-fixes
Open

kaleb-himes wants to merge 5 commits into
wolfSSL:masterfrom
kaleb-himes:kh-fenrir-ecc-curve25519-fixes

Conversation

@kaleb-himes

@kaleb-himes kaleb-himes commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Four correctness fixes. None is FIPS-gated.

Fenrir Problem Fix
F-16893 WOLFSSL_SAKKE_SMALL + custom curves: the pairing passed NULL for a, so every pairing failed with MP_VAL. Pass &params->a.
F-16900 Custom curves: the square-root non-residue search stopped at Z = 22, so some valid primes failed to decompress. Remove the clamp; the odd-prime check on compressed import now runs whenever custom curves are on.
F-16902 CURVE25519_SMALL: wc_curve25519_generic() did not mask bit 255 of u, so it computed X25519 on u + 19. Clear bit 255 first (RFC 7748 sec 5).
F-16903 WOLFSSL_SP_MATH: ecc_map_ex() used an #elif chain, so only the first compiled curve was mapped; others returned success unmapped. One #if per curve; anything else returns ECC_BAD_ARG_E.

Behavior changes: X25519 output changes only in CURVE25519_SMALL builds when bit 255 is set. Custom-curve compressed import now refuses a non-prime modulus without WOLFSSL_VALIDATE_ECC_IMPORT, so mp_prime_is_prime() is compiled in for custom curves with compressed keys.

Commit 2 fixes the new tests' build gates from review: static curve structs (WOLFSSL_ECC_CURVE_STATIC), P-224-only builds, and SP-math builds without P-384/P-521 SP code or without RSA/DH.

Commit 3: --enable-sakke=small defined WOLFCRYPT_SAKKE_SMALL, which nothing reads, so configure never built the small SAKKE code where F-16893 lives. It now defines WOLFSSL_SAKKE_SMALL.

Commit 4, from review:

  • WOLFSSL_SAKKE_SMALL without SP ECC used a square-and-multiply loop that branched on each bit of the secret exponent r. Small builds now use the existing constant-time ladder, which runs over the bits of the public order q.
  • The primality test this PR enables (WOLFSSL_SP_PRIME_GEN) calls sp_cnt_lsb(), which was not compiled in RSA-public-only builds without DH or keygen. It now is.

Testing

New tests: test_wc_ecc_import_compressed_custom, test_wc_ecc_map_curves (needs WOLFSSL_PUBLIC_MP + WOLFSSL_PUBLIC_ECC_ADD_DBL), and RFC 7748 sec 5.2 vector 2 in test_wc_curve25519_make_pub_generic.

Each fails with master's library sources and passes here (-Werror):

Build Fails on master
--enable-curve25519=small --enable-sakke --enable-eccsi --enable-ecccustcurves --enable-compkey CFLAGS=-DWOLFSSL_SAKKE_SMALL testwolfcrypt SAKKE, test_curve25519.c:686, test_ecc.c:1805
--enable-ecc --enable-sp --enable-sp-math --enable-sp-asm --enable-keygen + the two defines above test_ecc.c:4886 (P-384)

Test gate fixes, each failing on commit 1 and passing on commit 2:

Build Commit 1
--enable-ecccustcurves --enable-compkey CFLAGS=-DWOLFSSL_ECC_CURVE_STATIC -Werror build failure, test_ecc.c:1760 and :1782
--disable-tls13 --enable-ecccustcurves --enable-compkey CFLAGS="-DECC_USER_CURVES -DNO_ECC256 -DHAVE_ECC224" test_ecc.c:1804 (now skipped)
--enable-ecc --enable-sp=ec256 --enable-sp-math --disable-rsa --disable-dh + the two defines unit.test link failure, sp_mont_setup undefined
same, plus -DHAVE_ECC384 test_ecc.c:4894 (P-384); other ECC tests also fail here, as SP math has no P-384 code

make check passes with --enable-all plus SAKKE, ECCSI, custom curves and compressed keys; with the CURVE25519_SMALL + WOLFSSL_SAKKE_SMALL build; with SP-math only; and with fastmath and heapmath.

--enable-sakke=small (commit 3):

Build Result
commit 2 configure, master sakke.c WOLFSSL_SAKKE_SMALL not defined; SAKKE passes because the small code is never built
commit 3 configure, master sakke.c defined; testwolfcrypt SAKKE fails (F-16893)
commit 3 configure, this branch defined; SAKKE and ECCSI pass

make check also passes with --enable-sakke=small --enable-eccsi on default math, custom curves with compressed keys, --enable-all, fastmath and heapmath.

Commit 4 controls (commit 3 vs commit 4):

Build Commit 3 Commit 4
--enable-sakke=small --enable-eccsi --disable-sp, fastmath and heapmath; field multiplies per encapsulation, 4 SSVs (gdb) multiplies 506 to 535, squarings 1018 to 1021, varying with the SSV 1022 multiplies and 1022 squarings for every SSV
--enable-rsapub --disable-dh --disable-keygen --enable-ecccustcurves --enable-compkey CFLAGS=-DSQRTMOD_USE_MOD_EXP link failure, sp_cnt_lsb undefined (master links) links; testwolfcrypt RSA and ECC pass
same without SQRTMOD_USE_MOD_EXP link failure, also on master links; testwolfcrypt RSA and ECC pass

make check passes on commit 4 with --enable-sakke=small --enable-eccsi on SP, custom curves, fastmath, heapmath and --enable-all, and with non-small SAKKE on --enable-all and fastmath.

Checklist

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

Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:52
@kaleb-himes kaleb-himes self-assigned this Nov 19, 2026

This comment was marked as resolved.

wolfSSL-Fenrir-bot

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as off-topic.

wolfSSL-Fenrir-bot

This comment was marked as outdated.

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review November 19, 2026 18:48

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

This comment was marked as low quality.

@kaleb-himes

Copy link
Copy Markdown
Contributor Author

@claude review please.

claude[bot]

This comment was marked as outdated.

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

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): configure.ac, doc/ALGORITHM_DEFINES.md, tests/api/test_ecc.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: Lite

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.

🔵 Needs a closer look

Human assessment is needed to weigh the performance impact of repeated primality validation during compressed custom-curve imports.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@kaleb-himes

Copy link
Copy Markdown
Contributor Author

@claude review again please.

Comment thread wolfcrypt/src/ecc.c Resolved
@kaleb-himes
kaleb-himes marked this pull request as ready for review November 19, 2026 22:03
@github-actions

Copy link
Copy Markdown

retest this please

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m3

  • FLASH: .text +80 B (+0.1%, 133,766 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4

  • FLASH: .text +128 B (+0.1%, 211,117 B / 262,144 B, total: 81% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 74,996 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 198,820 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +64 B (+0.0%, 808,268 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +64 B (+0.0%, 225,105 B / 262,144 B, total: 86% used)

gcc-arm-cortex-m4-pq

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

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +64 B (+0.0%, 347,496 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +128 B (+0.1%, 134,542 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 253,703 B / 262,144 B, total: 97% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 211,117 B / 262,144 B, total: 81% used)

gcc-arm-cortex-m7-pq

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

gcc-arm-cortex-m7-tls13

  • FLASH: .text +64 B (+0.0%, 253,703 B / 262,144 B, total: 97% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,496 B (+4.8%, 296,076 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.

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