Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .ci/clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# output version
bash .ci/printinfo.sh

# tested with clang-tidy from llvm-6.0.0
# not tested with Travis-CI

#### we use the main test sets:
# readability
# misc
# clang-analyzer
# google
# performance
# modernize
# cert
# bugprone
# portability

#### the following checks are skipped
# google-readability-function-size
# readability-function-size
# google-readability-casting
# readability-braces-around-statements
# misc-macro-parentheses
# clang-analyzer-valist.Uninitialized

echo "Run clang-tidy version"

clang-tidy --version || exit 1

echo "Run clang-tidy..."

clang-tidy src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c -warnings-as-errors='*' --quiet --checks=-*,\
readability-*,-readability-function-size,-readability-braces-around-statements,\
misc-*,-misc-macro-parentheses,\
clang-analyzer-*,-clang-analyzer-valist.Uninitialized,\
google-*,-google-readability-function-size,-google-readability-casting,\
performance-*,\
modernize-*,\
cert-*,\
bugprone-*,\
portability-* -- -DUSE_LTM -DLTM_DESC -Isrc/headers -I../libtommath || { echo "clang-tidy FAILED!"; exit 1; }

echo "clang-tidy ok"

exit 0

# ref: $Format:%D$
# git commit: $Format:%H$
# commit time: $Format:%ai$
11 changes: 6 additions & 5 deletions src/ciphers/aes/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,19 @@ int ECB_KS(int *keysize)
{
LTC_ARGCHK(keysize != NULL);

if (*keysize < 16)
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
} else if (*keysize < 32) {
}
if (*keysize < 32) {
*keysize = 24;
return CRYPT_OK;
} else {
*keysize = 32;
return CRYPT_OK;
}
*keysize = 32;
return CRYPT_OK;
}

#endif
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/blowfish.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ int blowfish_keysize(int *keysize)

if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 56) {
}
if (*keysize > 56) {
*keysize = 56;
}
return CRYPT_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/cast5.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ int cast5_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 5) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 16) {
}
if (*keysize > 16) {
*keysize = 16;
}
return CRYPT_OK;
Expand Down
3 changes: 1 addition & 2 deletions src/ciphers/kasumi.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ int kasumi_keysize(int *keysize)
if (*keysize >= 16) {
*keysize = 16;
return CRYPT_OK;
} else {
return CRYPT_INVALID_KEYSIZE;
}
return CRYPT_INVALID_KEYSIZE;
}

int kasumi_test(void)
Expand Down
3 changes: 1 addition & 2 deletions src/ciphers/khazad.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,8 @@ int khazad_keysize(int *keysize)
if (*keysize >= 16) {
*keysize = 16;
return CRYPT_OK;
} else {
return CRYPT_INVALID_KEYSIZE;
}
return CRYPT_INVALID_KEYSIZE;
}

#endif
Expand Down
5 changes: 2 additions & 3 deletions src/ciphers/noekeon.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,9 @@ int noekeon_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
} else {
*keysize = 16;
return CRYPT_OK;
}
*keysize = 16;
return CRYPT_OK;
}

#endif
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/rc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ int rc2_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 1) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 128) {
}
if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/rc5.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ int rc5_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 128) {
}
if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/rc6.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ int rc6_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 128) {
}
if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
Expand Down
10 changes: 4 additions & 6 deletions src/ciphers/safer/safer.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,21 +358,19 @@ int safer_64_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
} else {
*keysize = 8;
return CRYPT_OK;
}
*keysize = 8;
return CRYPT_OK;
}

int safer_128_keysize(int *keysize)
{
LTC_ARGCHK(keysize != NULL);
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
} else {
*keysize = 16;
return CRYPT_OK;
}
*keysize = 16;
return CRYPT_OK;
}

int safer_k64_test(void)
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/skipjack.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ int skipjack_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 10) {
return CRYPT_INVALID_KEYSIZE;
} else if (*keysize > 10) {
}
if (*keysize > 10) {
*keysize = 10;
}
return CRYPT_OK;
Expand Down
13 changes: 6 additions & 7 deletions src/ciphers/twofish/twofish.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,25 +689,24 @@ void twofish_done(symmetric_key *skey)
int twofish_keysize(int *keysize)
{
LTC_ARGCHK(keysize);
if (*keysize < 16)
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
} else if (*keysize < 32) {
}
if (*keysize < 32) {
*keysize = 24;
return CRYPT_OK;
} else {
*keysize = 32;
return CRYPT_OK;
}
*keysize = 32;
return CRYPT_OK;
}

#endif




/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
6 changes: 3 additions & 3 deletions src/mac/hmac/hmac_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ int hmac_test(void)

if (failed != 0) {
return CRYPT_FAIL_TESTVECTOR;
} else if (tested == 0) {
}
if (tested == 0) {
return CRYPT_NOP;
} else {
return CRYPT_OK;
}
return CRYPT_OK;
#endif
}

Expand Down
12 changes: 6 additions & 6 deletions src/misc/base64/base64_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ static int _base64_decode_internal(const char *in, unsigned long inlen,
continue;
}
if (c == 253) {
if (mode == strict)
if (mode == strict) {
return CRYPT_INVALID_PACKET;
else
continue; /* allow to ignore white-spaces (relaxed+insane) */
}
continue; /* allow to ignore white-spaces (relaxed+insane) */
}
if (c == 255) {
if (mode == insane)
if (mode == insane) {
continue; /* allow to ignore invalid garbage (insane) */
else
return CRYPT_INVALID_PACKET;
}
return CRYPT_INVALID_PACKET;
}
if ((g > 0) && (mode != insane)) {
/* we only allow '=' to be at the end (strict+relaxed) */
Expand Down
3 changes: 1 addition & 2 deletions src/misc/error_to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ const char *error_to_string(int err)
{
if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
return "Invalid error code.";
} else {
return err_2_str[err];
}
return err_2_str[err];
}


Expand Down
3 changes: 1 addition & 2 deletions src/misc/hkdf/hkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ int hkdf_extract(int hash_idx, const unsigned char *salt, unsigned long saltlen
valid results for HKDF. */
if (salt == NULL || saltlen == 0) {
return hmac_memory(hash_idx, (const unsigned char *)"", 1, in, inlen, out, outlen);
} else {
return hmac_memory(hash_idx, salt, saltlen, in, inlen, out, outlen);
}
return hmac_memory(hash_idx, salt, saltlen, in, inlen, out, outlen);
}

int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
Expand Down
6 changes: 3 additions & 3 deletions src/misc/hkdf/hkdf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ int hkdf_test(void)

if (failed != 0) {
return CRYPT_FAIL_TESTVECTOR;
} else if (tested == 0) {
}
if (tested == 0) {
return CRYPT_NOP;
} else {
return CRYPT_OK;
}
return CRYPT_OK;
#endif
}

Expand Down
47 changes: 23 additions & 24 deletions src/modes/cbc/cbc_decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,31 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s

if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
return cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
} else {
while (len) {
/* decrypt */
if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
return err;
}

/* xor IV against plaintext */
#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
}
#else
for (x = 0; x < cbc->blocklen; x++) {
tmpy = tmp[x] ^ cbc->IV[x];
cbc->IV[x] = ct[x];
pt[x] = tmpy;
}
#endif
}
while (len) {
/* decrypt */
if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
return err;
}

ct += cbc->blocklen;
pt += cbc->blocklen;
len -= cbc->blocklen;
/* xor IV against plaintext */
#if defined(LTC_FAST)
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
}
#else
for (x = 0; x < cbc->blocklen; x++) {
tmpy = tmp[x] ^ cbc->IV[x];
cbc->IV[x] = ct[x];
pt[x] = tmpy;
}
#endif

ct += cbc->blocklen;
pt += cbc->blocklen;
len -= cbc->blocklen;
}
return CRYPT_OK;
}
Expand Down
Loading