|
Leancrypto 1.6.0
Post-Quantum Cryptographic Library
|
#include "ext_headers.h"#include "lc_ascon_hash.h"#include "lc_hash.h"#include "lc_rng.h"#include "lc_sha3.h"Go to the source code of this file.
Data Structures | |
| struct | lc_sphincs_shake_128s_sk |
| Sphincs secret key. More... | |
| struct | lc_sphincs_shake_128s_pk |
| Sphincs public key. More... | |
| struct | lc_sphincs_shake_128s_sig |
| Sphincs signature. More... | |
| struct | lc_sphincs_ctx |
Macros | |
| #define | LC_SPHINCS_CTX_ON_STACK(name) |
| Allocate stack memory for the Sphincs stream context or additional parameter relevant for the signature operation. | |
Functions | |
| int | lc_sphincs_shake_128s_ctx_alloc (struct lc_sphincs_ctx **ctx) |
| Allocate Sphincs stream context on heap. | |
| void | lc_sphincs_shake_128s_ctx_zero_free (struct lc_sphincs_ctx *ctx) |
| Zeroize and free Sphincs stream context. | |
| static void | lc_sphincs_shake_128s_ctx_zero (struct lc_sphincs_ctx *ctx) |
| Zeroize Sphincs context allocated with LC_SPHINCS_CTX_ON_STACK or lc_sphincs_ctx_alloc. | |
| static LC_PURE unsigned int | lc_sphincs_shake_128s_sk_size (void) |
| Return the size of the Sphincs secret key. | |
| static LC_PURE unsigned int | lc_sphincs_shake_128s_pk_size (void) |
| Return the size of the Sphincs public key. | |
| static LC_PURE unsigned int | lc_sphincs_shake_128s_sig_size (void) |
| Return the size of the Sphincs signature. | |
| int | lc_sphincs_shake_128s_keypair (struct lc_sphincs_shake_128s_pk *pk, struct lc_sphincs_shake_128s_sk *sk, struct lc_rng_ctx *rng_ctx) |
| Generates Sphincs public and private key. | |
| int | lc_sphincs_shake_128s_keypair_from_seed (struct lc_sphincs_shake_128s_pk *pk, struct lc_sphincs_shake_128s_sk *sk, const uint8_t *seed, size_t seedlen) |
| Generates Sphincs public and private key from a given seed. | |
| int | lc_sphincs_shake_128s_sign (struct lc_sphincs_shake_128s_sig *sig, const uint8_t *m, size_t mlen, const struct lc_sphincs_shake_128s_sk *sk, struct lc_rng_ctx *rng_ctx) |
| Computes SLH-DSA signature in one shot. | |
| int | lc_sphincs_shake_128s_sign_ctx (struct lc_sphincs_shake_128s_sig *sig, struct lc_sphincs_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_sphincs_shake_128s_sk *sk, struct lc_rng_ctx *rng_ctx) |
| Computes signature with Sphincs context in one shot. | |
| int | lc_sphincs_shake_128s_sign_init (struct lc_sphincs_ctx *ctx, const struct lc_sphincs_shake_128s_sk *sk) |
| Initializes a signature operation. | |
| int | lc_sphincs_shake_128s_sign_update (struct lc_sphincs_ctx *ctx, const uint8_t *m, size_t mlen) |
| Add more data to an already initialized signature state. | |
| int | lc_sphincs_shake_128s_sign_final (struct lc_sphincs_shake_128s_sig *sig, struct lc_sphincs_ctx *ctx, const struct lc_sphincs_shake_128s_sk *sk, struct lc_rng_ctx *rng_ctx) |
| Computes signature. | |
| int | lc_sphincs_shake_128s_verify (const struct lc_sphincs_shake_128s_sig *sig, const uint8_t *m, size_t mlen, const struct lc_sphincs_shake_128s_pk *pk) |
| Verifies SLH-DSA signature in one shot. | |
| int | lc_sphincs_shake_128s_verify_ctx (const struct lc_sphincs_shake_128s_sig *sig, struct lc_sphincs_ctx *ctx, const uint8_t *m, size_t mlen, const struct lc_sphincs_shake_128s_pk *pk) |
| Verifies signature with Sphincs context in one shot. | |
| int | lc_sphincs_shake_128s_verify_init (struct lc_sphincs_ctx *ctx, const struct lc_sphincs_shake_128s_pk *pk) |
| Initializes a signature verification operation. | |
| int | lc_sphincs_shake_128s_verify_update (struct lc_sphincs_ctx *ctx, const uint8_t *m, size_t mlen) |
| Add more data to an already initialized signature state. | |
| int | lc_sphincs_shake_128s_verify_final (const struct lc_sphincs_shake_128s_sig *sig, struct lc_sphincs_ctx *ctx, const struct lc_sphincs_shake_128s_pk *pk) |
| Verifies signature. | |
| struct lc_sphincs_shake_128s_sk |
Sphincs secret key.
Definition at line 526 of file lc_sphincs_shake_128s.h.
| Data Fields | ||
|---|---|---|
| uint8_t | pk[2 *LC_SPX_N] | |
| uint8_t | sk_prf[LC_SPX_N] | |
| uint8_t | sk_seed[LC_SPX_N] | |
| struct lc_sphincs_shake_128s_pk |
Sphincs public key.
Definition at line 535 of file lc_sphincs_shake_128s.h.
| Data Fields | ||
|---|---|---|
| uint8_t | pk[2 *LC_SPX_N] | |
| struct lc_sphincs_shake_128s_sig |
Sphincs signature.
Definition at line 542 of file lc_sphincs_shake_128s.h.
| Data Fields | ||
|---|---|---|
| uint8_t | r[LC_SPX_N] | |
| uint8_t | sigfors[LC_SPX_FORS_BYTES] | |
| uint8_t | sight[LC_SPX_D *LC_SPX_WOTS_BYTES+LC_SPX_FULL_HEIGHT *LC_SPX_N] | |
| struct lc_sphincs_ctx |
Definition at line 550 of file lc_sphincs_shake_128f.h.
| Data Fields | ||
|---|---|---|
| uint8_t | shake_state[LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE)] | State memory of the hash context used internally to the library - it should not be touched by the user. |
| unsigned int | slh_dsa_internal:1 |
When set to true, only the SLH-DSA.Sign_internal or SLH-DSA.Verify_internal are performed (see FIPS 205 chapter 6). Otherwise the SLH-DSA.Sign / SLH-DSA.Verify (see FIPS chapter 5) is applied.
|
| struct lc_hash_ctx | sphincs_hash_ctx | Hash context used internally to the library - it should not be touched by the user. |
| const struct lc_hash * | sphincs_prehash_type |
When using HashSLH-DSA, set the hash reference used for the hash operation. Allowed values are lc_sha256, lc_sha512, lc_sha3_256, lc_sha3_384, lc_sha3_512, lc_shake128 and lc_shake256. Note, the actual message digest operation can be performed external to leancrypto. This parameter only shall indicate the used hash operation.
|
| const uint8_t * | userctx |
buffer with a caller-specified context string
|
| size_t | userctxlen |
length of the user context (allowed range between 0 and 255 bytes)
|
| #define LC_SPHINCS_CTX_ON_STACK | ( | name | ) |
Allocate stack memory for the Sphincs stream context or additional parameter relevant for the signature operation.
| [in] | name | Name of the stack variable |
Definition at line 624 of file lc_sphincs_shake_128s.h.
| int lc_sphincs_shake_128s_ctx_alloc | ( | struct lc_sphincs_ctx ** | ctx | ) |
Allocate Sphincs stream context on heap.
| [out] | ctx | Allocated Sphincs stream context |
|
inlinestatic |
Zeroize Sphincs context allocated with LC_SPHINCS_CTX_ON_STACK or lc_sphincs_ctx_alloc.
| [in] | ctx | Sphincs context to be zeroized |
Definition at line 658 of file lc_sphincs_shake_128s.h.
| void lc_sphincs_shake_128s_ctx_zero_free | ( | struct lc_sphincs_ctx * | ctx | ) |
Zeroize and free Sphincs stream context.
| [in] | ctx | Sphincs stream context to be zeroized and freed |
| int lc_sphincs_shake_128s_keypair | ( | struct lc_sphincs_shake_128s_pk * | pk, |
| struct lc_sphincs_shake_128s_sk * | sk, | ||
| struct lc_rng_ctx * | rng_ctx ) |
Generates Sphincs public and private key.
| [out] | pk | pointer to allocated output public key |
| [out] | sk | pointer to allocated output private key |
| [in] | rng_ctx | pointer to seeded random number generator context |
| int lc_sphincs_shake_128s_keypair_from_seed | ( | struct lc_sphincs_shake_128s_pk * | pk, |
| struct lc_sphincs_shake_128s_sk * | sk, | ||
| const uint8_t * | seed, | ||
| size_t | seedlen ) |
Generates Sphincs public and private key from a given seed.
The idea of the function is the allowance of FIPS 205 to maintain the seed used to generate a key pair in lieu of maintaining a private key or the key pair (which used much more memory). The seed must be treated equally sensitive as a private key.
The seed is generated by simply obtaining 32 bytes from a properly seeded DRNG, i.e. the same way as a symmetric key would be generated.
| [out] | pk | pointer to allocated output public key |
| [out] | sk | pointer to allocated output private key |
| [in] | seed | buffer with the seed data which must be exactly 32 bytes in size |
| [in] | seedlen | length of the seed buffer |
|
inlinestatic |
Return the size of the Sphincs public key.
Definition at line 681 of file lc_sphincs_shake_128s.h.
|
inlinestatic |
Return the size of the Sphincs signature.
Definition at line 690 of file lc_sphincs_shake_128s.h.
| int lc_sphincs_shake_128s_sign | ( | struct lc_sphincs_shake_128s_sig * | sig, |
| const uint8_t * | m, | ||
| size_t | mlen, | ||
| const struct lc_sphincs_shake_128s_sk * | sk, | ||
| struct lc_rng_ctx * | rng_ctx ) |
Computes SLH-DSA signature in one shot.
| [out] | sig | pointer to output signature |
| [in] | m | pointer to message to be signed |
| [in] | mlen | length of message |
| [in] | sk | pointer to bit-packed secret key |
| [in] | rng_ctx | pointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing. |
| int lc_sphincs_shake_128s_sign_ctx | ( | struct lc_sphincs_shake_128s_sig * | sig, |
| struct lc_sphincs_ctx * | ctx, | ||
| const uint8_t * | m, | ||
| size_t | mlen, | ||
| const struct lc_sphincs_shake_128s_sk * | sk, | ||
| struct lc_rng_ctx * | rng_ctx ) |
Computes signature with Sphincs context in one shot.
This API allows the caller to provide an arbitrary context buffer which is hashed together with the message to form the message digest to be signed.
| [out] | sig | pointer to output signature |
| [in] | ctx | reference to the allocated Sphincs context handle |
| [in] | m | pointer to message to be signed |
| [in] | mlen | length of message |
| [in] | sk | pointer to bit-packed secret key |
| [in] | rng_ctx | pointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing. |
| int lc_sphincs_shake_128s_sign_final | ( | struct lc_sphincs_shake_128s_sig * | sig, |
| struct lc_sphincs_ctx * | ctx, | ||
| const struct lc_sphincs_shake_128s_sk * | sk, | ||
| struct lc_rng_ctx * | rng_ctx ) |
Computes signature.
| [out] | sig | pointer to output signature |
| [in] | ctx | pointer to Sphincs context that was initialized with lc_sphincs_sign_init and filled with lc_sphincs_sign_update |
| [in] | sk | pointer to bit-packed secret key |
| [in] | rng_ctx | pointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing. |
| int lc_sphincs_shake_128s_sign_init | ( | struct lc_sphincs_ctx * | ctx, |
| const struct lc_sphincs_shake_128s_sk * | sk ) |
Initializes a signature operation.
This call is intended to support messages that are located in non-contiguous places and even becomes available at different times. This call is to be used together with the lc_sphincs_sign_update and lc_sphincs_sign_final.
NOTE: The use of the init/update/final API implies that automatically HashSLH-DSA is used. This is due to the fact that SLH-DSA cannot be used in the init/update/final mode due to mathematical issues. By default, the following hashes are used which are compliant to the requirement that the message digest must be twice as large as the parameter n:
Sphincs 256s/f: SHA3-512 Sphincs 192s/f: SHA3-384 Sphincs 128s/f: SHA3-256
It is permissible for the caller to select other message digest algorithms by using setting the requested algorithm in the ctx using the lc_sphincs_ctx_hash method before this init function is used.
| [in,out] | ctx | pointer to an allocated Sphincs context |
| [in] | sk | pointer to bit-packed secret key |
| int lc_sphincs_shake_128s_sign_update | ( | struct lc_sphincs_ctx * | ctx, |
| const uint8_t * | m, | ||
| size_t | mlen ) |
Add more data to an already initialized signature state.
This call is intended to support messages that are located in non-contiguous places and even becomes available at different times. This call is to be used together with the lc_sphincs_sign_init and lc_sphincs_sign_final.
| [in] | ctx | pointer to Sphincs context that was initialized with lc_sphincs_sign_init |
| [in] | m | pointer to message to be signed |
| [in] | mlen | length of message |
|
inlinestatic |
Return the size of the Sphincs secret key.
Definition at line 672 of file lc_sphincs_shake_128s.h.
| int lc_sphincs_shake_128s_verify | ( | const struct lc_sphincs_shake_128s_sig * | sig, |
| const uint8_t * | m, | ||
| size_t | mlen, | ||
| const struct lc_sphincs_shake_128s_pk * | pk ) |
Verifies SLH-DSA signature in one shot.
| [in] | sig | pointer to input signature |
| [in] | m | pointer to message |
| [in] | mlen | length of message |
| [in] | pk | pointer to bit-packed public key |
| int lc_sphincs_shake_128s_verify_ctx | ( | const struct lc_sphincs_shake_128s_sig * | sig, |
| struct lc_sphincs_ctx * | ctx, | ||
| const uint8_t * | m, | ||
| size_t | mlen, | ||
| const struct lc_sphincs_shake_128s_pk * | pk ) |
Verifies signature with Sphincs context in one shot.
This API allows the caller to provide an arbitrary context buffer which is hashed together with the message to form the message digest to be signed.
| [in] | sig | pointer to input signature |
| [in] | ctx | reference to the allocated Sphincs context handle |
| [in] | m | pointer to message |
| [in] | mlen | length of message |
| [in] | pk | pointer to bit-packed public key |
| int lc_sphincs_shake_128s_verify_final | ( | const struct lc_sphincs_shake_128s_sig * | sig, |
| struct lc_sphincs_ctx * | ctx, | ||
| const struct lc_sphincs_shake_128s_pk * | pk ) |
Verifies signature.
| [in] | sig | pointer to output signature |
| [in] | ctx | pointer to Sphincs context that was initialized with lc_sphincs_sign_init and filled with lc_sphincs_sign_update |
| [in] | pk | pointer to bit-packed public key |
| int lc_sphincs_shake_128s_verify_init | ( | struct lc_sphincs_ctx * | ctx, |
| const struct lc_sphincs_shake_128s_pk * | pk ) |
Initializes a signature verification operation.
This call is intended to support messages that are located in non-contiguous places and even becomes available at different times. This call is to be used together with the lc_sphincs_verify_update and lc_sphincs_verify_final.
NOTE: The use of the init/update/final API implies that automatically HashSLH-DSA is used. This is due to the fact that SLH-DSA cannot be used in the init/update/final mode due to mathematical issues. By default, the following hashes are used which are compliant to the requirement that the message digest must be twice as large as the parameter n:
Sphincs 256s/f: SHA3-512 Sphincs 192s/f: SHA3-384 Sphincs 128s/f: SHA3-256
It is permissible for the caller to select other message digest algorithms by using setting the requested algorithm in the ctx using the lc_sphincs_ctx_hash method before this init function is used.
| [in,out] | ctx | pointer to an allocated Sphincs context |
| [in] | pk | pointer to bit-packed public key |
| int lc_sphincs_shake_128s_verify_update | ( | struct lc_sphincs_ctx * | ctx, |
| const uint8_t * | m, | ||
| size_t | mlen ) |
Add more data to an already initialized signature state.
This call is intended to support messages that are located in non-contiguous places and even becomes available at different times. This call is to be used together with the lc_sphincs_verify_init and lc_sphincs_verify_final.
| [in,out] | ctx | pointer to Sphincs context that was initialized with lc_sphincs_sign_init |
| [in] | m | pointer to message to be signed |
| [in] | mlen | length of message |