From 964cc72c38acff7dabf6eff25748bac8a5426f0e Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 31 Jul 2026 15:26:24 +0200 Subject: [PATCH] mldsa: remove tautological ret operand in wc_MlDsaKey_CheckKey Premise: wc_mldsa.c:11544 `if (ret == 0) {` opens the block containing the claimed condition. Claim: wc_mldsa.c:11589 `if ((ret == 0) && (x != 0))` -- the `ret == 0` operand. Proof: :11544 dominates :11589 and nothing in between assigns ret: the block decodes, NTTs, matrix-multiplies and XOR-accumulates into x through mldsa_vec_decode_*, mldsa_vec_ntt_small_full, mldsa_matrix_mul, mldsa_vec_red, mldsa_vec_invntt_full, mldsa_vec_add/sub/make_pos -- all void-returning. A grep of the span for `ret` finds only the two conditions themselves. The operand is invariantly true and its independence pair is unreachable. Scope: the only preprocessor construct in the span is WOLFSSL_MLDSA_SMALL at :11566, which adds another void call. Evidence: llvm-cov MC/DC records this condition as never false (reports/mldsa/GAPS.md row 11479:13:11479:35:0, pre-drift numbering). The nearby `ret == 0` guards at :11485 and :11488 stay: prvKeySet / pubKeySet are user-controlled and those decisions are live. Compiler cross-check: gcc -O2 emits byte-identical code for this file before and after this commit -- the optimiser had already folded the removed condition, independently confirming it was dead. --- wolfcrypt/src/wc_mldsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/wc_mldsa.c b/wolfcrypt/src/wc_mldsa.c index a7b1c8e7f6..57a25b4322 100644 --- a/wolfcrypt/src/wc_mldsa.c +++ b/wolfcrypt/src/wc_mldsa.c @@ -11586,7 +11586,7 @@ int wc_MlDsaKey_CheckKey(wc_MlDsaKey* key) x |= key->p[i] ^ key->k[i]; } - if ((ret == 0) && (x != 0)) { + if (x != 0) { ret = PUBLIC_KEY_E; } }