Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00f098e
coding: remove unreachable len operand in Base64_SkipNewline
danielinux Jul 31, 2026
03e40fd
coding: remove unreachable out operand in the Base64 decoders
danielinux Jul 31, 2026
413fcc5
coding: remove unreachable in operand in Base16_Decode
danielinux Jul 31, 2026
fc72ef8
md5: remove unreachable len operand in wc_Md5Update
danielinux Jul 31, 2026
0090560
sha3: remove unreachable len operand in the PSOC6 Update paths
danielinux Jul 31, 2026
f043241
tfm: remove unreachable fp_gcd zero-operand branches
danielinux Jul 31, 2026
e11b5e1
integer: remove unreachable tmpc NULL check in s_mp_add
danielinux Jul 31, 2026
4acfa99
sp_int: remove tautological err check in sp_todecimal
danielinux Jul 31, 2026
d851828
sp_int: remove tautological err check in _sp_lcm
danielinux Jul 31, 2026
738454d
memory: remove unreachable res operand in wolfSSL_Realloc
danielinux Jul 31, 2026
aeb153c
mlkem: remove unreachable BAD_STATE_E re-check in wc_mlkemkey_check_h
danielinux Jul 31, 2026
0477435
mldsa: remove tautological loop operand in mldsa_vec_check_low_c
danielinux Jul 31, 2026
5aecf75
mldsa: remove tautological ret operand in wc_MlDsaKey_CheckKey
danielinux Jul 31, 2026
cd1324f
mldsa: remove tautological ret operand in the small-mem sign entry
danielinux Jul 31, 2026
5cd3ba0
mldsa: remove tautological ret operand in two break-dominated inner l…
danielinux Jul 31, 2026
7283dc8
lms: remove unreachable inited operand in wc_hss_reload_key
danielinux Jul 31, 2026
23b3a7a
integer: remove unreachable mp_init failure handling in mp_init_multi
danielinux Jul 31, 2026
5cdce96
aes: remove unreachable bit lower-bound in wc_AesFeedbackCFB1
danielinux Jul 31, 2026
c62fad3
ed448: remove unreachable privKeySet operand in wc_ed448_check_key
danielinux Jul 31, 2026
500c0bc
ed448: remove unreachable Y == p case in wc_ed448_check_key
danielinux Jul 31, 2026
536f85f
kdf: remove tautological ret operand in the KDA-KDF CMAC loop
danielinux Jul 31, 2026
a219774
pwdbased: remove unreachable NULL check in DoPKCS12Hash
danielinux Jul 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -16504,7 +16504,7 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB1(
}

if (ret == 0) {
if (bit >= 0 && bit < 7) {
if (bit < 7) {
out[0] = cur;
}
}
Expand Down
8 changes: 4 additions & 4 deletions wolfcrypt/src/coding.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int Base64_SkipNewline(const byte* in, word32 *inLen,
curChar = in[++j];
len--;
}
if (len && (curChar == '\r' || curChar == '\n')) {
if (curChar == '\r' || curChar == '\n') {
j++;
len--;
if (curChar == '\r') {
Expand Down Expand Up @@ -278,7 +278,7 @@ int Base64_Decode_nonCT(const byte* in, word32 inLen, byte* out, word32* outLen)
}

/* If the output buffer has a room for an extra byte, add a null terminator */
if (out && *outLen > i)
if (*outLen > i)
out[i]= '\0';

/* Note, *outLen won't reflect the optional terminating null. */
Expand Down Expand Up @@ -392,7 +392,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
}

/* If the output buffer has a room for an extra byte, add a null terminator */
if (out && *outLen > i)
if (*outLen > i)
out[i]= '\0';

/* Note, *outLen won't reflect the optional terminating null. */
Expand Down Expand Up @@ -660,7 +660,7 @@ int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
if (in == NULL || out == NULL || outLen == NULL)
return BAD_FUNC_ARG;

if (inLen == 1 && *outLen && in) {
if (inLen == 1 && *outLen) {
byte b = (byte)(in[inIdx++] - BASE16_MIN); /* 0 starts at 0x30 */

/* sanity check */
Expand Down
46 changes: 17 additions & 29 deletions wolfcrypt/src/ed448.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,41 +1521,29 @@ int wc_ed448_check_key(ed448_key* key)
}
}
/* No private key, check Y is valid. */
else if ((ret == 0) && (!key->privKeySet)) {
else if (ret == 0) {
/* Verify that xQ and yQ are integers in the interval [0, p - 1].
* Only have yQ so check that ordinate.
* p = 2^448-2^224-1 = 0xff..fe..ff
*/
if (ret == 0) {
int i;
ret = PUBLIC_KEY_E;
int i;
ret = PUBLIC_KEY_E;

/* Check top part before 0xFE. */
for (i = ED448_PUB_KEY_SIZE - 1; i > ED448_PUB_KEY_SIZE/2; i--) {
if (key->p[i] < 0xff) {
ret = 0;
break;
}
/* Check top part before 0xFE. */
for (i = ED448_PUB_KEY_SIZE - 1; i > ED448_PUB_KEY_SIZE/2; i--) {
if (key->p[i] < 0xff) {
ret = 0;
break;
}
if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
/* Check against 0xFE. */
if (key->p[ED448_PUB_KEY_SIZE/2] < 0xfe) {
ret = 0;
}
else if (key->p[ED448_PUB_KEY_SIZE/2] == 0xfe) {
/* Check bottom part before last byte. */
for (i = ED448_PUB_KEY_SIZE/2 - 1; i > 0; i--) {
if (key->p[i] != 0xff) {
ret = 0;
break;
}
}
/* Check last byte. */
if ((ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) &&
(key->p[0] < 0xff)) {
ret = 0;
}
}
}
if (ret == WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
/* Every byte above the 0xFE position is 0xff here, so y is out of
* range only if this byte is 0xff too. The two encodings that are
* in range by this test but still invalid, y == p and y == p - 1,
* are already rejected by ed448_is_small_order() above, so no
* further check of the low bytes is needed. */
if (key->p[ED448_PUB_KEY_SIZE/2] <= 0xfe) {
ret = 0;
}
}

Expand Down
41 changes: 9 additions & 32 deletions wolfcrypt/src/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,44 +102,22 @@ word32 CheckRunTimeSettings(void)
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
mp_int* f)
{
int res = MP_OKAY;

if (a) XMEMSET(a, 0, sizeof(mp_int));
if (b) XMEMSET(b, 0, sizeof(mp_int));
if (c) XMEMSET(c, 0, sizeof(mp_int));
if (d) XMEMSET(d, 0, sizeof(mp_int));
if (e) XMEMSET(e, 0, sizeof(mp_int));
if (f) XMEMSET(f, 0, sizeof(mp_int));

if (a && ((res = mp_init(a)) != MP_OKAY))
return res;

if (b && ((res = mp_init(b)) != MP_OKAY)) {
mp_clear(a);
return res;
}

if (c && ((res = mp_init(c)) != MP_OKAY)) {
mp_clear(a); mp_clear(b);
return res;
}
/* mp_init() only fails on a NULL argument, already excluded here. */
if (a) (void)mp_init(a);
if (b) (void)mp_init(b);
if (c) (void)mp_init(c);
if (d) (void)mp_init(d);
if (e) (void)mp_init(e);
if (f) (void)mp_init(f);

if (d && ((res = mp_init(d)) != MP_OKAY)) {
mp_clear(a); mp_clear(b); mp_clear(c);
return res;
}

if (e && ((res = mp_init(e)) != MP_OKAY)) {
mp_clear(a); mp_clear(b); mp_clear(c); mp_clear(d);
return res;
}

if (f && ((res = mp_init(f)) != MP_OKAY)) {
mp_clear(a); mp_clear(b); mp_clear(c); mp_clear(d); mp_clear(e);
return res;
}

return res;
return MP_OKAY;
}


Expand Down Expand Up @@ -1792,8 +1770,7 @@ int s_mp_add (mp_int * a, mp_int * b, mp_int * c)
tmpc = c->dp;

/* sanity-check dp pointers. */
if ((min_ab > 0) &&
((tmpa == NULL) || (tmpb == NULL) || (tmpc == NULL)))
if ((min_ab > 0) && ((tmpa == NULL) || (tmpb == NULL)))
{
return MP_VAL;
}
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ int wc_KDA_KDF_PRF_cmac(const byte* Kin, word32 KinSz,
}
#endif

while (ret == 0 && len_rem >= WC_AES_BLOCK_SIZE) {
while (len_rem >= WC_AES_BLOCK_SIZE) {
/* cmac in place in block size increments */
c32toa(counter, counterBuf);
#ifdef WOLFSSL_DEBUG_KDF
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len)
if (md5->buffLen >= WC_MD5_BLOCK_SIZE)
return BUFFER_E;

if (data == NULL && len == 0) {
/* valid, but do nothing */
if (data == NULL) {
/* len is 0 here: valid, but do nothing */
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type)
}
}

if (pt != NULL && res == NULL) {
if (pt != NULL) {
word32 prvSz;

res = pt->buffer;
Expand Down
4 changes: 0 additions & 4 deletions wolfcrypt/src/pwdbased.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ static int DoPKCS12Hash(enum wc_HashType hashT, byte* buffer, word32 totalLen,
int ret = 0;
WC_DECLARE_VAR(hash, wc_HashAlg, 1, 0);

if ((buffer == NULL) || (Ai == NULL)) {
return BAD_FUNC_ARG;
}

/* initialize hash */
WC_ALLOC_VAR_EX(hash, wc_HashAlg, 1, NULL, DYNAMIC_TYPE_HASHCTX,
return MEMORY_E);
Expand Down
12 changes: 6 additions & 6 deletions wolfcrypt/src/sha3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,8 @@ static int wc_Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, word32 p)
return BAD_FUNC_ARG;
}

if (data == NULL && len == 0) {
/* valid, but do nothing */
if (data == NULL) {
/* len is 0 here: valid, but do nothing */
return 0;
}

Expand Down Expand Up @@ -1865,8 +1865,8 @@ int wc_Shake128_Update(wc_Shake* shake, const byte* data, word32 len)
return BAD_FUNC_ARG;
}

if (data == NULL && len == 0) {
/* valid, but do nothing */
if (data == NULL) {
/* len is 0 here: valid, but do nothing */
return 0;
}

Expand Down Expand Up @@ -2163,8 +2163,8 @@ int wc_Shake256_Update(wc_Shake* shake, const byte* data, word32 len)
return BAD_FUNC_ARG;
}

if (data == NULL && len == 0) {
/* valid, but do nothing */
if (data == NULL) {
/* len is 0 here: valid, but do nothing */
return 0;
}

Expand Down
18 changes: 7 additions & 11 deletions wolfcrypt/src/sp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -18906,13 +18906,11 @@ int sp_todecimal(const sp_int* a, char* str)
/* Terminate string. */
str[i] = '\0';

if (err == MP_OKAY) {
/* Reverse string to big endian. */
for (j = 0; j <= (i - 1) / 2; j++) {
int c = (unsigned char)str[j];
str[j] = str[i - 1 - j];
str[i - 1 - j] = (char)c;
}
/* Reverse string to big endian. */
for (j = 0; j <= (i - 1) / 2; j++) {
int c = (unsigned char)str[j];
str[j] = str[i - 1 - j];
str[i - 1 - j] = (char)c;
}
}

Expand Down Expand Up @@ -19950,10 +19948,8 @@ static int _sp_lcm(const sp_int* a, const sp_int* b, sp_int* r)
_sp_init_size(t[0], used);
_sp_init_size(t[1], used);

if (err == MP_OKAY) {
/* 1. t0 = gcd(a, b) */
err = sp_gcd(a, b, t[0]);
}
/* 1. t0 = gcd(a, b) */
err = sp_gcd(a, b, t[0]);

if (err == MP_OKAY) {
/* Divide the greater by the common divisor and multiply by other
Expand Down
12 changes: 2 additions & 10 deletions wolfcrypt/src/tfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5511,23 +5511,15 @@ int fp_gcd(fp_int *a, fp_int *b, fp_int *c)
}

/* either zero than gcd is the largest */
if (fp_iszero (a) == FP_YES && fp_iszero (b) == FP_NO) {
if (fp_iszero (a) == FP_YES) {
fp_abs (b, c);
return FP_OKAY;
}
if (fp_iszero (a) == FP_NO && fp_iszero (b) == FP_YES) {
if (fp_iszero (b) == FP_YES) {
fp_abs (a, c);
return FP_OKAY;
}

/* optimized. At this point if a == 0 then
* b must equal zero too
*/
if (fp_iszero (a) == FP_YES) {
fp_zero(c);
return FP_OKAY;
}

#ifdef WOLFSSL_SMALL_STACK
u = (fp_int*)XMALLOC(sizeof(fp_int) * 3, NULL, DYNAMIC_TYPE_BIGINT);
if (u == NULL) {
Expand Down
5 changes: 1 addition & 4 deletions wolfcrypt/src/wc_lms_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3589,9 +3589,6 @@ int wc_hss_reload_key(LmsState* state, const byte* priv_raw,
#endif

wc_hss_priv_data_load(state->params, priv_key, priv_data);
#ifndef WOLFSSL_WC_LMS_SMALL
priv_key->inited = 0;
#endif

#ifdef WOLFSSL_WC_LMS_SERIALIZE_STATE
if (pub_root != NULL)
Expand All @@ -3600,7 +3597,7 @@ int wc_hss_reload_key(LmsState* state, const byte* priv_raw,
/* Expand the raw private key into the private key data. */
ret = wc_hss_expand_private_key(state, priv_key->priv, priv_raw, 0);
#ifndef WOLFSSL_WC_LMS_SMALL
if ((ret == 0) && (!priv_key->inited)) {
if (ret == 0) {
/* Initialize the authentication paths and caches for all trees. */
ret = wc_hss_init_auth_path(state, priv_key, pub_root);
#ifndef WOLFSSL_LMS_NO_SIGN_SMOOTHING
Expand Down
10 changes: 5 additions & 5 deletions wolfcrypt/src/wc_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -5063,7 +5063,7 @@ static int mldsa_vec_check_low_c(const sword32* a, byte l, sword32 hi)
unsigned int i;

/* For each polynomial of vector. */
for (i = 0; (ret == 1) && (i < l); i++) {
for (i = 0; i < l; i++) {
ret = mldsa_check_low(a, hi);
if (ret == 0) {
break;
Expand Down Expand Up @@ -8100,7 +8100,7 @@ static int mldsa_make_key_from_seed(wc_MlDsaKey* key, const byte* seed)

/* Put r/i into buffer to be hashed. */
aseed[MLDSA_PUB_SEED_SZ + 1] = (byte)r;
for (s = 0; (ret == 0) && (s < params->l); s++) {
for (s = 0; s < params->l; s++) {
/* Put s into buffer to be hashed. */
aseed[MLDSA_PUB_SEED_SZ + 0] = (byte)s;
/* Step 3: Expand public seed into a matrix of polynomials. */
Expand Down Expand Up @@ -8727,7 +8727,7 @@ static int mldsa_sign_with_seed_mu(wc_MlDsaKey* key,
sizeof(priv_rand_seed));
#endif
/* Check the signature buffer isn't too small. */
if ((ret == 0) && (*sigLen < params->sigSz)) {
if (*sigLen < params->sigSz) {
ret = BUFFER_E;
}
if (ret == 0) {
Expand Down Expand Up @@ -8892,7 +8892,7 @@ static int mldsa_sign_with_seed_mu(wc_MlDsaKey* key,
/* Put r/i into buffer to be hashed. */
aseed[MLDSA_PUB_SEED_SZ + 1] = r;
/* Alg 26. Step 2: Loop over second dimension of matrix. */
for (s = 0; (ret == 0) && (s < params->l); s++) {
for (s = 0; s < params->l; s++) {
/* Put s into buffer to be hashed. */
aseed[MLDSA_PUB_SEED_SZ + 0] = s;
/* Alg 26. Step 3: Create polynomial from hashing seed. */
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 0 additions & 4 deletions wolfcrypt/src/wc_mlkem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,6 @@ static int wc_mlkemkey_check_h(MlKemKey* key)
XFREE(pubKey, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
}
if ((ret == 0) && ((key->flags & MLKEM_FLAG_H_SET) == 0)) {
/* Implementation issue if h not cached and flag not set. */
ret = BAD_STATE_E;
}

return ret;
}
Expand Down
Loading