Leancrypto 0.12.0
Post-Quantum Cryptographic Library
|
Macros | |
#define | LC_HASH_CTX_ON_STACK(name, hashname) |
Allocate stack memory for the hash context. | |
Functions | |
static void | lc_hash_init (struct lc_hash_ctx *hash_ctx) |
Initialize hash context. | |
static void | lc_hash_update (struct lc_hash_ctx *hash_ctx, const uint8_t *in, size_t inlen) |
Update hash. | |
static void | lc_hash_final (struct lc_hash_ctx *hash_ctx, uint8_t *digest) |
Calculate message digest. | |
static 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. | |
static size_t | lc_hash_digestsize (struct lc_hash_ctx *hash_ctx) |
Get the size of the message digest. | |
static 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) | |
static unsigned int | lc_hash_ctxsize (struct lc_hash_ctx *hash_ctx) |
Get the context size of the message digest implementation. | |
static 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. | |
void | lc_hash_zero_free (struct lc_hash_ctx *hash_ctx) |
Zeroize and free hash context. | |
void | lc_hash (const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest) |
Calculate message digest - one-shot. | |
void | 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. | |
static int | lc_sponge (const struct lc_hash *hash, void *state, unsigned int rounds) |
Perform Sponge permutation on buffer. | |
static 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. | |
static 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 from offset*8 to offset*8 + length*8. | |
static 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. | |
Concept of hashes in leancrypto
All hashes can be used with the API calls documented below. However, the allocation part is hash-specific. Thus, perform the following steps
#define LC_HASH_CTX_ON_STACK | ( | name, | |
hashname ) |
Allocate stack memory for the hash context.
[in] | name | Name of the stack variable |
[in] | hashname | Pointer of type struct hash referencing the hash implementation to be used - see lc_sha256.h, lc_sha3.h, lc_sha512.h, lc_ascon_hash.h |
void lc_hash | ( | const struct lc_hash * | hash, |
const uint8_t * | in, | ||
size_t | inlen, | ||
uint8_t * | digest ) |
Calculate message digest - one-shot.
[in] | hash | Reference to hash implementation to be used to perform hash calculation with - see lc_sha256.h, lc_sha3.h, lc_sha512.h, lc_ascon_hash.h |
[in] | in | Buffer holding the data whose MAC shall be calculated |
[in] | inlen | Length of the input buffer |
[out] | digest | Buffer with at least the size of the message digest. |
The hash calculation operates entirely on the stack.
int lc_hash_alloc | ( | const struct lc_hash * | hash, |
struct lc_hash_ctx ** | hash_ctx ) |
Allocate Hash context on heap.
[in] | hash | Reference to hash implementation to be used to perform hash calculation with - see lc_sha256.h, lc_sha3.h, lc_sha512.h, lc_ascon_hash.h |
[out] | hash_ctx | Allocated hash context |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Calculate message digest.
For SHAKE, it is permissible to calculate the final digest in chunks by invoking the message digest calculation multiple times. The following code example illustrates it:
See the test shake_squeeze_more_tester.c
for an example.
[in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
[out] | digest | Buffer with at least the size of the message digest. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
void lc_hash_zero_free | ( | struct lc_hash_ctx * | hash_ctx | ) |
Zeroize and free hash context.
[in] | hash_ctx | hash context to be zeroized and freed |
|
inlinestatic |
Perform Sponge permutation on buffer.
[in] | hash | Reference to hash implementation to be used to perform Sponge calculation with - see lc_sha3.h, lc_ascon_hash.h |
[in] | state | State buffer of 200 bytes (Keccak) or 320 bits (Ascon) aligned to LC_HASH_COMMON_ALIGNMENT. |
[in] | rounds | Number of sponge rounds - may be ignored by sponge implementation |
|
inlinestatic |
Function to add (in GF(2), using bitwise exclusive-or) data given as bytes into the sponge state.
The bit positions that are affected by this function are from offset*8 to offset*8 + length*8.
[in] | hash | Reference to hash implementation to be used to perform Sponge calculation with - see lc_sha3.h, lc_ascon_hash.h |
[in] | state | Pointer to the state. |
[in] | data | Pointer to the input data. |
[in] | offset | Offset in bytes within the state. |
[in] | length | Number of bytes. |
LC_SHA3_STATE_SIZE
for Keccak or LC_ASCON_HASH_STATE_SIZE
for Ascon).
|
inlinestatic |
Function to retrieve data from the state. The bit positions that are retrieved by this function are from offset*8 to offset*8 + length*8.
[in] | hash | Reference to hash implementation to be used to perform sponge calculation with - see lc_sha3.h, lc_ascon_hash.h |
[in] | state | Pointer to the state. |
[out] | data | Pointer to the area where to store output data. |
[in] | offset | Offset in bytes within the state. |
[in] | length | Number of bytes. |
LC_SHA3_STATE_SIZE
for Keccak or LC_ASCON_HASH_STATE_SIZE
for Ascon).
|
inlinestatic |
Function to insert a complete new sponge state.
[in] | hash | Reference to hash implementation to be used to perform sponge calculation with - see lc_sha3.h, lc_ascon_hash.h |
[in] | state | Pointer to the state. |
[out] | data | Pointer to new state |
[in] | offset | Offset in bytes within the state. |
[in] | length | Number of bytes. |
LC_SHA3_STATE_SIZE
for Keccak or LC_ASCON_HASH_STATE_SIZE
for Ascon).void 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.
[in] | xof | Reference to hash implementation to be used to perform hash calculation with - see lc_sha3.h, lc_ascon_hash.h |
[in] | in | Buffer holding the data whose MAC shall be calculated |
[in] | inlen | Length of the input buffer |
[out] | digest | Buffer with at least the size of the message digest. |
[in] | digestlen | Size of the message digest to calculate. |
The hash calculation operates entirely on the stack.