From c86235085b3cc74cebcf0f634a52382a8299ca7f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Nov 2014 14:42:06 +0100 Subject: specs for sha3, rawshake and shake 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 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/libkeccak/spec.h b/src/libkeccak/spec.h index fe6ce98..0d1dd98 100644 --- a/src/libkeccak/spec.h +++ b/src/libkeccak/spec.h @@ -21,7 +21,24 @@ /** - * This datastructure describes the parameters + * Message suffix for SHA3 hashing + */ +#define LIBKECCAK_SHA3_SUFFIX "01" + +/** + * Message suffix for RawSHAKE hashing + */ +#define LIBKECCAK_RAWSHAKE_SUFFIX "11" + +/** + * Message suffix for SHAKE hashing + */ +#define LIBKECCAK_SHAKE_SUFFIX "1111" + + + +/** + * Datastructure that describes the parameters * that should be used when hashing */ typedef struct libkeccak_spec @@ -44,5 +61,47 @@ typedef struct libkeccak_spec } libkeccak_spec_t; + +/** + * Fill in a `libkeccak_spec_t` for a SHA3-x hashing + * + * @param spec The specifications datastructure to fill in + * @param x The value of x in `SHA3-x`, the output size + */ +static inline __attribute__((leaf, nonnull, nothrow)) +void libkeccak_spec_sha3(libkeccak_spec_t* restrict spec, long x) +{ + spec->bitrate = 1600 - 2 * x; + spec->capacity = 2 * x; + spec->output = x; +} + + +/** + * Fill in a `libkeccak_spec_t` for a RawSHAKEx hashing + * + * @param spec The specifications datastructure to fill in + * @param x The value of x in `RawSHAKEx`, half the capacity + * @param d The output size + */ +static inline __attribute__((leaf, nonnull, nothrow)) +void libkeccak_spec_rawshake(libkeccak_spec_t* restrict spec, long x, long d) +{ + spec->bitrate = 1600 - 2 * x; + spec->capacity = 2 * x; + spec->output = d; +} + + +/** + * Fill in a `libkeccak_spec_t` for a SHAKEx hashing + * + * @param spec:libkeccak_spec_t* The specifications datastructure to fill in + * @param x:long The value of x in `SHAKEx`, half the capacity + * @param d:long The output size + */ +#define libkeccak_spec_shake libkeccak_spec_rawshake + + #undef -- cgit v1.2.3-70-g09d2