Regenerate SP sources: constant-time sp_*_from_mp#10898
Open
danielinux wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR regenerates the single-precision (“sp”) implementation sources to make sp_<N>_from_mp() convert secret mp_int inputs in constant time by iterating a fixed amount (bounded by output size) and masking digits at/after a->used.
Changes:
- Regenerated multiple
sp_*_from_mp()implementations to avoid looping based ona->used(magnitude-dependent timing). - Added branchless masking logic to zero out digits beyond
a->usedduring conversion. - Applied the same pattern across several architecture-specific and generic SP backends.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| wolfcrypt/src/sp_x86_64.c | Regenerated constant-time masking conversion for sp_*_from_mp() in SP x86_64 backend. |
| wolfcrypt/src/sp_cortexm.c | Regenerated constant-time masking conversion for sp_*_from_mp() in Cortex-M backend. |
| wolfcrypt/src/sp_c64.c | Regenerated constant-time masking conversion for sp_*_from_mp() in 64-bit C backend. |
| wolfcrypt/src/sp_c32.c | Regenerated constant-time masking conversion for sp_*_from_mp() in 32-bit C backend. |
| wolfcrypt/src/sp_armthumb.c | Regenerated constant-time masking conversion for sp_*_from_mp() in ARM Thumb backend. |
| wolfcrypt/src/sp_arm64.c | Regenerated constant-time masking conversion for sp_*_from_mp() in ARM64 backend. |
| wolfcrypt/src/sp_arm32.c | Regenerated constant-time masking conversion for sp_*_from_mp() in ARM32 backend. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
danielinux
added a commit
to danielinux/wolfssl
that referenced
this pull request
Jul 14, 2026
Regenerated with the updated generator so sp_<N>_from_mp() clamps the read index to a valid digit (0 when a->used == 0), avoiding an out-of-bounds or NULL digit read in the fixed-count constant-time loop while keeping the conversion constant time. Addresses the Copilot review comments on this PR (wolfSSL#10898) and on wolfSSL/scripts#626. Verified (--enable-sp, gcc 15.2): ec_p521_kex diff 0, ec_p521_sign diff 55; make check passes. Generated by wolfSSL/scripts#626
danielinux
force-pushed
the
sp-from-mp-const-time
branch
from
July 14, 2026 12:08
fe810aa to
0046469
Compare
Member
Author
|
Jenkins retest this please |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10898
Scan targets checked: wolfcrypt-bugs, wolfcrypt-src
No new issues found in the changed files. ✅
danielinux
force-pushed
the
sp-from-mp-const-time
branch
from
July 16, 2026 00:18
0a13a42 to
c25bb9f
Compare
Member
Author
|
Jenkins retest this please |
danielinux
force-pushed
the
sp-from-mp-const-time
branch
2 times, most recently
from
July 17, 2026 06:57
e14b237 to
4c36537
Compare
Regenerated the single-precision C sources so that sp_<N>_from_mp() converts secret inputs (ECDH/ECDSA private keys and nonces) in constant time: a fixed-count loop bounded by the output size with masked reads at/after a->used, instead of looping a->used times (which leaked the value's magnitude through the executed-instruction count). Fixes the ct-callgrind constant-time failures for P-521 (ec_p521_kex, ec_p521_sign) and hardens the same pattern across all curves and key sizes (108 sp_*_from_mp functions in sp_c32/sp_c64, sp_arm32/sp_arm64/sp_armthumb/ sp_cortexm and sp_x86_64). Verified (--enable-sp, gcc 15.2): ec_p521_kex diff 156 -> 0, ec_p521_sign diff 367 -> 55 (tol 300); testwolfcrypt RSA/ECC KATs pass. Generated by wolfSSL/scripts#626
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
Regenerated the single-precision C sources so that sp__from_mp() converts secret inputs (ECDH/ECDSA private keys and nonces) in constant time: a fixed-count loop bounded by the output size with masked reads at/after a->used, instead of looping a->used times (which leaked the value's magnitude through the executed-instruction count).
Testing
Fixes the ct-callgrind constant-time failures for P-521 (ec_p521_kex, ec_p521_sign) and hardens the same pattern across all curves and key sizes (108 sp_*_from_mp functions in sp_c32/sp_c64, sp_arm32/sp_arm64/sp_armthumb/ sp_cortexm and sp_x86_64).
Verified (--enable-sp, gcc 15.2): ec_p521_kex diff 156 -> 0, ec_p521_sign diff 367 -> 55 (tol 300); testwolfcrypt RSA/ECC KATs pass.
Generated by https://github.com/wolfSSL/scripts/pull/626