Repository navigation
ECC key derivation fixes - #11420
ECC key derivation fixes#11420stenslae wants to merge 4 commits into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
|
1cb63e0 to
8ce0584
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The helper can cause NO_ASN link failures and unnecessarily fail hardware-only derivation paths during RNG initialization.
4 open findings
What changed in this PR
Adds public-point derivation for SEC1 ECC private keys that omit the optional public key.
Changes:
- Introduces a shared ECC public-point derivation helper.
- Integrates derivation into PKCS7, static ephemeral, and OpenSSL-compatible loaders.
- Adds API and white-box regression coverage.
| File | Description |
|---|---|
wolfssl/wolfcrypt/asn_public.h |
Declares and documents the helper. |
wolfcrypt/src/pkcs7.c |
Completes imported PKCS7 ECC keys. |
wolfcrypt/src/evp.c |
Completes keys during EVP operations. |
wolfcrypt/src/asn.c |
Implements conditional public-point derivation. |
tests/unit-mcdc/test_asn_keys_whitebox.c |
Tests helper internals. |
tests/api/test_ssl_pk.h |
Registers static-key tests. |
tests/api/test_ssl_pk.c |
Tests static ephemeral private-only keys. |
tests/api/test_pkcs7.h |
Registers PKCS7 coverage. |
tests/api/test_pkcs7.c |
Tests PKCS7 private-only keys. |
tests/api/test_ossl_ec.c |
Expands OpenSSL compatibility tests. |
tests/api/test_asn.h |
Registers ASN tests. |
tests/api/test_asn.c |
Tests decode and explicit derivation. |
tests/api/api.h |
Adds ECC derivation capability detection. |
src/ssl_api_pk.c |
Derives static ECDH public points. |
src/pk_ec.c |
Updates EC loaders and private-only handling. |
doc/dox_comments/header_files/asn_public.h |
Documents private-only decoding. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 5 of 11 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_asn.c, tests/api/test_ossl_ec.c, tests/api/test_pkcs7.c, tests/api/test_ssl_pk.c, tests/unit-mcdc/test_asn_keys_whitebox.c, wolfssl/wolfcrypt/asn_public.h
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.
8ce0584 to
045c58e
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Coverage: 7 of 12 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_asn.c, tests/api/test_pkcs7.c, tests/api/test_ssl_pk.c, wolfssl/wolfcrypt/asn_public.h, wolfssl/wolfcrypt/ecc.h
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
045c58e to
b2de0ed
Compare
b2de0ed to
ba66010
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.h
Coverage: 11 of 13 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_asn.c, wolfssl/wolfcrypt/asn_public.h
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: Max
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.h
Coverage: 2 of 2 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: Lite
There was a problem hiding this comment.
🟡 Changes recommended
Key loading can fail for pending callbacks in mixed-backend builds, and private-only public-key derivation can leak three existing coordinate allocations with heap math enabled.
2 open issues
3 resolved since last review
Review effort: Balanced
ba66010 to
2c8390d
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.h
Coverage: 2 of 2 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.
SEC1 leaves that key private-only until the caller derives the point, and a failed derivation must not cache an all-zero one. The helpers let later tests skip builds that cannot derive and share the test key.
2c8390d to
354745d
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.h
Coverage: 0 of 1 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_asn.c
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
There was a problem hiding this comment.
🟡 Changes recommended
EC key handling can expose stale public coordinates after synchronization failures, while PKCS#8 assignment still bypasses public-point derivation and can reject private-only keys.
2 open issues
1 resolved since last review
Review effort: Balanced
354745d to
d8c0a53
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Unchanged since last review (not re-run): wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.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
There was a problem hiding this comment.
🟡 Changes recommended
The RNG documentation needs qualification because SP-accelerated base-point calls do not receive the RNG, so passing it does not guarantee multiplication blinding on every backend.
1 open issue
2 resolved since last review
Review effort: Balanced
SEC1 makes the public point optional. Derive it in one place that waits on async, fails closed, and says when the build cannot derive. In wolfmath.c/h, not ecc.c/h, so FIPS builds with tagged copies have it.
These decode SEC1 and then need the point. An EC_KEY given only its private key is now private-only, not a key with an all-zero point. pk_ec.c tried before under an ecc.c-private guard it never sees.
Under WOLFSSL_ECC_BLIND_K, wc_ecc_key_get_priv() leaves a plain copy. FIPS and self-test copies of ecc.h lack ecc_put_k(), so skip it there.
d8c0a53 to
d0bd701
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11420
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/asn_public.h, tests/api/api.h, tests/api/test_asn.h, tests/api/test_pkcs7.h, tests/api/test_ssl_pk.h
Coverage: 2 of 2 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



Description
RFC 5915 makes the publicKey field of an ECC private key optional. wc_EccPrivateKeyDecode() leaves such a key as ECC_PRIVATEKEY_ONLY. Several callers then used the key as if it had a point, or tried to derive it in ways that never compiled in.
Added wc_ecc_derive_pub_if_needed(key, rng). It derives the point of a private-only key, waits on async devices, and resets the key to private-only if derivation fails, so an all-zero point is never cached.
A private-only key loaded for the tls static ephemeral key share now gets its point derived. If derivation fails, the handshake fails instead of quietly generating a different key.
PKCS#7 signing now derives the point if needed before wc_ecc_check_key().
d2i_ECPrivateKey, EC_KEY_LoadDer, and PEM_write_*ECPrivateKey share one helper, wolfssl_ec_key_derive_pub(), which uses an RNG to blind the scalar multiply.
EVP_PKEY_set1_EC_KEY/assign_EC_KEY and EVP_PKEY_cmp use the same blinded helper and copy the derived point back into the EC_KEY. As before, they fail if the point can't be derived.
EC_KEY_set_private_key() with no public key: the key is now private-only, not a key with an all-zero point
under WOLFSSL_ECC_BLIND_K, the plain copy of the private scalar made while reading an EC_KEY is now wiped
Testing
Added coverage over pr changes.
Checklist