diff --git a/tests/api/test_curve448.c b/tests/api/test_curve448.c index 170ac54fb3..83fd0f8c37 100644 --- a/tests/api/test_curve448.c +++ b/tests/api/test_curve448.c @@ -1106,8 +1106,17 @@ int test_wc_curve448_cryptocb(void) wc_curve448_free(&keyB); #ifndef WC_NO_CONSTRUCTORS + /* result_code and key_p are both optional */ + { + curve448_key* keyC = NULL; + ExpectNotNull(keyC = wc_curve448_new(HEAP_HINT, devId, NULL)); + if (keyC != NULL) { + DoExpectIntEQ(wc_curve448_delete(keyC, NULL), 0); + } + } if (keyA != NULL) { DoExpectIntEQ(wc_curve448_delete(keyA, &keyA), 0); + ExpectNull(keyA); } ExpectIntEQ(wc_curve448_delete(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); diff --git a/wolfcrypt/src/curve448.c b/wolfcrypt/src/curve448.c index 653a119832..058b7f44cc 100644 --- a/wolfcrypt/src/curve448.c +++ b/wolfcrypt/src/curve448.c @@ -342,9 +342,9 @@ int wc_curve448_shared_secret_ex(curve448_key* private_key, wc_MemZero_Add("wc_curve448_shared_secret_ex o", o, CURVE448_PUB_KEY_SIZE); #endif - if (ret == 0) { - ret = curve448(o, private_key->k, public_key->p); - } + /* ret is 0 here: the argument checks return early and the cryptocb block + * either returns or resets it. */ + ret = curve448(o, private_key->k, public_key->p); #ifndef WOLFSSL_NO_ECDHX_SHARED_ZERO_CHECK if (ret == 0) { byte t = 0; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 335d936114..0a70c61bf8 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -80467,7 +80467,10 @@ static wc_test_ret_t curve448_onlycb_test(myCryptoDevCtx *ctx) ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key); if (ret != 0) ret = WC_TEST_RET_ENC_EC(ret); - else if (!key.privSet || !key.pubSet || (key.p[0] != 0xC3) || + else if (!key.privSet || !key.pubSet || + !curve448_buf_is(key.p, 0xC3, CURVE448_PUB_KEY_SIZE) || + (key.k[0] != 0x58) || + !curve448_buf_is(key.k + 1, 0x5A, CURVE448_KEY_SIZE - 2) || (key.k[CURVE448_KEY_SIZE-1] != 0xDA)) ret = WC_TEST_RET_ENC_NC; @@ -80557,7 +80560,8 @@ static wc_test_ret_t curve448_onlycb_test(myCryptoDevCtx *ctx) ret = wc_curve448_shared_secret(&key, &pubKey, out, &outLen); if (ret != 0) ret = WC_TEST_RET_ENC_EC(ret); - else if ((outLen != CURVE448_KEY_SIZE) || (out[0] != 0xA5)) + else if ((outLen != CURVE448_KEY_SIZE) || + !curve448_buf_is(out, 0xA5, CURVE448_PUB_KEY_SIZE)) ret = WC_TEST_RET_ENC_NC; } if (ret == 0) { @@ -81206,12 +81210,12 @@ static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx) printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar); #endif if (myCtx->exampleVar == 99) { + info->pk.curve448kg.key->devId = devIdArg; /* the dispatcher must hand over a usable payload */ if ((info->pk.curve448kg.rng == NULL) || (info->pk.curve448kg.size != CURVE448_KEY_SIZE)) { return BAD_FUNC_ARG; } - info->pk.curve448kg.key->devId = devIdArg; /* deterministic key material so the caller can prove the * callback's output actually reached it */ XMEMSET(info->pk.curve448kg.key->k, 0x5A, CURVE448_KEY_SIZE);