fix clang-analyzer warnings

This fixes #80
This commit is contained in:
Steffen Jaeckel 2015-10-24 16:22:28 +02:00
parent 16f397d55c
commit 460b8716c9
14 changed files with 28 additions and 28 deletions

View File

@ -127,11 +127,6 @@ int ccm_memory(int cipher,
L = 15 - noncelen; L = 15 - noncelen;
} }
/* decrease noncelen to match L */
if ((noncelen + L) > 15) {
noncelen = 15 - L;
}
/* allocate mem for the symmetric key */ /* allocate mem for the symmetric key */
if (uskey == NULL) { if (uskey == NULL) {
skey = XMALLOC(sizeof(*skey)); skey = XMALLOC(sizeof(*skey));
@ -147,7 +142,7 @@ int ccm_memory(int cipher,
} else { } else {
skey = uskey; skey = uskey;
} }
/* initialize buffer for pt */ /* initialize buffer for pt */
if (direction == CCM_DECRYPT) { if (direction == CCM_DECRYPT) {
pt_work = XMALLOC(ptlen); pt_work = XMALLOC(ptlen);

View File

@ -5,9 +5,15 @@
#include <signal.h> #include <signal.h>
/* this is the default LibTomCrypt macro */ /* this is the default LibTomCrypt macro */
void crypt_argchk(char *v, char *s, int d); #if defined(__clang__) || defined(__GNUC_MINOR__)
#define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } #define NORETURN __attribute__ ((noreturn))
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x) #else
#define NORETURN
#endif
void crypt_argchk(char *v, char *s, int d) NORETURN;
#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
#define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
#elif ARGTYPE == 1 #elif ARGTYPE == 1

View File

@ -68,15 +68,13 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) { if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
goto LBL_ERR; goto LBL_ERR;
} }
if(hashsize < LTC_HMAC_BLOCKSIZE) {
zeromem((hmac->key) + hashsize, (size_t)(LTC_HMAC_BLOCKSIZE - hashsize));
}
keylen = hashsize; keylen = hashsize;
} else { } else {
XMEMCPY(hmac->key, key, (size_t)keylen); XMEMCPY(hmac->key, key, (size_t)keylen);
if(keylen < LTC_HMAC_BLOCKSIZE) { }
zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
} if(keylen < LTC_HMAC_BLOCKSIZE) {
zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
} }
/* Create the initial vector for step (3) */ /* Create the initial vector for step (3) */

View File

@ -13,15 +13,14 @@
/** /**
@file crypt_argchk.c @file crypt_argchk.c
Perform argument checking, Tom St Denis Perform argument checking, Tom St Denis
*/ */
#if (ARGTYPE == 0) #if (ARGTYPE == 0)
#include <signal.h>
void crypt_argchk(char *v, char *s, int d) void crypt_argchk(char *v, char *s, int d)
{ {
fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n", fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
v, d, s); v, d, s);
(void)raise(SIGABRT); abort();
} }
#endif #endif

View File

@ -110,7 +110,9 @@ int xts_decrypt(const unsigned char *ct, unsigned long ptlen, unsigned char *pt,
} }
for (i = 0; i < lim; i++) { for (i = 0; i < lim; i++) {
err = tweak_uncrypt(ct, pt, T, xts); if ((err = tweak_uncrypt(ct, pt, T, xts)) != CRYPT_OK) {
return err;
}
ct += 16; ct += 16;
pt += 16; pt += 16;
} }

View File

@ -113,7 +113,9 @@ int xts_encrypt(const unsigned char *pt, unsigned long ptlen, unsigned char *ct,
} }
for (i = 0; i < lim; i++) { for (i = 0; i < lim; i++) {
err = tweak_crypt(pt, ct, T, xts); if ((err = tweak_crypt(pt, ct, T, xts)) != CRYPT_OK) {
return err;
}
ct += 16; ct += 16;
pt += 16; pt += 16;
} }

View File

@ -46,7 +46,6 @@ int der_length_integer(void *num, unsigned long *outlen)
} else { } else {
/* it's negative */ /* it's negative */
/* find power of 2 that is a multiple of eight and greater than count bits */ /* find power of 2 that is a multiple of eight and greater than count bits */
leading_zero = 0;
z = mp_count_bits(num); z = mp_count_bits(num);
z = z + (8 - (z & 7)); z = z + (8 - (z & 7));
if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z; if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z;

View File

@ -44,6 +44,8 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
type = va_arg(args, ltc_asn1_type); type = va_arg(args, ltc_asn1_type);
size = va_arg(args, unsigned long); size = va_arg(args, unsigned long);
data = va_arg(args, void*); data = va_arg(args, void*);
LTC_UNUSED_PARAM(size);
LTC_UNUSED_PARAM(data);
if (type == LTC_ASN1_EOL) { if (type == LTC_ASN1_EOL) {
break; break;

View File

@ -45,6 +45,8 @@ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
type = va_arg(args, ltc_asn1_type); type = va_arg(args, ltc_asn1_type);
size = va_arg(args, unsigned long); size = va_arg(args, unsigned long);
data = va_arg(args, void*); data = va_arg(args, void*);
LTC_UNUSED_PARAM(size);
LTC_UNUSED_PARAM(data);
if (type == LTC_ASN1_EOL) { if (type == LTC_ASN1_EOL) {
break; break;

View File

@ -246,8 +246,6 @@ int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
if (inlen < keysize) { if (inlen < keysize) {
err = CRYPT_INVALID_PACKET; err = CRYPT_INVALID_PACKET;
goto LBL_ERR; goto LBL_ERR;
} else {
inlen -= keysize;
} }
if (keysize > *outlen) { if (keysize > *outlen) {

View File

@ -85,7 +85,6 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
*/ */
err = CRYPT_OK;
ret = CRYPT_OK; ret = CRYPT_OK;
/* must have leading 0x00 byte */ /* must have leading 0x00 byte */

View File

@ -94,8 +94,7 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
/* copy out the hash */ /* copy out the hash */
XMEMCPY(hash, sig + x, hLen); XMEMCPY(hash, sig + x, hLen);
x += hLen; /* x += hLen; */
/* check the MSB */ /* check the MSB */
if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen)))) != 0) { if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen)))) != 0) {

View File

@ -116,7 +116,7 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
x += modulus_len - saltlen - hLen - 2; x += modulus_len - saltlen - hLen - 2;
DB[x++] = 0x01; DB[x++] = 0x01;
XMEMCPY(DB + x, salt, saltlen); XMEMCPY(DB + x, salt, saltlen);
x += saltlen; /* x += saltlen; */
/* generate mask of length modulus_len - hLen - 1 from hash */ /* generate mask of length modulus_len - hLen - 1 from hash */
if ((err = pkcs_1_mgf1(hash_idx, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) { if ((err = pkcs_1_mgf1(hash_idx, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {

View File

@ -300,7 +300,6 @@ unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state
#endif #endif
c = &(prng->sober128); c = &(prng->sober128);
t = 0;
tlen = outlen; tlen = outlen;
/* handle any previously buffered bytes */ /* handle any previously buffered bytes */