diff --git a/tests/api.c b/tests/api.c index 95372ac40..7430b1f25 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2748,6 +2748,9 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args) } ctx = wolfSSL_CTX_new(method); } + if (ctx == NULL) { + goto done; + } #if defined(HAVE_SESSION_TICKET) && \ ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM)) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 71f451007..3260d02fc 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -6188,7 +6188,7 @@ void bench_eccsiPairGen(void) byte id[] = { 0x01, 0x23, 0x34, 0x45 }; int ret; - mp_init(&ssk); + (void)mp_init(&ssk); pvt = wc_ecc_new_point(); wc_InitEccsiKey(&genKey, NULL, INVALID_DEVID); (void)wc_MakeEccsiKey(&genKey, &gRng); @@ -6227,7 +6227,7 @@ void bench_eccsiValidate(void) int valid; int ret; - mp_init(&ssk); + (void)mp_init(&ssk); pvt = wc_ecc_new_point(); wc_InitEccsiKey(&genKey, NULL, INVALID_DEVID); (void)wc_MakeEccsiKey(&genKey, &gRng); @@ -6272,7 +6272,7 @@ void bench_eccsi(void) int ret; int verified; - mp_init(&ssk); + (void)mp_init(&ssk); pvt = wc_ecc_new_point(); (void)wc_InitEccsiKey(&genKey, NULL, INVALID_DEVID); (void)wc_MakeEccsiKey(&genKey, &gRng); @@ -6518,10 +6518,10 @@ void bench_sakke(void) bench_stats_asym_finish("SAKKE", 1024, desc[10], 0, count, start, 0); len = 0; - wc_GenerateSakkeRskTable(&genKey, rsk, NULL, &len); + (void)wc_GenerateSakkeRskTable(&genKey, rsk, NULL, &len); if (len > 0) { table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - wc_GenerateSakkeRskTable(&genKey, rsk, table, &len); + (void)wc_GenerateSakkeRskTable(&genKey, rsk, table, &len); } (void)wc_SetSakkeRsk(&genKey, rsk, table, len); diff --git a/wolfcrypt/src/sakke.c b/wolfcrypt/src/sakke.c index c07f3e345..8468d08b5 100644 --- a/wolfcrypt/src/sakke.c +++ b/wolfcrypt/src/sakke.c @@ -6134,6 +6134,10 @@ static int sakke_hash_to_range(SakkeKey* key, enum wc_HashType hashType, XMEMSET(h, 0, hashSz); err = 0; /* reset err value after getting digest size */ } + else if (err == 0) { + /* invalid hash digest size */ + err = BAD_FUNC_ARG; + } /* Step 3: l = Ceiling(lg(n)/hashlen) */ /* Step 4: For each i in 1 to l, do */ diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 4de350fc9..ef665c9d6 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -27281,7 +27281,7 @@ static int eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt) return -10117; decPvt = wc_ecc_new_point(); - if (ret != 0) + if (decPvt == NULL) return -10118; ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz); @@ -27645,80 +27645,100 @@ static int eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng, int eccsi_test(void) { - int ret; + int ret = 0; WC_RNG rng; - EccsiKey* priv; - EccsiKey* pub; - mp_int* ssk; - ecc_point* pvt; + EccsiKey* priv = NULL; + EccsiKey* pub = NULL; + mp_int* ssk = NULL; + ecc_point* pvt = NULL; priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL) { - return -10205; + ret = -10205; } - pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, + + if (ret == 0) { + pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (pub == NULL) { - XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -10206; - } - ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (ssk == NULL) { - XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -10207; + if (pub == NULL) { + ret = -10206; + } } -#ifndef HAVE_FIPS - ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); -#else - ret = wc_InitRng(&rng); -#endif - if (ret != 0) - return -10200; + if (ret == 0) { + ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER); + if (ssk == NULL) { + ret = -10207; + } + } - pvt = wc_ecc_new_point(); - if (pvt == NULL) - return -10201; - ret = mp_init(ssk); - if (ret != 0) - return -10202; + if (ret == 0) { + #ifndef HAVE_FIPS + ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); + #else + ret = wc_InitRng(&rng); + #endif + if (ret != 0) + ret = -10200; + } - ret = eccsi_api_test(&rng, priv, ssk, pvt); - if (ret != 0) - return ret; + if (ret == 0) { + pvt = wc_ecc_new_point(); + if (pvt == NULL) + ret = -10201; + } - ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID); - if (ret != 0) - return -10203; + if (ret == 0) { + ret = mp_init(ssk); + if (ret != 0) + ret = -10202; + } - ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID); - if (ret != 0) - return -10204; + if (ret == 0) { + ret = eccsi_api_test(&rng, priv, ssk, pvt); + } - ret = eccsi_kat_verify_test(pub, pvt); - if (ret != 0) - return ret; + if (ret == 0) { + ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID); + if (ret != 0) + ret = -10203; + } - ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt); - if (ret != 0) - return ret; + if (ret == 0) { + ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID); + if (ret != 0) + ret = -10204; + } - ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt); - if (ret != 0) - return ret; + if (ret == 0) { + ret = eccsi_kat_verify_test(pub, pvt); + } + + if (ret == 0) { + ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt); + } + + if (ret == 0) { + ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt); + } wc_FreeEccsiKey(priv); wc_FreeEccsiKey(pub); mp_free(ssk); wc_ecc_del_point(pvt); - wc_FreeRng(&rng); - XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return 0; + if (ret != -10200) + wc_FreeRng(&rng); + if (ssk != NULL) + XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (pub != NULL) + XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (priv != NULL) + XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + + return ret; } #endif /* WOLFCRYPT_HAVE_ECCSI */