@@ -43,7 +43,7 @@ extern "C" { | |||||
* @param [out] sponge The object to initialize. | * @param [out] sponge The object to initialize. | ||||
* @param [in] params The sponge's parameter description. | * @param [in] params The sponge's parameter description. | ||||
*/ | */ | ||||
void decaf_sponge_init ( | |||||
void decaf_sha3_init ( | |||||
decaf_keccak_sponge_t sponge, | decaf_keccak_sponge_t sponge, | ||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) DECAF_API_VIS; | ) 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. | * 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. */ | const decaf_keccak_sponge_t sponge /**< [inout] The context. */ | ||||
) DECAF_API_VIS; | ) 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. | * 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. */ | const decaf_keccak_sponge_t sponge /**< [inout] The context. */ | ||||
) DECAF_API_VIS; | ) 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. | * @brief Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0. | ||||
* @param [out] sponge The context. | * @param [out] sponge The context. | ||||
*/ | */ | ||||
void decaf_sponge_destroy ( | |||||
void decaf_sha3_destroy ( | |||||
decaf_keccak_sponge_t sponge | decaf_keccak_sponge_t sponge | ||||
) DECAF_API_VIS; | ) DECAF_API_VIS; | ||||
@@ -138,11 +138,11 @@ void decaf_sponge_destroy ( | |||||
* @param [in] outlen The length of the output data. | * @param [in] outlen The length of the output data. | ||||
* @param [in] params The parameters of the sponge hash. | * @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, | uint8_t *out, | ||||
size_t outlen, | size_t outlen, | ||||
const uint8_t *in, | |||||
size_t inlen, | |||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) DECAF_API_VIS; | ) 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; \ | 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]; \ | 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) { \ | 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) { \ | 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 ) { \ | 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); \ | 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 ) { \ | 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_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 ) { \ | 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); \ | 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) { \ | 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 ) { \ | 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) \ | #define DECAF_DEC_SHA3(n) \ | ||||
extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s DECAF_API_VIS; \ | 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]; \ | 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) { \ | 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) { \ | 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 ) { \ | 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); \ | 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 ) { \ | 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_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; \ | 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 ) { \ | 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); \ | 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) { \ | 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) { \ | 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 */ | /** @endcond */ | ||||
@@ -38,7 +38,7 @@ protected: | |||||
decaf_keccak_sponge_t wrapped; | decaf_keccak_sponge_t wrapped; | ||||
/** Initialize from parameters */ | /** 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 */ | /** @endcond */ | ||||
public: | public: | ||||
@@ -94,12 +94,12 @@ public: | |||||
/** @brief Return the sponge's default output size. */ | /** @brief Return the sponge's default output size. */ | ||||
inline size_t default_output_size() const DECAF_NOEXCEPT { | 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. */ | /** @brief Return the sponge's maximum output size. */ | ||||
inline size_t max_output_size() const DECAF_NOEXCEPT { | 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. */ | /** Output the default number of bytes. */ | ||||
@@ -116,7 +116,7 @@ public: | |||||
inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } | inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } | ||||
/** Destructor zeroizes state */ | /** Destructor zeroizes state */ | ||||
inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sponge_destroy(wrapped); } | |||||
inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sha3_destroy(wrapped); } | |||||
}; | }; | ||||
/** Fixed-output-length SHA3 */ | /** Fixed-output-length SHA3 */ | ||||
@@ -82,7 +82,7 @@ decaf_spongerng_destroy ( | |||||
/* Implementations of inline functions */ | /* Implementations of inline functions */ | ||||
/***************************************/ | /***************************************/ | ||||
void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { | void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { | ||||
decaf_sponge_destroy(doomed->sponge); | |||||
decaf_sha3_destroy(doomed->sponge); | |||||
} | } | ||||
/** @endcond */ /* internal */ | /** @endcond */ /* internal */ | ||||
@@ -43,7 +43,7 @@ extern "C" { | |||||
* @param [out] sponge The object to initialize. | * @param [out] sponge The object to initialize. | ||||
* @param [in] params The sponge's parameter description. | * @param [in] params The sponge's parameter description. | ||||
*/ | */ | ||||
void decaf_sponge_init ( | |||||
void decaf_sha3_init ( | |||||
decaf_keccak_sponge_t sponge, | decaf_keccak_sponge_t sponge, | ||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) DECAF_API_VIS; | ) 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. | * 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. */ | const decaf_keccak_sponge_t sponge /**< [inout] The context. */ | ||||
) DECAF_API_VIS; | ) 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. | * 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. */ | const decaf_keccak_sponge_t sponge /**< [inout] The context. */ | ||||
) DECAF_API_VIS; | ) 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. | * @brief Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0. | ||||
* @param [out] sponge The context. | * @param [out] sponge The context. | ||||
*/ | */ | ||||
void decaf_sponge_destroy ( | |||||
void decaf_sha3_destroy ( | |||||
decaf_keccak_sponge_t sponge | decaf_keccak_sponge_t sponge | ||||
) DECAF_API_VIS; | ) DECAF_API_VIS; | ||||
@@ -138,11 +138,11 @@ void decaf_sponge_destroy ( | |||||
* @param [in] outlen The length of the output data. | * @param [in] outlen The length of the output data. | ||||
* @param [in] params The parameters of the sponge hash. | * @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, | uint8_t *out, | ||||
size_t outlen, | size_t outlen, | ||||
const uint8_t *in, | |||||
size_t inlen, | |||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) DECAF_API_VIS; | ) 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; \ | 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]; \ | 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) { \ | 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) { \ | 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 ) { \ | 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); \ | 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 ) { \ | 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_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 ) { \ | 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); \ | 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) { \ | 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 ) { \ | 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) \ | #define DECAF_DEC_SHA3(n) \ | ||||
extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s DECAF_API_VIS; \ | 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]; \ | 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) { \ | 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) { \ | 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 ) { \ | 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); \ | 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 ) { \ | 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_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; \ | 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 ) { \ | 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); \ | 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) { \ | 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) { \ | 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 */ | /** @endcond */ | ||||
@@ -38,7 +38,7 @@ protected: | |||||
decaf_keccak_sponge_t wrapped; | decaf_keccak_sponge_t wrapped; | ||||
/** Initialize from parameters */ | /** 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 */ | /** @endcond */ | ||||
public: | public: | ||||
@@ -94,12 +94,12 @@ public: | |||||
/** @brief Return the sponge's default output size. */ | /** @brief Return the sponge's default output size. */ | ||||
inline size_t default_output_size() const DECAF_NOEXCEPT { | 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. */ | /** @brief Return the sponge's maximum output size. */ | ||||
inline size_t max_output_size() const DECAF_NOEXCEPT { | 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. */ | /** Output the default number of bytes. */ | ||||
@@ -116,7 +116,7 @@ public: | |||||
inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } | inline void reset() DECAF_NOEXCEPT { decaf_sha3_reset(wrapped); } | ||||
/** Destructor zeroizes state */ | /** Destructor zeroizes state */ | ||||
inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sponge_destroy(wrapped); } | |||||
inline ~KeccakHash() DECAF_NOEXCEPT { decaf_sha3_destroy(wrapped); } | |||||
}; | }; | ||||
/** Fixed-output-length SHA3 */ | /** Fixed-output-length SHA3 */ | ||||
@@ -82,7 +82,7 @@ decaf_spongerng_destroy ( | |||||
/* Implementations of inline functions */ | /* Implementations of inline functions */ | ||||
/***************************************/ | /***************************************/ | ||||
void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { | void decaf_spongerng_destroy (decaf_keccak_prng_t doomed) { | ||||
decaf_sponge_destroy(doomed->sponge); | |||||
decaf_sha3_destroy(doomed->sponge); | |||||
} | } | ||||
/** @endcond */ /* internal */ | /** @endcond */ /* internal */ | ||||
@@ -173,14 +173,16 @@ decaf_error_t decaf_sha3_final ( | |||||
void decaf_sha3_reset ( | void decaf_sha3_reset ( | ||||
decaf_keccak_sponge_t decaf_sponge | 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->flags = FLAG_ABSORBING; | ||||
decaf_sponge->params->remaining = decaf_sponge->params->max_out; | 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, | decaf_keccak_sponge_t decaf_sponge, | ||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) { | ) { | ||||
@@ -189,18 +191,18 @@ void decaf_sponge_init ( | |||||
decaf_sponge->params->position = 0; | 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, | uint8_t *out, | ||||
size_t outlen, | size_t outlen, | ||||
const uint8_t *in, | |||||
size_t inlen, | |||||
const struct decaf_kparams_s *params | const struct decaf_kparams_s *params | ||||
) { | ) { | ||||
decaf_keccak_sponge_t decaf_sponge; | 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_sha3_update(decaf_sponge, in, inlen); | ||||
decaf_error_t ret = decaf_sha3_output(decaf_sponge, out, outlen); | decaf_error_t ret = decaf_sha3_output(decaf_sponge, out, outlen); | ||||
decaf_sponge_destroy(decaf_sponge); | |||||
decaf_sha3_destroy(decaf_sponge); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -212,7 +214,7 @@ decaf_error_t decaf_sponge_hash ( | |||||
const struct decaf_kparams_s DECAF_SHA3_##n##_params_s = \ | const struct decaf_kparams_s DECAF_SHA3_##n##_params_s = \ | ||||
{ 0, FLAG_ABSORBING, 200-n/4, 0, 0x06, 0x80, n/8, n/8 }; | { 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 | const decaf_keccak_sponge_t s | ||||
) { | ) { | ||||
return (s->params->max_out == 0xFF) | return (s->params->max_out == 0xFF) | ||||
@@ -220,7 +222,7 @@ size_t decaf_sponge_default_output_bytes ( | |||||
: ((200-s->params->rate)/2); | : ((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 | const decaf_keccak_sponge_t s | ||||
) { | ) { | ||||
return (s->params->max_out == 0xFF) | return (s->params->max_out == 0xFF) | ||||
@@ -137,7 +137,7 @@ void decaf_spongerng_init_from_buffer ( | |||||
size_t len, | size_t len, | ||||
int deterministic | 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 */ | prng->sponge->params->remaining = !deterministic; /* A bit of a hack; this param is ignored for SHAKE */ | ||||
decaf_spongerng_stir(prng, in, len); | decaf_spongerng_stir(prng, in, len); | ||||
} | } | ||||
@@ -148,7 +148,7 @@ decaf_error_t decaf_spongerng_init_from_file ( | |||||
size_t len, | size_t len, | ||||
int deterministic | 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 */ | prng->sponge->params->remaining = !deterministic; /* A bit of a hack; this param is ignored for SHAKE */ | ||||
if (!len) return DECAF_FAILURE; | if (!len) return DECAF_FAILURE; | ||||
@@ -77,7 +77,7 @@ int main(int argc, char **argv) { | |||||
decaf_sha512_destroy(decaf_sha512); | decaf_sha512_destroy(decaf_sha512); | ||||
} else { | } else { | ||||
decaf_sha3_output(sponge,buf,outlen); | decaf_sha3_output(sponge,buf,outlen); | ||||
decaf_sponge_destroy(sponge); | |||||
decaf_sha3_destroy(sponge); | |||||
} | } | ||||
unsigned i; | unsigned i; | ||||
for (i=0; i<outlen; i++) { | for (i=0; i<outlen; i++) { | ||||