forked from wolfSSL/wolfssl
add support for importing private only EC key to a WOLFSSL_EVP_PKEY struct
This commit is contained in:
15
tests/api.c
15
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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user