From 17461f2271afd027144f1057576b3d63c598b1bf Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 20 Aug 2026 15:49:49 -0700 Subject: [PATCH] Derive the expected ECC rejection in the priv-only key test wolfSSL master now rejects a private scalar outside [1, n-1] when importing one, so the zeroed key that test_IdentifyAsn1Key_EccPrivOnlyDerFailure builds fails in wc_EccPrivateKeyDecode instead of reaching the wc_ecc_make_pub fallback in IdentifyAsn1Key. The identify call then reports the key as unidentified, WS_UNIMPLEMENTED_E, rather than WS_CRYPTO_FAILED, and the test failed against any wolfSSL built from master. - decode the corrupted DER first and expect the rejection the linked wolfSSL performs, so the assertion stays strict on either library --- tests/unit.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/unit.c b/tests/unit.c index bae11550..e1eff261 100644 --- a/tests/unit.c +++ b/tests/unit.c @@ -11167,6 +11167,7 @@ static int test_IdentifyAsn1Key_EccPrivOnlyDerFailure(int curveSz, byte* eccDer = NULL; int eccDerSz; int i; + int expected = WS_CRYPTO_FAILED; WMEMSET(&eccKey, 0, sizeof(eccKey)); if (wc_ecc_init(&eccKey) != 0) { @@ -11209,12 +11210,30 @@ static int test_IdentifyAsn1Key_EccPrivOnlyDerFailure(int curveSz, } } + /* Some wolfSSL builds reject the zeroed scalar while decoding the DER, + * so IdentifyAsn1Key never reaches the derivation and reports the key + * as unidentified. Ask this build which rejection to expect. */ + { + ecc_key probeKey; + word32 probeIdx = 0; + + if (wc_ecc_init(&probeKey) != 0) { + WFREE(eccDer, NULL, 0); + return -6939; + } + if (wc_EccPrivateKeyDecode(eccDer, &probeIdx, &probeKey, + (word32)eccDerSz) != 0) { + expected = WS_UNIMPLEMENTED_E; + } + wc_ecc_free(&probeKey); + } + ret = IdentifyAsn1Key(eccDer, (word32)eccDerSz, 1, NULL, NULL); WFREE(eccDer, NULL, 0); - if (ret != WS_CRYPTO_FAILED) { - printf("IdentifyAsn1Key: private-only ECC %s DER fallback derivation " - "expected WS_CRYPTO_FAILED, got %d\n", curveName, ret); + if (ret != expected) { + printf("IdentifyAsn1Key: private-only ECC %s DER rejection expected " + "%d, got %d\n", curveName, expected, ret); return -6938; }