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
3 changes: 2 additions & 1 deletion src/ciphers/des.c
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,9 @@ int des_keysize(int *keysize)
int des3_keysize(int *keysize)
{
LTC_ARGCHK(keysize != NULL);
if (*keysize < 16)
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/safer/safer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ static void Safer_Expand_Userkey(const unsigned char *userkey_1,
unsigned char ka[LTC_SAFER_BLOCK_LEN + 1];
unsigned char kb[LTC_SAFER_BLOCK_LEN + 1];

if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds)
if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds) {
nof_rounds = LTC_SAFER_MAX_NOF_ROUNDS;
}
*key++ = (unsigned char)nof_rounds;
ka[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;
kb[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/safer/saferp.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ int saferp_keysize(int *keysize)
{
LTC_ARGCHK(keysize != NULL);

if (*keysize < 16)
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
}
if (*keysize < 24) {
*keysize = 16;
} else if (*keysize < 32) {
Expand Down
5 changes: 3 additions & 2 deletions src/encauth/ocb3/ocb3_decrypt_last.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ct
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
for(x=last_block_len; x<ocb->block_len; x++) {
if (x == last_block_len)
if (x == last_block_len) {
ocb->checksum[x] ^= 0x80;
else
} else {
ocb->checksum[x] ^= 0x00;
}
}

/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */
Expand Down
8 changes: 4 additions & 4 deletions src/encauth/ocb3/ocb3_encrypt_last.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
for(x=last_block_len; x<ocb->block_len; x++) {
if (x == last_block_len)
if (x == last_block_len) {
ocb->checksum[x] ^= 0x80;
else
} else {
ocb->checksum[x] ^= 0x00;
}
}

/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */
Expand All @@ -82,8 +83,7 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->tag_part, ocb->tag_part, &ocb->key)) != CRYPT_OK) {
goto LBL_ERR;
}
}
else {
} else {
/* Tag = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) xor HASH(K,A) */
/* at this point we calculate only: Tag_part = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) */
for(x=0; x<ocb->block_len; x++) {
Expand Down
20 changes: 12 additions & 8 deletions src/hashes/blake2b.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ static int blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0]

static void blake2b_set_lastblock(hash_state *md)
{
if (md->blake2b.last_node)
if (md->blake2b.last_node) {
blake2b_set_lastnode(md);

}
md->blake2b.f[0] = CONST64(0xffffffffffffffff);
}

Expand All @@ -177,8 +177,9 @@ static void blake2b_init0(hash_state *md)
unsigned long i;
XMEMSET(&md->blake2b, 0, sizeof(md->blake2b));

for (i = 0; i < 8; ++i)
for (i = 0; i < 8; ++i) {
md->blake2b.h[i] = blake2b_IV[i];
}
}

/* init xors IV with input parameter block */
Expand Down Expand Up @@ -219,11 +220,12 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,

LTC_ARGCHK(md != NULL);

if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
return CRYPT_INVALID_ARG;

if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES))
}
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES)) {
return CRYPT_INVALID_ARG;
}

XMEMSET(P, 0, sizeof(P));

Expand Down Expand Up @@ -416,16 +418,18 @@ int blake2b_done(hash_state *md, unsigned char *out)

/* if(md->blakebs.outlen != outlen) return CRYPT_INVALID_ARG; */

if (blake2b_is_lastblock(md))
if (blake2b_is_lastblock(md)) {
return CRYPT_ERROR;
}

blake2b_increment_counter(md, md->blake2b.curlen);
blake2b_set_lastblock(md);
XMEMSET(md->blake2b.buf + md->blake2b.curlen, 0, BLAKE2B_BLOCKBYTES - md->blake2b.curlen); /* Padding */
blake2b_compress(md, md->blake2b.buf);

for (i = 0; i < 8; ++i) /* Output full hash to temp buffer */
for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
STORE64L(md->blake2b.h[i], buffer + i * 8);
}

XMEMCPY(out, buffer, md->blake2b.outlen);
zeromem(md, sizeof(hash_state));
Expand Down
28 changes: 16 additions & 12 deletions src/hashes/blake2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ static int blake2s_is_lastblock(const hash_state *md) { return md->blake2s.f[0]

static void blake2s_set_lastblock(hash_state *md)
{
if (md->blake2s.last_node)
if (md->blake2s.last_node) {
blake2s_set_lastnode(md);

}
md->blake2s.f[0] = 0xffffffffUL;
}

Expand All @@ -169,8 +169,9 @@ static int blake2s_init0(hash_state *md)
int i;
XMEMSET(&md->blake2s, 0, sizeof(struct blake2s_state));

for (i = 0; i < 8; ++i)
for (i = 0; i < 8; ++i) {
md->blake2s.h[i] = blake2s_IV[i];
}

return CRYPT_OK;
}
Expand Down Expand Up @@ -213,11 +214,12 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,

LTC_ARGCHK(md != NULL);

if ((!outlen) || (outlen > BLAKE2S_OUTBYTES))
if ((!outlen) || (outlen > BLAKE2S_OUTBYTES)) {
return CRYPT_INVALID_ARG;

if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES))
}
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES)) {
return CRYPT_INVALID_ARG;
}

XMEMSET(P, 0, sizeof(P));

Expand Down Expand Up @@ -308,8 +310,9 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
LOAD32L(m[i], buf + i * sizeof(m[i]));
}

for (i = 0; i < 8; ++i)
for (i = 0; i < 8; ++i) {
v[i] = md->blake2s.h[i];
}

v[8] = blake2s_IV[0];
v[9] = blake2s_IV[1];
Expand All @@ -331,9 +334,9 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
ROUND(8);
ROUND(9);

for (i = 0; i < 8; ++i)
for (i = 0; i < 8; ++i) {
md->blake2s.h[i] = md->blake2s.h[i] ^ v[i] ^ v[i + 8];

}
return CRYPT_OK;
}
#undef G
Expand Down Expand Up @@ -404,16 +407,17 @@ int blake2s_done(hash_state *md, unsigned char *out)

/* if(md->blake2s.outlen != outlen) return CRYPT_INVALID_ARG; */

if (blake2s_is_lastblock(md))
if (blake2s_is_lastblock(md)) {
return CRYPT_ERROR;

}
blake2s_increment_counter(md, md->blake2s.curlen);
blake2s_set_lastblock(md);
XMEMSET(md->blake2s.buf + md->blake2s.curlen, 0, BLAKE2S_BLOCKBYTES - md->blake2s.curlen); /* Padding */
blake2s_compress(md, md->blake2s.buf);

for (i = 0; i < 8; ++i) /* Output full hash to temp buffer */
for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
STORE32L(md->blake2s.h[i], buffer + i * 4);
}

XMEMCPY(out, buffer, md->blake2s.outlen);
zeromem(md, sizeof(hash_state));
Expand Down
13 changes: 8 additions & 5 deletions src/hashes/sha3.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ static void keccakf(ulong64 s[25])

for(round = 0; round < SHA3_KECCAK_ROUNDS; round++) {
/* Theta */
for(i = 0; i < 5; i++)
for(i = 0; i < 5; i++) {
bc[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20];

}
for(i = 0; i < 5; i++) {
t = bc[(i + 4) % 5] ^ ROL64(bc[(i + 1) % 5], 1);
for(j = 0; j < 25; j += 5)
for(j = 0; j < 25; j += 5) {
s[j + i] ^= t;
}
}
/* Rho Pi */
t = s[1];
Expand All @@ -185,10 +186,12 @@ static void keccakf(ulong64 s[25])
}
/* Chi */
for(j = 0; j < 25; j += 5) {
for(i = 0; i < 5; i++)
for(i = 0; i < 5; i++) {
bc[i] = s[j + i];
for(i = 0; i < 5; i++)
}
for(i = 0; i < 5; i++) {
s[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
}
}
/* Iota */
s[0] ^= keccakf_rndc[round];
Expand Down
6 changes: 4 additions & 2 deletions src/misc/adler32.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length--;
} while (length % 8 != 0);

if (s1 >= _adler32_base)
if (s1 >= _adler32_base) {
s1 -= _adler32_base;
}
s2 %= _adler32_base;
}

Expand All @@ -67,8 +68,9 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length -= 8;
input += 8;

if (s1 >= _adler32_base)
if (s1 >= _adler32_base) {
s1 -= _adler32_base;
}
s2 %= _adler32_base;
}

Expand Down
7 changes: 5 additions & 2 deletions src/misc/base16/base16_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ int base16_encode(const unsigned char *in, unsigned long inlen,
x--;
*outlen = x; /* returning the length without terminating NUL */

if (options == 0) alphabet = alphabets[0];
else alphabet = alphabets[1];
if (options == 0) {
alphabet = alphabets[0];
} else {
alphabet = alphabets[1];
}

for (i = 0; i < x; i += 2) {
out[i] = alphabet[(in[i/2] >> 4) & 0x0f];
Expand Down
3 changes: 2 additions & 1 deletion src/misc/burn_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ void burn_stack(unsigned long len)
{
unsigned char buf[32];
zeromem(buf, sizeof(buf));
if (len > (unsigned long)sizeof(buf))
if (len > (unsigned long)sizeof(buf)) {
burn_stack(len - sizeof(buf));
}
}


Expand Down
6 changes: 3 additions & 3 deletions src/misc/compare_testvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ static void _print_hex(const char* what, const void* v, const unsigned long l)
int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
{
int res = 0;
if(is_len != should_len)
if(is_len != should_len) {
res = is_len > should_len ? -1 : 1;
else
} else {
res = XMEMCMP(is, should, is_len);

}
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
if (res != 0) {
fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
Expand Down
3 changes: 2 additions & 1 deletion src/misc/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long le
LTC_ARGCHKVD(input != NULL);
crc = ctx->crc;

while (length--)
while (length--) {
crc = crc32_m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);
}

ctx->crc = crc;
}
Expand Down
3 changes: 2 additions & 1 deletion src/misc/crypt/crypt_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
if (number_len < 0)
if (number_len < 0) {
return -1;
}
total_len += number_len;
}

Expand Down
3 changes: 2 additions & 1 deletion src/misc/crypt/crypt_sizes.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
if (number_len < 0)
if (number_len < 0) {
return -1;
}
total_len += number_len;
/* this last +1 is for newlines (and ending NULL) */
}
Expand Down
9 changes: 6 additions & 3 deletions src/misc/hkdf/hkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
hashsize = hash_descriptor[hash_idx].hashsize;

/* RFC5869 parameter restrictions */
if (inlen < hashsize || outlen > hashsize * 255)
if (inlen < hashsize || outlen > hashsize * 255) {
return CRYPT_INVALID_ARG;
if (info == NULL && infolen != 0)
}
if (info == NULL && infolen != 0) {
return CRYPT_INVALID_ARG;
}
LTC_ARGCHK(out != NULL);

Tlen = hashsize + infolen + 1;
Expand Down Expand Up @@ -86,8 +88,9 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
}
outoff += Noutlen;

if (outoff >= outlen) /* loop exit condition */
if (outoff >= outlen) { /* loop exit condition */
break;
}

/* All subsequent HMAC data T(N) DOES include the previous hash value */
XMEMCPY(T, out + hashsize * (N-1), hashsize);
Expand Down
7 changes: 5 additions & 2 deletions src/misc/padding/padding_pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded
type = mode & LTC_PAD_MASK;

if (*padded_length < l) {
if (type != LTC_PAD_ISO_10126) *padded_length = l;
else *padded_length = length + 256;
if (type != LTC_PAD_ISO_10126) {
*padded_length = l;
} else {
*padded_length = length + 256;
}
return CRYPT_BUFFER_OVERFLOW;
}

Expand Down
Loading