Repository navigation
Conversation
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues remain: an unguarded test helper breaks feature-disabled builds, and noncanonical field comparisons reject valid compressed P-256 and P-521 points.
3 open issues
What changed in this PR
This PR corrects compressed ECC point recovery in wolfCrypt and adds checks to reject coordinates with no valid square root.
Changes:
- Uses Atkin’s method for primes congruent to 5 modulo 8 under
SQRTMOD_USE_MOD_EXP, with square-back validation. - Adds recovered-root validation across nine generated single-precision arithmetic backends.
- Adds compressed-point regression tests and skips unsupported P-224 round trips under
SQRTMOD_USE_MOD_EXP.
| File | Description |
|---|---|
wolfcrypt/test/test.c |
Skips unsupported compressed P-224 round trips. |
wolfcrypt/src/sp_x86_64.c |
Adds root validation for x86-64 decompression. |
wolfcrypt/src/sp_riscv64.c |
Adds root validation for RISC-V decompression. |
wolfcrypt/src/sp_dsp32.c |
Adds root validation for DSP P-256 decompression. |
wolfcrypt/src/sp_cortexm.c |
Adds root validation for Cortex-M decompression. |
wolfcrypt/src/sp_c64.c |
Adds root validation for portable 64-bit decompression. |
wolfcrypt/src/sp_c32.c |
Adds root validation for portable 32-bit decompression. |
wolfcrypt/src/sp_armthumb.c |
Adds root validation for ARM Thumb decompression. |
wolfcrypt/src/sp_arm64.c |
Adds root validation for ARM64 decompression. |
wolfcrypt/src/sp_arm32.c |
Adds root validation for ARM32 decompression. |
wolfcrypt/src/ecc.c |
Corrects modular square-root calculation and validates results. |
tests/api/test_ecc.h |
Registers the compressed-point regression test. |
tests/api/test_ecc.c |
Adds known-point, no-root, and round-trip tests. |
Review effort: Balanced
dgarske
force-pushed
the
ecc_sqrtmod
branch
2 times, most recently
from
November 3, 2026 23:42
c0576a4 to
9bf5d5f
Compare
… with no square root
Member
Author
|
Jenkins retest this please "Found unhandled java.io.IOException exception:" and FIleExceptions. |
SparkiDev
requested changes
Nov 4, 2026
| else if (res == MP_OKAY && i == 5) { | ||
| res = mp_sub_d(prime, 1, &e); | ||
|
|
||
| /* prime mod 8 = 5: v = (2N)^((p-5)/8), i = 2N.v^2, ret = N.v.(i-1) */ |
Contributor
There was a problem hiding this comment.
Put #if guard around the prime mod 8 = 5 code.
It is not regularly needed and should be dropped when the user defines something.
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.

Under
SQRTMOD_USE_MOD_EXP,mp_sqrtmod_prime()used the exponent (p-1)/4 for a prime that is 5 mod 8, which never yields a root, so a compressed secp224k1 point decompressed to a wrong y; it also returned a value for an x with no square root. It now uses Atkin's method for p = 5 mod 8, squares the result and returnsMP_VALwhen it is not a root, and keeps its small stack footprint; a prime that is 1 mod 8 (P-224) stays unsupported under that define and the crypt test skips it there. The generatedsp_ecc_uncompress_256/384/521()now square the recovered y as well, reducing both sides below the modulus first assp_<n>_map_<w>()does, so a trusted compressed import in SP builds can no longer produce a point off the curve. Also reported by @mimoex (ZD 22735) and Resolves F-16899.