Commit 110776cb authored by Davide Galassi's avatar Davide Galassi

Static code check via the clang scan-build tool

parent d7a6f29f
Pipeline #55021445 passed with stages
in 1 minute and 49 seconds
#include <cry/des.h>
#define GET_BIT(buf, bit) \
(buf[(bit) / 8] & (0x80 >> ((bit) % 8)))
#define SET_BIT(buf, bit) \
(buf[(bit) / 8] |= (0x80 >> ((bit) % 8)))
#define CLEAR_BIT(buf, bit) \
(buf[(bit) / 8] &= ~(0x80 >> ((bit) % 8)))
#define EXPANSION_BLOCK_SIZE 6
#define PC1_KEY_SIZE 7
......@@ -136,6 +129,14 @@ static const unsigned char sbox[8][64] = {
}
};
#define GET_BIT(buf, bit) \
(buf[(bit) / 8] & (0x80 >> ((bit) % 8)))
#define SET_BIT(buf, bit) \
(buf[(bit) / 8] |= (0x80 >> ((bit) % 8)))
/*
* Implement the initial and final permutation functions. 'permute_tab'
* and 'dst' must have exactly len and len * 8 number of entries,
......@@ -149,11 +150,10 @@ static void permute(unsigned char *dst, const unsigned char *src,
{
unsigned int i;
memset(dst, 0, len);
for (i = 0; i < len * 8; i++) {
if (GET_BIT(src, tab[i] - 1))
SET_BIT(dst, i);
else
CLEAR_BIT(dst, i);
}
}
......
......@@ -72,7 +72,7 @@ int cry_mpi_mul_comba(cry_mpi *r, const cry_mpi *a, const cry_mpi *b)
}
cry_mpi_set_used(dst, pa);
c0 = c1 = c2 = 0;
c1 = c2 = 0;
for (ix = 0; ix < pa; ix++) {
/* get offsets into the two bignums */
......
......@@ -37,9 +37,9 @@ int cry_mpi_rand_range(cry_mpi *a, const cry_mpi *max)
int n, ret;
n = cry_mpi_count_bits(max);
if ((ret = cry_mpi_rand(a, n)) != 0)
return ret;
if (cry_mpi_cmp_abs(a, max) >= 0)
ret = cry_mpi_mod(a, a, max);
return 0;
if ((ret = cry_mpi_rand(a, n)) == 0) {
if (cry_mpi_cmp_abs(a, max) >= 0)
ret = cry_mpi_mod(a, a, max);
}
return ret;
}
......@@ -21,15 +21,18 @@ int cry_prng_aes_init(const unsigned char *seed, size_t seed_siz)
unsigned char key[BLOCK_SIZ] = {0};
sz = CRY_MIN(seed_siz, BLOCK_SIZ);
memcpy(key, seed, sz);
if (seed != NULL)
memcpy(key, seed, sz);
cry_aes_key_set(&prng_ctx.aes, key, BLOCK_SIZ);
seed += sz;
if (seed != NULL)
seed += sz;
seed_siz -= sz;
sz = CRY_MIN(seed_siz, BLOCK_SIZ);
memset(prng_ctx.ctr, 0, BLOCK_SIZ);
memcpy(prng_ctx.ctr, seed, sz);
if (seed != NULL)
memcpy(prng_ctx.ctr, seed, sz);
prng_ctx.ix = 0;
init = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment