Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new ECC encoder still needs deterministic regression coverage for fixed-width padding, returned size, and undersized-buffer error handling without modifying the buffer.
1 open issue
What changed in this PR
This PR removes scalar-bit-length-dependent sizing from the ECC private-key export path used by wc_ecc_export_private_only() and HPKE receiver key copying.
Changes:
- Uses constant-time encoding for unsigned binary exports when the output width covers the curve order.
- Handles undersized buffers explicitly and retains the existing exporter for other formats or widths.
| File | Description |
|---|---|
wolfcrypt/src/ecc.c |
Adds constant-time private-scalar encoding with output-length and buffer checks. |
Review effort: Balanced
|
SparkiDev
force-pushed
the
hpke_p256_ct
branch
from
November 13, 2026 00:35
e364aea to
f7b58e6
Compare
wc_export_int() sized the scalar with mp_unsigned_bin_size(), which counts its bits and so takes time that depends on the scalar's bit length. It is reached from wc_ecc_export_private_only() and from the HPKE receiver key copy. Since d is in [1, n-1], it always fits when the output covers the order: encode it with mp_to_unsigned_bin_len_ct() instead.
SparkiDev
force-pushed
the
hpke_p256_ct
branch
from
November 13, 2026 00:47
f7b58e6 to
81f3da9
Compare
Contributor
Author
|
Jenkins: 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
wc_export_int() sized the scalar with mp_unsigned_bin_size(), which counts its bits and so takes time that depends on the scalar's bit length. It is reached from wc_ecc_export_private_only() and from the HPKE receiver key copy. Since d is in [1, n-1], it always fits when the output covers the order: encode it with
mp_to_unsigned_bin_len_ct() instead.
Fixes zd#22808
Testing
./configure --enable-hpke