Leancrypto 0.12.0
Post-Quantum Cryptographic Library
|
#include "ext_headers.h"
#include "lc_hash.h"
#include "lc_rng.h"
#include "lc_sha3.h"
#include "lc_ed25519.h"
#include "lc_sha512.h"
Go to the source code of this file.
Data Structures | |
struct | lc_dilithium_65_sk |
Dilithium secret key. More... | |
struct | lc_dilithium_65_pk |
Dilithium public key. More... | |
struct | lc_dilithium_65_sig |
Dilithium signature. More... | |
struct | lc_dilithium_ctx |
Dilithium stream context. More... | |
struct | lc_dilithium_65_ed25519_sk |
Dilithium secret key. More... | |
struct | lc_dilithium_65_ed25519_pk |
Dilithium public key. More... | |
struct | lc_dilithium_65_ed25519_sig |
Dilithium signature. More... | |
struct | lc_dilithium_ed25519_ctx |
Dilithium stream context. More... | |
Macros | |
#define | LC_DILITHIUM_CTX_ON_STACK(name) |
Allocate stack memory for the Dilithium-ED25519 stream context. | |
#define | LC_DILITHIUM_ED25519_SIG |
#define | LC_DILITHIUM_ED25519_CTX_ON_STACK(name) |
Allocate stack memory for the Dilithium-ED25519 stream context. | |
Functions | |
static void | lc_dilithium_65_ctx_zero (struct lc_dilithium_ctx *ctx) |
Zeroize Dilithium context allocated with LC_DILITHIUM_CTX_ON_STACK lc_dilithium_ed25519_alloc. | |
int | lc_dilithium_65_ctx_alloc (struct lc_dilithium_ctx **ctx) |
Allocate Dilithium stream context on heap. | |
void | lc_dilithium_65_ctx_zero_free (struct lc_dilithium_ctx *ctx) |
Zeroize and free Dilithium stream context. | |
static LC_PURE unsigned int | lc_dilithium_65_sk_size (void) |
Return the size of the Dilithium secret key. | |
static LC_PURE unsigned int | lc_dilithium_65_pk_size (void) |
Return the size of the Dilithium public key. | |
static LC_PURE unsigned int | lc_dilithium_65_sig_size (void) |
Return the size of the Dilithium signature. | |
int | lc_dilithium_65_keypair (struct lc_dilithium_65_pk *pk, struct lc_dilithium_65_sk *sk, struct lc_rng_ctx *rng_ctx) |
Generates Dilithium public and private key. | |
int | lc_dilithium_65_keypair_from_seed (struct lc_dilithium_65_pk *pk, struct lc_dilithium_65_sk *sk, const uint8_t *seed, size_t seedlen) |
Generates Dilithium public and private key from a given seed. | |
int | lc_dilithium_65_sign (struct lc_dilithium_65_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_65_sk *sk, struct lc_rng_ctx *rng_ctx) |
Computes signature in one shot. | |
int | lc_dilithium_65_sign_init (struct lc_dilithium_ctx *ctx, const struct lc_dilithium_65_sk *sk) |
Initializes a signature operation. | |
int | lc_dilithium_65_sign_update (struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen) |
Add more data to an already initialized signature state. | |
int | lc_dilithium_65_sign_final (struct lc_dilithium_65_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_65_sk *sk, struct lc_rng_ctx *rng_ctx) |
Computes signature. | |
int | lc_dilithium_65_verify (const struct lc_dilithium_65_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_65_pk *pk) |
Verifies signature in one shot. | |
int | lc_dilithium_65_verify_init (struct lc_dilithium_ctx *ctx, const struct lc_dilithium_65_pk *pk) |
Initializes a signature verification operation. | |
int | lc_dilithium_65_verify_update (struct lc_dilithium_ctx *ctx, const uint8_t *m, size_t mlen) |
Add more data to an already initialized signature state. | |
int | lc_dilithium_65_verify_final (const struct lc_dilithium_65_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_65_pk *pk) |
Verifies signature. | |
static void | lc_dilithium_65_ed25519_ctx_zero (struct lc_dilithium_ed25519_ctx *ctx) |
Zeroize Dilithium-ED25519 context allocated with LC_DILITHIUM_ED25519_CTX_ON_STACK lc_dilithium_ed25519_alloc. | |
int | lc_dilithium_65_ed25519_ctx_alloc (struct lc_dilithium_ed25519_ctx **ctx) |
Allocate Dilithium-ED25519 stream context on heap. | |
void | lc_dilithium_65_ed25519_ctx_zero_free (struct lc_dilithium_ed25519_ctx *ctx) |
Zeroize and free Dilithium-ED25519 stream context. | |
int | lc_dilithium_65_ed25519_keypair (struct lc_dilithium_65_ed25519_pk *pk, struct lc_dilithium_65_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx) |
Generates Dilithium public and private key. | |
int | lc_dilithium_65_ed25519_sign (struct lc_dilithium_65_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_65_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx) |
Computes signature in one shot. | |
int | lc_dilithium_65_ed25519_sign_init (struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_65_ed25519_sk *sk) |
int | lc_dilithium_65_ed25519_sign_update (struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen) |
int | lc_dilithium_65_ed25519_sign_final (struct lc_dilithium_65_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_65_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx) |
int | lc_dilithium_65_ed25519_verify (const struct lc_dilithium_65_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_65_ed25519_pk *pk) |
Verifies signature in one shot. | |
int | lc_dilithium_65_ed25519_verify_init (struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_65_ed25519_pk *pk) |
int | lc_dilithium_65_ed25519_verify_update (struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen) |
int | lc_dilithium_65_ed25519_verify_final (const struct lc_dilithium_65_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_65_ed25519_pk *pk) |
struct lc_dilithium_65_sk |
Dilithium secret key.
Definition at line 147 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
uint8_t | sk[LC_DILITHIUM_SECRETKEYBYTES] |
struct lc_dilithium_65_pk |
Dilithium public key.
Definition at line 154 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
uint8_t | pk[LC_DILITHIUM_PUBLICKEYBYTES] |
struct lc_dilithium_65_sig |
Dilithium signature.
Definition at line 161 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
uint8_t | sig[LC_DILITHIUM_CRYPTO_BYTES] |
struct lc_dilithium_ctx |
Dilithium stream context.
This structure is used for the init/update/final operation of the Dilithium signature operation.
Definition at line 172 of file lc_dilithium_44.h.
Data Fields | ||
---|---|---|
struct lc_hash_ctx | dilithium_hash_ctx | |
uint8_t | shake_state[LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE)] |
struct lc_dilithium_65_ed25519_sk |
Dilithium secret key.
Definition at line 439 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
struct lc_dilithium_65_sk | sk | |
struct lc_ed25519_sk | sk_ed25519 |
struct lc_dilithium_65_ed25519_pk |
Dilithium public key.
Definition at line 447 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
struct lc_dilithium_65_pk | pk | |
struct lc_ed25519_pk | pk_ed25519 |
struct lc_dilithium_65_ed25519_sig |
Dilithium signature.
Definition at line 455 of file lc_dilithium_65.h.
Data Fields | ||
---|---|---|
struct lc_dilithium_65_sig | sig | |
struct lc_ed25519_sig | sig_ed25519 |
struct lc_dilithium_ed25519_ctx |
Dilithium stream context.
This structure is used for the init/update/final operation of the Dilithium-ED25519 hybrid.
Definition at line 467 of file lc_dilithium_44.h.
Data Fields | ||
---|---|---|
struct lc_dilithium_ctx | dilithium_ctx | |
struct lc_hash_ctx | ed25519_hash_ctx | |
uint8_t | sha512_state[LC_SHA512_STATE_SIZE+LC_HASH_COMMON_ALIGNMENT] |
#define LC_DILITHIUM_CTX_ON_STACK | ( | name | ) |
Allocate stack memory for the Dilithium-ED25519 stream context.
[in] | name | Name of the stack variable |
Definition at line 191 of file lc_dilithium_65.h.
#define LC_DILITHIUM_ED25519_CTX_ON_STACK | ( | name | ) |
Allocate stack memory for the Dilithium-ED25519 stream context.
[in] | name | Name of the stack variable |
Definition at line 487 of file lc_dilithium_65.h.
#define LC_DILITHIUM_ED25519_SIG |
Definition at line 430 of file lc_dilithium_65.h.
int lc_dilithium_65_ctx_alloc | ( | struct lc_dilithium_ctx ** | ctx | ) |
Allocate Dilithium stream context on heap.
[out] | ctx | Allocated Dilithium stream context |
|
inlinestatic |
Zeroize Dilithium context allocated with LC_DILITHIUM_CTX_ON_STACK lc_dilithium_ed25519_alloc.
[in] | ctx | Dilithium context to be zeroized |
Definition at line 209 of file lc_dilithium_65.h.
void lc_dilithium_65_ctx_zero_free | ( | struct lc_dilithium_ctx * | ctx | ) |
Zeroize and free Dilithium stream context.
[in] | ctx | Dilithium stream context to be zeroized and freed |
int lc_dilithium_65_ed25519_ctx_alloc | ( | struct lc_dilithium_ed25519_ctx ** | ctx | ) |
Allocate Dilithium-ED25519 stream context on heap.
[out] | ctx | Allocated Dilithium-ED25519 stream context |
|
inlinestatic |
Zeroize Dilithium-ED25519 context allocated with LC_DILITHIUM_ED25519_CTX_ON_STACK lc_dilithium_ed25519_alloc.
[in] | ctx | Dilithium-ED25519 context to be zeroized |
Definition at line 506 of file lc_dilithium_65.h.
void lc_dilithium_65_ed25519_ctx_zero_free | ( | struct lc_dilithium_ed25519_ctx * | ctx | ) |
Zeroize and free Dilithium-ED25519 stream context.
[in] | ctx | Dilithium-ED25519 stream context to be zeroized and freed |
int lc_dilithium_65_ed25519_keypair | ( | struct lc_dilithium_65_ed25519_pk * | pk, |
struct lc_dilithium_65_ed25519_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
Generates Dilithium 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_dilithium_65_ed25519_sign | ( | struct lc_dilithium_65_ed25519_sig * | sig, |
const uint8_t * | m, | ||
size_t | mlen, | ||
const struct lc_dilithium_65_ed25519_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
Computes 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_dilithium_65_ed25519_sign_final | ( | struct lc_dilithium_65_ed25519_sig * | sig, |
struct lc_dilithium_ed25519_ctx * | ctx, | ||
const struct lc_dilithium_65_ed25519_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
int lc_dilithium_65_ed25519_sign_init | ( | struct lc_dilithium_ed25519_ctx * | ctx, |
const struct lc_dilithium_65_ed25519_sk * | sk ) |
int lc_dilithium_65_ed25519_sign_update | ( | struct lc_dilithium_ed25519_ctx * | ctx, |
const uint8_t * | m, | ||
size_t | mlen ) |
int lc_dilithium_65_ed25519_verify | ( | const struct lc_dilithium_65_ed25519_sig * | sig, |
const uint8_t * | m, | ||
size_t | mlen, | ||
const struct lc_dilithium_65_ed25519_pk * | pk ) |
Verifies 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_dilithium_65_ed25519_verify_final | ( | const struct lc_dilithium_65_ed25519_sig * | sig, |
struct lc_dilithium_ed25519_ctx * | ctx, | ||
const struct lc_dilithium_65_ed25519_pk * | pk ) |
int lc_dilithium_65_ed25519_verify_init | ( | struct lc_dilithium_ed25519_ctx * | ctx, |
const struct lc_dilithium_65_ed25519_pk * | pk ) |
int lc_dilithium_65_ed25519_verify_update | ( | struct lc_dilithium_ed25519_ctx * | ctx, |
const uint8_t * | m, | ||
size_t | mlen ) |
int lc_dilithium_65_keypair | ( | struct lc_dilithium_65_pk * | pk, |
struct lc_dilithium_65_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
Generates Dilithium 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_dilithium_65_keypair_from_seed | ( | struct lc_dilithium_65_pk * | pk, |
struct lc_dilithium_65_sk * | sk, | ||
const uint8_t * | seed, | ||
size_t | seedlen ) |
Generates Dilithium public and private key from a given seed.
The idea of the function is the allowance of FIPS 204 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 Dilithium public key.
Definition at line 245 of file lc_dilithium_65.h.
|
inlinestatic |
Return the size of the Dilithium signature.
Definition at line 254 of file lc_dilithium_65.h.
int lc_dilithium_65_sign | ( | struct lc_dilithium_65_sig * | sig, |
const uint8_t * | m, | ||
size_t | mlen, | ||
const struct lc_dilithium_65_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
Computes 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_dilithium_65_sign_final | ( | struct lc_dilithium_65_sig * | sig, |
struct lc_dilithium_ctx * | ctx, | ||
const struct lc_dilithium_65_sk * | sk, | ||
struct lc_rng_ctx * | rng_ctx ) |
Computes signature.
[out] | sig | pointer to output signature |
[in] | ctx | pointer to Dilithium context that was initialized with lc_dilithium_sign_init and filled with lc_dilithium_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_dilithium_65_sign_init | ( | struct lc_dilithium_ctx * | ctx, |
const struct lc_dilithium_65_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_dilithium_sign_update and lc_dilithium_sign_final.
[in,out] | ctx | pointer to an allocated Dilithium context |
[in] | sk | pointer to bit-packed secret key |
int lc_dilithium_65_sign_update | ( | struct lc_dilithium_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_dilithium_sign_init and lc_dilithium_sign_final.
[in] | ctx | pointer to Dilithium context that was initialized with lc_dilithium_sign_init |
[in] | m | pointer to message to be signed |
[in] | mlen | length of message |
|
inlinestatic |
Return the size of the Dilithium secret key.
Definition at line 236 of file lc_dilithium_65.h.
int lc_dilithium_65_verify | ( | const struct lc_dilithium_65_sig * | sig, |
const uint8_t * | m, | ||
size_t | mlen, | ||
const struct lc_dilithium_65_pk * | pk ) |
Verifies 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_dilithium_65_verify_final | ( | const struct lc_dilithium_65_sig * | sig, |
struct lc_dilithium_ctx * | ctx, | ||
const struct lc_dilithium_65_pk * | pk ) |
Verifies signature.
[in] | sig | pointer to output signature |
[in] | ctx | pointer to Dilithium context that was initialized with lc_dilithium_sign_init and filled with lc_dilithium_sign_update |
[in] | pk | pointer to bit-packed public key |
int lc_dilithium_65_verify_init | ( | struct lc_dilithium_ctx * | ctx, |
const struct lc_dilithium_65_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_dilithium_verify_update and lc_dilithium_verify_final.
[in,out] | ctx | pointer to an allocated Dilithium context |
[in] | pk | pointer to bit-packed public key |
int lc_dilithium_65_verify_update | ( | struct lc_dilithium_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_dilithium_verify_init and lc_dilithium_verify_final.
[in,out] | ctx | pointer to Dilithium context that was initialized with lc_dilithium_sign_init |
[in] | m | pointer to message to be signed |
[in] | mlen | length of message |