Loading...
Searching...
No Matches
shake.h
Go to the documentation of this file.
#ifndef __DECAF_SHAKE_H__
#define __DECAF_SHAKE_H__
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h> /* for NULL */
#include <decaf/common.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef INTERNAL_SPONGE_STRUCT
typedef struct decaf_keccak_sponge_s {
uint64_t opaque[26];
} decaf_keccak_sponge_s;
typedef struct decaf_keccak_sponge_s decaf_keccak_sponge_t[1];
struct decaf_kparams_s;
#endif
void DECAF_API_VIS decaf_sha3_init (
decaf_keccak_sponge_t sponge,
const struct decaf_kparams_s *params
);
decaf_error_t DECAF_API_VIS decaf_sha3_update (
struct decaf_keccak_sponge_s * __restrict__ sponge,
const uint8_t *in,
size_t len
);
decaf_error_t DECAF_API_VIS decaf_sha3_output (
decaf_keccak_sponge_t sponge,
uint8_t * __restrict__ out,
size_t len
);
decaf_error_t DECAF_API_VIS decaf_sha3_final (
decaf_keccak_sponge_t sponge,
uint8_t * __restrict__ out,
size_t len
);
void DECAF_API_VIS decaf_sha3_reset (
decaf_keccak_sponge_t sponge
);
size_t DECAF_API_VIS decaf_sha3_default_output_bytes (
const decaf_keccak_sponge_t sponge
);
size_t DECAF_API_VIS decaf_sha3_max_output_bytes (
const decaf_keccak_sponge_t sponge
);
void DECAF_API_VIS decaf_sha3_destroy (
decaf_keccak_sponge_t sponge
);
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
);
/* FUTURE: expand/doxygenate individual DECAF_SHAKE/DECAF_SHA3 instances? */
#if defined _MSC_VER
#define DECAF_DEC_SHAKE(n) \
extern const struct DECAF_API_VIS decaf_kparams_s DECAF_SHAKE##n##_params_s; \
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_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_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_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_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_sha3_destroy(sponge->s); \
}
#define DECAF_DEC_SHA3(n) \
extern const struct DECAF_API_VIS decaf_kparams_s DECAF_SHA3_##n##_params_s; \
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_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_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_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_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_sha3_destroy(sponge->s); \
}
#else // _MSC_VER
#define DECAF_DEC_SHAKE(n) \
DECAF_API_VIS extern const struct decaf_kparams_s DECAF_SHAKE##n##_params_s; \
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_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_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_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_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_sha3_destroy(sponge->s); \
}
#define DECAF_DEC_SHA3(n) \
DECAF_API_VIS extern const struct decaf_kparams_s DECAF_SHA3_##n##_params_s; \
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_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_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_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_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_sha3_destroy(sponge->s); \
}
#endif // _MSC_VER
DECAF_DEC_SHAKE(128)
DECAF_DEC_SHAKE(256)
DECAF_DEC_SHA3(224)
DECAF_DEC_SHA3(256)
DECAF_DEC_SHA3(384)
DECAF_DEC_SHA3(512)
#undef DECAF_DEC_SHAKE
#undef DECAF_DEC_SHA3
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __DECAF_SHAKE_H__ */
common.h
Common utility headers for Decaf library.
decaf_error_t
decaf_error_t
Another boolean type used to indicate success or failure.
Definition common.h:120
decaf_sha3_hash
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)
decaf_sha3_destroy
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.
decaf_sha3_max_output_bytes
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...
decaf_keccak_sponge_t
struct decaf_keccak_sponge_s decaf_keccak_sponge_t[1]
Convenience GMP-style one-element array version.
Definition shake.h:33
decaf_sha3_update
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_sha3_output
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.
decaf_sha3_init
void DECAF_API_VIS decaf_sha3_init(decaf_keccak_sponge_t sponge, const struct decaf_kparams_s *params)
Initialize a sponge context object.
decaf_sha3_final
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.
decaf_sha3_default_output_bytes
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...
decaf_sha3_reset
void DECAF_API_VIS decaf_sha3_reset(decaf_keccak_sponge_t sponge)
Reset the sponge to the empty string.
decaf_keccak_sponge_s
Sponge container object for the various primitives.
Definition shake.h:26