|
Leancrypto 1.6.0
Post-Quantum Cryptographic Library
|
Macros | |
| #define | LC_HASH_CTX_ON_STACK(name, hashname) |
| Allocate stack memory for the hash context. | |
Functions | |
| int | lc_hash_init (struct lc_hash_ctx *hash_ctx) |
| Initialize hash context. | |
| void | lc_hash_update (struct lc_hash_ctx *hash_ctx, const uint8_t *in, size_t inlen) |
| Update hash. | |
| void | lc_hash_final (struct lc_hash_ctx *hash_ctx, uint8_t *digest) |
| Calculate message digest. | |
| 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. | |
| size_t | lc_hash_digestsize (struct lc_hash_ctx *hash_ctx) |
| Get the size of the message digest. | |
| 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). | |
| unsigned int | lc_hash_ctxsize (struct lc_hash_ctx *hash_ctx) |
| Get the context size of the message digest implementation. | |
| 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. | |
| int | lc_hash (const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest) |
| Calculate message digest - one-shot. | |
| 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_sponge (const struct lc_hash *hash, void *state, unsigned int rounds) |
| Perform Sponge permutation on buffer. | |
| 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_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. | |
| 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. | |
| uint64_t | lc_hash_algorithm_type (const struct lc_hash *hash) |
| Obtain algorithm type usable with lc_alg_status. | |
| uint64_t | lc_hash_ctx_algorithm_type (const struct lc_hash_ctx *ctx) |
| Obtain algorithm type usable with lc_alg_status. | |
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 |
| int 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.
| uint64_t lc_hash_algorithm_type | ( | const struct lc_hash * | hash | ) |
Obtain algorithm type usable with lc_alg_status.
| [in] | hash | Hash algorithm instance |
| 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 |
| 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).
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
| uint64_t lc_hash_ctx_algorithm_type | ( | const struct lc_hash_ctx * | ctx | ) |
Obtain algorithm type usable with lc_alg_status.
| [in] | ctx | Hash context handle |
| unsigned int lc_hash_ctxsize | ( | struct lc_hash_ctx * | hash_ctx | ) |
Get the context size of the message digest implementation.
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
| size_t lc_hash_digestsize | ( | struct lc_hash_ctx * | hash_ctx | ) |
Get the size of the message digest.
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
| void lc_hash_final | ( | struct lc_hash_ctx * | hash_ctx, |
| uint8_t * | digest ) |
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. |
| int lc_hash_init | ( | struct lc_hash_ctx * | hash_ctx | ) |
Initialize hash context.
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
The caller must provide an allocated hash_ctx. This can be achieved by using LC_HASH_CTX_ON_STACK or by using hash_alloc.
| 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.
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
| [in] | digestsize | Size of the requested digest. |
| void lc_hash_update | ( | struct lc_hash_ctx * | hash_ctx, |
| const uint8_t * | in, | ||
| size_t | inlen ) |
Update hash.
| [in] | hash_ctx | Reference to hash context implementation to be used to perform hash calculation with. |
| [in] | in | Buffer holding the data whose MAC shall be calculated |
| [in] | inlen | Length of the input buffer |
| 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.
| [in] | hash_ctx | Hash context to be zeroized |
| 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 |
| int lc_sponge | ( | const struct lc_hash * | hash, |
| void * | state, | ||
| unsigned int | rounds ) |
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 |
| 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.
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).| 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.
| [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).| 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.
| [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).| 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.
| [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.