Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Functions
cx_mlkem_util.c File Reference

ML-KEM utility functions (FIPS 203). More...

#include <string.h>
#include "lcx_mlkem.h"
#include "cx_mlkem_util.h"
#include "lcx_sha3.h"
Include dependency graph for cx_mlkem_util.c:

Go to the source code of this file.

Functions

void MLKEM_UTIL_hash_h (uint8_t out[CX_SHA3_256_SIZE], const uint8_t *in, size_t in_len)
 Computes the H hash function (SHA3-256) as defined in FIPS 203.
 
void MLKEM_UTIL_hash_g (uint8_t *out, const uint8_t *in, size_t in_len)
 Computes the G hash function (SHA3-512) as defined in FIPS 203.
 
void MLKEM_UTIL_hash_j (uint8_t *out, const uint8_t *in, size_t inlen)
 
void MLKEM_UTIL_prf (uint8_t *out, size_t outlen, const uint8_t *key, uint8_t nonce)
 Computes the PRF function (SHAKE256) as defined in FIPS 203.
 
void MLKEM_UTIL_xof_squeeze (uint8_t *out, size_t outlen, const uint8_t *seed, uint8_t x, uint8_t y)
 Computes the XOF function (SHAKE128) as defined in FIPS 203.
 
void MLKEM_UTIL_ct_cmov (uint8_t *dst, const uint8_t *src, size_t len, uint8_t b)
 
cx_err_t MLKEM_UTIL_check_ek (const uint8_t *ek, const MLKEM_param_info_t *p)
 Validates encapsulation key modulus (FIPS 203 §7.2).
 

Detailed Description

ML-KEM utility functions (FIPS 203).

Implements the hash functions H (SHA3-256) and G (SHA3-512), the PRF (SHAKE256), the XOF (SHAKE128) used throughout the ML-KEM implementation.

Definition in file cx_mlkem_util.c.

Function Documentation

◆ MLKEM_UTIL_check_ek()

cx_err_t MLKEM_UTIL_check_ek ( const uint8_t *  ek,
const MLKEM_param_info_t p 
)

Validates encapsulation key modulus (FIPS 203 §7.2).

Verifies that every 12-bit decoded coefficient of the public polynomial vector is in [0, q-1].

Parameters
[in]ekEncapsulation key bytes (polynomial vector portion).
[in]pML-KEM parameter set.
Returns
cx_err_t
Return values
CX_OKek is valid
CX_INVALID_PARAMETERek is not valid.

Definition at line 71 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_ct_cmov()

void MLKEM_UTIL_ct_cmov ( uint8_t *  dst,
const uint8_t *  src,
size_t  len,
uint8_t  b 
)

Definition at line 63 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_hash_g()

void MLKEM_UTIL_hash_g ( uint8_t *  out,
const uint8_t *  in,
size_t  in_len 
)

Computes the G hash function (SHA3-512) as defined in FIPS 203.

Parameters
[out]outOutput buffer of at least 64 bytes.
[in]inInput data to hash.
[in]in_lenLength of the input data in bytes.

Definition at line 35 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_hash_h()

void MLKEM_UTIL_hash_h ( uint8_t  out[CX_SHA3_256_SIZE],
const uint8_t *  in,
size_t  in_len 
)

Computes the H hash function (SHA3-256) as defined in FIPS 203.

Parameters
[out]outOutput buffer of size CX_SHA3_256_SIZE bytes.
[in]inInput data to hash.
[in]in_lenLength of the input data in bytes.

Definition at line 30 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_hash_j()

void MLKEM_UTIL_hash_j ( uint8_t *  out,
const uint8_t *  in,
size_t  inlen 
)

Definition at line 40 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_prf()

void MLKEM_UTIL_prf ( uint8_t *  out,
size_t  outlen,
const uint8_t *  key,
uint8_t  nonce 
)

Computes the PRF function (SHAKE256) as defined in FIPS 203.

Parameters
[out]outOutput buffer.
[in]outlenNumber of bytes to produce.
[in]keyInput key of MLKEM_SYMBYTES bytes.
[in]nonceSingle-byte nonce appended to the key.

Definition at line 45 of file cx_mlkem_util.c.

◆ MLKEM_UTIL_xof_squeeze()

void MLKEM_UTIL_xof_squeeze ( uint8_t *  out,
size_t  outlen,
const uint8_t *  seed,
uint8_t  x,
uint8_t  y 
)

Computes the XOF function (SHAKE128) as defined in FIPS 203.

Parameters
[out]outOutput buffer.
[in]outlenNumber of bytes to produce.
[in]seedInput seed of MLKEM_SYMBYTES bytes.
[in]xFirst index byte appended to the seed.
[in]ySecond index byte appended to the seed.

Definition at line 54 of file cx_mlkem_util.c.