Repository navigation
Conversation
sp_int.c has fixed size multiply and square routines for 256-bit and 384-bit numbers that speed up the generic ECC code, and leaves them out whenever WOLFSSL_HAVE_SP_ECC is defined. With WOLFSSL_SP_MATH_ALL the generic code still works on numbers of those sizes: for curves the SP code does not implement (P-384 when only SP P-256 is built, Brainpool and Koblitz curves) and for callers of the public mp API. On MIPS32 with SP code for P-256 only, generic P-384 signing and verification became about 19% slower than with no SP code at all. Keep them with WOLFSSL_SP_MATH_ALL.
|
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and found no bugs. It turns on the unrolled and inline-asm multiply and square routines in builds that have both SP ECC and sp-math-all, a combination many default configurations use, so a human look at the core bignum arithmetic is still worthwhile.
What was reviewed:
- All four guard sites (the
_sp_mul_*and_sp_sqr_*definitions and their dispatch insp_mul()/sp_sqr()) use the same new condition, and the#endifcomments match. - The dangling
elsechains insp_mul()/sp_sqr()keep the same structure. Only the outer condition changed, so every macro combination still produces a valid statement. - No other uses of
WOLFSSL_HAVE_SP_ECCor callers of these helpers insp_int.cneed to change with it.
Extended reasoning...
The change only edits four preprocessor conditions in wolfcrypt/src/sp_int.c. They now compile and dispatch to the fixed-size 256/384-bit multiply and square helpers (C and SQR_MUL_ASM variants) when WOLFSSL_HAVE_SP_ECC and WOLFSSL_SP_MATH_ALL are both defined. Each helper definition and its call site use the same guard, so no symbols go missing or unused. The change is crypto-sensitive: these routines will now do multiprecision arithmetic for generic ECC curves and public mp_* callers in builds that never ran them before, including timing-relevant inline assembly on several CPUs. That expanded runtime exposure in core crypto code is why I'm deferring to a human rather than approving.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11911
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 1 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
Description
sp_int.chas fixed size multiply and square routines for 256-bit and 384-bit numbers (_sp_mul_4/6/8/12,_sp_sqr_4/6/8/12, with inline assembly on several CPUs) that speed up the generic ECC code. They are left out wheneverWOLFSSL_HAVE_SP_ECCis defined, on the assumption that the SP code does the ECC work.With
WOLFSSL_SP_MATH_ALLthat is not always true: the generic code still works on numbers of those sizes--enable-sp=ec256, and on 32-bit CPUs--enable-sp=yesonly gives P-256), or the Brainpool and Koblitz curves;mp_*calls.So enabling SP for one curve made the others slower than with no SP code at all. On a MIPS 24Kc at 650 MHz with
--enable-sp=ec256:WPA3-SAE with hunting-and-pecking on P-256 (hostapd and wpa_supplicant from the same build, together with #11912) went from 337 ms to 314 ms per connection, and hostapd's CPU time from 228 ms to 202 ms.
This keeps the routines when
WOLFSSL_SP_MATH_ALLis defined.WOLFSSL_SP_MATHbuilds and builds without SP ECC are unchanged. The cost is the code size of the routines in SP ECC + sp-math-all builds: on MIPS32 about 16 KB of library (about 2 KB compressed).Testing
./tests/unit.test --api --group eccandtestwolfcryptpass, on macOS arm64, with:--enable-sp=ec256 --disable-sp-asm --enable-ecccustcurves=all--enable-sp=ec256,ec384,ec521 --enable-sp-asm --enable-ecccustcurves=all--enable-sp=smallec256,smallec384,smallec521 --disable-sp-asm --enable-ecccustcurves=all--enable-sp-math --enable-sp=yes,384,521--disable-sp --enable-ecccustcurves=all--enable-sp=ec256and--enable-sp=ec256,ec384,ec521):testwolfcryptpasses, and the benchmark numbers above.Checklist