Skip to content

Commit 98ad88b

Browse files
authored
Merge pull request #422 from libtom/pr/clang-tidy-google-readability-braces-around-statements
fix clang-tidy warning: google-readability-braces-around-statements
2 parents e02694c + a3dab04 commit 98ad88b

26 files changed

+124
-75
lines changed

src/ciphers/des.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2068,8 +2068,9 @@ int des_keysize(int *keysize)
20682068
int des3_keysize(int *keysize)
20692069
{
20702070
LTC_ARGCHK(keysize != NULL);
2071-
if (*keysize < 16)
2071+
if (*keysize < 16) {
20722072
return CRYPT_INVALID_KEYSIZE;
2073+
}
20732074
if (*keysize < 24) {
20742075
*keysize = 16;
20752076
return CRYPT_OK;

src/ciphers/safer/safer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ static void Safer_Expand_Userkey(const unsigned char *userkey_1,
113113
unsigned char ka[LTC_SAFER_BLOCK_LEN + 1];
114114
unsigned char kb[LTC_SAFER_BLOCK_LEN + 1];
115115

116-
if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds)
116+
if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds) {
117117
nof_rounds = LTC_SAFER_MAX_NOF_ROUNDS;
118+
}
118119
*key++ = (unsigned char)nof_rounds;
119120
ka[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;
120121
kb[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;

src/ciphers/safer/saferp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ int saferp_keysize(int *keysize)
547547
{
548548
LTC_ARGCHK(keysize != NULL);
549549

550-
if (*keysize < 16)
550+
if (*keysize < 16) {
551551
return CRYPT_INVALID_KEYSIZE;
552+
}
552553
if (*keysize < 24) {
553554
*keysize = 16;
554555
} else if (*keysize < 32) {

src/encauth/ocb3/ocb3_decrypt_last.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ct
6666
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
6767
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
6868
for(x=last_block_len; x<ocb->block_len; x++) {
69-
if (x == last_block_len)
69+
if (x == last_block_len) {
7070
ocb->checksum[x] ^= 0x80;
71-
else
71+
} else {
7272
ocb->checksum[x] ^= 0x00;
73+
}
7374
}
7475

7576
/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */

src/encauth/ocb3/ocb3_encrypt_last.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
6868
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
6969
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
7070
for(x=last_block_len; x<ocb->block_len; x++) {
71-
if (x == last_block_len)
71+
if (x == last_block_len) {
7272
ocb->checksum[x] ^= 0x80;
73-
else
73+
} else {
7474
ocb->checksum[x] ^= 0x00;
75+
}
7576
}
7677

7778
/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */
@@ -82,8 +83,7 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
8283
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->tag_part, ocb->tag_part, &ocb->key)) != CRYPT_OK) {
8384
goto LBL_ERR;
8485
}
85-
}
86-
else {
86+
} else {
8787
/* Tag = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) xor HASH(K,A) */
8888
/* at this point we calculate only: Tag_part = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) */
8989
for(x=0; x<ocb->block_len; x++) {

src/hashes/blake2b.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ static int blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0]
160160

161161
static void blake2b_set_lastblock(hash_state *md)
162162
{
163-
if (md->blake2b.last_node)
163+
if (md->blake2b.last_node) {
164164
blake2b_set_lastnode(md);
165-
165+
}
166166
md->blake2b.f[0] = CONST64(0xffffffffffffffff);
167167
}
168168

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

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

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

220221
LTC_ARGCHK(md != NULL);
221222

222-
if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
223+
if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
223224
return CRYPT_INVALID_ARG;
224-
225-
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES))
225+
}
226+
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES)) {
226227
return CRYPT_INVALID_ARG;
228+
}
227229

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

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

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

419-
if (blake2b_is_lastblock(md))
421+
if (blake2b_is_lastblock(md)) {
420422
return CRYPT_ERROR;
423+
}
421424

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

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

430434
XMEMCPY(out, buffer, md->blake2b.outlen);
431435
zeromem(md, sizeof(hash_state));

src/hashes/blake2s.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ static int blake2s_is_lastblock(const hash_state *md) { return md->blake2s.f[0]
152152

153153
static void blake2s_set_lastblock(hash_state *md)
154154
{
155-
if (md->blake2s.last_node)
155+
if (md->blake2s.last_node) {
156156
blake2s_set_lastnode(md);
157-
157+
}
158158
md->blake2s.f[0] = 0xffffffffUL;
159159
}
160160

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

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

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

214215
LTC_ARGCHK(md != NULL);
215216

216-
if ((!outlen) || (outlen > BLAKE2S_OUTBYTES))
217+
if ((!outlen) || (outlen > BLAKE2S_OUTBYTES)) {
217218
return CRYPT_INVALID_ARG;
218-
219-
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES))
219+
}
220+
if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES)) {
220221
return CRYPT_INVALID_ARG;
222+
}
221223

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

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

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

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

334-
for (i = 0; i < 8; ++i)
337+
for (i = 0; i < 8; ++i) {
335338
md->blake2s.h[i] = md->blake2s.h[i] ^ v[i] ^ v[i + 8];
336-
339+
}
337340
return CRYPT_OK;
338341
}
339342
#undef G
@@ -404,16 +407,17 @@ int blake2s_done(hash_state *md, unsigned char *out)
404407

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

407-
if (blake2s_is_lastblock(md))
410+
if (blake2s_is_lastblock(md)) {
408411
return CRYPT_ERROR;
409-
412+
}
410413
blake2s_increment_counter(md, md->blake2s.curlen);
411414
blake2s_set_lastblock(md);
412415
XMEMSET(md->blake2s.buf + md->blake2s.curlen, 0, BLAKE2S_BLOCKBYTES - md->blake2s.curlen); /* Padding */
413416
blake2s_compress(md, md->blake2s.buf);
414417

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

418422
XMEMCPY(out, buffer, md->blake2s.outlen);
419423
zeromem(md, sizeof(hash_state));

src/hashes/sha3.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,14 @@ static void keccakf(ulong64 s[25])
167167

168168
for(round = 0; round < SHA3_KECCAK_ROUNDS; round++) {
169169
/* Theta */
170-
for(i = 0; i < 5; i++)
170+
for(i = 0; i < 5; i++) {
171171
bc[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20];
172-
172+
}
173173
for(i = 0; i < 5; i++) {
174174
t = bc[(i + 4) % 5] ^ ROL64(bc[(i + 1) % 5], 1);
175-
for(j = 0; j < 25; j += 5)
175+
for(j = 0; j < 25; j += 5) {
176176
s[j + i] ^= t;
177+
}
177178
}
178179
/* Rho Pi */
179180
t = s[1];
@@ -185,10 +186,12 @@ static void keccakf(ulong64 s[25])
185186
}
186187
/* Chi */
187188
for(j = 0; j < 25; j += 5) {
188-
for(i = 0; i < 5; i++)
189+
for(i = 0; i < 5; i++) {
189190
bc[i] = s[j + i];
190-
for(i = 0; i < 5; i++)
191+
}
192+
for(i = 0; i < 5; i++) {
191193
s[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
194+
}
192195
}
193196
/* Iota */
194197
s[0] ^= keccakf_rndc[round];

src/misc/adler32.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
4141
length--;
4242
} while (length % 8 != 0);
4343

44-
if (s1 >= _adler32_base)
44+
if (s1 >= _adler32_base) {
4545
s1 -= _adler32_base;
46+
}
4647
s2 %= _adler32_base;
4748
}
4849

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

70-
if (s1 >= _adler32_base)
71+
if (s1 >= _adler32_base) {
7172
s1 -= _adler32_base;
73+
}
7274
s2 %= _adler32_base;
7375
}
7476

src/misc/base16/base16_encode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ int base16_encode(const unsigned char *in, unsigned long inlen,
5252
x--;
5353
*outlen = x; /* returning the length without terminating NUL */
5454

55-
if (options == 0) alphabet = alphabets[0];
56-
else alphabet = alphabets[1];
55+
if (options == 0) {
56+
alphabet = alphabets[0];
57+
} else {
58+
alphabet = alphabets[1];
59+
}
5760

5861
for (i = 0; i < x; i += 2) {
5962
out[i] = alphabet[(in[i/2] >> 4) & 0x0f];

src/misc/burn_stack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ void burn_stack(unsigned long len)
2121
{
2222
unsigned char buf[32];
2323
zeromem(buf, sizeof(buf));
24-
if (len > (unsigned long)sizeof(buf))
24+
if (len > (unsigned long)sizeof(buf)) {
2525
burn_stack(len - sizeof(buf));
26+
}
2627
}
2728

2829

src/misc/compare_testvector.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ static void _print_hex(const char* what, const void* v, const unsigned long l)
6363
int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
6464
{
6565
int res = 0;
66-
if(is_len != should_len)
66+
if(is_len != should_len) {
6767
res = is_len > should_len ? -1 : 1;
68-
else
68+
} else {
6969
res = XMEMCMP(is, should, is_len);
70-
70+
}
7171
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
7272
if (res != 0) {
7373
fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);

src/misc/crc32.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long le
153153
LTC_ARGCHKVD(input != NULL);
154154
crc = ctx->crc;
155155

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

159160
ctx->crc = crc;
160161
}

src/misc/crypt/crypt_constants.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
265265
/* calculate amount of memory required for the list */
266266
for (i=0; i<count; i++) {
267267
number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
268-
if (number_len < 0)
268+
if (number_len < 0) {
269269
return -1;
270+
}
270271
total_len += number_len;
271272
}
272273

src/misc/crypt/crypt_sizes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
326326
/* calculate amount of memory required for the list */
327327
for (i=0; i<count; i++) {
328328
number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
329-
if (number_len < 0)
329+
if (number_len < 0) {
330330
return -1;
331+
}
331332
total_len += number_len;
332333
/* this last +1 is for newlines (and ending NULL) */
333334
}

src/misc/hkdf/hkdf.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
5454
hashsize = hash_descriptor[hash_idx].hashsize;
5555

5656
/* RFC5869 parameter restrictions */
57-
if (inlen < hashsize || outlen > hashsize * 255)
57+
if (inlen < hashsize || outlen > hashsize * 255) {
5858
return CRYPT_INVALID_ARG;
59-
if (info == NULL && infolen != 0)
59+
}
60+
if (info == NULL && infolen != 0) {
6061
return CRYPT_INVALID_ARG;
62+
}
6163
LTC_ARGCHK(out != NULL);
6264

6365
Tlen = hashsize + infolen + 1;
@@ -86,8 +88,9 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
8688
}
8789
outoff += Noutlen;
8890

89-
if (outoff >= outlen) /* loop exit condition */
91+
if (outoff >= outlen) { /* loop exit condition */
9092
break;
93+
}
9194

9295
/* All subsequent HMAC data T(N) DOES include the previous hash value */
9396
XMEMCPY(T, out + hashsize * (N-1), hashsize);

src/misc/padding/padding_pad.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded
9999
type = mode & LTC_PAD_MASK;
100100

101101
if (*padded_length < l) {
102-
if (type != LTC_PAD_ISO_10126) *padded_length = l;
103-
else *padded_length = length + 256;
102+
if (type != LTC_PAD_ISO_10126) {
103+
*padded_length = l;
104+
} else {
105+
*padded_length = length + 256;
106+
}
104107
return CRYPT_BUFFER_OVERFLOW;
105108
}
106109

0 commit comments

Comments
 (0)