Commit 5ea268c
committed
evp: fix EVP_PKEY2PKCS8 returning NULL for private-key-only EC keys
When an EC_KEY is created via EC_KEY_new + EC_KEY_set_group +
EC_KEY_set_private_key (no public point set), SetECKeyInternal
incorrectly marks the internal ecc_key as ECC_PRIVATEKEY (instead of
ECC_PRIVATEKEY_ONLY) because pub_key is always non-NULL — EC_KEY_new
always allocates it as an empty, zero-initialised EC_POINT.
ECC_populate_EVP_PKEY only calls wc_ecc_make_pub for ECC_PRIVATEKEY_ONLY
keys, so the zero public-key point was serialised into the DER stored in
pkey->pkey.ptr. After commit 929dd99 made wc_ecc_import_x963_ex always
pass untrusted=1, the re-decode inside wolfSSL_EVP_PKEY2PKCS8 →
wolfSSL_d2i_PrivateKey_EVP correctly rejected that zero point with an
on-curve failure, causing EVP_PKEY2PKCS8 to return NULL.
Fix: in ECC_populate_EVP_PKEY, also call wc_ecc_make_pub when the key
type is ECC_PRIVATEKEY but pubkey.x is zero (meaning the public key was
never actually populated). This reconstructs the public key from the
private scalar so that the encoded DER contains a valid on-curve point.1 parent 2d2713a commit 5ea268c
1 file changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3704 | 3704 | | |
3705 | 3705 | | |
3706 | 3706 | | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
3707 | 3711 | | |
3708 | 3712 | | |
3709 | 3713 | | |
| |||
3758 | 3762 | | |
3759 | 3763 | | |
3760 | 3764 | | |
| 3765 | + | |
| 3766 | + | |
3761 | 3767 | | |
3762 | 3768 | | |
3763 | 3769 | | |
| |||
9516 | 9522 | | |
9517 | 9523 | | |
9518 | 9524 | | |
9519 | | - | |
| 9525 | + | |
| 9526 | + | |
| 9527 | + | |
| 9528 | + | |
| 9529 | + | |
| 9530 | + | |
| 9531 | + | |
| 9532 | + | |
| 9533 | + | |
9520 | 9534 | | |
9521 | 9535 | | |
9522 | 9536 | | |
| |||
0 commit comments