Leancrypto 0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_dilithium_44.h File Reference
#include "ext_headers.h"
#include "lc_hash.h"
#include "lc_rng.h"
#include "lc_sha3.h"
#include "lc_ed25519.h"
#include "lc_sha512.h"
+ Include dependency graph for lc_dilithium_44.h:

Go to the source code of this file.

Data Structures

struct  lc_dilithium_44_sk
 Dilithium secret key. More...
 
struct  lc_dilithium_44_pk
 Dilithium public key. More...
 
struct  lc_dilithium_44_sig
 Dilithium signature. More...
 
struct  lc_dilithium_ctx
 Dilithium stream context. More...
 
struct  lc_dilithium_44_ed25519_sk
 Dilithium secret key. More...
 
struct  lc_dilithium_44_ed25519_pk
 Dilithium public key. More...
 
struct  lc_dilithium_44_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_44_ctx_zero (struct lc_dilithium_ctx *ctx)
 Zeroize Dilithium context allocated with LC_DILITHIUM_CTX_ON_STACK lc_dilithium_ed25519_alloc.
 
int lc_dilithium_44_ctx_alloc (struct lc_dilithium_ctx **ctx)
 Allocate Dilithium stream context on heap.
 
void lc_dilithium_44_ctx_zero_free (struct lc_dilithium_ctx *ctx)
 Zeroize and free Dilithium stream context.
 
static LC_PURE unsigned int lc_dilithium_44_sk_size (void)
 Return the size of the Dilithium secret key.
 
static LC_PURE unsigned int lc_dilithium_44_pk_size (void)
 Return the size of the Dilithium public key.
 
static LC_PURE unsigned int lc_dilithium_44_sig_size (void)
 Return the size of the Dilithium signature.
 
int lc_dilithium_44_keypair (struct lc_dilithium_44_pk *pk, struct lc_dilithium_44_sk *sk, struct lc_rng_ctx *rng_ctx)
 Generates Dilithium public and private key.
 
int lc_dilithium_44_keypair_from_seed (struct lc_dilithium_44_pk *pk, struct lc_dilithium_44_sk *sk, const uint8_t *seed, size_t seedlen)
 Generates Dilithium public and private key from a given seed.
 
int lc_dilithium_44_sign (struct lc_dilithium_44_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_44_sk *sk, struct lc_rng_ctx *rng_ctx)
 Computes signature in one shot.
 
int lc_dilithium_44_sign_init (struct lc_dilithium_ctx *ctx, const struct lc_dilithium_44_sk *sk)
 Initializes a signature operation.
 
int lc_dilithium_44_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_44_sign_final (struct lc_dilithium_44_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_44_sk *sk, struct lc_rng_ctx *rng_ctx)
 Computes signature.
 
int lc_dilithium_44_verify (const struct lc_dilithium_44_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_44_pk *pk)
 Verifies signature in one shot.
 
int lc_dilithium_44_verify_init (struct lc_dilithium_ctx *ctx, const struct lc_dilithium_44_pk *pk)
 Initializes a signature verification operation.
 
int lc_dilithium_44_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_44_verify_final (const struct lc_dilithium_44_sig *sig, struct lc_dilithium_ctx *ctx, const struct lc_dilithium_44_pk *pk)
 Verifies signature.
 
static void lc_dilithium_44_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_44_ed25519_ctx_alloc (struct lc_dilithium_ed25519_ctx **ctx)
 Allocate Dilithium-ED25519 stream context on heap.
 
void lc_dilithium_44_ed25519_ctx_zero_free (struct lc_dilithium_ed25519_ctx *ctx)
 Zeroize and free Dilithium-ED25519 stream context.
 
int lc_dilithium_44_ed25519_keypair (struct lc_dilithium_44_ed25519_pk *pk, struct lc_dilithium_44_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
 Generates Dilithium public and private key.
 
int lc_dilithium_44_ed25519_sign (struct lc_dilithium_44_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_44_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
 Computes signature in one shot.
 
int lc_dilithium_44_ed25519_sign_init (struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_44_ed25519_sk *sk)
 
int lc_dilithium_44_ed25519_sign_update (struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen)
 
int lc_dilithium_44_ed25519_sign_final (struct lc_dilithium_44_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_44_ed25519_sk *sk, struct lc_rng_ctx *rng_ctx)
 
int lc_dilithium_44_ed25519_verify (const struct lc_dilithium_44_ed25519_sig *sig, const uint8_t *m, size_t mlen, const struct lc_dilithium_44_ed25519_pk *pk)
 Verifies signature in one shot.
 
int lc_dilithium_44_ed25519_verify_init (struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_44_ed25519_pk *pk)
 
int lc_dilithium_44_ed25519_verify_update (struct lc_dilithium_ed25519_ctx *ctx, const uint8_t *m, size_t mlen)
 
int lc_dilithium_44_ed25519_verify_final (const struct lc_dilithium_44_ed25519_sig *sig, struct lc_dilithium_ed25519_ctx *ctx, const struct lc_dilithium_44_ed25519_pk *pk)
 

Data Structure Documentation

◆ lc_dilithium_44_sk

struct lc_dilithium_44_sk

Dilithium secret key.

Definition at line 147 of file lc_dilithium_44.h.

Data Fields
uint8_t sk[LC_DILITHIUM_SECRETKEYBYTES]

◆ lc_dilithium_44_pk

struct lc_dilithium_44_pk

Dilithium public key.

Definition at line 154 of file lc_dilithium_44.h.

Data Fields
uint8_t pk[LC_DILITHIUM_PUBLICKEYBYTES]

◆ lc_dilithium_44_sig

struct lc_dilithium_44_sig

Dilithium signature.

Definition at line 161 of file lc_dilithium_44.h.

Data Fields
uint8_t sig[LC_DILITHIUM_CRYPTO_BYTES]

◆ lc_dilithium_ctx

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)]

◆ lc_dilithium_44_ed25519_sk

struct lc_dilithium_44_ed25519_sk

Dilithium secret key.

Definition at line 439 of file lc_dilithium_44.h.

+ Collaboration diagram for lc_dilithium_44_ed25519_sk:
Data Fields
struct lc_dilithium_44_sk sk
struct lc_ed25519_sk sk_ed25519

◆ lc_dilithium_44_ed25519_pk

struct lc_dilithium_44_ed25519_pk

Dilithium public key.

Definition at line 447 of file lc_dilithium_44.h.

+ Collaboration diagram for lc_dilithium_44_ed25519_pk:
Data Fields
struct lc_dilithium_44_pk pk
struct lc_ed25519_pk pk_ed25519

◆ lc_dilithium_44_ed25519_sig

struct lc_dilithium_44_ed25519_sig

Dilithium signature.

Definition at line 455 of file lc_dilithium_44.h.

+ Collaboration diagram for lc_dilithium_44_ed25519_sig:
Data Fields
struct lc_dilithium_44_sig sig
struct lc_ed25519_sig sig_ed25519

◆ lc_dilithium_ed25519_ctx

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.

+ Collaboration diagram for lc_dilithium_ed25519_ctx:
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]

Macro Definition Documentation

◆ LC_DILITHIUM_CTX_ON_STACK

#define LC_DILITHIUM_CTX_ON_STACK ( name)
Value:
_Pragma("GCC diagnostic push") _Pragma( \
"GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
name##_ctx_buf, LC_DILITHIUM_ED25519_CTX_SIZE, \
LC_HASH_COMMON_ALIGNMENT); \
struct lc_dilithium_ctx *name = \
(struct lc_dilithium_ctx *)name##_ctx_buf; \
LC_SHAKE_256_CTX((&(name)->dilithium_hash_ctx)); \
_Pragma("GCC diagnostic pop")
#define LC_ALIGNED_BUFFER(name, size, alignment)
Allocate aligned stack memory.

Allocate stack memory for the Dilithium-ED25519 stream context.

Parameters
[in]nameName of the stack variable

Definition at line 191 of file lc_dilithium_44.h.

◆ LC_DILITHIUM_ED25519_CTX_ON_STACK

#define LC_DILITHIUM_ED25519_CTX_ON_STACK ( name)
Value:
_Pragma("GCC diagnostic push") _Pragma( \
"GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
name##_ctx_buf, LC_DILITHIUM_ED25519_CTX_SIZE, \
LC_HASH_COMMON_ALIGNMENT); \
struct lc_dilithium_ed25519_ctx *name = \
(struct lc_dilithium_ed25519_ctx *)name##_ctx_buf; \
LC_SHAKE_256_CTX((&(name)->dilithium_ctx.dilithium_hash_ctx)); \
LC_SHA512_CTX((&(name)->ed25519_hash_ctx)); \
_Pragma("GCC diagnostic pop")

Allocate stack memory for the Dilithium-ED25519 stream context.

Parameters
[in]nameName of the stack variable

Definition at line 487 of file lc_dilithium_44.h.

◆ LC_DILITHIUM_ED25519_SIG

#define LC_DILITHIUM_ED25519_SIG

Definition at line 430 of file lc_dilithium_44.h.

Function Documentation

◆ lc_dilithium_44_ctx_alloc()

int lc_dilithium_44_ctx_alloc ( struct lc_dilithium_ctx ** ctx)

Allocate Dilithium stream context on heap.

Parameters
[out]ctxAllocated Dilithium stream context
Returns
: 0 on success, < 0 on error

◆ lc_dilithium_44_ctx_zero()

static void lc_dilithium_44_ctx_zero ( struct lc_dilithium_ctx * ctx)
inlinestatic

Zeroize Dilithium context allocated with LC_DILITHIUM_CTX_ON_STACK lc_dilithium_ed25519_alloc.

Parameters
[in]ctxDilithium context to be zeroized

Definition at line 209 of file lc_dilithium_44.h.

◆ lc_dilithium_44_ctx_zero_free()

void lc_dilithium_44_ctx_zero_free ( struct lc_dilithium_ctx * ctx)

Zeroize and free Dilithium stream context.

Parameters
[in]ctxDilithium stream context to be zeroized and freed

◆ lc_dilithium_44_ed25519_ctx_alloc()

int lc_dilithium_44_ed25519_ctx_alloc ( struct lc_dilithium_ed25519_ctx ** ctx)

Allocate Dilithium-ED25519 stream context on heap.

Parameters
[out]ctxAllocated Dilithium-ED25519 stream context
Returns
: 0 on success, < 0 on error

◆ lc_dilithium_44_ed25519_ctx_zero()

static void lc_dilithium_44_ed25519_ctx_zero ( struct lc_dilithium_ed25519_ctx * ctx)
inlinestatic

Zeroize Dilithium-ED25519 context allocated with LC_DILITHIUM_ED25519_CTX_ON_STACK lc_dilithium_ed25519_alloc.

Parameters
[in]ctxDilithium-ED25519 context to be zeroized

Definition at line 506 of file lc_dilithium_44.h.

◆ lc_dilithium_44_ed25519_ctx_zero_free()

void lc_dilithium_44_ed25519_ctx_zero_free ( struct lc_dilithium_ed25519_ctx * ctx)

Zeroize and free Dilithium-ED25519 stream context.

Parameters
[in]ctxDilithium-ED25519 stream context to be zeroized and freed

◆ lc_dilithium_44_ed25519_keypair()

int lc_dilithium_44_ed25519_keypair ( struct lc_dilithium_44_ed25519_pk * pk,
struct lc_dilithium_44_ed25519_sk * sk,
struct lc_rng_ctx * rng_ctx )

Generates Dilithium public and private key.

Parameters
[out]pkpointer to allocated output public key
[out]skpointer to allocated output private key
[in]rng_ctxpointer to seeded random number generator context
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_ed25519_sign()

int lc_dilithium_44_ed25519_sign ( struct lc_dilithium_44_ed25519_sig * sig,
const uint8_t * m,
size_t mlen,
const struct lc_dilithium_44_ed25519_sk * sk,
struct lc_rng_ctx * rng_ctx )

Computes signature in one shot.

Parameters
[out]sigpointer to output signature
[in]mpointer to message to be signed
[in]mlenlength of message
[in]skpointer to bit-packed secret key
[in]rng_ctxpointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing.
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_ed25519_sign_final()

int lc_dilithium_44_ed25519_sign_final ( struct lc_dilithium_44_ed25519_sig * sig,
struct lc_dilithium_ed25519_ctx * ctx,
const struct lc_dilithium_44_ed25519_sk * sk,
struct lc_rng_ctx * rng_ctx )

◆ lc_dilithium_44_ed25519_sign_init()

int lc_dilithium_44_ed25519_sign_init ( struct lc_dilithium_ed25519_ctx * ctx,
const struct lc_dilithium_44_ed25519_sk * sk )

◆ lc_dilithium_44_ed25519_sign_update()

int lc_dilithium_44_ed25519_sign_update ( struct lc_dilithium_ed25519_ctx * ctx,
const uint8_t * m,
size_t mlen )

◆ lc_dilithium_44_ed25519_verify()

int lc_dilithium_44_ed25519_verify ( const struct lc_dilithium_44_ed25519_sig * sig,
const uint8_t * m,
size_t mlen,
const struct lc_dilithium_44_ed25519_pk * pk )

Verifies signature in one shot.

Parameters
[in]sigpointer to input signature
[in]mpointer to message
[in]mlenlength of message
[in]pkpointer to bit-packed public key
Returns
0 if signature could be verified correctly and -EBADMSG when signature cannot be verified, < 0 on other errors

◆ lc_dilithium_44_ed25519_verify_final()

int lc_dilithium_44_ed25519_verify_final ( const struct lc_dilithium_44_ed25519_sig * sig,
struct lc_dilithium_ed25519_ctx * ctx,
const struct lc_dilithium_44_ed25519_pk * pk )

◆ lc_dilithium_44_ed25519_verify_init()

int lc_dilithium_44_ed25519_verify_init ( struct lc_dilithium_ed25519_ctx * ctx,
const struct lc_dilithium_44_ed25519_pk * pk )

◆ lc_dilithium_44_ed25519_verify_update()

int lc_dilithium_44_ed25519_verify_update ( struct lc_dilithium_ed25519_ctx * ctx,
const uint8_t * m,
size_t mlen )

◆ lc_dilithium_44_keypair()

int lc_dilithium_44_keypair ( struct lc_dilithium_44_pk * pk,
struct lc_dilithium_44_sk * sk,
struct lc_rng_ctx * rng_ctx )

Generates Dilithium public and private key.

Parameters
[out]pkpointer to allocated output public key
[out]skpointer to allocated output private key
[in]rng_ctxpointer to seeded random number generator context
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_keypair_from_seed()

int lc_dilithium_44_keypair_from_seed ( struct lc_dilithium_44_pk * pk,
struct lc_dilithium_44_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.

Parameters
[out]pkpointer to allocated output public key
[out]skpointer to allocated output private key
[in]seedbuffer with the seed data which must be exactly 32 bytes in size
[in]seedlenlength of the seed buffer
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_pk_size()

static LC_PURE unsigned int lc_dilithium_44_pk_size ( void )
inlinestatic

Return the size of the Dilithium public key.

Definition at line 245 of file lc_dilithium_44.h.

◆ lc_dilithium_44_sig_size()

static LC_PURE unsigned int lc_dilithium_44_sig_size ( void )
inlinestatic

Return the size of the Dilithium signature.

Definition at line 254 of file lc_dilithium_44.h.

◆ lc_dilithium_44_sign()

int lc_dilithium_44_sign ( struct lc_dilithium_44_sig * sig,
const uint8_t * m,
size_t mlen,
const struct lc_dilithium_44_sk * sk,
struct lc_rng_ctx * rng_ctx )

Computes signature in one shot.

Parameters
[out]sigpointer to output signature
[in]mpointer to message to be signed
[in]mlenlength of message
[in]skpointer to bit-packed secret key
[in]rng_ctxpointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing.
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_sign_final()

int lc_dilithium_44_sign_final ( struct lc_dilithium_44_sig * sig,
struct lc_dilithium_ctx * ctx,
const struct lc_dilithium_44_sk * sk,
struct lc_rng_ctx * rng_ctx )

Computes signature.

Parameters
[out]sigpointer to output signature
[in]ctxpointer to Dilithium context that was initialized with lc_dilithium_sign_init and filled with lc_dilithium_sign_update
[in]skpointer to bit-packed secret key
[in]rng_ctxpointer to seeded random number generator context - when pointer is non-NULL, perform a randomized signing. Otherwise use deterministic signing.
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_sign_init()

int lc_dilithium_44_sign_init ( struct lc_dilithium_ctx * ctx,
const struct lc_dilithium_44_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.

Parameters
[in,out]ctxpointer to an allocated Dilithium context
[in]skpointer to bit-packed secret key
Returns
0 (success) or < 0 on error; -EOPNOTSUPP is returned if a different hash than lc_shake256 is used.

◆ lc_dilithium_44_sign_update()

int lc_dilithium_44_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.

Parameters
[in]ctxpointer to Dilithium context that was initialized with lc_dilithium_sign_init
[in]mpointer to message to be signed
[in]mlenlength of message
Returns
0 (success) or < 0 on error

◆ lc_dilithium_44_sk_size()

static LC_PURE unsigned int lc_dilithium_44_sk_size ( void )
inlinestatic

Return the size of the Dilithium secret key.

Definition at line 236 of file lc_dilithium_44.h.

◆ lc_dilithium_44_verify()

int lc_dilithium_44_verify ( const struct lc_dilithium_44_sig * sig,
const uint8_t * m,
size_t mlen,
const struct lc_dilithium_44_pk * pk )

Verifies signature in one shot.

Parameters
[in]sigpointer to input signature
[in]mpointer to message
[in]mlenlength of message
[in]pkpointer to bit-packed public key
Returns
0 if signature could be verified correctly and -EBADMSG when signature cannot be verified, < 0 on other errors

◆ lc_dilithium_44_verify_final()

int lc_dilithium_44_verify_final ( const struct lc_dilithium_44_sig * sig,
struct lc_dilithium_ctx * ctx,
const struct lc_dilithium_44_pk * pk )

Verifies signature.

Parameters
[in]sigpointer to output signature
[in]ctxpointer to Dilithium context that was initialized with lc_dilithium_sign_init and filled with lc_dilithium_sign_update
[in]pkpointer to bit-packed public key
Returns
0 if signature could be verified correctly and -EBADMSG when signature cannot be verified, < 0 on other errors

◆ lc_dilithium_44_verify_init()

int lc_dilithium_44_verify_init ( struct lc_dilithium_ctx * ctx,
const struct lc_dilithium_44_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.

Parameters
[in,out]ctxpointer to an allocated Dilithium context
[in]pkpointer to bit-packed public key
Returns
0 (success) or < 0 on error; -EOPNOTSUPP is returned if a different hash than lc_shake256 is used.

◆ lc_dilithium_44_verify_update()

int lc_dilithium_44_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.

Parameters
[in,out]ctxpointer to Dilithium context that was initialized with lc_dilithium_sign_init
[in]mpointer to message to be signed
[in]mlenlength of message
Returns
0 (success) or < 0 on error