23#include "ext_headers.h"
34 int (*init)(
void *state);
35 int (*init_nocheck)(
void *state);
36 void (*update)(
void *state,
const uint8_t *in,
size_t inlen);
37 void (*
final)(
void *state, uint8_t *digest);
38 void (*set_digestsize)(
void *state,
size_t digestsize);
39 size_t (*get_digestsize)(
void *state);
42 void (*sponge_permutation)(
void *state,
unsigned int rounds);
43 void (*sponge_add_bytes)(
void *state,
const uint8_t *data,
44 size_t offset,
size_t length);
45 void (*sponge_extract_bytes)(
const void *state, uint8_t *data,
46 size_t offset,
size_t length);
47 void (*sponge_newstate)(
void *state,
const uint8_t *newstate,
48 size_t offset,
size_t length);
49 uint64_t algorithm_type;
52 unsigned short statesize;
69#ifndef LC_HASH_COMMON_ALIGNMENT
71#define LC_HASH_COMMON_ALIGNMENT 8
74#define LC_ALIGN_HASH_MASK(p) \
75 LC_ALIGN_PTR_64(p, LC_ALIGNMENT_MASK(LC_HASH_COMMON_ALIGNMENT))
77#define LC_SHA_MAX_SIZE_DIGEST 64
96#define LC_HASH_STATE_SIZE_NONALIGNED(x) ((unsigned long)(x->statesize))
97#define LC_HASH_STATE_SIZE(x) \
98 (LC_HASH_STATE_SIZE_NONALIGNED(x) + LC_HASH_COMMON_ALIGNMENT)
99#define LC_HASH_CTX_SIZE(x) (sizeof(struct lc_hash_ctx) + LC_HASH_STATE_SIZE(x))
101#define _LC_HASH_SET_CTX(name, hashname, ctx, offset) \
102 name->hash_state = LC_ALIGN_HASH_MASK(((uint8_t *)(ctx)) + (offset)); \
103 name->hash = hashname
105#define LC_HASH_SET_CTX(name, hashname) \
106 _LC_HASH_SET_CTX(name, hashname, name, sizeof(struct lc_hash_ctx))
236#define LC_HASH_CTX_ON_STACK(name, hashname) \
237 _Pragma("GCC diagnostic push") \
238 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
239 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
240 LC_ALIGNED_BUFFER(name##_ctx_buf, \
241 LC_HASH_CTX_SIZE(hashname), \
242 LC_HASH_COMMON_ALIGNMENT); \
243 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
244 LC_HASH_SET_CTX(name, hashname); \
245 _Pragma("GCC diagnostic pop")
302 uint8_t *digest,
size_t digestlen);
349 const uint8_t *data,
size_t offset,
size_t length);
374 uint8_t *data,
size_t offset,
size_t length);
394 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.
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.
void 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_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
uint64_t lc_hash_algorithm_type(const struct lc_hash *hash)
Obtain algorithm type usable with lc_alg_status.
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_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.
uint64_t lc_hash_ctx_algorithm_type(const struct lc_hash_ctx *ctx)
Obtain algorithm type usable with lc_alg_status.
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.