Skip to content

Commit 4046525

Browse files
committed
fix: guard wc_ecc_make_pub with HAVE_ECC_MAKE_PUB
In builds without HAVE_ECC_MAKE_PUB (e.g. hardware/CB-only), keep the historical import behaviour instead of failing. Gate the test with the same define.
1 parent 89ab411 commit 4046525

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/pk_ec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3435,13 +3435,18 @@ WOLFSSL_EC_KEY* wolfSSL_d2i_ECPrivateKey(WOLFSSL_EC_KEY** key,
34353435
* wc_EccPrivateKeyDecode leaves type == ECC_PRIVATEKEY_ONLY with the
34363436
* public point uninitialised. Derive the public point now so that
34373437
* all downstream operations (sign, ECDH, export) have a valid key,
3438-
* matching the behaviour of OpenSSL's d2i_ECPrivateKey. */
3438+
* matching the behaviour of OpenSSL's d2i_ECPrivateKey.
3439+
* In builds without HAVE_ECC_MAKE_PUB (e.g. hardware/CB-only),
3440+
* keep the historical import behaviour and leave the key as
3441+
* private-only instead of failing import. */
3442+
#ifdef HAVE_ECC_MAKE_PUB
34393443
if (((ecc_key*)ret->internal)->type == ECC_PRIVATEKEY_ONLY) {
34403444
if (wc_ecc_make_pub((ecc_key*)ret->internal, NULL) != 0) {
34413445
WOLFSSL_MSG("wc_ecc_make_pub error deriving public key");
34423446
err = 1;
34433447
}
34443448
}
3449+
#endif
34453450
}
34463451

34473452
if (!err) {

tests/api/test_ossl_ec.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ int test_d2i_ECPrivateKey_no_pubkey(void)
16321632
{
16331633
EXPECT_DECLS;
16341634
#if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
1635-
defined(HAVE_ECC_KEY_IMPORT)
1635+
defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_MAKE_PUB)
16361636
/* RFC 5915 ECPrivateKey DER with version + privateKey + parameters [0]
16371637
* but NO publicKey [1] field. */
16381638
static const byte kPrivOnlyDer[] = {
@@ -1669,7 +1669,7 @@ int test_d2i_ECPrivateKey_no_pubkey(void)
16691669

16701670
XMEMSET(hash, 0xab, sizeof(hash));
16711671

1672-
/* Import private-only DER must succeed and auto-derive the public key. */
1672+
/* Import private-only DER -- must succeed and auto-derive the public key. */
16731673
ExpectNotNull(key = d2i_ECPrivateKey(NULL, &der, sizeof(kPrivOnlyDer)));
16741674

16751675
/* Structural validity: public point on curve, priv/pub consistent. */
@@ -1691,7 +1691,8 @@ int test_d2i_ECPrivateKey_no_pubkey(void)
16911691
ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
16921692

16931693
EC_KEY_free(key);
1694-
#endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP && HAVE_ECC_KEY_IMPORT */
1694+
#endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP && HAVE_ECC_KEY_IMPORT
1695+
* && HAVE_ECC_MAKE_PUB */
16951696
return EXPECT_RESULT();
16961697
}
16971698

0 commit comments

Comments
 (0)