From 19b7eac3e84f62744b26304b1eeb4d21fdf0b1c9 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 10:39:42 +0100 Subject: [PATCH 1/8] Cover Ed448 key IDs and HMAC label-only keys --- tests/api/test_ed448.c | 5 +++++ tests/api/test_hmac.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/api/test_ed448.c b/tests/api/test_ed448.c index 13b2701605b..20187b20ddb 100644 --- a/tests/api/test_ed448.c +++ b/tests/api/test_ed448.c @@ -227,6 +227,11 @@ int test_wc_ed448_init_id(void) ExpectIntEQ(wc_ed448_init_id(&key, NULL, 0, NULL, INVALID_DEVID), 0); ExpectIntEQ(key.idLen, 0); wc_ed448_free(&key); +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + ExpectIntEQ(wc_ed448_init_id(&key, id, 0, NULL, INVALID_DEVID), 0); + ExpectIntEQ(key.idLen, 0); + wc_ed448_free(&key); +#endif ExpectIntEQ(wc_ed448_init_id(&key, id, ED448_MAX_ID_LEN, NULL, INVALID_DEVID), 0); ExpectIntEQ(key.idLen, ED448_MAX_ID_LEN); diff --git a/tests/api/test_hmac.c b/tests/api/test_hmac.c index 4cf3945faa0..8c84a7ff82e 100644 --- a/tests/api/test_hmac.c +++ b/tests/api/test_hmac.c @@ -1254,6 +1254,22 @@ int test_wc_HmacId_NoDevice(void) XFREE(bigKey, NULL, DYNAMIC_TYPE_TMP_BUFFER); #ifdef WOLF_CRYPTO_CB + { + word32 macSz = sizeof(mac); + + ExpectIntEQ(wc_HmacInit_Label(&hmac, "hmac-key", NULL, + INVALID_DEVID), 0); + ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, 0), 0); + ExpectIntEQ(wc_HmacUpdate(&hmac, msg, sizeof(msg)), + WC_NO_ERR_TRACE(MISSING_KEY)); + ExpectIntEQ(wc_HmacFinal(&hmac, mac), WC_NO_ERR_TRACE(MISSING_KEY)); + ExpectIntEQ(wc_HmacGenerate_ex(&hmac, WC_SHA256, mac, &macSz, msg, + sizeof(msg), NULL, 0, NULL, INVALID_DEVID), + WC_NO_ERR_TRACE(MISSING_KEY)); + ExpectIntEQ(hmac.idLen, 0); + ExpectIntGT(hmac.labelLen, 0); + wc_HmacFree(&hmac); + } ExpectIntEQ(wc_HmacInit_Id(&hmac, id, (int)sizeof(id), NULL, INVALID_DEVID), 0); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, 0), 0); From c19f404a2aff639e56b92c4f081a86df8199ca51 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 10:45:50 +0100 Subject: [PATCH 2/8] Cover ECCSI order-read failure and SAKKE RSK cleanup --- tests/unit-mcdc/test_eccsi_fault_whitebox.c | 29 ++++++++++++++++++++- tests/unit-mcdc/test_sakke_whitebox.c | 8 ++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/unit-mcdc/test_eccsi_fault_whitebox.c b/tests/unit-mcdc/test_eccsi_fault_whitebox.c index 658adf16241..ec2b2c6caea 100644 --- a/tests/unit-mcdc/test_eccsi_fault_whitebox.c +++ b/tests/unit-mcdc/test_eccsi_fault_whitebox.c @@ -805,6 +805,27 @@ static void wb_mp_sweeps(WC_RNG* rng) WB_NOTE("big-integer fault sweeps done"); } +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +static int wb_check_ssk_order(EccsiKey* key) +{ + int ret; + int retFault; + + /* With a readable order, the order itself is an out-of-range SSK. + * Hold that input fixed when forcing the order read to fail. */ + ret = eccsi_check_ssk(key, &key->params.order); + mcdc_fm_arm(1); + retFault = eccsi_check_ssk(key, &key->params.order); + mcdc_fm_disarm(); + + if (ret != WC_NO_ERR_TRACE(ECC_PRIV_KEY_E) || retFault != MCDC_FM_ERR) { + printf(" [wb] SSK order check returned %d and %d\n", ret, retFault); + return 1; + } + return 0; +} +#endif + int main(int argc, char** argv) { int do_sweep = !(argc > 1 && strcmp(argv[1], "baseline") == 0); @@ -818,6 +839,7 @@ int main(int argc, char** argv) mp_digit mp = 0; int ret; int n_idx; + int sskFailed = 0; const int K = 60; /* over-sweep past the mulmod/point-add allocation sites */ /* Unbuffered: if an armed call ever crashes, the notes printed so far @@ -873,6 +895,11 @@ int main(int argc, char** argv) goto cleanup; } +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + if (do_sweep) + sskFailed = wb_check_ssk_order(&key); +#endif + /* ---- baseline: one unarmed success of each targeted helper (err==0 * TRUE side of the map guard, both map polarities). ---- */ (void)reload_base(&key); @@ -965,7 +992,7 @@ int main(int argc, char** argv) printf("done (%s)\n", wb_error ? "with failures" : (wb_fail ? "with skips" : "ok")); (void)wb_fail; - return 0; + return sskFailed; } #endif /* WOLFCRYPT_HAVE_ECCSI && WOLFCRYPT_ECCSI_CLIENT */ diff --git a/tests/unit-mcdc/test_sakke_whitebox.c b/tests/unit-mcdc/test_sakke_whitebox.c index f4c0a399dc9..b8f85d578a6 100644 --- a/tests/unit-mcdc/test_sakke_whitebox.c +++ b/tests/unit-mcdc/test_sakke_whitebox.c @@ -122,6 +122,14 @@ int main(void) idBig[sizeof(idBig) - 1] = 0x5A; XMEMSET(&key, 0, sizeof(key)); +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + /* Invalid arguments stop before the key's temporary integers exist. */ + if (wc_MakeSakkeRsk(&key, id, sizeof(id), NULL) != + WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { + wb_fail = 1; + } +#endif + if (wc_InitRng(&rng) != 0) wb_fail = 1; if (wc_InitSakkeKey_ex(&key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID) != 0) wb_fail = 1; From 784084221683bc2bafa72bf3e33e24d7b2abb9fa Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 10:49:03 +0100 Subject: [PATCH 3/8] Cover DSA subgroup sizes and DH zero prime validation --- tests/api/test_dsa.c | 18 ++++++++++++++++++ wolfcrypt/test/test.c | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/tests/api/test_dsa.c b/tests/api/test_dsa.c index 839d7afd459..fb14ca7f019 100644 --- a/tests/api/test_dsa.c +++ b/tests/api/test_dsa.c @@ -132,6 +132,11 @@ int test_wc_DsaSignVerify(void) mp_free(&key.q); ExpectIntEQ(mp_init(&key.q), 0); ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); +#ifdef NO_DSA_PUBKEY_CHECK + /* With domain checks disabled, verify must still reject an empty q. */ + ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); +#endif mp_set(&key.q, 1); ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); @@ -647,6 +652,8 @@ int test_wc_DsaCheckPubKey(void) byte digest[WC_SHA_DIGEST_SIZE]; /* signature is r || s, each q-sized (20 bytes for 160-bit q). */ byte sig[2 * 20]; + const byte oversizedQ[DSA_MAX_HALF_SIZE + 1] = { 1 }; + byte oversizedSig[2 * sizeof(oversizedQ)] = { 0 }; XMEMSET(&key, 0, sizeof(DsaKey)); XMEMSET(digest, 0xAA, sizeof(digest)); @@ -743,6 +750,17 @@ int test_wc_DsaCheckPubKey(void) ExpectIntEQ(mp_set(&key.q, 1), 0); ExpectIntEQ(wc_DsaCheckPubKey(&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* q = p-1 is even and g = y = p-1, so both exponentiation checks + * evaluate to 1. Verify independently enforces the signature's q limit. */ + ExpectIntEQ(mp_read_unsigned_bin(&key.q, oversizedQ, sizeof(oversizedQ)), + MP_OKAY); + ExpectIntEQ(mp_add_d(&key.q, 1, &key.p), MP_OKAY); + ExpectIntEQ(mp_copy(&key.q, &key.g), MP_OKAY); + ExpectIntEQ(mp_copy(&key.q, &key.y), MP_OKAY); + ExpectIntEQ(wc_DsaCheckPubKey(&key), 0); + ExpectIntEQ(wc_DsaVerify(digest, oversizedSig, &key, &answer), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + wc_FreeDsaKey(&key); #endif return EXPECT_RESULT(); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index e824cfe5d38..afdfefda3d9 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -45872,6 +45872,12 @@ static wc_test_ret_t dh_test_check_pubvalue(void) #undef INIT_PUBVAL_FAIL #undef INIT_PUBVAL_PASS + /* An all-zero prime buffer is exhausted while stripping its padding. */ + ret = wc_DhCheckPubValue(pubValZeroLong, sizeof(pubValZeroLong), + pubValTwo, sizeof(pubValTwo)); + if (ret != WC_NO_ERR_TRACE(MP_VAL)) + return WC_TEST_RET_ENC_EC(ret); + for (j = 0; j < sizeof(dh_primes) / sizeof(*dh_primes); j++) { for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) { From ecee18a1cfc12ff7e04071c27081e7c89a607074 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 10:54:08 +0100 Subject: [PATCH 4/8] Cover log marks, heap hints, callbacks and word carry checks --- tests/unit-mcdc/test_cryptocb_whitebox.c | 54 +++++++++++++++++++ .../unit-mcdc/test_logging_globalq_whitebox.c | 28 ++++++++++ tests/unit-mcdc/test_logging_whitebox.c | 24 +++++++++ tests/unit-mcdc/test_memory_whitebox.c | 28 ++++++++++ wolfcrypt/test/test.c | 36 +++++++++++++ 5 files changed, 170 insertions(+) diff --git a/tests/unit-mcdc/test_cryptocb_whitebox.c b/tests/unit-mcdc/test_cryptocb_whitebox.c index 55988b136ce..d0661ec31bf 100644 --- a/tests/unit-mcdc/test_cryptocb_whitebox.c +++ b/tests/unit-mcdc/test_cryptocb_whitebox.c @@ -519,6 +519,14 @@ int main(void) wc_CryptoCb_Ed25519MakePub(&e1, edPub, sizeof(edPub))); WB_DRIVE3(e1.devId, wc_CryptoCb_Ed25519CheckKey(&e1)); +#if defined(ED25519_MAX_ID_LEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + e1.devId = WB_DEVID; + e1.idLen = 1; + (void)wc_CryptoCb_Ed25519CheckKey(&e1); + e1.idLen = 0; + e1.labelLen = 1; + (void)wc_CryptoCb_Ed25519CheckKey(&e1); +#endif WB_NOTE("Ed25519: Gen/Sign/Verify/MakePub/CheckKey dev&&dev->cb " "driven"); @@ -543,6 +551,9 @@ int main(void) #ifdef HAVE_ED448 { ed448_key e4; +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + byte edPub[ED448_PUB_KEY_SIZE]; +#endif XMEMSET(&e4, 0, sizeof(e4)); (void)wc_ed448_init_ex(&e4, NULL, 0); @@ -553,12 +564,55 @@ int main(void) WB_DRIVE3(e4.devId, wc_CryptoCb_Ed448Verify(out, sizeof(out), in, sizeof(in), &res, &e4, 0, NULL, 0)); +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + XMEMSET(edPub, 0, sizeof(edPub)); + WB_DRIVE3(e4.devId, wc_CryptoCb_Ed448Gen(NULL, ED448_KEY_SIZE, &e4)); + WB_DRIVE3(e4.devId, + wc_CryptoCb_Ed448MakePub(&e4, edPub, sizeof(edPub))); + WB_DRIVE3(e4.devId, wc_CryptoCb_Ed448CheckKey(&e4)); + + e4.devId = WB_DEVID; + (void)wc_CryptoCb_Ed448MakePub(NULL, edPub, sizeof(edPub)); + (void)wc_CryptoCb_Ed448MakePub(&e4, NULL, sizeof(edPub)); + (void)wc_CryptoCb_Ed448MakePub(&e4, edPub, sizeof(edPub) - 1); + #ifdef ED448_MAX_ID_LEN + e4.idLen = 1; + (void)wc_CryptoCb_Ed448CheckKey(&e4); + e4.idLen = 0; + e4.labelLen = 1; + (void)wc_CryptoCb_Ed448CheckKey(&e4); + #endif +#endif + wc_ed448_free(&e4); + WB_NOTE("Ed448: Ed448Sign/Ed448Verify dev&&dev->cb driven"); } #else WB_NOTE("HAVE_ED448 not defined; Ed448 dispatch skipped"); #endif /* HAVE_ED448 */ +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + #ifndef NO_DH + { + DhKey dh; + XMEMSET(&dh, 0, sizeof(dh)); + outLen = sizeof(out); + WB_DRIVE3(dh.devId, wc_CryptoCb_Dh(&dh, in, sizeof(in), in, + sizeof(in), out, &outLen)); + } + #endif + #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) + WB_DRIVE3(devId, wc_CryptoCb_Chacha20Poly1305Encrypt(devId, in, nonce, + NULL, 0, in, sizeof(in), out, tag)); + WB_DRIVE3(devId, wc_CryptoCb_Chacha20Poly1305Decrypt(devId, in, nonce, + NULL, 0, in, sizeof(in), tag, out)); + #endif + #if defined(HAVE_PBKDF2) && !defined(NO_HMAC) && !defined(NO_PWDBASED) + WB_DRIVE3(devId, wc_CryptoCb_Pbkdf2(out, in, sizeof(in), nonce, + sizeof(nonce), 1, sizeof(out), WC_HASH_TYPE_SHA256, devId)); + #endif +#endif + /* ---- AES ---- */ #ifndef NO_AES { diff --git a/tests/unit-mcdc/test_logging_globalq_whitebox.c b/tests/unit-mcdc/test_logging_globalq_whitebox.c index 73828abd95a..dd84bca665e 100644 --- a/tests/unit-mcdc/test_logging_globalq_whitebox.c +++ b/tests/unit-mcdc/test_logging_globalq_whitebox.c @@ -308,6 +308,30 @@ static void wb_pull_frees_node(void) #endif } +#if defined(WOLFSSL_HAVE_ERROR_QUEUE) && !defined(ERROR_QUEUE_PER_THREAD) && \ + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +static void wb_error_queue_marks(void) +{ + wc_ClearErrorNodes(); + WB_CHECK(wc_SetErrorNodeMark() == 0, "cannot mark an empty queue"); + WB_CHECK(wc_PopErrorNodesToMark() == 0, "no mark in empty queue"); + if (wc_AddErrorNode(WC_NO_ERR_TRACE(BAD_FUNC_ARG), 1, (char*)"mark", + (char*)"synthetic.c") != 0 || wc_last_node == NULL) { + WB_CHECK(0, "cannot add an entry for marking"); + wc_ClearErrorNodes(); + return; + } + + wc_last_node->marks = WOLFSSL_MAX_32BIT; + WB_CHECK(wc_SetErrorNodeMark() == 0, "cannot add a mark at saturation"); + WB_CHECK(wc_last_node->marks == WOLFSSL_MAX_32BIT, "mark did not wrap"); + wc_last_node->marks = 0; + WB_CHECK(wc_SetErrorNodeMark() == 1, "mark a populated queue"); + WB_CHECK(wc_PopErrorNodesToMark() == 1, "pop the existing mark"); + wc_ClearErrorNodes(); +} +#endif + int main(void) { printf("logging.c global error-queue white-box supplement\n"); @@ -323,6 +347,10 @@ int main(void) wb_peek_line_data_ignore_err(); wb_remove_error_node(); wb_pull_frees_node(); +#if defined(WOLFSSL_HAVE_ERROR_QUEUE) && !defined(ERROR_QUEUE_PER_THREAD) && \ + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + wb_error_queue_marks(); +#endif #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && !defined(ERROR_QUEUE_PER_THREAD) (void)wc_LoggingCleanup(); diff --git a/tests/unit-mcdc/test_logging_whitebox.c b/tests/unit-mcdc/test_logging_whitebox.c index e2faf785c7e..1713a5c76c4 100644 --- a/tests/unit-mcdc/test_logging_whitebox.c +++ b/tests/unit-mcdc/test_logging_whitebox.c @@ -241,6 +241,11 @@ static void wb_error_queue(void) wc_ClearErrorNodes(); +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + if (wc_SetErrorNodeMark() != 0) + wb_fail = 1; +#endif + /* get_abs_idx() via wc_PeekErrorNode(): (count==0)=T -> short circuit, * decision TRUE regardless of relative_idx. */ ret = wc_PeekErrorNode(0, &file, &reason, &line); @@ -250,6 +255,25 @@ static void wb_error_queue(void) (char*)"synthetic.c") != 0) wb_fail = 1; +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + { + struct wc_error_entry* entry = get_entry(-1); + + if (entry == NULL) { + wb_fail = 1; + } + else { + entry->marks = WOLFSSL_MAX_32BIT; + if (wc_SetErrorNodeMark() != 0 || + entry->marks != WOLFSSL_MAX_32BIT) + wb_fail = 1; + entry->marks = 0; + if (wc_SetErrorNodeMark() != 1 || wc_PopErrorNodesToMark() != 1) + wb_fail = 1; + } + } +#endif + /* (count==0)=F, (relative_idx >= count)=T -> decision TRUE via 2nd * operand. */ ret = wc_PeekErrorNode(5, &file, &reason, &line); diff --git a/tests/unit-mcdc/test_memory_whitebox.c b/tests/unit-mcdc/test_memory_whitebox.c index 82df762315b..aae3d33ec11 100644 --- a/tests/unit-mcdc/test_memory_whitebox.c +++ b/tests/unit-mcdc/test_memory_whitebox.c @@ -175,6 +175,30 @@ static byte s_bufIOPool[45000]; static byte s_bufIOFixed[45000]; static byte s_bufScratchLoad[512]; /* used only for the NULL-arg vectors */ +#if defined(USE_WOLFSSL_MEMORY) && defined(WOLFSSL_STATIC_MEMORY) && \ + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +static void wb_heap_hint_refcount(void) +{ + WOLFSSL_HEAP_HINT hint; + WOLFSSL_HEAP heap; + + XMEMSET(&hint, 0, sizeof(hint)); + hint.memory = &heap; + WB_CHECK(!wc_HeapHint_IsRefCounted(&hint), "application-owned hint"); + hint.sslOwned = 1; + WB_CHECK(wc_HeapHint_IsRefCounted(&hint), "SSL-owned hint with a pool"); + hint.memory = NULL; + WB_CHECK(!wc_HeapHint_IsRefCounted(&hint), "SSL-owned hint without a pool"); + + hint.refCount = 2; + WB_CHECK(wc_HeapHint_Drop(NULL) == NULL, "drop no hint"); + WB_CHECK(wc_HeapHint_Drop(&hint) == NULL, "drop a nonfinal reference"); + WB_CHECK(hint.refCount == 1, "one reference left"); + WB_CHECK(wc_HeapHint_Drop(&hint) == &hint, "drop the last reference"); + WB_CHECK(hint.refCount == 0, "no references left"); +} +#endif + int main(void) { printf("memory.c white-box supplement\n"); @@ -185,6 +209,10 @@ int main(void) int ret; void* p; +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + wb_heap_hint_refcount(); +#endif + XMEMSET(s_scratch, 0, sizeof(s_scratch)); XMEMSET(s_bufGeneral, 0, sizeof(s_bufGeneral)); XMEMSET(s_bufIOPool, 0, sizeof(s_bufIOPool)); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index afdfefda3d9..8fcfd414a59 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -4649,6 +4649,35 @@ static wc_test_ret_t safe_sub_sword64_test(void) { } #endif /* WORD64_AVAILABLE */ +#if defined(WOLFSSL_W64_WRAPPER) && defined(WORD64_AVAILABLE) && \ + !defined(WOLFSSL_W64_WRAPPER_TEST) && !defined(NO_INLINE) && \ + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +static wc_test_ret_t w64_wrap_test(void) +{ + w64wrapper zero = w64From32(0, 0); + w64wrapper one = w64From32(0, 1); + w64wrapper max = w64From32(WOLFSSL_MAX_32BIT, WOLFSSL_MAX_32BIT); + byte wrap = 0; + + if (!w64Equal(w64Add32(zero, 1, &wrap), one) || wrap != 0) + return WC_TEST_RET_ENC_NC; + if (!w64Equal(w64Add32(max, 1, NULL), zero)) + return WC_TEST_RET_ENC_NC; + if (!w64Equal(w64Add32(max, 1, &wrap), zero) || wrap != 1) + return WC_TEST_RET_ENC_NC; + + wrap = 0; + if (!w64Equal(w64Sub32(one, 1, &wrap), zero) || wrap != 0) + return WC_TEST_RET_ENC_NC; + if (!w64Equal(w64Sub32(zero, 1, NULL), max)) + return WC_TEST_RET_ENC_NC; + if (!w64Equal(w64Sub32(zero, 1, &wrap), max) || wrap != 1) + return WC_TEST_RET_ENC_NC; + + return 0; +} +#endif + WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void) { wc_test_ret_t ret; @@ -4661,6 +4690,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void) if (ret == 0) ret = safe_sub_sword32_test(); +#if defined(WOLFSSL_W64_WRAPPER) && defined(WORD64_AVAILABLE) && \ + !defined(WOLFSSL_W64_WRAPPER_TEST) && !defined(NO_INLINE) && \ + !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + if (ret == 0) + ret = w64_wrap_test(); +#endif + #ifdef WORD64_AVAILABLE if (ret == 0) ret = safe_sum_word64_test(); From 89380d71ee227ce493af362e5229133eb10b301a Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 11:03:36 +0100 Subject: [PATCH 5/8] Cover cleanup-abort state transitions --- tests/unit-mcdc/test_wc_port_whitebox.c | 43 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tests/unit-mcdc/test_wc_port_whitebox.c b/tests/unit-mcdc/test_wc_port_whitebox.c index 69450a5a7a8..b6f3740ac49 100644 --- a/tests/unit-mcdc/test_wc_port_whitebox.c +++ b/tests/unit-mcdc/test_wc_port_whitebox.c @@ -330,14 +330,51 @@ static void wb_cloexec_wrappers(void) { WB_NOTE("POSIX cloexec wrappers not compiled in this variant; skipped"); } #endif +#if defined(WOLF_CRYPTO_CB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +static int wb_init_cleanup_abort(void) +{ + WC_DECLARE_INIT_STATE(state); + union wc_init_state_bitfields value; + int failed = 0; + + value.u = 0; + value.c.state = WC_INIT_STATE_INITED; + value.c.count = 1; + WOLFSSL_ATOMIC_STORE(state, value.u); + if (wc_local_InitDownAbort(&state) != WC_NO_ERR_TRACE(BAD_STATE_E)) + failed = 1; + + value.c.state = WC_INIT_STATE_CLEANING_UP; + value.c.count = 2; + WOLFSSL_ATOMIC_STORE(state, value.u); + if (wc_local_InitDownAbort(&state) != WC_NO_ERR_TRACE(BAD_STATE_E)) + failed = 1; + + value.c.count = 1; + WOLFSSL_ATOMIC_STORE(state, value.u); + if (wc_local_InitDownAbort(&state) != 0) + failed = 1; + value.u = WOLFSSL_ATOMIC_LOAD(state); + if (value.c.state != WC_INIT_STATE_INITED || value.c.count != 1) + failed = 1; + + if (failed) + puts("wc_port white-box: cleanup-abort state checks failed"); + return failed; +} +#endif + int main(void) { + int failed = 0; + setvbuf(stdout, NULL, _IONBF, 0); printf("wc_port white-box\n"); wb_strnstr(); wb_cloexec_wrappers(); +#if defined(WOLF_CRYPTO_CB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) + failed = wb_init_cleanup_abort(); +#endif printf(" [wb] failures: %d\n", wb_fail); - /* Always 0: a non-zero exit makes the test harness discard the - * whole variant rather than record its coverage. */ - return 0; + return failed; } From 093f7d028ffba5026fd94e09aa8d4cc3fa11d24e Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 11:06:30 +0100 Subject: [PATCH 6/8] Cover public-key callback publication and signed coordinates --- tests/unit-mcdc/test_cryptocb_whitebox.c | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/unit-mcdc/test_cryptocb_whitebox.c b/tests/unit-mcdc/test_cryptocb_whitebox.c index d0661ec31bf..71ae67f6936 100644 --- a/tests/unit-mcdc/test_cryptocb_whitebox.c +++ b/tests/unit-mcdc/test_cryptocb_whitebox.c @@ -312,6 +312,29 @@ int main(void) NULL) != 0) wb_fail = 1; +#if defined(WC_CRYPTOCB_KEYGEN_ID_CHECK) && !defined(HAVE_FIPS) && \ + !defined(HAVE_SELFTEST) + { + CryptoCb* publishing = wc_CryptoCb_GetFreeDevice(); + + if (wc_CryptoCb_HasPkDevice(WB_DEVID) != 1 || + wc_CryptoCb_HasPkDevice(WB_DEVID_NONE) != 0 || + wc_CryptoCb_HasPkDevice(WB_DEVID_NOCB) != 0) { + wb_fail = 1; + } + /* Registration publishes the callback before publishing its ID. */ + if (publishing == NULL) { + wb_fail = 1; + } + else { + publishing->cb = wb_cb; + if (wc_CryptoCb_HasPkDevice(INVALID_DEVID) != 0) + wb_fail = 1; + publishing->cb = NULL; + } + } +#endif + /* ---- RSA ---- */ #ifndef NO_RSA { @@ -423,6 +446,30 @@ int main(void) /* Residual: EccCheckPubKey's "key == NULL || key->dp == NULL". */ (void)wc_CryptoCb_EccCheckPubKey(NULL, 0, 0); /* key==NULL */ (void)wc_CryptoCb_EccCheckPubKey(&eccKeyNoDp, 0, 0); /* dp==NULL */ + #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \ + defined(WOLFSSL_SP_INT_NEGATIVE)) && !defined(HAVE_FIPS) && \ + !defined(HAVE_SELFTEST) + { + int type = eccKey.type; + + eccKey.type = ECC_PUBLICKEY; + if (mp_read_radix(eccKey.pubkey.x, "-1", MP_RADIX_HEX) != + MP_OKAY || + wc_CryptoCb_EccCheckPubKey(&eccKey, 0, 0) != + WC_NO_ERR_TRACE(ECC_OUT_OF_RANGE_E)) { + wb_fail = 1; + } + mp_zero(eccKey.pubkey.x); + if (mp_read_radix(eccKey.pubkey.y, "-1", MP_RADIX_HEX) != + MP_OKAY || + wc_CryptoCb_EccCheckPubKey(&eccKey, 0, 0) != + WC_NO_ERR_TRACE(ECC_OUT_OF_RANGE_E)) { + wb_fail = 1; + } + mp_zero(eccKey.pubkey.y); + eccKey.type = type; + } + #endif #endif WB_NOTE("ECC: EccMakePub/EccCheckPubKey arg-validation guard " "(key==NULL / pubOut==NULL / key->dp==NULL) driven"); From 43177a2bc48d7668ad9eff0d28de94fd89172b64 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 1 Dec 2026 20:01:07 +0100 Subject: [PATCH 7/8] Report CryptoCb and SAKKE assertion failures --- tests/unit-mcdc/test_cryptocb_whitebox.c | 19 ++++++++++++------- tests/unit-mcdc/test_sakke_whitebox.c | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/unit-mcdc/test_cryptocb_whitebox.c b/tests/unit-mcdc/test_cryptocb_whitebox.c index 71ae67f6936..ffce7bb361a 100644 --- a/tests/unit-mcdc/test_cryptocb_whitebox.c +++ b/tests/unit-mcdc/test_cryptocb_whitebox.c @@ -317,10 +317,11 @@ int main(void) { CryptoCb* publishing = wc_CryptoCb_GetFreeDevice(); - if (wc_CryptoCb_HasPkDevice(WB_DEVID) != 1 || + if (!wb_fail && (wc_CryptoCb_HasPkDevice(WB_DEVID) != 1 || wc_CryptoCb_HasPkDevice(WB_DEVID_NONE) != 0 || - wc_CryptoCb_HasPkDevice(WB_DEVID_NOCB) != 0) { - wb_fail = 1; + wc_CryptoCb_HasPkDevice(WB_DEVID_NOCB) != 0)) { + WB_NOTE("unexpected public-key device lookup result"); + wb_bad = 1; } /* Registration publishes the callback before publishing its ID. */ if (publishing == NULL) { @@ -328,8 +329,10 @@ int main(void) } else { publishing->cb = wb_cb; - if (wc_CryptoCb_HasPkDevice(INVALID_DEVID) != 0) - wb_fail = 1; + if (wc_CryptoCb_HasPkDevice(INVALID_DEVID) != 0) { + WB_NOTE("unpublished public-key device found"); + wb_bad = 1; + } publishing->cb = NULL; } } @@ -457,14 +460,16 @@ int main(void) MP_OKAY || wc_CryptoCb_EccCheckPubKey(&eccKey, 0, 0) != WC_NO_ERR_TRACE(ECC_OUT_OF_RANGE_E)) { - wb_fail = 1; + WB_NOTE("negative ECC x coordinate check failed"); + wb_bad = 1; } mp_zero(eccKey.pubkey.x); if (mp_read_radix(eccKey.pubkey.y, "-1", MP_RADIX_HEX) != MP_OKAY || wc_CryptoCb_EccCheckPubKey(&eccKey, 0, 0) != WC_NO_ERR_TRACE(ECC_OUT_OF_RANGE_E)) { - wb_fail = 1; + WB_NOTE("negative ECC y coordinate check failed"); + wb_bad = 1; } mp_zero(eccKey.pubkey.y); eccKey.type = type; diff --git a/tests/unit-mcdc/test_sakke_whitebox.c b/tests/unit-mcdc/test_sakke_whitebox.c index b8f85d578a6..44fce899bc7 100644 --- a/tests/unit-mcdc/test_sakke_whitebox.c +++ b/tests/unit-mcdc/test_sakke_whitebox.c @@ -126,7 +126,8 @@ int main(void) /* Invalid arguments stop before the key's temporary integers exist. */ if (wc_MakeSakkeRsk(&key, id, sizeof(id), NULL) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { - wb_fail = 1; + puts("sakke.c: wc_MakeSakkeRsk did not reject NULL output"); + return 1; } #endif From d8410b2c15724e122647c715e198cac99e7ae501 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 4 Dec 2026 09:27:39 +0100 Subject: [PATCH 8/8] Free ECC keys in CryptoCb white-box tests Release the initialized ECC keys so heap math frees the digits allocated by the negative-coordinate checks. --- tests/unit-mcdc/test_cryptocb_whitebox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit-mcdc/test_cryptocb_whitebox.c b/tests/unit-mcdc/test_cryptocb_whitebox.c index ffce7bb361a..24c8ef43005 100644 --- a/tests/unit-mcdc/test_cryptocb_whitebox.c +++ b/tests/unit-mcdc/test_cryptocb_whitebox.c @@ -471,7 +471,6 @@ int main(void) WB_NOTE("negative ECC y coordinate check failed"); wb_bad = 1; } - mp_zero(eccKey.pubkey.y); eccKey.type = type; } #endif @@ -489,6 +488,7 @@ int main(void) "ecc_point (not the zeroed pubOutPt used above) so the " "subsequent mp_read_unsigned_bin calls are safe; left " "out of scope for this pass rather than risk it"); + (void)wc_ecc_free(&eccKeyNoDp); } else { WB_NOTE("ECC: wc_ecc_set_curve failed; EccMakePub/" @@ -497,6 +497,8 @@ int main(void) WB_NOTE("ECC: MakeEccKey/Ecdh/EccSign/EccVerify/EccCheckPrivKey/" "EccGetSize/EccGetSigSize dev&&dev->cb driven"); + (void)wc_ecc_free(&eccKey2); + (void)wc_ecc_free(&eccKey); } #else WB_NOTE("HAVE_ECC not defined; ECC dispatch skipped");