Skip to content

Commit 3416a0f

Browse files
authored
Merge pull request wolfSSL#9393 from rlm2002/zd20756
Integer overflow and dead code removal
2 parents 98d84eb + ec60d88 commit 3416a0f

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

wolfcrypt/src/aes.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4777,18 +4777,17 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
47774777
}
47784778
#endif
47794779

4780+
#if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE < 256
47804781
if (checkKeyLen) {
4781-
if (keylen != 16 && keylen != 24 && keylen != 32) {
4782-
return BAD_FUNC_ARG;
4783-
}
4784-
#if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE < 256
47854782
/* Check key length only when AES_MAX_KEY_SIZE doesn't allow
47864783
* all key sizes. Otherwise this condition is never true. */
47874784
if (keylen > (AES_MAX_KEY_SIZE / 8)) {
47884785
return BAD_FUNC_ARG;
47894786
}
4790-
#endif
47914787
}
4788+
#else
4789+
(void) checkKeyLen;
4790+
#endif
47924791

47934792
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
47944793
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS) || \

wolfcrypt/src/asn.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34201,7 +34201,7 @@ static int SetKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey,
3420134201
cert->skidSz = KEYID_SIZE;
3420234202
#endif
3420334203
}
34204-
else if (kid_type == AKID_TYPE) {
34204+
else {
3420534205
int hashId = HashIdAlg((word32)cert->sigType);
3420634206
ret = CalcHashId_ex(buf, (word32)bufferSz, cert->akid, hashId);
3420734207
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
@@ -34210,8 +34210,6 @@ static int SetKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey,
3421034210
cert->akidSz = KEYID_SIZE;
3421134211
#endif
3421234212
}
34213-
else
34214-
ret = BAD_FUNC_ARG;
3421534213

3421634214
XFREE(buf, cert->heap, DYNAMIC_TYPE_TMP_BUFFER);
3421734215
return ret;

wolfcrypt/src/sp_c32.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20177,28 +20177,28 @@ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit*
2017720177
a32 = t + 8;
2017820178

2017920179
a32[0] = a[0];
20180-
a32[0] |= a[1] << 29U;
20180+
a32[0] |= (int64_t)a[1] << 29U;
2018120181
a32[0] &= 0xffffffffL;
2018220182
a32[1] = (a[1] >> 3);
20183-
a32[1] |= a[2] << 26U;
20183+
a32[1] |= (int64_t)a[2] << 26U;
2018420184
a32[1] &= 0xffffffffL;
2018520185
a32[2] = (a[2] >> 6);
20186-
a32[2] |= a[3] << 23U;
20186+
a32[2] |= (int64_t)a[3] << 23U;
2018720187
a32[2] &= 0xffffffffL;
2018820188
a32[3] = (a[3] >> 9);
20189-
a32[3] |= a[4] << 20U;
20189+
a32[3] |= (int64_t)a[4] << 20U;
2019020190
a32[3] &= 0xffffffffL;
2019120191
a32[4] = (a[4] >> 12);
20192-
a32[4] |= a[5] << 17U;
20192+
a32[4] |= (int64_t)a[5] << 17U;
2019320193
a32[4] &= 0xffffffffL;
2019420194
a32[5] = (a[5] >> 15);
20195-
a32[5] |= a[6] << 14U;
20195+
a32[5] |= (int64_t)a[6] << 14U;
2019620196
a32[5] &= 0xffffffffL;
2019720197
a32[6] = (a[6] >> 18);
20198-
a32[6] |= a[7] << 11U;
20198+
a32[6] |= (int64_t)a[7] << 11U;
2019920199
a32[6] &= 0xffffffffL;
2020020200
a32[7] = (a[7] >> 21);
20201-
a32[7] |= a[8] << 8U;
20201+
a32[7] |= (int64_t)a[8] << 8U;
2020220202
a32[7] &= 0xffffffffL;
2020320203

2020420204
/* 1 1 0 -1 -1 -1 -1 0 */
@@ -27177,42 +27177,42 @@ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit
2717727177
a32 = t + 12;
2717827178

2717927179
a32[0] = a[0];
27180-
a32[0] |= a[1] << 26U;
27180+
a32[0] |= (int64_t)a[1] << 26U;
2718127181
a32[0] &= 0xffffffffL;
2718227182
a32[1] = (a[1] >> 6);
27183-
a32[1] |= a[2] << 20U;
27183+
a32[1] |= (int64_t)a[2] << 20U;
2718427184
a32[1] &= 0xffffffffL;
2718527185
a32[2] = (a[2] >> 12);
27186-
a32[2] |= a[3] << 14U;
27186+
a32[2] |= (int64_t)a[3] << 14U;
2718727187
a32[2] &= 0xffffffffL;
2718827188
a32[3] = (a[3] >> 18);
27189-
a32[3] |= a[4] << 8U;
27189+
a32[3] |= (int64_t)a[4] << 8U;
2719027190
a32[3] &= 0xffffffffL;
2719127191
a32[4] = (a[4] >> 24);
27192-
a32[4] |= a[5] << 2U;
27193-
a32[4] |= a[6] << 28U;
27192+
a32[4] |= (int64_t)a[5] << 2U;
27193+
a32[4] |= (int64_t)a[6] << 28U;
2719427194
a32[4] &= 0xffffffffL;
2719527195
a32[5] = (a[6] >> 4);
27196-
a32[5] |= a[7] << 22U;
27196+
a32[5] |= (int64_t)a[7] << 22U;
2719727197
a32[5] &= 0xffffffffL;
2719827198
a32[6] = (a[7] >> 10);
27199-
a32[6] |= a[8] << 16U;
27199+
a32[6] |= (int64_t)a[8] << 16U;
2720027200
a32[6] &= 0xffffffffL;
2720127201
a32[7] = (a[8] >> 16);
27202-
a32[7] |= a[9] << 10U;
27202+
a32[7] |= (int64_t)a[9] << 10U;
2720327203
a32[7] &= 0xffffffffL;
2720427204
a32[8] = (a[9] >> 22);
27205-
a32[8] |= a[10] << 4U;
27206-
a32[8] |= a[11] << 30U;
27205+
a32[8] |= (int64_t)a[10] << 4U;
27206+
a32[8] |= (int64_t)a[11] << 30U;
2720727207
a32[8] &= 0xffffffffL;
2720827208
a32[9] = (a[11] >> 2);
27209-
a32[9] |= a[12] << 24U;
27209+
a32[9] |= (int64_t)a[12] << 24U;
2721027210
a32[9] &= 0xffffffffL;
2721127211
a32[10] = (a[12] >> 8);
27212-
a32[10] |= a[13] << 18U;
27212+
a32[10] |= (int64_t)a[13] << 18U;
2721327213
a32[10] &= 0xffffffffL;
2721427214
a32[11] = (a[13] >> 14);
27215-
a32[11] |= a[14] << 12U;
27215+
a32[11] |= (int64_t)a[14] << 12U;
2721627216
a32[11] &= 0xffffffffL;
2721727217

2721827218
/* 1 0 0 0 0 0 0 0 1 1 0 -1 */

0 commit comments

Comments
 (0)