Commit 0d8acd2
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.
Reproduces the failure seen in SoftHSM's ECDHTests::testPKCS8 and
ECDSATests::testPKCS8 which use exactly this pattern.1 parent a46a2f6 commit 0d8acd2
2 files changed
+87
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16265 | 16265 | | |
16266 | 16266 | | |
16267 | 16267 | | |
| 16268 | + | |
| 16269 | + | |
| 16270 | + | |
| 16271 | + | |
| 16272 | + | |
| 16273 | + | |
| 16274 | + | |
| 16275 | + | |
| 16276 | + | |
| 16277 | + | |
| 16278 | + | |
| 16279 | + | |
| 16280 | + | |
| 16281 | + | |
| 16282 | + | |
| 16283 | + | |
| 16284 | + | |
| 16285 | + | |
| 16286 | + | |
| 16287 | + | |
| 16288 | + | |
| 16289 | + | |
| 16290 | + | |
| 16291 | + | |
| 16292 | + | |
| 16293 | + | |
| 16294 | + | |
| 16295 | + | |
| 16296 | + | |
| 16297 | + | |
| 16298 | + | |
| 16299 | + | |
| 16300 | + | |
| 16301 | + | |
| 16302 | + | |
| 16303 | + | |
| 16304 | + | |
| 16305 | + | |
| 16306 | + | |
| 16307 | + | |
| 16308 | + | |
| 16309 | + | |
| 16310 | + | |
| 16311 | + | |
| 16312 | + | |
| 16313 | + | |
| 16314 | + | |
| 16315 | + | |
| 16316 | + | |
| 16317 | + | |
| 16318 | + | |
| 16319 | + | |
| 16320 | + | |
| 16321 | + | |
| 16322 | + | |
| 16323 | + | |
| 16324 | + | |
| 16325 | + | |
| 16326 | + | |
| 16327 | + | |
| 16328 | + | |
| 16329 | + | |
| 16330 | + | |
| 16331 | + | |
| 16332 | + | |
| 16333 | + | |
| 16334 | + | |
| 16335 | + | |
| 16336 | + | |
| 16337 | + | |
16268 | 16338 | | |
16269 | 16339 | | |
16270 | 16340 | | |
| |||
34923 | 34993 | | |
34924 | 34994 | | |
34925 | 34995 | | |
| 34996 | + | |
| 34997 | + | |
34926 | 34998 | | |
34927 | 34999 | | |
34928 | 35000 | | |
| |||
| 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