diff --git a/src/GENERATED/include/decaf/shake.h b/src/GENERATED/include/decaf/shake.h index 3fb13c7..ae125b9 100644 --- a/src/GENERATED/include/decaf/shake.h +++ b/src/GENERATED/include/decaf/shake.h @@ -43,7 +43,7 @@ extern "C" { * @param [out] sponge The object to initialize. * @param [in] params The sponge's parameter description. */ -void decaf_sponge_init ( +void decaf_sha3_init ( decaf_keccak_sponge_t sponge, const struct decaf_kparams_s *params ) DECAF_API_VIS; @@ -108,7 +108,7 @@ void decaf_sha3_reset ( * * Returns n/8 for DECAF_SHA3-n and 2n/8 for DECAF_SHAKE-n. */ -size_t decaf_sponge_default_output_bytes ( +size_t decaf_sha3_default_output_bytes ( const decaf_keccak_sponge_t sponge /**< [inout] The context. */ ) DECAF_API_VIS; @@ -118,7 +118,7 @@ size_t decaf_sponge_default_output_bytes ( * * Returns n/8 for DECAF_SHA3-n and SIZE_MAX for DECAF_SHAKE-n. */ -size_t decaf_sponge_max_output_bytes ( +size_t decaf_sha3_max_output_bytes ( const decaf_keccak_sponge_t sponge /**< [inout] The context. */ ) DECAF_API_VIS; @@ -126,7 +126,7 @@ size_t decaf_sponge_max_output_bytes ( * @brief Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0. * @param [out] sponge The context. */ -void decaf_sponge_destroy ( +void decaf_sha3_destroy ( decaf_keccak_sponge_t sponge ) DECAF_API_VIS; @@ -138,11 +138,11 @@ void decaf_sponge_destroy ( * @param [in] outlen The length of the output data. * @param [in] params The parameters of the sponge hash. */ -decaf_error_t decaf_sponge_hash ( - const uint8_t *in, - size_t inlen, +decaf_error_t decaf_sha3_hash ( uint8_t *out, size_t outlen, + const uint8_t *in, + size_t inlen, const struct decaf_kparams_s *params ) DECAF_API_VIS; @@ -153,53 +153,53 @@ decaf_error_t decaf_sponge_hash ( extern const struct decaf_kparams_s DECAF_SHAKE##n##_params_s DECAF_API_VIS; \ typedef struct decaf_shake##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_shake##n##_ctx_t[1]; \ static inline void DECAF_NONNULL decaf_shake##n##_init(decaf_shake##n##_ctx_t sponge) { \ - decaf_sponge_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_gen_init(decaf_keccak_sponge_t sponge) { \ - decaf_sponge_init(sponge, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge, &DECAF_SHAKE##n##_params_s); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_shake##n##_update(decaf_shake##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \ return decaf_sha3_update(sponge->s, in, inlen); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_final(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_sha3_output(sponge->s, out, outlen); \ - decaf_sponge_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_output(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_sha3_output(sponge->s, out, outlen); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \ - decaf_sponge_hash(in,inlen,out,outlen,&DECAF_SHAKE##n##_params_s); \ + decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_destroy( decaf_shake##n##_ctx_t sponge ) { \ - decaf_sponge_destroy(sponge->s); \ + decaf_sha3_destroy(sponge->s); \ } #define DECAF_DEC_SHA3(n) \ extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s DECAF_API_VIS; \ typedef struct decaf_sha3_##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_sha3_##n##_ctx_t[1]; \ static inline void DECAF_NONNULL decaf_sha3_##n##_init(decaf_sha3_##n##_ctx_t sponge) { \ - decaf_sponge_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_sha3_##n##_gen_init(decaf_keccak_sponge_t sponge) { \ - decaf_sponge_init(sponge, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge, &DECAF_SHA3_##n##_params_s); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_update(decaf_sha3_##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \ return decaf_sha3_update(sponge->s, in, inlen); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_final(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_error_t ret = decaf_sha3_output(sponge->s, out, outlen); \ - decaf_sponge_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ return ret; \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_output(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ return decaf_sha3_output(sponge->s, out, outlen); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \ - return decaf_sponge_hash(in,inlen,out,outlen,&DECAF_SHA3_##n##_params_s); \ + return decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHA3_##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_sha3_##n##_destroy(decaf_sha3_##n##_ctx_t sponge) { \ - decaf_sponge_destroy(sponge->s); \ + decaf_sha3_destroy(sponge->s); \ } /** @endcond */ diff --git a/src/GENERATED/include/decaf/shake.hxx b/src/GENERATED/include/decaf/shake.hxx index bb8b3e8..58e360b 100644 --- a/src/GENERATED/include/decaf/shake.hxx +++ b/src/GENERATED/include/decaf/shake.hxx @@ -38,7 +38,7 @@ protected: decaf_keccak_sponge_t wrapped; /** Initialize from parameters */ - inline KeccakHash(const decaf_kparams_s *params) DECAF_NOEXCEPT { decaf_sponge_init(wrapped, params); } + inline KeccakHash(const decaf_kparams_s *params) DECAF_NOEXCEPT { decaf_sha3_init(wrapped, params); } /** @endcond */ public: @@ -94,12 +94,12 @@ public: /** @brief Return the sponge's default output size. */ inline size_t default_output_size() const DECAF_NOEXCEPT { - return decaf_sponge_default_output_bytes(wrapped); + return decaf_sha3_default_output_bytes(wrapped); } /** @brief Return the sponge's maximum output size. */ inline size_t max_output_size() const DECAF_NOEXCEPT { - return decaf_sponge_max_output_bytes(wrapped); + return decaf_sha3_max_output_bytes(wrapped); } /** Output the default number of bytes. */ @@ -116,7 +116,7 @@ public: inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } /** Destructor zeroizes state */ - inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sponge_destroy(wrapped); } + inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sha3_destroy(wrapped); } }; /** Fixed-output-length SHA3 */ diff --git a/src/GENERATED/include/decaf/spongerng.h b/src/GENERATED/include/decaf/spongerng.h index f03b7eb..eaad167 100644 --- a/src/GENERATED/include/decaf/spongerng.h +++ b/src/GENERATED/include/decaf/spongerng.h @@ -82,7 +82,7 @@ decaf_spongerng_destroy ( /* Implementations of inline functions */ /***************************************/ void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { - decaf_sponge_destroy(doomed->sponge); + decaf_sha3_destroy(doomed->sponge); } /** @endcond */ /* internal */ diff --git a/src/public_include/decaf/shake.h b/src/public_include/decaf/shake.h index 3fb13c7..ae125b9 100644 --- a/src/public_include/decaf/shake.h +++ b/src/public_include/decaf/shake.h @@ -43,7 +43,7 @@ extern "C" { * @param [out] sponge The object to initialize. * @param [in] params The sponge's parameter description. */ -void decaf_sponge_init ( +void decaf_sha3_init ( decaf_keccak_sponge_t sponge, const struct decaf_kparams_s *params ) DECAF_API_VIS; @@ -108,7 +108,7 @@ void decaf_sha3_reset ( * * Returns n/8 for DECAF_SHA3-n and 2n/8 for DECAF_SHAKE-n. */ -size_t decaf_sponge_default_output_bytes ( +size_t decaf_sha3_default_output_bytes ( const decaf_keccak_sponge_t sponge /**< [inout] The context. */ ) DECAF_API_VIS; @@ -118,7 +118,7 @@ size_t decaf_sponge_default_output_bytes ( * * Returns n/8 for DECAF_SHA3-n and SIZE_MAX for DECAF_SHAKE-n. */ -size_t decaf_sponge_max_output_bytes ( +size_t decaf_sha3_max_output_bytes ( const decaf_keccak_sponge_t sponge /**< [inout] The context. */ ) DECAF_API_VIS; @@ -126,7 +126,7 @@ size_t decaf_sponge_max_output_bytes ( * @brief Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0. * @param [out] sponge The context. */ -void decaf_sponge_destroy ( +void decaf_sha3_destroy ( decaf_keccak_sponge_t sponge ) DECAF_API_VIS; @@ -138,11 +138,11 @@ void decaf_sponge_destroy ( * @param [in] outlen The length of the output data. * @param [in] params The parameters of the sponge hash. */ -decaf_error_t decaf_sponge_hash ( - const uint8_t *in, - size_t inlen, +decaf_error_t decaf_sha3_hash ( uint8_t *out, size_t outlen, + const uint8_t *in, + size_t inlen, const struct decaf_kparams_s *params ) DECAF_API_VIS; @@ -153,53 +153,53 @@ decaf_error_t decaf_sponge_hash ( extern const struct decaf_kparams_s DECAF_SHAKE##n##_params_s DECAF_API_VIS; \ typedef struct decaf_shake##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_shake##n##_ctx_t[1]; \ static inline void DECAF_NONNULL decaf_shake##n##_init(decaf_shake##n##_ctx_t sponge) { \ - decaf_sponge_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_gen_init(decaf_keccak_sponge_t sponge) { \ - decaf_sponge_init(sponge, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge, &DECAF_SHAKE##n##_params_s); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_shake##n##_update(decaf_shake##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \ return decaf_sha3_update(sponge->s, in, inlen); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_final(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_sha3_output(sponge->s, out, outlen); \ - decaf_sponge_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_output(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_sha3_output(sponge->s, out, outlen); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \ - decaf_sponge_hash(in,inlen,out,outlen,&DECAF_SHAKE##n##_params_s); \ + decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHAKE##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_shake##n##_destroy( decaf_shake##n##_ctx_t sponge ) { \ - decaf_sponge_destroy(sponge->s); \ + decaf_sha3_destroy(sponge->s); \ } #define DECAF_DEC_SHA3(n) \ extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s DECAF_API_VIS; \ typedef struct decaf_sha3_##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_sha3_##n##_ctx_t[1]; \ static inline void DECAF_NONNULL decaf_sha3_##n##_init(decaf_sha3_##n##_ctx_t sponge) { \ - decaf_sponge_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_sha3_##n##_gen_init(decaf_keccak_sponge_t sponge) { \ - decaf_sponge_init(sponge, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge, &DECAF_SHA3_##n##_params_s); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_update(decaf_sha3_##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \ return decaf_sha3_update(sponge->s, in, inlen); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_final(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ decaf_error_t ret = decaf_sha3_output(sponge->s, out, outlen); \ - decaf_sponge_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ + decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \ return ret; \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_output(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \ return decaf_sha3_output(sponge->s, out, outlen); \ } \ static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \ - return decaf_sponge_hash(in,inlen,out,outlen,&DECAF_SHA3_##n##_params_s); \ + return decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHA3_##n##_params_s); \ } \ static inline void DECAF_NONNULL decaf_sha3_##n##_destroy(decaf_sha3_##n##_ctx_t sponge) { \ - decaf_sponge_destroy(sponge->s); \ + decaf_sha3_destroy(sponge->s); \ } /** @endcond */ diff --git a/src/public_include/decaf/shake.hxx b/src/public_include/decaf/shake.hxx index bb8b3e8..58e360b 100644 --- a/src/public_include/decaf/shake.hxx +++ b/src/public_include/decaf/shake.hxx @@ -38,7 +38,7 @@ protected: decaf_keccak_sponge_t wrapped; /** Initialize from parameters */ - inline KeccakHash(const decaf_kparams_s *params) DECAF_NOEXCEPT { decaf_sponge_init(wrapped, params); } + inline KeccakHash(const decaf_kparams_s *params) DECAF_NOEXCEPT { decaf_sha3_init(wrapped, params); } /** @endcond */ public: @@ -94,12 +94,12 @@ public: /** @brief Return the sponge's default output size. */ inline size_t default_output_size() const DECAF_NOEXCEPT { - return decaf_sponge_default_output_bytes(wrapped); + return decaf_sha3_default_output_bytes(wrapped); } /** @brief Return the sponge's maximum output size. */ inline size_t max_output_size() const DECAF_NOEXCEPT { - return decaf_sponge_max_output_bytes(wrapped); + return decaf_sha3_max_output_bytes(wrapped); } /** Output the default number of bytes. */ @@ -116,7 +116,7 @@ public: inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } /** Destructor zeroizes state */ - inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sponge_destroy(wrapped); } + inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sha3_destroy(wrapped); } }; /** Fixed-output-length SHA3 */ diff --git a/src/public_include/decaf/spongerng.h b/src/public_include/decaf/spongerng.h index f03b7eb..eaad167 100644 --- a/src/public_include/decaf/spongerng.h +++ b/src/public_include/decaf/spongerng.h @@ -82,7 +82,7 @@ decaf_spongerng_destroy ( /* Implementations of inline functions */ /***************************************/ void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { - decaf_sponge_destroy(doomed->sponge); + decaf_sha3_destroy(doomed->sponge); } /** @endcond */ /* internal */ diff --git a/src/shake.c b/src/shake.c index b74b88e..7cd3a5b 100644 --- a/src/shake.c +++ b/src/shake.c @@ -173,14 +173,16 @@ decaf_error_t decaf_sha3_final ( void decaf_sha3_reset ( decaf_keccak_sponge_t decaf_sponge ) { - decaf_sponge_init(decaf_sponge, decaf_sponge->params); + decaf_sha3_init(decaf_sponge, decaf_sponge->params); decaf_sponge->params->flags = FLAG_ABSORBING; decaf_sponge->params->remaining = decaf_sponge->params->max_out; } -void decaf_sponge_destroy (decaf_keccak_sponge_t decaf_sponge) { decaf_bzero(decaf_sponge, sizeof(decaf_keccak_sponge_t)); } +void decaf_sha3_destroy (decaf_keccak_sponge_t decaf_sponge) { + decaf_bzero(decaf_sponge, sizeof(decaf_keccak_sponge_t)); +} -void decaf_sponge_init ( +void decaf_sha3_init ( decaf_keccak_sponge_t decaf_sponge, const struct decaf_kparams_s *params ) { @@ -189,18 +191,18 @@ void decaf_sponge_init ( decaf_sponge->params->position = 0; } -decaf_error_t decaf_sponge_hash ( - const uint8_t *in, - size_t inlen, +decaf_error_t decaf_sha3_hash ( uint8_t *out, size_t outlen, + const uint8_t *in, + size_t inlen, const struct decaf_kparams_s *params ) { decaf_keccak_sponge_t decaf_sponge; - decaf_sponge_init(decaf_sponge, params); + decaf_sha3_init(decaf_sponge, params); decaf_sha3_update(decaf_sponge, in, inlen); decaf_error_t ret = decaf_sha3_output(decaf_sponge, out, outlen); - decaf_sponge_destroy(decaf_sponge); + decaf_sha3_destroy(decaf_sponge); return ret; } @@ -212,7 +214,7 @@ decaf_error_t decaf_sponge_hash ( const struct decaf_kparams_s DECAF_SHA3_##n##_params_s = \ { 0, FLAG_ABSORBING, 200-n/4, 0, 0x06, 0x80, n/8, n/8 }; -size_t decaf_sponge_default_output_bytes ( +size_t decaf_sha3_default_output_bytes ( const decaf_keccak_sponge_t s ) { return (s->params->max_out == 0xFF) @@ -220,7 +222,7 @@ size_t decaf_sponge_default_output_bytes ( : ((200-s->params->rate)/2); } -size_t decaf_sponge_max_output_bytes ( +size_t decaf_sha3_max_output_bytes ( const decaf_keccak_sponge_t s ) { return (s->params->max_out == 0xFF) diff --git a/src/spongerng.c b/src/spongerng.c index 6b3136b..52630b5 100644 --- a/src/spongerng.c +++ b/src/spongerng.c @@ -137,7 +137,7 @@ void decaf_spongerng_init_from_buffer ( size_t len, int deterministic ) { - decaf_sponge_init(prng->sponge,&DECAF_SHAKE256_params_s); + decaf_sha3_init(prng->sponge,&DECAF_SHAKE256_params_s); prng->sponge->params->remaining = !deterministic; /* A bit of a hack; this param is ignored for SHAKE */ decaf_spongerng_stir(prng, in, len); } @@ -148,7 +148,7 @@ decaf_error_t decaf_spongerng_init_from_file ( size_t len, int deterministic ) { - decaf_sponge_init(prng->sponge,&DECAF_SHAKE256_params_s); + decaf_sha3_init(prng->sponge,&DECAF_SHAKE256_params_s); prng->sponge->params->remaining = !deterministic; /* A bit of a hack; this param is ignored for SHAKE */ if (!len) return DECAF_FAILURE; diff --git a/test/shakesum.c b/test/shakesum.c index efb24b2..e627797 100644 --- a/test/shakesum.c +++ b/test/shakesum.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) { decaf_sha512_destroy(decaf_sha512); } else { decaf_sha3_output(sponge,buf,outlen); - decaf_sponge_destroy(sponge); + decaf_sha3_destroy(sponge); } unsigned i; for (i=0; i