diff options
-rw-r--r-- | common.h | 11 | ||||
-rw-r--r-- | digest.c | 79 | ||||
-rw-r--r-- | libkeccak.h | 30 | ||||
-rw-r--r-- | libkeccak_behex_lower.c | 6 | ||||
-rw-r--r-- | libkeccak_behex_upper.c | 6 | ||||
-rw-r--r-- | libkeccak_degeneralise_spec.c | 15 | ||||
-rw-r--r-- | libkeccak_generalised_sum_fd.c | 9 | ||||
-rw-r--r-- | libkeccak_hmac_copy.c | 2 | ||||
-rw-r--r-- | libkeccak_hmac_digest.c | 2 | ||||
-rw-r--r-- | libkeccak_hmac_fast_digest.c | 2 | ||||
-rw-r--r-- | libkeccak_hmac_fast_update.c | 8 | ||||
-rw-r--r-- | libkeccak_hmac_set_key.c | 10 | ||||
-rw-r--r-- | libkeccak_hmac_unmarshal.c | 12 | ||||
-rw-r--r-- | libkeccak_hmac_update.c | 2 | ||||
-rw-r--r-- | libkeccak_state_initialise.c | 14 | ||||
-rw-r--r-- | libkeccak_state_marshal.c | 11 | ||||
-rw-r--r-- | libkeccak_state_unmarshal.c | 13 | ||||
-rw-r--r-- | libkeccak_unhex.c | 2 | ||||
-rw-r--r-- | test.c | 15 |
19 files changed, 170 insertions, 79 deletions
@@ -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 @@ -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 d830ed8..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. * @@ -808,7 +816,7 @@ struct libkeccak_hmac_state { */ unsigned char leftover; - char __pad[sizeof(void *) / sizeof(char) - 1]; + char __pad[sizeof(void *) - 1]; }; @@ -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; } @@ -1006,13 +1016,13 @@ static inline size_t libkeccak_hmac_marshal(const struct libkeccak_hmac_state *restrict state, void *restrict data_) { unsigned char *restrict data = data_; - size_t written = libkeccak_state_marshal(state ? &state->sponge : NULL, data); + size_t written = libkeccak_state_marshal(&state->sponge, data); if (data) { - data += written / sizeof(char); + data += written; *(size_t *)data = state->key_length; - data += sizeof(size_t) / sizeof(char); + data += sizeof(size_t); memcpy(data, state->key_opad, (state->key_length + 7) >> 3); - data += ((state->key_length + 7) >> 3) / sizeof(char); + data += (state->key_length + 7) >> 3; data[0] = (unsigned char)!!state->key_ipad; data[1] = state->leftover; } @@ -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_copy.c b/libkeccak_hmac_copy.c index 9c52328..6c61553 100644 --- a/libkeccak_hmac_copy.c +++ b/libkeccak_hmac_copy.c @@ -29,7 +29,7 @@ libkeccak_hmac_copy(struct libkeccak_hmac_state *restrict dest, const struct lib libkeccak_state_destroy(&dest->sponge); return -1; } - dest->key_ipad = dest->key_opad + size / sizeof(char); + dest->key_ipad = dest->key_opad + size; memcpy(dest->key_opad, src->key_opad, size); memcpy(dest->key_ipad, src->key_ipad, size); 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 f8f6a39..60ef775 100644 --- a/libkeccak_hmac_set_key.c +++ b/libkeccak_hmac_set_key.c @@ -23,9 +23,11 @@ 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; - state->key_ipad = state->key_opad + size / sizeof(char); + if (!state->key_opad) { + state->key_opad = old; + return -1; + } + state->key_ipad = state->key_opad + size; } memcpy(state->key_opad, key, key_bytes); @@ -33,7 +35,7 @@ libkeccak_hmac_set_key(struct libkeccak_hmac_state *restrict state, const void * state->key_opad[(key_bytes >> 3) - 1] &= (unsigned char)((1 << (key_length & 7)) - 1); if ((size_t)(state->sponge.r) > key_length) - __builtin_memset(state->key_opad + key_bytes / sizeof(char), 0, size - key_bytes); + __builtin_memset(state->key_opad + key_bytes, 0, size - key_bytes); for (i = 0; i < size; i++) { state->key_ipad[i] = state->key_opad[i] ^ HMAC_INNER_PAD; diff --git a/libkeccak_hmac_unmarshal.c b/libkeccak_hmac_unmarshal.c index 452efa3..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 @@ -22,10 +22,10 @@ libkeccak_hmac_unmarshal(struct libkeccak_hmac_state *restrict state, const void parsed = libkeccak_state_unmarshal(state ? &state->sponge : NULL, data); if (!parsed) return 0; - data += parsed / sizeof(char); + data += parsed; size = *(const size_t *)data; - data += sizeof(size_t) / sizeof(char); + data += sizeof(size_t); if (state) size = state->key_length; size = (state->key_length + 7) >> 3; @@ -37,12 +37,12 @@ libkeccak_hmac_unmarshal(struct libkeccak_hmac_state *restrict state, const void return 0; } memcpy(state->key_opad, data, size); - data += size / sizeof(char); + data += size; if (data[0]) { - state->key_ipad = state->key_opad + size / sizeof(char); + state->key_ipad = state->key_opad + size; memcpy(state->key_ipad, state->key_opad, size); - for (i = 0; i < size / sizeof(char); i++) + for (i = 0; i < size; i++) state->key_ipad[i] ^= (char)(HMAC_OUTER_PAD ^ HMAC_INNER_PAD); } 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 c4ce7f6..e4d2efa 100644 --- a/libkeccak_state_marshal.c +++ b/libkeccak_state_marshal.c @@ -2,17 +2,22 @@ #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 libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *restrict data_) { -#define set(type, var) *((type *)data) = state->var, data += sizeof(type) / sizeof(char) +#define set(type, var) *((type *)data) = state->var, data += sizeof(type) unsigned char *restrict data = data_; if (data) { set(long int, r); @@ -24,7 +29,7 @@ libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *rest set(long int, l); set(long int, nr); memcpy(data, state->S, sizeof(state->S)); - data += sizeof(state->S) / sizeof(char); + data += sizeof(state->S); set(size_t, mptr); set(size_t, mlen); memcpy(data, state->M, state->mptr * sizeof(char)); diff --git a/libkeccak_state_unmarshal.c b/libkeccak_state_unmarshal.c index e46db54..4e0df28 100644 --- a/libkeccak_state_unmarshal.c +++ b/libkeccak_state_unmarshal.c @@ -2,21 +2,26 @@ #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 libkeccak_state_unmarshal(struct libkeccak_state *restrict state, const void *restrict data_) { -#define get(type, var) state->var = *((const type *)data), data += sizeof(type) / sizeof(char) +#define get(type, var) state->var = *((const type *)data), data += sizeof(type) const unsigned char *restrict data = data_; if (!state) { - data += (7 * sizeof(long int) + 26 * sizeof(int64_t)) / sizeof(char); + data += (7 * sizeof(long int) + 26 * sizeof(int64_t)); return sizeof(struct libkeccak_state) - sizeof(char *) + *(const size_t *)data * sizeof(char); } get(long int, r); @@ -28,7 +33,7 @@ libkeccak_state_unmarshal(struct libkeccak_state *restrict state, const void *re get(long int, l); get(long int, nr); memcpy(state->S, data, sizeof(state->S)); - data += sizeof(state->S) / sizeof(char); + data += sizeof(state->S); get(size_t, mptr); get(size_t, mlen); state->M = malloc(state->mptr * sizeof(char)); 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 @@ -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); |