aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libkeccak/digest.c63
-rw-r--r--src/libkeccak/files.c2
-rw-r--r--src/libkeccak/generalised-spec.c2
-rw-r--r--src/libkeccak/hex.c23
-rw-r--r--src/libkeccak/state.c8
-rw-r--r--src/libkeccak/state.h3
6 files changed, 46 insertions, 55 deletions
diff --git a/src/libkeccak/digest.c b/src/libkeccak/digest.c
index 67301a6..a1f3d54 100644
--- a/src/libkeccak/digest.c
+++ b/src/libkeccak/digest.c
@@ -51,14 +51,14 @@ static const long LANE_TRANSPOSE_MAP[] = { LIST_25 };
/**
* Keccak-f round constants
*/
-static const int_fast64_t RC[] =
+static const uint_fast64_t RC[] =
{
- 0x0000000000000001LL, 0x0000000000008082LL, 0x800000000000808ALL, 0x8000000080008000LL,
- 0x000000000000808BLL, 0x0000000080000001LL, 0x8000000080008081LL, 0x8000000000008009LL,
- 0x000000000000008ALL, 0x0000000000000088LL, 0x0000000080008009LL, 0x000000008000000ALL,
- 0x000000008000808BLL, 0x800000000000008BLL, 0x8000000000008089LL, 0x8000000000008003LL,
- 0x8000000000008002LL, 0x8000000000000080LL, 0x000000000000800ALL, 0x800000008000000ALL,
- 0x8000000080008081LL, 0x8000000000008080LL, 0x0000000080000001LL, 0x8000000080008008LL
+ 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808AULL, 0x8000000080008000ULL,
+ 0x000000000000808BULL, 0x0000000080000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL,
+ 0x000000000000008AULL, 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000AULL,
+ 0x000000008000808BULL, 0x800000000000008BULL, 0x8000000000008089ULL, 0x8000000000008003ULL,
+ 0x8000000000008002ULL, 0x8000000000000080ULL, 0x000000000000800AULL, 0x800000008000000AULL,
+ 0x8000000080008081ULL, 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
};
@@ -184,13 +184,13 @@ void libkeccak_f(libkeccak_state_t* restrict state)
long i = 0, nr = state->nr;
if (nr == 24)
{
-#define X(N) libkeccak_f_round64(state, RC[N]);
+#define X(N) libkeccak_f_round64(state, (int_fast64_t)(RC[N]));
LIST_24
#undef X
}
else
for (; nr--; i++)
- libkeccak_f_round(state, RC[i] & state->wmod);
+ libkeccak_f_round(state, (int_fast64_t)(RC[i]) & state->wmod);
}
@@ -250,13 +250,13 @@ int_fast64_t libkeccak_to_lane64(const char* restrict message, size_t msglen, lo
* @param bits The number of bits in the end of the message that does not make a whole byte
*/
static __attribute__((nonnull, nothrow))
-void libkeccak_pad10star1(libkeccak_state_t* restrict state, long bits)
+void libkeccak_pad10star1(libkeccak_state_t* restrict state, size_t bits)
{
- long i, r = state->r;
- long nrf = state->mptr - !!bits;
- long len = (nrf << 3) | bits;
- long ll = len % r;
- char b = bits ? (state->M[nrf] | (1 << bits)) : 1;
+ size_t r = (size_t)(state->r);
+ size_t nrf = state->mptr - !!bits;
+ size_t len = (nrf << 3) | bits;
+ size_t ll = len % r;
+ char b = (char)(bits ? (state->M[nrf] | (1 << bits)) : 1);
if ((r - 8 <= ll) && (ll <= r - 2))
{
@@ -271,7 +271,7 @@ void libkeccak_pad10star1(libkeccak_state_t* restrict state, long bits)
state->M[nrf] = b;
__builtin_memset(state->M + nrf, 0, (len - nrf) * sizeof(char));
- state->M[len] = 0x80;
+ state->M[len] = (char)0x80;
}
}
@@ -285,28 +285,28 @@ void libkeccak_pad10star1(libkeccak_state_t* restrict state, long bits)
static __attribute__((nonnull, nothrow))
void libkeccak_absorption_phase(libkeccak_state_t* restrict state, size_t len)
{
- long w = state->w, rr = state->r >> 3, ww = state->w >> 3;
- long i = len / rr;
+ long rr = state->r >> 3, ww = state->w >> 3;
+ long i = (long)len / rr;
const char* restrict message = state->M;
if (__builtin_expect(ww >= 8, 1)) /* ww > 8 is impossible, it is just for optimisation possibilities. */
while (i--)
{
-#define X(N) state->S[N] ^= libkeccak_to_lane64(message, len, rr, LANE_TRANSPOSE_MAP[N] * 8);
+#define X(N) state->S[N] ^= libkeccak_to_lane64(message, len, rr, (size_t)(LANE_TRANSPOSE_MAP[N] * 8));
LIST_25
#undef X
libkeccak_f(state);
- message += rr;
- len -= rr;
+ message += (size_t)rr;
+ len -= (size_t)rr;
}
else
while (i--)
{
-#define X(N) state->S[N] ^= libkeccak_to_lane(message, len, rr, ww, LANE_TRANSPOSE_MAP[N] * ww);
+#define X(N) state->S[N] ^= libkeccak_to_lane(message, len, rr, ww, (size_t)(LANE_TRANSPOSE_MAP[N] * ww));
LIST_25
#undef X
libkeccak_f(state);
- message += rr;
- len -= rr;
+ message += (size_t)rr;
+ len -= (size_t)rr;
}
}
@@ -338,7 +338,7 @@ void libkeccak_squeezing_phase(libkeccak_state_t* restrict state,
libkeccak_f(state);
}
if (state->n & 7)
- hashsum[nn - 1] &= (1 << (state->n & 7)) - 1;
+ hashsum[nn - 1] &= (char)((1 << (state->n & 7)) - 1);
}
@@ -366,7 +366,7 @@ int libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg
__builtin_memcpy(state->M + state->mptr, msg, msglen * sizeof(char));
state->mptr += msglen;
len = state->mptr;
- len -= state->mptr % ((state->r * state->b) >> 3);
+ len -= state->mptr % (size_t)((state->r * state->b) >> 3);
state->mptr -= len;
libkeccak_absorption_phase(state, len);
@@ -390,11 +390,10 @@ int libkeccak_update(libkeccak_state_t* restrict state, const char* restrict msg
int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size_t msglen,
size_t bits, const char* restrict suffix, char* restrict hashsum)
{
- long len, ni, i, j = 0, k, ptr = 0, ext;
- long rr = state->r >> 3;
+ long rr = state->r >> 3, i;
long ww = state->w >> 3;
long nn = (state->n + 7) >> 3;
- long suffix_len = suffix ? __builtin_strlen(suffix) : 0;
+ size_t ext, suffix_len = suffix ? __builtin_strlen(suffix) : 0;
const char* restrict message = msg;
char* restrict new;
@@ -404,10 +403,10 @@ int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size
{
msglen += bits >> 3;
if ((bits &= 7))
- msg[msglen] &= (1 << bits) - 1;
+ msg[msglen] &= (char)((1 << bits) - 1);
}
- ext = msglen + ((bits + suffix_len + 7) >> 3) + (state->r >> 3);
+ ext = msglen + ((bits + suffix_len + 7) >> 3) + (size_t)rr;
if (state->mptr + ext > state->mlen)
{
state->mlen += ext;
@@ -425,7 +424,7 @@ int libkeccak_digest(libkeccak_state_t* restrict state, char* restrict msg, size
state->M[msglen] = 0;
while (suffix_len--)
{
- state->M[msglen] |= (*suffix++ & 1) << bits++;
+ state->M[msglen] |= (char)((*suffix++ & 1) << bits++);
if (bits == 8)
bits = 0, state->M[++msglen] = 0;
}
diff --git a/src/libkeccak/files.c b/src/libkeccak/files.c
index 5374620..e5b0c11 100644
--- a/src/libkeccak/files.c
+++ b/src/libkeccak/files.c
@@ -50,7 +50,7 @@ int libkeccak_generalised_sum_fd(int fd, libkeccak_state_t* restrict state,
if (fstat(fd, &attr) == 0)
if (attr.st_blksize > 0)
- blksize = attr.st_blksize;
+ blksize = (size_t)(attr.st_blksize);
chunk = alloca(blksize);
diff --git a/src/libkeccak/generalised-spec.c b/src/libkeccak/generalised-spec.c
index d3e0b0f..7bab1fc 100644
--- a/src/libkeccak/generalised-spec.c
+++ b/src/libkeccak/generalised-spec.c
@@ -20,7 +20,7 @@
#define have(v) (spec->v != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC)
-#define copy(v) (spec->v = v)
+#define copy(v) (v = spec->v)
#define deft(v, dv) (have(v) ? v : (dv))
diff --git a/src/libkeccak/hex.c b/src/libkeccak/hex.c
index 866cc8e..64afef8 100644
--- a/src/libkeccak/hex.c
+++ b/src/libkeccak/hex.c
@@ -34,10 +34,8 @@ void libkeccak_behex_lower(char* restrict output, const char* restrict hashsum,
output[2 * n] = '\0';
while (n--)
{
- char a = (hashsum[n] >> 4) & 255;
- char b = (hashsum[n] >> 0) & 255;
- output[2 * n + 0] = "0123456789abcdef"[a];
- output[2 * n + 1] = "0123456789abcdef"[b];
+ output[2 * n + 0] = "0123456789abcdef"[(hashsum[n] >> 4) & 15];
+ output[2 * n + 1] = "0123456789abcdef"[(hashsum[n] >> 0) & 15];
}
}
@@ -54,10 +52,8 @@ void libkeccak_behex_upper(char* restrict output, const char* restrict hashsum,
output[2 * n] = '\0';
while (n--)
{
- char a = (hashsum[n] >> 4) & 255;
- char b = (hashsum[n] >> 0) & 255;
- output[2 * n + 0] = "0123456789ABCDEF"[a];
- output[2 * n + 1] = "0123456789ABCDEF"[b];
+ output[2 * n + 0] = "0123456789ABCDEF"[(hashsum[n] >> 4) & 15];
+ output[2 * n + 1] = "0123456789ABCDEF"[(hashsum[n] >> 0) & 15];
}
}
@@ -77,15 +73,10 @@ void libkeccak_unhex(char* restrict output, const char* restrict hashsum)
char a = hashsum[2 * n + 0];
char b = hashsum[2 * n + 1];
- if (a >= 'a') a -= 'a' - 9;
- else if (a >= 'A') a -= 'A' - 9;
- else a -= '0';
+ a = (char)((a & 15) + (a > '9' ? 9 : 0));
+ b = (char)((b & 15) + (b > '9' ? 9 : 0));
- if (b >= 'a') b -= 'a' - 9;
- else if (b >= 'A') b -= 'A' - 9;
- else b -= '0';
-
- output[n] *= (a << 4) | b;
+ output[n] = (char)((a << 4) | b);
}
}
diff --git a/src/libkeccak/state.c b/src/libkeccak/state.c
index 532a33c..a4178be 100644
--- a/src/libkeccak/state.c
+++ b/src/libkeccak/state.c
@@ -46,7 +46,7 @@ int libkeccak_state_initialise(libkeccak_state_t* restrict state, const libkecca
for (x = 0; x < 25; x++)
state->S[x] = 0;
state->mptr = 0;
- state->mlen = (state->r * state->b) >> 2;
+ state->mlen = (size_t)(state->r * state->b) >> 2;
state->M = malloc(state->mlen * sizeof(char));
return state->M == NULL ? -1 : 0;
}
@@ -100,7 +100,6 @@ int libkeccak_state_copy(libkeccak_state_t* restrict dest, const libkeccak_state
size_t libkeccak_state_marshal(const libkeccak_state_t* restrict state, char* restrict data)
{
#define set(type, var) *((type*)data) = state->var, data += sizeof(type) / sizeof(char)
- size_t i;
set(long, r);
set(long, c);
set(long, n);
@@ -129,8 +128,7 @@ size_t libkeccak_state_marshal(const libkeccak_state_t* restrict state, char* re
*/
size_t libkeccak_state_unmarshal(libkeccak_state_t* restrict state, const char* restrict data)
{
-#define get(type, var) state->var = *((type*)data), data += sizeof(type) / sizeof(char)
- size_t i;
+#define get(type, var) state->var = *((const type*)data), data += sizeof(type) / sizeof(char)
get(long, r);
get(long, c);
get(long, n);
@@ -163,6 +161,6 @@ size_t libkeccak_state_unmarshal(libkeccak_state_t* restrict state, const char*
size_t libkeccak_state_unmarshal_skip(const char* restrict data)
{
data += (7 * sizeof(long) + 26 * sizeof(int_fast64_t)) / sizeof(char);
- return sizeof(libkeccak_state_t) - sizeof(char*) + *(size_t*)data * sizeof(char);
+ return sizeof(libkeccak_state_t) - sizeof(char*) + *(const size_t*)data * sizeof(char);
}
diff --git a/src/libkeccak/state.h b/src/libkeccak/state.h
index 7ee0152..7f4f3b6 100644
--- a/src/libkeccak/state.h
+++ b/src/libkeccak/state.h
@@ -190,8 +190,11 @@ void libkeccak_state_fast_free(libkeccak_state_t* restrict state)
static inline __attribute__((unused, optimize("-O0")))
void libkeccak_state_free(volatile libkeccak_state_t* restrict state)
{
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-qual"
libkeccak_state_destroy(state);
free((libkeccak_state_t*)state);
+# pragma GCC diagnostic pop
}