Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Macros | Functions
cx_mlkem_sample.c File Reference

ML-KEM sampling routines (FIPS 203). More...

#include <string.h>
#include "cx_mlkem_poly.h"
#include "cx_mlkem_util.h"
#include "cx_mlkem_sample.h"
Include dependency graph for cx_mlkem_sample.c:

Go to the source code of this file.

Macros

#define XOF_BLOCKBYTES   168U
 
#define REJ_UNIFORM_NBLOCKS   5U
 
#define REJ_UNIFORM_BUFLEN   (REJ_UNIFORM_NBLOCKS * XOF_BLOCKBYTES)
 
#define REJ_UNIFORM_BUFLEN_EXT   (REJ_UNIFORM_BUFLEN + (XOF_BLOCKBYTES * 3U))
 

Functions

static uint32_t load32_le (const uint8_t *x)
 
static uint32_t load24_le (const uint8_t *x)
 
void MLKEM_SAMPLE_cbd2 (poly *r, const uint8_t *buf)
 Samples a polynomial using the centered binomial distribution with eta=2.
 
void MLKEM_SAMPLE_cbd3 (poly *r, const uint8_t *buf)
 Samples a polynomial using the centered binomial distribution with eta=3.
 
void MLKEM_SAMPLE_getnoise (poly *r, const uint8_t *seed, uint8_t nonce, uint8_t eta)
 Samples a noise polynomial using PRF and CBD.
 
void MLKEM_SAMPLE_rej_uniform (poly *r, const uint8_t *seed, uint8_t x, uint8_t y)
 Samples a polynomial using rejection sampling from a uniform distribution.
 

Detailed Description

ML-KEM sampling routines (FIPS 203).

Implements rejection sampling (rej_uniform), centered binomial distribution sampling (CBD eta=2 and eta=3), and noise generation for ML-KEM.

Definition in file cx_mlkem_sample.c.

Macro Definition Documentation

◆ REJ_UNIFORM_BUFLEN

#define REJ_UNIFORM_BUFLEN   (REJ_UNIFORM_NBLOCKS * XOF_BLOCKBYTES)

Definition at line 36 of file cx_mlkem_sample.c.

◆ REJ_UNIFORM_BUFLEN_EXT

#define REJ_UNIFORM_BUFLEN_EXT   (REJ_UNIFORM_BUFLEN + (XOF_BLOCKBYTES * 3U))

Definition at line 98 of file cx_mlkem_sample.c.

◆ REJ_UNIFORM_NBLOCKS

#define REJ_UNIFORM_NBLOCKS   5U

Definition at line 35 of file cx_mlkem_sample.c.

◆ XOF_BLOCKBYTES

#define XOF_BLOCKBYTES   168U

Definition at line 34 of file cx_mlkem_sample.c.

Function Documentation

◆ load24_le()

static uint32_t load24_le ( const uint8_t *  x)
static

Definition at line 45 of file cx_mlkem_sample.c.

◆ load32_le()

static uint32_t load32_le ( const uint8_t *  x)
static

Definition at line 39 of file cx_mlkem_sample.c.

◆ MLKEM_SAMPLE_cbd2()

void MLKEM_SAMPLE_cbd2 ( poly r,
const uint8_t *  buf 
)

Samples a polynomial using the centered binomial distribution with eta=2.

Parameters
[out]rOutput polynomial.
[in]bufInput byte buffer of 2 * MLKEM_N / 4 bytes.

Definition at line 50 of file cx_mlkem_sample.c.

◆ MLKEM_SAMPLE_cbd3()

void MLKEM_SAMPLE_cbd3 ( poly r,
const uint8_t *  buf 
)

Samples a polynomial using the centered binomial distribution with eta=3.

Parameters
[out]rOutput polynomial.
[in]bufInput byte buffer of 3 * MLKEM_N / 4 bytes.

Definition at line 65 of file cx_mlkem_sample.c.

◆ MLKEM_SAMPLE_getnoise()

void MLKEM_SAMPLE_getnoise ( poly r,
const uint8_t *  seed,
uint8_t  nonce,
uint8_t  eta 
)

Samples a noise polynomial using PRF and CBD.

Parameters
[out]rOutput polynomial.
[in]seedSeed of MLKEM_SYMBYTES bytes.
[in]nonceNonce byte.
[in]etaCBD parameter (2 or 3).

Definition at line 81 of file cx_mlkem_sample.c.

◆ MLKEM_SAMPLE_rej_uniform()

void MLKEM_SAMPLE_rej_uniform ( poly r,
const uint8_t *  seed,
uint8_t  x,
uint8_t  y 
)

Samples a polynomial using rejection sampling from a uniform distribution.

Parameters
[out]rOutput polynomial with coefficients in [0, q-1].
[in]seedSeed of MLKEM_SYMBYTES bytes.
[in]xFirst index byte for the XOF.
[in]ySecond index byte for the XOF.

Definition at line 100 of file cx_mlkem_sample.c.