Repository navigation
Regenerate sp ecc code and add new test vectors - #12279
Conversation
- sp_<N>_ecc_mulmod_*() in sp_c32.c, sp_c64.c, sp_arm32.c, sp_arm64.c, sp_armthumb.c, sp_cortexm.c, sp_riscv64.c and sp_x86_64.c (regenerated), and sp_256_ecc_mulmod_10() in sp_dsp32.c, checks the stripe table generation result. Issue: F-19086
- Regenerate WOLFSSL_SP_SMALL variant of sp_<N>_lshift_<W>() in sp_c32.c and sp_c64.c. - tests/api: test_wc_ecc_import_x963_off_curve also expects wc_ecc_import_x963_ex() to reject six off-curve P-256, P-384 and P-521 points. Issue: F-19090
- Regenerate sp_256_div_9(), sp_384_div_15() and sp_521_div_21() in sp_c32.c, and sp_256_div_5(), sp_384_div_7() and sp_521_div_9() in sp_c64.c. - tests/api: test_wc_ecc_import_x963_off_curve also expects wc_ecc_import_x963_ex() to reject four off-curve P-521 points. Issue: F-19132
There was a problem hiding this comment.
🟡 Changes recommended
The tests leave the allocation-failure path and cache recovery unverified, while the existing sweep discards verification outputs and cannot detect acceptance of a forged signature.
1 open issue
What changed in this PR
Regenerates wolfCrypt’s single-precision (SP) ECC backends to address three defects in cached point multiplication and modular reduction, and adds off-curve regression vectors.
Changes:
- Propagates table-generation failures and resets cache entries for safe retries across nine backends.
- Corrects carry handling in shifts and borrow propagation in portable C reductions.
- Adds ten crafted P-256, P-384, and P-521 off-curve test points.
| File | Description |
|---|---|
wolfcrypt/src/sp_x86_64.c |
Fixes cache-generation error handling, including AVX2 paths. |
wolfcrypt/src/sp_riscv64.c |
Fixes cache-generation error handling for RISC-V. |
wolfcrypt/src/sp_dsp32.c |
Fixes P-256 cache-generation error handling for DSP. |
wolfcrypt/src/sp_cortexm.c |
Fixes cache-generation error handling for Cortex-M. |
wolfcrypt/src/sp_c64.c |
Fixes cache errors, shifts, and reduction in portable 64-bit C. |
wolfcrypt/src/sp_c32.c |
Fixes cache errors, shifts, and reduction in portable 32-bit C. |
wolfcrypt/src/sp_armthumb.c |
Fixes cache-generation error handling for ARM Thumb. |
wolfcrypt/src/sp_arm64.c |
Fixes cache-generation error handling for ARM64. |
wolfcrypt/src/sp_arm32.c |
Fixes cache-generation error handling for ARM32. |
tests/api/test_ecc.c |
Adds ten off-curve import regression vectors. |
Review effort: Balanced
|
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. It changes regenerated SP modular-arithmetic and ECC scalar-multiplication code across nine backends and closes three security findings, so a human with SP generator context should still look at it.
What was reviewed:
- FP_ECC
gen_stripe_tableerror handling in eachsp_<N>_ecc_mulmod_*: on failurecache->cntresets to 1 and neither mulmod path runs, so the error is returned. - The new low-to-high
lshiftloops with double-width accumulators (SMALL variants, plus the RSA/DH ones in sp_c64.c), and the div normalization that now starts at&t1[i]and moves the top-limb carry by hand. - Not done: no build or test run, so the off-curve vectors and the per-arch/asm variants were checked only by reading.
Extended reasoning...
The change touches wolfCrypt's generated SP math files (sp_c32/c64, arm32/arm64/armthumb/cortexm, riscv64, x86_64, dsp32) and adds off-curve point vectors to tests/api/test_ecc.c. This is security-sensitive crypto: ECC point multiplication, modular reduction and division, where a wrong carry can let invalid points or forged signatures through. The bug hunt found nothing, and the fixes look consistent across backends. Still, the change is large, cryptographic, and comes from a generator that isn't in this repo, so it doesn't qualify for automated approval. An inline Copilot thread on sp_c64.c was resolved only by the PR author.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12279
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): wolfcrypt/src/sp_arm32.c, wolfcrypt/src/sp_arm64.c, wolfcrypt/src/sp_armthumb.c, wolfcrypt/src/sp_cortexm.c, wolfcrypt/src/sp_dsp32.c, wolfcrypt/src/sp_x86_64.c
Coverage: 4 of 4 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

Problem
Three defects in the generated SP ECC code.
Fix (
wolfcrypt/src/sp_c32.c,sp_c64.c, and the other SP backends)The SP C files are regenerated from wolfSSL/scripts#730 except for sp_dsp32.c, one commit per finding.
Closes F-19086, F-19090 and F-19132
Tests
test_wc_ecc_import_x963_off_curvealso checks 10 crafted off-curve points that the faulty reduction accepted (P-256/384/521 for F-19090, P-521 for F-19132). It fails on the unpatched--enable-spand--enable-sp=smallbuilds, at both word sizes.Verification
wc_ecc_verify_hash()in turn) shows the forged signature accepted before the fix and rejected after, onsp_c64.c,sp_c32.candsp_arm64.c. With the fix it also passes onsp_x86_64.cand, under qemu,sp_arm32.candsp_riscv64.c. Not added to the suite.sp_<N>_mod_*against exact arithmetic on 187,785 inputs: P-521 mod p gave 3343 wrong results (c64) and 1174 (c32) before, 0 after. P-256/P-384 mod p and all mod n results were correct before and after.testwolfcryptand the fullunit.testpass for--enable-spand--enable-sp=smallat both word sizes and with FP_ECC + small stack. ASan + UBSan are clean.Not in this PR
sp_dsp32.calready fails to compile for Hexagon with theIDE/HEXAGONsettings (5 errors on master). This change adds no new diagnostics.