Repository navigation
Conversation
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Signed SP math configurations, such as OPENSSL_EXTRA, now fail to link unit.test when WC_NO_CACHE_RESISTANT is defined or ECC_TIMING_RESISTANT is absent: the test is enabled although sp_cond_swap_ct is unavailable. Separately, the P-521 regression does not cover same-size curve selection or ambiguous-prime rejection, leaving the other order-selection fix and new rejection behavior unprotected.
2 open issues
What changed in this PR
This PR corrects elliptic-curve arithmetic and strengthens sensitive-data cleanup in wolfCrypt’s math implementations.
Changes:
- Select curve orders by prime when reducing oversized FP ECC scalars.
- Wipe temporary arithmetic buffers across SP backends.
- Preserve signs during conditional swaps and add regression tests.
| File | Description |
|---|---|
| wolfcrypt/src/tfm.c | Swap signs alongside integer values. |
| wolfcrypt/src/sp_x86_64.c | Wipe x86-64 arithmetic scratch. |
| wolfcrypt/src/sp_riscv64.c | Wipe RISC-V arithmetic scratch. |
| wolfcrypt/src/sp_int.c | Add zeroizing cleanup for integer temporaries. |
| wolfcrypt/src/sp_cortexm.c | Wipe Cortex-M arithmetic scratch. |
| wolfcrypt/src/sp_c64.c | Wipe portable 64-bit arithmetic scratch. |
| wolfcrypt/src/sp_c32.c | Wipe portable 32-bit arithmetic scratch. |
| wolfcrypt/src/sp_armthumb.c | Wipe ARM Thumb arithmetic scratch. |
| wolfcrypt/src/sp_arm64.c | Wipe ARM64 arithmetic scratch. |
| wolfcrypt/src/sp_arm32.c | Wipe ARM32 arithmetic scratch. |
| wolfcrypt/src/ecc.c | Match curve orders by prime; reject ambiguity. |
| tests/api/test_wolfmath.h | Register math regression tests. |
| tests/api/test_wolfmath.c | Test signed swaps and scratch cleanup. |
| tests/api/test_ecc.h | Register oversized-scalar regression. |
| tests/api/test_ecc.c | Test P-521 multiply-add with oversized scalars. |
Review effort: Balanced
Member
Author
|
retest this please |
Member
Author
|
retest this please |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
accel_fp_mul()andaccel_fp_mul2add()reduce a scalar wider than the modulus by the curve order, which they looked up as the firstecc_setsentry of the same size. A staleif (y == 66) --xback-off then selected the previous curve's order for P-521, and same-size curves such as secp256k1 and the Brainpool curves got P-256's order, giving a wrong point. A newfp_ecc_get_order()matches the curve by its prime. It returnsECC_BAD_ARG_Ewhen no curve matches or when two compiled-in curves share the prime but have different orders (some opt-in SECG and X9.62 curves). (F-19394)sp_int.cfreed the scratch of its exponentiation, inversion, gcd and lcm functions without wiping it: the RSA-CRT half result and Montgomery base, and inverses of private values._sp_exptmod_ex(),_sp_exptmod_mont_ex(),_sp_exptmod_nct(),_sp_exptmod_base_2*(),_sp_invmod*(),_sp_gcd()and_sp_lcm()now wipe it first, with newFREE_*_ZEROmacros that take the length from the allocation. (F-17660)d. Generator change: wolfSSL/scripts#739. (F-14668)fp_cond_swap_ct_ex()intfm.cswappedusedand the digits but notsign, unlikeinteger.candsp_int.c. (F-9976)Resolves F-19394, F-17660, F-14668, F-9976.
Testing
New tests in
tests/api: a P-521 FP ECC multiply-add with oversized scalars checked against the expected point, a whitebox check that the exptmod, base-2 exptmod, non-constant-time exptmod and invmod scratch is wiped when freed (sp-math-all with smallstack), and a conditional swap of signed values. Each fails without its fix. The generated SP wipes aren't observable from a test.--enable-all, FP ECC with SP math and with fastmath, sp-math-all with smallstack (with and withoutWC_NO_CACHE_RESISTANT), SP C 64-bit (stack, smallstack,SP_RSA_PRIVATE_EXP_D) andSP_WORD_SIZE=32, and x86_64 SP assembly, with ASan and-Werror.sp_arm32.c,sp_arm64.c,sp_cortexm.candsp_armthumb.ccross-compiled with-Werror;sp_riscv64.cnot compiled.