Skip to content

Commit 17461f2

Browse files
ejohnstownJacobBarthelmeh
authored andcommitted
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
1 parent e7c8dc2 commit 17461f2

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

tests/unit.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11167,6 +11167,7 @@ static int test_IdentifyAsn1Key_EccPrivOnlyDerFailure(int curveSz,
1116711167
byte* eccDer = NULL;
1116811168
int eccDerSz;
1116911169
int i;
11170+
int expected = WS_CRYPTO_FAILED;
1117011171

1117111172
WMEMSET(&eccKey, 0, sizeof(eccKey));
1117211173
if (wc_ecc_init(&eccKey) != 0) {
@@ -11209,12 +11210,30 @@ static int test_IdentifyAsn1Key_EccPrivOnlyDerFailure(int curveSz,
1120911210
}
1121011211
}
1121111212

11213+
/* Some wolfSSL builds reject the zeroed scalar while decoding the DER,
11214+
* so IdentifyAsn1Key never reaches the derivation and reports the key
11215+
* as unidentified. Ask this build which rejection to expect. */
11216+
{
11217+
ecc_key probeKey;
11218+
word32 probeIdx = 0;
11219+
11220+
if (wc_ecc_init(&probeKey) != 0) {
11221+
WFREE(eccDer, NULL, 0);
11222+
return -6939;
11223+
}
11224+
if (wc_EccPrivateKeyDecode(eccDer, &probeIdx, &probeKey,
11225+
(word32)eccDerSz) != 0) {
11226+
expected = WS_UNIMPLEMENTED_E;
11227+
}
11228+
wc_ecc_free(&probeKey);
11229+
}
11230+
1121211231
ret = IdentifyAsn1Key(eccDer, (word32)eccDerSz, 1, NULL, NULL);
1121311232
WFREE(eccDer, NULL, 0);
1121411233

11215-
if (ret != WS_CRYPTO_FAILED) {
11216-
printf("IdentifyAsn1Key: private-only ECC %s DER fallback derivation "
11217-
"expected WS_CRYPTO_FAILED, got %d\n", curveName, ret);
11234+
if (ret != expected) {
11235+
printf("IdentifyAsn1Key: private-only ECC %s DER rejection expected "
11236+
"%d, got %d\n", curveName, expected, ret);
1121811237
return -6938;
1121911238
}
1122011239

0 commit comments

Comments
 (0)