23#include "ext_headers.h"
35 int (*init)(
void *state);
36 int (*init_nocheck)(
void *state);
37 void (*update)(
void *state,
const uint8_t *in,
size_t inlen);
38 void (*
final)(
void *state, uint8_t *digest);
39 void (*set_digestsize)(
void *state,
size_t digestsize);
40 size_t (*get_digestsize)(
void *state);
43 void (*sponge_permutation)(
void *state,
unsigned int rounds);
44 void (*sponge_add_bytes)(
void *state,
const uint8_t *data,
45 size_t offset,
size_t length);
46 void (*sponge_extract_bytes)(
const void *state, uint8_t *data,
47 size_t offset,
size_t length);
48 void (*sponge_newstate)(
void *state,
const uint8_t *newstate,
49 size_t offset,
size_t length);
50 uint64_t algorithm_type;
53 unsigned short statesize;
70#ifndef LC_HASH_COMMON_ALIGNMENT
72#define LC_HASH_COMMON_ALIGNMENT 64
75#define LC_ALIGN_HASH_MASK(p) \
76 LC_ALIGN_PTR_64(p, LC_ALIGNMENT_MASK(LC_HASH_COMMON_ALIGNMENT))
78#define LC_SHA_MAX_SIZE_DIGEST 64
80#define LC_HASH_STATE_SIZE_ALIGN(x) (x + LC_HASH_COMMON_ALIGNMENT)
99#define LC_HASH_STATE_SIZE_NONALIGNED(x) ((unsigned long)(x->statesize))
100#define LC_HASH_STATE_SIZE(x) \
101 (LC_HASH_STATE_SIZE_NONALIGNED(x) + LC_HASH_COMMON_ALIGNMENT)
102#define LC_HASH_CTX_SIZE(x) (sizeof(struct lc_hash_ctx) + LC_HASH_STATE_SIZE(x))
104#define _LC_HASH_SET_CTX(name, hashname, ctx, offset) \
105 name->hash_state = LC_ALIGN_HASH_MASK(((uint8_t *)(ctx)) + (offset)); \
106 name->hash = hashname
108#define LC_HASH_SET_CTX(name, hashname) \
109 _LC_HASH_SET_CTX(name, hashname, name, sizeof(struct lc_hash_ctx))
241#define LC_HASH_CTX_ON_STACK(name, hashname) \
242 _Pragma("GCC diagnostic push") \
243 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
244 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
245 LC_ALIGNED_BUFFER(name##_ctx_buf, \
246 LC_HASH_CTX_SIZE(hashname), \
247 LC_HASH_COMMON_ALIGNMENT); \
248 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
249 LC_HASH_SET_CTX(name, hashname); \
250 _Pragma("GCC diagnostic pop")
307 uint8_t *digest,
size_t digestlen);
354 const uint8_t *data,
size_t offset,
size_t length);
379 uint8_t *data,
size_t offset,
size_t length);
399 const uint8_t *data,
size_t offset,
size_t length);
void lc_hash_update(struct lc_hash_ctx *hash_ctx, const uint8_t *in, size_t inlen)
Update hash.
int lc_sponge(const struct lc_hash *hash, void *state, unsigned int rounds)
Perform Sponge permutation on buffer.
enum lc_alg_status_val lc_hash_alg_status(const struct lc_hash *hash)
Obtain algorithm status.
unsigned int lc_hash_blocksize(struct lc_hash_ctx *hash_ctx)
Get the block size of the message digest (or the "rate" in terms of Sponge-based algorithms)
void lc_hash_zero(struct lc_hash_ctx *hash_ctx)
Zeroize Hash context allocated with either LC_HASH_CTX_ON_STACK or lc_hmac_alloc.
int lc_hash_alloc(const struct lc_hash *hash, struct lc_hash_ctx **hash_ctx)
Allocate Hash context on heap.
int lc_xof(const struct lc_hash *xof, const uint8_t *in, size_t inlen, uint8_t *digest, size_t digestlen)
Calculate message digest for an XOF - one-shot.
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
unsigned int lc_hash_ctxsize(struct lc_hash_ctx *hash_ctx)
Get the context size of the message digest implementation.
int lc_hash_init(struct lc_hash_ctx *hash_ctx)
Initialize hash context.
void lc_hash_final(struct lc_hash_ctx *hash_ctx, uint8_t *digest)
Calculate message digest.
int lc_sponge_extract_bytes(const struct lc_hash *hash, const void *state, uint8_t *data, size_t offset, size_t length)
Function to retrieve data from the state. The bit positions that are retrieved by this function are f...
int lc_hash_set_digestsize(struct lc_hash_ctx *hash_ctx, size_t digestsize)
Set the size of the message digest - this call is intended for SHAKE.
int lc_sponge_add_bytes(const struct lc_hash *hash, void *state, const uint8_t *data, size_t offset, size_t length)
Function to add (in GF(2), using bitwise exclusive-or) data given as bytes into the sponge state.
int lc_sponge_newstate(const struct lc_hash *hash, void *state, const uint8_t *data, size_t offset, size_t length)
Function to insert a complete new sponge state.
void lc_hash_zero_free(struct lc_hash_ctx *hash_ctx)
Zeroize and free hash context.
size_t lc_hash_digestsize(struct lc_hash_ctx *hash_ctx)
Get the size of the message digest.
enum lc_alg_status_val lc_hash_ctx_alg_status(const struct lc_hash_ctx *ctx)
Obtain algorithm status.