diff --git a/tests/api.c b/tests/api.c index a35b674d1..736ac6013 100644 --- a/tests/api.c +++ b/tests/api.c @@ -26372,6 +26372,21 @@ static int test_wc_EccPrivateKeyToDer (void) if (ret == 0) { ret = wc_EccPrivateKeyToDer(&eccKey, output, inLen); if (ret > 0) { + #ifdef OPENSSL_EXTRA + /* test importing private only into a PKEY struct */ + EC_KEY* ec; + EVP_PKEY* pkey; + const unsigned char* der = output; + + pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, ret); + AssertNotNull(pkey); + + der = output; + ec = d2i_ECPrivateKey(NULL, &der, ret); + AssertNotNull(ec); + AssertIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS); + EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */ + #endif ret = 0; } } diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 11311c701..59003f219 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -7320,6 +7320,12 @@ static int ECC_populate_EVP_PKEY(EVP_PKEY* pkey, WOLFSSL_EC_KEY *key) else #endif /* HAVE_PKCS8 */ { + if (ecc->type == ECC_PRIVATEKEY_ONLY) { + if (wc_ecc_make_pub(ecc, NULL) != MP_OKAY) { + return WOLFSSL_FAILURE; + } + } + /* if not, the pkey will be traditional ecc key */ if ((derSz = wc_EccKeyDerSize(ecc, 1)) > 0) { derBuf = (byte*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_OPENSSL);