From b7d0b681e66e1ad53fd3ef27a7cf96510898fa1c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Nov 2014 15:04:15 +0100 Subject: check that the state size is a multiple of 25 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libkeccak/spec.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libkeccak/spec.h b/src/libkeccak/spec.h index be82043..ace667c 100644 --- a/src/libkeccak/spec.h +++ b/src/libkeccak/spec.h @@ -62,11 +62,17 @@ #define LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE 5 /** - * Invalue `libkeccak_spec_t` values: `.bitrate + `.capacity` + * Invalid `libkeccak_spec_t` values: `.bitrate + `.capacity` * is greater 1600 which is the largest supported state size */ #define LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE 6 +/** + * Invalid `libkeccak_spec_t` values: + * `.bitrate + `.capacity` is not a multiple of 25 + */ +#define LIBKECCAK_SPEC_ERROR_STATE_MOD_25 7 + /** @@ -144,13 +150,14 @@ void libkeccak_spec_rawshake(libkeccak_spec_t* restrict spec, long x, long d) static inline __attribute__((leaf, nonnull, nothrow, unused, warn_unused_result, pure)) int libkeccak_spec_check(libkeccak_spec_t* restrict spec) { + long state_size = spec->capacity + spec->bitrate; if (spec->bitrate <= 0) return LIBKECCAK_SPEC_ERROR_BITRATE_NONPOSITIVE; if (spec->bitrate % 8) return LIBKECCAK_SPEC_ERROR_BITRATE_MOD_8; if (spec->capacity <= 0) return LIBKECCAK_SPEC_ERROR_CAPACITY_NONPOSITIVE; if (spec->capacity % 8) return LIBKECCAK_SPEC_ERROR_CAPACITY_MOD_8; if (spec->output <= 0) return LIBKECCAK_SPEC_ERROR_OUTPUT_NONPOSITIVE; - if (spec->capacity + spec->bitrate > 1600) - return LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE; + if (state_size > 1600) return LIBKECCAK_SPEC_ERROR_STATE_TOO_LARGE; + if (state_size % 25) return LIBKECCAK_SPEC_ERROR_STATE_MOD_25; return 0; } -- cgit v1.2.3-70-g09d2