11#ifndef __DECAF_SHAKE_H__
12#define __DECAF_SHAKE_H__
24#ifndef INTERNAL_SPONGE_STRUCT
38 struct decaf_kparams_s;
48 const struct decaf_kparams_s *params
78 uint8_t * __restrict__ out,
92 uint8_t * __restrict__ out,
146 const struct decaf_kparams_s *params
154#define DECAF_DEC_SHAKE(n) \
155 extern const struct DECAF_API_VIS decaf_kparams_s DECAF_SHAKE##n##_params_s; \
156 typedef struct decaf_shake##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_shake##n##_ctx_t[1]; \
157 static inline void DECAF_NONNULL decaf_shake##n##_init(decaf_shake##n##_ctx_t sponge) { \
158 decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \
160 static inline void DECAF_NONNULL decaf_shake##n##_gen_init(decaf_keccak_sponge_t sponge) { \
161 decaf_sha3_init(sponge, &DECAF_SHAKE##n##_params_s); \
163 static inline decaf_error_t DECAF_NONNULL decaf_shake##n##_update(decaf_shake##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
164 return decaf_sha3_update(sponge->s, in, inlen); \
166 static inline void DECAF_NONNULL decaf_shake##n##_final(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
167 decaf_sha3_output(sponge->s, out, outlen); \
168 decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \
170 static inline void DECAF_NONNULL decaf_shake##n##_output(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
171 decaf_sha3_output(sponge->s, out, outlen); \
173 static inline void DECAF_NONNULL decaf_shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
174 decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHAKE##n##_params_s); \
176 static inline void DECAF_NONNULL decaf_shake##n##_destroy( decaf_shake##n##_ctx_t sponge ) { \
177 decaf_sha3_destroy(sponge->s); \
180#define DECAF_DEC_SHA3(n) \
181 extern const struct DECAF_API_VIS decaf_kparams_s DECAF_SHA3_##n##_params_s; \
182 typedef struct decaf_sha3_##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_sha3_##n##_ctx_t[1]; \
183 static inline void DECAF_NONNULL decaf_sha3_##n##_init(decaf_sha3_##n##_ctx_t sponge) { \
184 decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \
186 static inline void DECAF_NONNULL decaf_sha3_##n##_gen_init(decaf_keccak_sponge_t sponge) { \
187 decaf_sha3_init(sponge, &DECAF_SHA3_##n##_params_s); \
189 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_update(decaf_sha3_##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
190 return decaf_sha3_update(sponge->s, in, inlen); \
192 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_final(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
193 decaf_error_t ret = decaf_sha3_output(sponge->s, out, outlen); \
194 decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \
197 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_output(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
198 return decaf_sha3_output(sponge->s, out, outlen); \
200 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
201 return decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHA3_##n##_params_s); \
203 static inline void DECAF_NONNULL decaf_sha3_##n##_destroy(decaf_sha3_##n##_ctx_t sponge) { \
204 decaf_sha3_destroy(sponge->s); \
211#define DECAF_DEC_SHAKE(n) \
212 DECAF_API_VIS extern const struct decaf_kparams_s DECAF_SHAKE##n##_params_s; \
213 typedef struct decaf_shake##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_shake##n##_ctx_t[1]; \
214 static inline void DECAF_NONNULL decaf_shake##n##_init(decaf_shake##n##_ctx_t sponge) { \
215 decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \
217 static inline void DECAF_NONNULL decaf_shake##n##_gen_init(decaf_keccak_sponge_t sponge) { \
218 decaf_sha3_init(sponge, &DECAF_SHAKE##n##_params_s); \
220 static inline decaf_error_t DECAF_NONNULL decaf_shake##n##_update(decaf_shake##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
221 return decaf_sha3_update(sponge->s, in, inlen); \
223 static inline void DECAF_NONNULL decaf_shake##n##_final(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
224 decaf_sha3_output(sponge->s, out, outlen); \
225 decaf_sha3_init(sponge->s, &DECAF_SHAKE##n##_params_s); \
227 static inline void DECAF_NONNULL decaf_shake##n##_output(decaf_shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
228 decaf_sha3_output(sponge->s, out, outlen); \
230 static inline void DECAF_NONNULL decaf_shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
231 decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHAKE##n##_params_s); \
233 static inline void DECAF_NONNULL decaf_shake##n##_destroy( decaf_shake##n##_ctx_t sponge ) { \
234 decaf_sha3_destroy(sponge->s); \
237#define DECAF_DEC_SHA3(n) \
238 DECAF_API_VIS extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s; \
239 typedef struct decaf_sha3_##n##_ctx_s { decaf_keccak_sponge_t s; } decaf_sha3_##n##_ctx_t[1]; \
240 static inline void DECAF_NONNULL decaf_sha3_##n##_init(decaf_sha3_##n##_ctx_t sponge) { \
241 decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \
243 static inline void DECAF_NONNULL decaf_sha3_##n##_gen_init(decaf_keccak_sponge_t sponge) { \
244 decaf_sha3_init(sponge, &DECAF_SHA3_##n##_params_s); \
246 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_update(decaf_sha3_##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
247 return decaf_sha3_update(sponge->s, in, inlen); \
249 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_final(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
250 decaf_error_t ret = decaf_sha3_output(sponge->s, out, outlen); \
251 decaf_sha3_init(sponge->s, &DECAF_SHA3_##n##_params_s); \
254 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_output(decaf_sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
255 return decaf_sha3_output(sponge->s, out, outlen); \
257 static inline decaf_error_t DECAF_NONNULL decaf_sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
258 return decaf_sha3_hash(out,outlen,in,inlen,&DECAF_SHA3_##n##_params_s); \
260 static inline void DECAF_NONNULL decaf_sha3_##n##_destroy(decaf_sha3_##n##_ctx_t sponge) { \
261 decaf_sha3_destroy(sponge->s); \
275#undef DECAF_DEC_SHAKE
Common utility headers for Decaf library.
decaf_error_t
Another boolean type used to indicate success or failure.
Definition common.h:120
decaf_error_t DECAF_API_VIS decaf_sha3_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen, const struct decaf_kparams_s *params)
Hash (in) to (out)
void DECAF_API_VIS decaf_sha3_destroy(decaf_keccak_sponge_t sponge)
Destroy a DECAF_SHA3 or DECAF_SHAKE sponge context by overwriting it with 0.
size_t DECAF_API_VIS decaf_sha3_max_output_bytes(const decaf_keccak_sponge_t sponge)
Return the default output length of the sponge construction, for the purpose of C++ default operators...
struct decaf_keccak_sponge_s decaf_keccak_sponge_t[1]
Convenience GMP-style one-element array version.
Definition shake.h:33
decaf_error_t DECAF_API_VIS decaf_sha3_update(struct decaf_keccak_sponge_s *__restrict__ sponge, const uint8_t *in, size_t len)
Absorb data into a DECAF_SHA3 or DECAF_SHAKE hash context.
decaf_error_t DECAF_API_VIS decaf_sha3_output(decaf_keccak_sponge_t sponge, uint8_t *__restrict__ out, size_t len)
Squeeze output data from a DECAF_SHA3 or DECAF_SHAKE hash context.
void DECAF_API_VIS decaf_sha3_init(decaf_keccak_sponge_t sponge, const struct decaf_kparams_s *params)
Initialize a sponge context object.
decaf_error_t DECAF_API_VIS decaf_sha3_final(decaf_keccak_sponge_t sponge, uint8_t *__restrict__ out, size_t len)
Squeeze output data from a DECAF_SHA3 or DECAF_SHAKE hash context.
size_t DECAF_API_VIS decaf_sha3_default_output_bytes(const decaf_keccak_sponge_t sponge)
Return the default output length of the sponge construction, for the purpose of C++ default operators...
void DECAF_API_VIS decaf_sha3_reset(decaf_keccak_sponge_t sponge)
Reset the sponge to the empty string.
Sponge container object for the various primitives.
Definition shake.h:26