aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-07-30 18:29:05 +0200
committerMattias Andrée <maandree@kth.se>2021-07-30 18:29:05 +0200
commit8af021382087293e2205eb15642346c6fdd30a59 (patch)
tree985a3f4217a55d2e6c46192d94a9ce94cee36ab2
parentDo not divide by sizeof(char) (diff)
downloadlibkeccak-8af021382087293e2205eb15642346c6fdd30a59.tar.gz
libkeccak-8af021382087293e2205eb15642346c6fdd30a59.tar.bz2
libkeccak-8af021382087293e2205eb15642346c6fdd30a59.tar.xz
Fix clang warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--common.h11
-rw-r--r--digest.c79
-rw-r--r--libkeccak.h20
-rw-r--r--libkeccak_behex_lower.c6
-rw-r--r--libkeccak_behex_upper.c6
-rw-r--r--libkeccak_degeneralise_spec.c15
-rw-r--r--libkeccak_generalised_sum_fd.c9
-rw-r--r--libkeccak_hmac_digest.c2
-rw-r--r--libkeccak_hmac_fast_digest.c2
-rw-r--r--libkeccak_hmac_fast_update.c8
-rw-r--r--libkeccak_hmac_set_key.c6
-rw-r--r--libkeccak_hmac_unmarshal.c2
-rw-r--r--libkeccak_hmac_update.c2
-rw-r--r--libkeccak_state_initialise.c14
-rw-r--r--libkeccak_state_marshal.c7
-rw-r--r--libkeccak_state_unmarshal.c7
-rw-r--r--libkeccak_unhex.c2
-rw-r--r--test.c15
18 files changed, 152 insertions, 61 deletions
diff --git a/common.h b/common.h
index 4953da2..c573719 100644
--- a/common.h
+++ b/common.h
@@ -44,9 +44,18 @@
#ifdef NEED_EXPLICIT_BZERO
static void *(*volatile my_explicit_memset)(void *, int, size_t) = memset;
-static __attribute__((__optimize__("-O0"))) void
+
+# if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wunknown-attributes"
+# endif
+__attribute__((__optimize__("-O0")))
+static void
my_explicit_bzero(void *ptr, size_t size)
{
(*my_explicit_memset)(ptr, 0, size);
}
+# if defined(__clang__)
+# pragma clang diagnostic pop
+# endif
#endif
diff --git a/digest.c b/digest.c
index b8c56ae..902d549 100644
--- a/digest.c
+++ b/digest.c
@@ -84,7 +84,7 @@ libkeccak_f_round(register struct libkeccak_state *restrict state, register int_
/* θ step (step 1 of 3). */
#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4];
- LIST_5;
+ LIST_5
#undef X
/* θ step (step 2 of 3). */
@@ -105,7 +105,7 @@ libkeccak_f_round(register struct libkeccak_state *restrict state, register int_
/* ξ step. */
#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25]);
- LIST_25;
+ LIST_25
#undef X
/* ι step. */
@@ -130,7 +130,7 @@ libkeccak_f_round64(register struct libkeccak_state *restrict state, register in
/* θ step (step 1 of 3). */
#define X(N) C[N] = A[N * 5] ^ A[N * 5 + 1] ^ A[N * 5 + 2] ^ A[N * 5 + 3] ^ A[N * 5 + 4];
- LIST_5;
+ LIST_5
#undef X
/* θ step (step 2 of 3). */
@@ -151,7 +151,7 @@ libkeccak_f_round64(register struct libkeccak_state *restrict state, register in
/* ξ step. */
#define X(N) A[N] = B[N] ^ ((~(B[(N + 5) % 25])) & B[(N + 10) % 25]);
- LIST_25;
+ LIST_25
#undef X
/* ι step. */
@@ -225,7 +225,7 @@ libkeccak_to_lane64(register const unsigned char *restrict message, register siz
message += off;
#define X(N) if (__builtin_expect(N < n, 1)) rc |= (int_fast64_t)(unsigned char)(message[N]) << (N * 8);\
else return rc;
- LIST_8;
+ LIST_8
#undef X
return rc;
}
@@ -280,7 +280,7 @@ libkeccak_absorption_phase(register struct libkeccak_state *restrict state, regi
if (__builtin_expect(ww >= 8, 1)) { /* ww > 8 is impossible, it is just for optimisation possibilities. */
while (n--) {
#define X(N) state->S[N] ^= libkeccak_to_lane64(message, len, rr, (size_t)(LANE_TRANSPOSE_MAP[N] * 8));
- LIST_25;
+ LIST_25
#undef X
libkeccak_f(state);
message += (size_t)rr;
@@ -289,7 +289,7 @@ libkeccak_absorption_phase(register struct libkeccak_state *restrict state, regi
} else {
while (n--) {
#define X(N) state->S[N] ^= libkeccak_to_lane(message, len, rr, ww, (size_t)(LANE_TRANSPOSE_MAP[N] * ww));
- LIST_25;
+ LIST_25
#undef X
libkeccak_f(state);
message += (size_t)rr;
@@ -324,7 +324,8 @@ libkeccak_squeezing_phase(register struct libkeccak_state *restrict state, long
for (k = 0; k++ < ww && j++ < nn; v >>= 8)
*hashsum++ = (unsigned char)v;
}
- if (olen -= state->r, olen > 0)
+ olen -= state->r;
+ if (olen > 0)
libkeccak_f(state);
}
if (state->n & 7)
@@ -350,8 +351,10 @@ libkeccak_fast_update(struct libkeccak_state *restrict state, const void *restri
if (__builtin_expect(state->mptr + msglen > state->mlen, 0)) {
state->mlen += msglen;
new = realloc(state->M, state->mlen * sizeof(char));
- if (!new)
- return state->mlen -= msglen, -1;
+ if (!new) {
+ state->mlen -= msglen;
+ return -1;
+ }
state->M = new;
}
@@ -386,8 +389,10 @@ libkeccak_update(struct libkeccak_state *restrict state, const void *restrict ms
if (__builtin_expect(state->mptr + msglen > state->mlen, 0)) {
state->mlen += msglen;
new = malloc(state->mlen * sizeof(char));
- if (!new)
- return state->mlen -= msglen, -1;
+ if (!new) {
+ state->mlen -= msglen;
+ return -1;
+ }
libkeccak_state_wipe_message(state);
free(state->M);
state->M = new;
@@ -411,7 +416,7 @@ libkeccak_update(struct libkeccak_state *restrict state, const void *restrict ms
* without wiping sensitive data when possible
*
* @param state The hashing state
- * @param msg The rest of the message, may be `NULL`
+ * @param msg_ The rest of the message, may be `NULL`
* @param msglen The length of the partial message
* @param bits The number of bits at the end of the message not covered by `msglen`
* @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
@@ -429,17 +434,22 @@ libkeccak_fast_digest(struct libkeccak_state *restrict state, const void *restri
register size_t ext;
register long int i;
- if (!msg)
- msglen = bits = 0;
- else
- msglen += bits >> 3, bits &= 7;
+ if (!msg) {
+ msglen = 0;
+ bits = 0;
+ } else {
+ msglen += bits >> 3;
+ bits &= 7;
+ }
ext = msglen + ((bits + suffix_len + 7) >> 3) + (size_t)rr;
if (__builtin_expect(state->mptr + ext > state->mlen, 0)) {
state->mlen += ext;
new = realloc(state->M, state->mlen * sizeof(char));
- if (!new)
- return state->mlen -= ext, -1;
+ if (!new) {
+ state->mlen -= ext;
+ return -1;
+ }
state->M = new;
}
@@ -454,8 +464,10 @@ libkeccak_fast_digest(struct libkeccak_state *restrict state, const void *restri
state->M[state->mptr] = 0;
while (suffix_len--) {
state->M[state->mptr] |= (unsigned char)((*suffix++ & 1) << bits++);
- if (bits == 8)
- bits = 0, state->M[++(state->mptr)] = 0;
+ if (bits == 8) {
+ bits = 0;
+ state->M[++(state->mptr)] = 0;
+ }
}
}
if (bits)
@@ -480,7 +492,7 @@ libkeccak_fast_digest(struct libkeccak_state *restrict state, const void *restri
* and wipe sensitive data when possible
*
* @param state The hashing state
- * @param msg The rest of the message, may be `NULL`
+ * @param msg_ The rest of the message, may be `NULL`
* @param msglen The length of the partial message
* @param bits The number of bits at the end of the message not covered by `msglen`
* @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
@@ -498,17 +510,22 @@ libkeccak_digest(struct libkeccak_state *restrict state, const void *restrict ms
register size_t ext;
register long int i;
- if (!msg)
- msglen = bits = 0;
- else
- msglen += bits >> 3, bits &= 7;
+ if (!msg) {
+ msglen = 0;
+ bits = 0;
+ } else {
+ msglen += bits >> 3;
+ bits &= 7;
+ }
ext = msglen + ((bits + suffix_len + 7) >> 3) + (size_t)rr;
if (__builtin_expect(state->mptr + ext > state->mlen, 0)) {
state->mlen += ext;
new = malloc(state->mlen * sizeof(char));
- if (!new)
- return state->mlen -= ext, -1;
+ if (!new) {
+ state->mlen -= ext;
+ return -1;
+ }
libkeccak_state_wipe_message(state);
free(state->M);
state->M = new;
@@ -525,8 +542,10 @@ libkeccak_digest(struct libkeccak_state *restrict state, const void *restrict ms
state->M[state->mptr] = 0;
while (suffix_len--) {
state->M[state->mptr] |= (unsigned char)((*suffix++ & 1) << bits++);
- if (bits == 8)
- bits = 0, state->M[++(state->mptr)] = 0;
+ if (bits == 8) {
+ bits = 0;
+ state->M[++(state->mptr)] = 0;
+ }
}
}
if (bits)
diff --git a/libkeccak.h b/libkeccak.h
index df712d8..42c9178 100644
--- a/libkeccak.h
+++ b/libkeccak.h
@@ -9,6 +9,14 @@
#include <string.h>
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+# pragma clang diagnostic ignored "-Wunknown-attributes"
+#endif
+
+
+
/**
* Only include some C code if compiling with GCC.
*
@@ -988,9 +996,11 @@ LIBKECCAK_GCC_ONLY(__attribute__((__nonnull__, __unused__, __warn_unused_result_
static inline struct libkeccak_hmac_state *
libkeccak_hmac_duplicate(const struct libkeccak_hmac_state *restrict src)
{
- struct libkeccak_hmac_state* restrict dest = malloc(sizeof(struct libkeccak_hmac_state));
- if (!dest || libkeccak_hmac_copy(dest, src))
- return libkeccak_hmac_free(dest), NULL;
+ struct libkeccak_hmac_state *restrict dest = malloc(sizeof(struct libkeccak_hmac_state));
+ if (!dest || libkeccak_hmac_copy(dest, src)) {
+ libkeccak_hmac_free(dest);
+ return NULL;
+ }
return dest;
}
@@ -1094,4 +1104,8 @@ int libkeccak_hmac_digest(struct libkeccak_hmac_state *restrict state, const voi
#include "libkeccak-legacy.h"
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
#endif
diff --git a/libkeccak_behex_lower.c b/libkeccak_behex_lower.c
index 5098ecf..fe71e19 100644
--- a/libkeccak_behex_lower.c
+++ b/libkeccak_behex_lower.c
@@ -5,9 +5,9 @@
/**
* Convert a binary hashsum to lower case hexadecimal representation
*
- * @param output Output array, should have an allocation size of at least `2 * n + 1`
- * @param hashsum The hashsum to convert
- * @param n The size of `hashsum`
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum_ The hashsum to convert
+ * @param n The size of `hashsum`
*/
void
libkeccak_behex_lower(char *restrict output, const void *restrict hashsum_, size_t n)
diff --git a/libkeccak_behex_upper.c b/libkeccak_behex_upper.c
index b581f58..e3bae6a 100644
--- a/libkeccak_behex_upper.c
+++ b/libkeccak_behex_upper.c
@@ -5,9 +5,9 @@
/**
* Convert a binary hashsum to upper case hexadecimal representation
*
- * @param output Output array, should have an allocation size of at least `2 * n + 1`
- * @param hashsum The hashsum to convert
- * @param n The size of `hashsum`
+ * @param output Output array, should have an allocation size of at least `2 * n + 1`
+ * @param hashsum_ The hashsum to convert
+ * @param n The size of `hashsum`
*/
void
libkeccak_behex_upper(char *restrict output, const void *restrict hashsum_, size_t n)
diff --git a/libkeccak_degeneralise_spec.c b/libkeccak_degeneralise_spec.c
index ad5d415..d2c4ea5 100644
--- a/libkeccak_degeneralise_spec.c
+++ b/libkeccak_degeneralise_spec.c
@@ -2,7 +2,10 @@
#include "common.h"
-#ifdef __GNUC__
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wconditional-uninitialized"
+#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
@@ -50,8 +53,10 @@ libkeccak_degeneralise_spec(struct libkeccak_generalised_spec *restrict spec,
return LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_TOO_LARGE;
if (have_state_size && state_size != word_size * 25)
return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_WORD_INCOHERENCY;
- else if (!have_state_size)
- spec->state_size = 1, state_size = word_size * 25;
+ else if (!have_state_size) {
+ spec->state_size = 1;
+ state_size = word_size * 25;
+ }
}
if (have_capacity) {
@@ -112,6 +117,8 @@ libkeccak_degeneralise_spec(struct libkeccak_generalised_spec *restrict spec,
#undef deft
-#ifdef __GNUC__
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
diff --git a/libkeccak_generalised_sum_fd.c b/libkeccak_generalised_sum_fd.c
index 4aa7a94..bc81451 100644
--- a/libkeccak_generalised_sum_fd.c
+++ b/libkeccak_generalised_sum_fd.c
@@ -37,7 +37,16 @@ libkeccak_generalised_sum_fd(int fd, struct libkeccak_state *restrict state, con
#if ALLOCA_LIMIT > 0
if (blksize > (size_t)ALLOCA_LIMIT)
blksize = (size_t)ALLOCA_LIMIT;
+# if defined(__clang__)
+ /* We are using a limit so it's just like declaring an array
+ * in a function, except we might use less of the stack. */
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Walloca"
+# endif
chunk = alloca(blksize);
+# if defined(__clang__)
+# pragma clang diagnostic pop
+# endif
#else
chunk = malloc(blksize);
if (!chunk)
diff --git a/libkeccak_hmac_digest.c b/libkeccak_hmac_digest.c
index 76f21f6..2e1732f 100644
--- a/libkeccak_hmac_digest.c
+++ b/libkeccak_hmac_digest.c
@@ -10,7 +10,7 @@
* You may use `&state->sponge` for continued squeezing
*
* @param state The hashing state
- * @param msg The rest of the message, may be `NULL`, may be modified
+ * @param msg_ The rest of the message, may be `NULL`, may be modified
* @param msglen The length of the partial message
* @param bits The number of bits at the end of the message not covered by `msglen`
* @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
diff --git a/libkeccak_hmac_fast_digest.c b/libkeccak_hmac_fast_digest.c
index d8b4509..db242a5 100644
--- a/libkeccak_hmac_fast_digest.c
+++ b/libkeccak_hmac_fast_digest.c
@@ -9,7 +9,7 @@
* You may use `&state->sponge` for continued squeezing
*
* @param state The hashing state
- * @param msg The rest of the message, may be `NULL`, may be modified
+ * @param msg_ The rest of the message, may be `NULL`, may be modified
* @param msglen The length of the partial message
* @param bits The number of bits at the end of the message not covered by `msglen`
* @param suffix The suffix concatenate to the message, only '1':s and '0':s, and NUL-termination
diff --git a/libkeccak_hmac_fast_update.c b/libkeccak_hmac_fast_update.c
index 5a1eb70..2f541d4 100644
--- a/libkeccak_hmac_fast_update.c
+++ b/libkeccak_hmac_fast_update.c
@@ -7,7 +7,7 @@
* without wiping sensitive data when possible
*
* @param state The hashing state
- * @param msg The partial message
+ * @param msg_ The partial message
* @param msglen The length of the partial message, in bytes
* @return Zero on success, -1 on error
*/
@@ -35,8 +35,10 @@ libkeccak_hmac_fast_update(struct libkeccak_hmac_state *restrict state, const vo
if (msglen != state->buffer_size) {
state->buffer = realloc(old = state->buffer, msglen);
- if (!state->buffer)
- return state->buffer = old, -1;
+ if (!state->buffer) {
+ state->buffer = old;
+ return -1;
+ }
state->buffer_size = msglen;
}
diff --git a/libkeccak_hmac_set_key.c b/libkeccak_hmac_set_key.c
index b056439..60ef775 100644
--- a/libkeccak_hmac_set_key.c
+++ b/libkeccak_hmac_set_key.c
@@ -23,8 +23,10 @@ libkeccak_hmac_set_key(struct libkeccak_hmac_state *restrict state, const void *
if (size != key_bytes) {
state->key_opad = realloc(old = state->key_opad, 2 * size);
- if (!state->key_opad)
- return state->key_opad = old, -1;
+ if (!state->key_opad) {
+ state->key_opad = old;
+ return -1;
+ }
state->key_ipad = state->key_opad + size;
}
diff --git a/libkeccak_hmac_unmarshal.c b/libkeccak_hmac_unmarshal.c
index 2084e23..bc76275 100644
--- a/libkeccak_hmac_unmarshal.c
+++ b/libkeccak_hmac_unmarshal.c
@@ -7,7 +7,7 @@
*
* @param state The slot for the unmarshalled state, must not be
* initialised (memory leak otherwise), can be `NULL`
- * @param data The input buffer
+ * @param data_ The input buffer
* @return The number of bytes read from `data`, 0 on error
*/
size_t
diff --git a/libkeccak_hmac_update.c b/libkeccak_hmac_update.c
index 535b099..6f38348 100644
--- a/libkeccak_hmac_update.c
+++ b/libkeccak_hmac_update.c
@@ -8,7 +8,7 @@
* and wipe sensitive data when possible
*
* @param state The hashing state
- * @param msg The partial message
+ * @param msg_ The partial message
* @param msglen The length of the partial message, in bytes
* @return Zero on success, -1 on error
*/
diff --git a/libkeccak_state_initialise.c b/libkeccak_state_initialise.c
index aa77051..7644ff7 100644
--- a/libkeccak_state_initialise.c
+++ b/libkeccak_state_initialise.c
@@ -21,9 +21,17 @@ libkeccak_state_initialise(struct libkeccak_state *restrict state, const struct
state->w = x = state->b / 25;
state->l = 0;
- if (x & 0xF0L) state->l |= 4, x >>= 4;
- if (x & 0x0CL) state->l |= 2, x >>= 2;
- if (x & 0x02L) state->l |= 1;
+ if (x & 0xF0L) {
+ state->l |= 4;
+ x >>= 4;
+ }
+ if (x & 0x0CL) {
+ state->l |= 2;
+ x >>= 2;
+ }
+ if (x & 0x02L) {
+ state->l |= 1;
+ }
state->nr = 12 + (state->l << 1);
state->wmod = (state->w == 64) ? ~0LL : (int64_t)((1ULL << state->w) - 1);
diff --git a/libkeccak_state_marshal.c b/libkeccak_state_marshal.c
index 896676d..e4d2efa 100644
--- a/libkeccak_state_marshal.c
+++ b/libkeccak_state_marshal.c
@@ -2,11 +2,16 @@
#include "common.h"
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+
/**
* Marshal a `struct libkeccak_state` into a buffer
*
* @param state The state to marshal
- * @param data The output buffer, can be `NULL`
+ * @param data_ The output buffer, can be `NULL`
* @return The number of bytes stored to `data`
*/
size_t
diff --git a/libkeccak_state_unmarshal.c b/libkeccak_state_unmarshal.c
index 6922a3e..4e0df28 100644
--- a/libkeccak_state_unmarshal.c
+++ b/libkeccak_state_unmarshal.c
@@ -2,12 +2,17 @@
#include "common.h"
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
+
/**
* Unmarshal a `struct libkeccak_state` from a buffer
*
* @param state The slot for the unmarshalled state, must not be
* initialised (memory leak otherwise), can be `NULL`
- * @param data The input buffer
+ * @param data_ The input buffer
* @return The number of bytes read from `data`, 0 on error
*/
size_t
diff --git a/libkeccak_unhex.c b/libkeccak_unhex.c
index 00bb039..26a6e7d 100644
--- a/libkeccak_unhex.c
+++ b/libkeccak_unhex.c
@@ -6,7 +6,7 @@
* Convert a hexadecimal hashsum (both lower case, upper
* case and mixed is supported) to binary representation
*
- * @param output Output array, should have an allocation size of at least `strlen(hashsum) / 2`
+ * @param output_ Output array, should have an allocation size of at least `strlen(hashsum) / 2`
* @param hashsum The hashsum to convert
*/
void
diff --git a/test.c b/test.c
index 020e045..7cd5ab4 100644
--- a/test.c
+++ b/test.c
@@ -177,8 +177,10 @@ test_digest_case(const struct libkeccak_spec *restrict spec, const char *restric
return -1;
}
- if (libkeccak_digest(&state, msg, strlen(msg) - !!bits, (size_t)bits, suffix, hashsum))
- return perror("libkeccak_digest"), -1;
+ if (libkeccak_digest(&state, msg, strlen(msg) - !!bits, (size_t)bits, suffix, hashsum)) {
+ perror("libkeccak_digest");
+ return -1;
+ }
libkeccak_state_fast_destroy(&state);
libkeccak_behex_lower(hexsum, hashsum, (size_t)((spec->output + 7) / 8));
@@ -649,6 +651,11 @@ test_squeeze(void)
return -1;
}
+# if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcomma"
+# endif
+
printf("Testing squeeze functions with slow initial digest:\n");
printf(" 1 extra squeeze, including 0 fast squeezes: "), run_test(0, 1, 0);
printf(" 2 extra squeezes, including 0 fast squeezes: "), run_test(0, 2, 0);
@@ -675,6 +682,10 @@ test_squeeze(void)
printf(" 4 extra squeezes, including 3 fast squeezes: "), run_test(3, 4, 1);
printf("\n");
+# if defined(__clang__)
+# pragma clang diagnostic pop
+# endif
+
libkeccak_state_fast_destroy(&state);
free(hashsum);
free(hexsum);