Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The P-256 test guard omits the minimum-key-size condition, causing the new test to fail on valid builds where ECC_MIN_KEY_SZ exceeds 256 and P-256 is excluded.
1 open issue
What changed in this PR
Follows up on #12023 by hardening wolfCrypt’s ECC scalar-length checks and correcting random-integer generation when reusing heap-math values.
Changes:
- Replaces scalar bit-count checks with digit-based checks that avoid timing dependence on the top set bit while preserving existing limits.
- Clears heap-math
mp_rand()output before sizing it, preventing stale high digits and sign from surviving. - Adds regression tests for ECC scalar-length boundaries and random-integer reuse.
| File | Description |
|---|---|
wolfcrypt/src/wolfmath.c |
Clears reused heap-math integers before random generation. |
wolfcrypt/src/ecc.c |
Adds and applies the scalar-length helper across multiplication paths. |
tests/api/test_wolfmath.c |
Tests random generation into a previously wider integer. |
tests/api/test_ecc.h |
Declares and registers the scalar-length test. |
tests/api/test_ecc.c |
Adds P-256 and P-521 scalar-length boundary tests. |
Review effort: Balanced
|
b999b63 to
d4ffd30
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Secret-scalar timing changes require human validation of target/compiler side-channel behavior on targets without bit-scan instructions, which source inspection and a standalone boundary check cannot establish.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12129
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_ecc.h
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
d4ffd30 to
6bb19b2
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12129
Scan targets checked: wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): tests/api/test_ecc.h
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
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
|
Jenkins retest this please |
6bb19b2 to
243bb78
Compare

Description
Two follow-ups to #12023.
ECC scalar length. The generic point multiplication entry points (
wc_ecc_mulmod_ex(),wc_ecc_mulmod_ex2()and the SP wrapper) range-checked the scalar withmp_count_bits(), and the FP_ECC comb compared its byte length. With fastmath and heap math, and with SP math on targets that have no bit-scan instruction,mp_count_bits()loops over the bits of the top digit, so the time it takes depends on the scalar's bit length.ecc_k_too_long()now ORs together the bits of the scalar at and above the limit instead, so only the number of digits in the scalar affects the time. The limits and error codes are unchanged. The remaining value-dependent branches in the generic point arithmetic, and the separatewc_ecc_mulmod_ex()implementations in the NXP KSDK and STM32 ports, are not changed here.mp_rand on heap math.
mp_rand()sized its output withmp_set_bit(), which only ORs one bit into whateveraalready holds. Whenahad more digits than requested, the result kept the old high digits and their sign.ais now zeroed first, withmp_2expt(). SP math and fastmath setuseddirectly and are unchanged.Testing
test_wc_ecc_mulmod_k_lencovers the scalar length boundary on P-256 and P-521, andtest_mp_randcovers a call on anmp_intthat already holds a wider value, on every math back end.ZD 22745. Reported by Alexandre Laroche.