Commit 4c23d4d
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 2a0b3bd commit 4c23d4d
1 file changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3715 | 3715 | | |
3716 | 3716 | | |
3717 | 3717 | | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
3718 | 3722 | | |
3719 | 3723 | | |
3720 | 3724 | | |
| |||
3769 | 3773 | | |
3770 | 3774 | | |
3771 | 3775 | | |
| 3776 | + | |
| 3777 | + | |
3772 | 3778 | | |
3773 | 3779 | | |
3774 | 3780 | | |
| |||
9521 | 9527 | | |
9522 | 9528 | | |
9523 | 9529 | | |
9524 | | - | |
| 9530 | + | |
| 9531 | + | |
| 9532 | + | |
| 9533 | + | |
| 9534 | + | |
| 9535 | + | |
| 9536 | + | |
| 9537 | + | |
| 9538 | + | |
9525 | 9539 | | |
9526 | 9540 | | |
9527 | 9541 | | |
| |||
0 commit comments