Leancrypto 0.12.0
Post-Quantum Cryptographic Library
|
Go to the source code of this file.
Macros | |
#define | LC_KMAC_FLAGS_SUPPORT_REINIT (1 << 0) |
#define | LC_KMAC_CTX_ON_STACK(name, hashname) |
Allocate stack memory for the KMAC context. | |
#define | LC_KMAC_CTX_ON_STACK_REINIT(name, hashname) |
Allocate stack memory for the KMAC context. | |
#define | LC_KMAC_KDF_DRNG_CTX_SIZE(hashname) (sizeof(struct lc_rng_ctx) + LC_KMAC_CTX_SIZE(hashname)) |
#define | LC_KMAC_KDF_DRNG_SET_CTX(name, hashname) LC_KMAC_SET_CTX(name, hashname) |
#define | LC_KMAC_KDF_RNG_CTX(name, hashname) |
#define | LC_KMAC_KDF_DRNG_CTX_ON_STACK(name, hashname) |
Allocate stack memory for the KMAC DRNG context. | |
Functions | |
void | lc_kmac_init (struct lc_kmac_ctx *kmac_ctx, const uint8_t *key, size_t klen, const uint8_t *s, size_t slen) |
Initialize KMAC context. | |
void | lc_kmac_reinit (struct lc_kmac_ctx *kmac_ctx) |
Re-initialize KMAC context after a kmac_final operation. | |
void | lc_kmac_update (struct lc_kmac_ctx *kmac_ctx, const uint8_t *in, size_t inlen) |
Update KMAC. | |
void | lc_kmac_final (struct lc_kmac_ctx *kmac_ctx, uint8_t *mac, size_t maclen) |
Calculate KMAC MAC. | |
void | lc_kmac_final_xof (struct lc_kmac_ctx *kmac_ctx, uint8_t *mac, size_t maclen) |
Calculate KMAC MAC in XOF mode. | |
int | lc_kmac_alloc (const struct lc_hash *hash, struct lc_kmac_ctx **kmac_ctx, uint32_t flags) |
Allocate KMAC context on heap. | |
void | lc_kmac_zero_free (struct lc_kmac_ctx *kmac_ctx) |
Zeroize and free KMAC context. | |
static void | lc_kmac_zero (struct lc_kmac_ctx *kmac_ctx) |
Zeroize KMAC context allocated with either LC_KMAC_CTX_ON_STACK or lc_kmac_alloc. | |
static size_t | lc_kmac_macsize (struct lc_kmac_ctx *kmac_ctx) |
Return the MAC size. | |
static void | lc_kmac (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *s, size_t slen, const uint8_t *in, size_t inlen, uint8_t *mac, size_t maclen) |
Calculate KMAC - one-shot. | |
static void | lc_kmac_xof (const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *s, size_t slen, const uint8_t *in, size_t inlen, uint8_t *mac, size_t maclen) |
Calculate KMAC in XOF mode - one-shot. | |
int | lc_kmac_rng_alloc (struct lc_rng_ctx **state, const struct lc_hash *hash) |
Allocation of a KMAC DRNG context. | |
Variables | |
const struct lc_rng * | lc_kmac_rng |
#define LC_KMAC_CTX_ON_STACK | ( | name, | |
hashname ) |
Allocate stack memory for the KMAC context.
This allocates the memory without re-initialization support
[in] | name | Name of the stack variable - use lc_cshake256 or lc_cshake128 |
[in] | hashname | Pointer of type struct hash referencing the hash implementation to be used |
#define LC_KMAC_CTX_ON_STACK_REINIT | ( | name, | |
hashname ) |
Allocate stack memory for the KMAC context.
This allocates the memory with re-initialization support. See KMAC_FLAGS_SUPPORT_REINIT for the explanation about re-initialization.
[in] | name | Name of the stack variable - use lc_cshake256 or lc_cshake128 |
[in] | hashname | Pointer of type struct hash referencing the hash implementation to be used |
#define LC_KMAC_KDF_DRNG_CTX_ON_STACK | ( | name, | |
hashname ) |
Allocate stack memory for the KMAC DRNG context.
[in] | name | Name of the stack variable |
[in] | hashname | Reference to lc_hash implementation - use lc_cshake256 or lc_cshake128. |
#define LC_KMAC_KDF_DRNG_CTX_SIZE | ( | hashname | ) | (sizeof(struct lc_rng_ctx) + LC_KMAC_CTX_SIZE(hashname)) |
#define LC_KMAC_KDF_DRNG_SET_CTX | ( | name, | |
hashname ) LC_KMAC_SET_CTX(name, hashname) |
#define LC_KMAC_KDF_RNG_CTX | ( | name, | |
hashname ) |
|
inlinestatic |
Calculate KMAC - one-shot.
[in] | hash | Reference to hash implementation to be used to perform KMAC calculation with. Use lc_cshake256 or lc_cshake128. |
[in] | key | MAC key of arbitrary size |
[in] | keylen | Size of the MAC key |
[in] | in | Buffer holding the data whose MAC shall be calculated |
[in] | inlen | Length of the input buffer |
[in] | s | Optional customization string - if not needed, use NULL |
[in] | slen | Size of s |
[out] | mac | Buffer with at least the size of the message digest. |
[in] | maclen | Size of the requested MAC |
The KMAC calculation operates entirely on the stack.
int lc_kmac_alloc | ( | const struct lc_hash * | hash, |
struct lc_kmac_ctx ** | kmac_ctx, | ||
uint32_t | flags ) |
Allocate KMAC context on heap.
NOTE: This is defined for cshake256 as of now.
[in] | hash | Reference to hash implementation to be used to perform KMAC calculation with. Use cshake256! |
[out] | kmac_ctx | Allocated KMAC context |
[in] | flags | Zero or more of the flags defined below |
void lc_kmac_final | ( | struct lc_kmac_ctx * | kmac_ctx, |
uint8_t * | mac, | ||
size_t | maclen ) |
Calculate KMAC MAC.
If the cipher handle shall be used for a new KMAC operation with the same key after this call, you MUST re-initialize the handle with kmac_reinit.
[in] | kmac_ctx | Reference to kmac context implementation to be used to perform KMAC calculation with. |
[out] | mac | Buffer with at least the size of the message digest that is returned by kmac_macsize. |
[in] | maclen | Size of the requested MAC |
void lc_kmac_final_xof | ( | struct lc_kmac_ctx * | kmac_ctx, |
uint8_t * | mac, | ||
size_t | maclen ) |
Calculate KMAC MAC in XOF mode.
If the cipher handle shall be used for a new KMAC operation with the same key after this call, you MUST re-initialize the handle with kmac_reinit.
This call is can be to be invoked multiple times It generates more message digest.
E.g. the following calls are equal:
size_t maclen = LC_SHA3_256_SIZE_BLOCK * 3 + 5;
lc_kmac_final_xof(ctx, mac, maclen);
and
[in] | kmac_ctx | Reference to kmac context implementation to be used to perform KMAC calculation with. |
[out] | mac | Buffer to hold the message digest |
[in] | maclen | Size of the requested MAC |
void lc_kmac_init | ( | struct lc_kmac_ctx * | kmac_ctx, |
const uint8_t * | key, | ||
size_t | klen, | ||
const uint8_t * | s, | ||
size_t | slen ) |
Initialize KMAC context.
[in] | kmac_ctx | Reference to kmac context implementation to be used to perform KMAC calculation with. |
[in] | key | MAC key of arbitrary size |
[in] | klen | Size of the MAC key |
[in] | s | Optional customization string - if not needed, use NULL |
[in] | slen | Size of s |
The caller must provide an allocated kmac_ctx. This can be achieved by using KMAC_CTX_ON_STACK or by using kmac_alloc.
|
inlinestatic |
void lc_kmac_reinit | ( | struct lc_kmac_ctx * | kmac_ctx | ) |
Re-initialize KMAC context after a kmac_final operation.
This operation allows the KMAC context to be used again with the same key set during kmac_init.
[in] | kmac_ctx | Reference to kmac context implementation to be used to perform KMAC calculation with. |
int lc_kmac_rng_alloc | ( | struct lc_rng_ctx ** | state, |
const struct lc_hash * | hash ) |
Allocation of a KMAC DRNG context.
[out] | state | KMAC DRNG context allocated by the function |
[in] | hash | Reference to hash implementation to be used to perform RNG operation with. Use lc_cshake256 or lc_cshake128. |
The cipher handle including its memory is allocated with this function.
The memory is pinned so that the DRNG state cannot be swapped out to disk.
You need to seed the DRNG!
void lc_kmac_update | ( | struct lc_kmac_ctx * | kmac_ctx, |
const uint8_t * | in, | ||
size_t | inlen ) |
Update KMAC.
[in] | kmac_ctx | Reference to kmac context implementation to be used to perform KMAC calculation with. |
[in] | in | Buffer holding the data whose MAC shall be calculated |
[in] | inlen | Length of the input buffer |
|
inlinestatic |
Calculate KMAC in XOF mode - one-shot.
[in] | hash | Reference to hash implementation to be used to perform KMAC calculation with. Use lc_cshake256 or lc_cshake128. |
[in] | key | MAC key of arbitrary size |
[in] | keylen | Size of the MAC key |
[in] | in | Buffer holding the data whose MAC shall be calculated |
[in] | inlen | Length of the input buffer |
[in] | s | Optional customization string - if not needed, use NULL |
[in] | slen | Size of s |
[out] | mac | Buffer with at least the size of the message digest. |
[in] | maclen | Size of the requested MAC |
The KMAC calculation operates entirely on the stack.
|
inlinestatic |
void lc_kmac_zero_free | ( | struct lc_kmac_ctx * | kmac_ctx | ) |
Zeroize and free KMAC context.
[in] | kmac_ctx | KMAC context to be zeroized and freed |
|
extern |