Skip to content

Commit cc97c47

Browse files
authored
Add pq-crypto/ to cppcheck (#2351)
* Add pq-crypto/ to cppcheck * Convert line endings dos2unix on sike_r2/ec_isogeny.c * Remove specific line numbers from cppcheck_suppressions.txt; move suppressions inline where appropriate * Fix indents * More indent fixes * More pq cppcheck fixes * Remove unecessary cppcheck suppresions * Really fix the indents this time
1 parent 2a7cebb commit cc97c47

33 files changed

+1120
-1083
lines changed
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
// Message: [tests/unit/s2n_stuffer_text_test.c:28]: (style:variableScope) The scope of the variable 'text' can be reduced.
1+
// Message: (style:variableScope) The scope of the variable 'text' can be reduced.
22
// Reason: Don't error for being able to reduce scope of variables in tests
33
variableScope:tests/unit/*
44

5-
// cppcheck Message: [utils/s2n_socket.c:87]: (information:ConfigurationNotChecked) Skipping configuration 'SO_RCVLOWAT' since the value of 'SO_RCVLOWAT' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
5+
// cppcheck Message: (information:ConfigurationNotChecked) Skipping configuration 'SO_RCVLOWAT' since the value of 'SO_RCVLOWAT' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
66
// Reason: There are many Config options that aren't checked by Cppcheck, and it warns for each. Ignore these so that they don't clutter the output.
77
ConfigurationNotChecked:bin/s2nd.c
88
ConfigurationNotChecked:tls/s2n_x509_validator.c
99
ConfigurationNotChecked:utils/s2n_safety.c
1010
ConfigurationNotChecked:utils/s2n_socket.c
1111

12-
// cppcheck Message: [tests/unit/s2n_timer_test.c:49]: (style:redundantAssignment) Variable 'mock_time' is reassigned a value before the old one has been used.
12+
// cppcheck Message: (information:ConfigurationNotChecked) Skipping configuration 'static_assert' since the value of 'static_assert' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
13+
// Reason: Same as above.
14+
ConfigurationNotChecked:pq-crypto/bike_r1/bike_defs.h
15+
ConfigurationNotChecked:pq-crypto/bike_r1/gf2x_mul.c
16+
ConfigurationNotChecked:pq-crypto/bike_r1/sha.h
17+
ConfigurationNotChecked:pq-crypto/bike_r1/aes_ctr_prf.c
18+
ConfigurationNotChecked:pq-crypto/bike_r1/secure_decode_portable.c
19+
ConfigurationNotChecked:pq-crypto/bike_r1/decode.c
20+
ConfigurationNotChecked:pq-crypto/bike_r2/bike_defs.h
21+
ConfigurationNotChecked:pq-crypto/bike_r2/gf2x_mul.c
22+
ConfigurationNotChecked:pq-crypto/bike_r2/sha.h
23+
ConfigurationNotChecked:pq-crypto/bike_r2/aes_ctr_prf.c
24+
ConfigurationNotChecked:pq-crypto/bike_r2/secure_decode_portable.c
25+
ConfigurationNotChecked:pq-crypto/bike_r2/decode.c
26+
ConfigurationNotChecked:pq-crypto/bike_r2/bike_r2_kem.c
27+
28+
// cppcheck Message: (style:redundantAssignment) Variable 'mock_time' is reassigned a value before the old one has been used.
1329
// Reason: s2n_config_set_monotonic_clock() takes a reference to mock_time so that whenever it's modified locally, the timer sees the update when it dereferences the pointer.
1430
redundantAssignment:tests/unit/s2n_timer_test.c
31+
32+
// cppcheck Message: (error:shiftTooManyBits) Shifting 32-bit value by 64 bits is undefined behaviour.
33+
// Reason: In the SIKE arithmetic macros, this is actually a 128-bit typedef being shifted by 64 bits.
34+
shiftTooManyBits:pq-crypto/sike_r2/fp.c
35+
36+
// cppcheck Message (information:unmatchedSuppression) Unmatched suppression: shiftTooManyBits
37+
// Reason: After applying the shiftTooManyBits suppression above, cppcheck complains (erroneously) that it is not necessary
38+
unmatchedSuppression:pq-crypto/sike_r2/fp.c

codebuild/bin/run_cppcheck.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ CPPCHECK_EXECUTABLE=${CPPCHECK_INSTALL_DIR}/cppcheck/cppcheck
3030

3131
FAILED=0
3232
$CPPCHECK_EXECUTABLE --version
33-
$CPPCHECK_EXECUTABLE --std=c99 --error-exitcode=-1 --quiet --force -j 8 --enable=all --template='[{file}:{line}]: ({severity}:{id}) {message}' --inline-suppr --suppressions-list=codebuild/bin/cppcheck_suppressions.txt -I . -I ./tests api bin crypto error stuffer ./tests/unit tls utils || FAILED=1
34-
33+
$CPPCHECK_EXECUTABLE --std=c99 --error-exitcode=-1 --quiet --force -j 8 --enable=all --template='[{file}:{line}]: ({severity}:{id}) {message}' --inline-suppr --suppressions-list=codebuild/bin/cppcheck_suppressions.txt -I . -I ./tests api bin crypto error stuffer ./tests/unit tls utils pq-crypto || FAILED=1
3534
if [ $FAILED == 1 ];
3635
then
3736
printf "\\033[31;1mFAILED cppcheck\\033[0m\\n"

pq-crypto/bike_r1/aes_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ _INLINE_ void
6666
aes256_free_ks(OUT aes256_ks_t *ks)
6767
{
6868
EVP_CIPHER_CTX_free(*ks);
69-
ks = NULL;
69+
*ks = NULL;
7070
}

pq-crypto/bike_r1/gf2x_portable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
void
2020
gf2x_mul_1x1(uint64_t *c, uint64_t a, uint64_t b)
2121
{
22-
uint64_t h = 0, l = 0, g1, g2, u[8];
22+
uint64_t h = 0, l = 0, u[8];
2323
const uint64_t w = 64;
2424
const uint64_t s = 3;
2525
// Multiplying 64 bits by 7 can results in an overflow of 3 bits.
@@ -41,8 +41,8 @@ gf2x_mul_1x1(uint64_t *c, uint64_t a, uint64_t b)
4141
h = (u[(a >> 3) & 7] >> 61);
4242
for(uint32_t i = (2 * s); i < w; i += (2 * s))
4343
{
44-
g1 = u[(a >> i) & 7];
45-
g2 = u[(a >> (i + s)) & 7];
44+
uint64_t g1 = u[(a >> i) & 7];
45+
uint64_t g2 = u[(a >> (i + s)) & 7];
4646

4747
l ^= (g1 << i) ^ (g2 << (i + s));
4848
h ^= (g1 >> (w - i)) ^ (g2 >> (w - (i + s)));

pq-crypto/bike_r1/openssl_utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ _INLINE_ void
3434
reverse_endian(OUT uint8_t *res, IN const uint8_t *in, IN const uint32_t n)
3535
{
3636
uint32_t i;
37-
uint64_t tmp;
3837

3938
for(i = 0; i < (n / 2); i++)
4039
{
41-
tmp = in[i];
40+
uint64_t tmp = in[i];
4241
res[i] = in[n - 1 - i];
4342
res[n - 1 - i] = tmp;
4443
}

pq-crypto/bike_r1/sampling.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ get_rand_mod_len(OUT uint32_t * rand_pos,
3131
break;
3232
}
3333

34-
} while(1 == 1);
34+
} while(1);
3535

3636
return SUCCESS;
3737
}

pq-crypto/bike_r1/sampling_portable.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ secure_set_bits(IN OUT uint64_t * a,
2424
assert(weight <= MAX_WEIGHT);
2525
uint64_t qw_pos[MAX_WEIGHT];
2626
uint64_t bit_pos[MAX_WEIGHT];
27-
uint64_t tmp = 0;
2827

2928
// 1. Identify the QW position of each value and the bit position inside this
3029
// QW.
@@ -37,7 +36,7 @@ secure_set_bits(IN OUT uint64_t * a,
3736
// 2. Fill each QW in a constant time.
3837
for(uint32_t qw = 0; qw < (a_len_bytes / 8); qw++)
3938
{
40-
tmp = 0;
39+
uint64_t tmp = 0;
4140
for(uint32_t j = 0; j < weight; j++)
4241
{
4342
uint64_t mask = (-1ULL) + (!secure_cmp32(qw_pos[j], qw));

pq-crypto/bike_r2/aes_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ _INLINE_ void
6767
aes256_free_ks(OUT aes256_ks_t *ks)
6868
{
6969
EVP_CIPHER_CTX_free(*ks);
70-
ks = NULL;
70+
*ks = NULL;
7171
}

pq-crypto/bike_r2/gf2x_portable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
void
2020
gf2x_mul_1x1(uint64_t *c, uint64_t a, uint64_t b)
2121
{
22-
uint64_t h = 0, l = 0, g1, g2, u[8];
22+
uint64_t h = 0, l = 0, u[8];
2323
const uint64_t w = 64;
2424
const uint64_t s = 3;
2525
// Multiplying 64 bits by 7 can results in an overflow of 3 bits.
@@ -41,8 +41,8 @@ gf2x_mul_1x1(uint64_t *c, uint64_t a, uint64_t b)
4141
h = (u[(a >> 3) & 7] >> 61);
4242
for(uint32_t i = (2 * s); i < w; i += (2 * s))
4343
{
44-
g1 = u[(a >> i) & 7];
45-
g2 = u[(a >> (i + s)) & 7];
44+
uint64_t g1 = u[(a >> i) & 7];
45+
uint64_t g2 = u[(a >> (i + s)) & 7];
4646

4747
l ^= (g1 << i) ^ (g2 << (i + s));
4848
h ^= (g1 >> (w - i)) ^ (g2 >> (w - (i + s)));

pq-crypto/bike_r2/openssl_utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ _INLINE_ void
3434
reverse_endian(OUT uint8_t *res, IN const uint8_t *in, IN const uint32_t n)
3535
{
3636
uint32_t i;
37-
uint64_t tmp;
3837

3938
for(i = 0; i < (n / 2); i++)
4039
{
41-
tmp = in[i];
40+
uint64_t tmp = in[i];
4241
res[i] = in[n - 1 - i];
4342
res[n - 1 - i] = tmp;
4443
}

0 commit comments

Comments
 (0)