Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Functions | Variables
cx_mldsa_poly.c File Reference

ML-DSA polynomial arithmetic (FIPS 204). More...

#include "cx_mldsa_poly.h"
Include dependency graph for cx_mldsa_poly.c:

Go to the source code of this file.

Functions

int32_t MLDSA_POLY_montgomery_reduce (int64_t a)
 Montgomery reduction: given a 64-bit integer, compute a*q^{-1} mod 2^32.
 
int32_t MLDSA_POLY_reduce32 (int32_t a)
 Reduce coefficient to representative in about (-6283009, 6283009).
 
int32_t MLDSA_POLY_caddq (int32_t a)
 Adds q if input is negative.
 
void MLDSA_POLY_reduce (mldsa_poly *a)
 Applies reduce32 to all coefficients of a polynomial.
 
void MLDSA_POLY_caddq_all (mldsa_poly *a)
 Applies caddq to all coefficients of a polynomial.
 
void MLDSA_POLY_add (mldsa_poly *a, const mldsa_poly *b)
 Adds polynomial b to polynomial a in place.
 
void MLDSA_POLY_sub (mldsa_poly *a, const mldsa_poly *b)
 Subtracts polynomial b from polynomial a in place.
 
void MLDSA_POLY_shiftl (mldsa_poly *a)
 Shifts all coefficients left by D bits.
 
void MLDSA_POLY_ntt (mldsa_poly *a)
 Forward NTT in place.
 
void MLDSA_POLY_invntt_tomont (mldsa_poly *a)
 Inverse NTT and multiply by Montgomery factor.
 
void MLDSA_POLY_pointwise_montgomery (mldsa_poly *c, const mldsa_poly *a, const mldsa_poly *b, int first)
 Pointwise multiplication (Montgomery) with accumulation.
 
int MLDSA_POLY_chknorm (const mldsa_poly *a, int32_t B)
 Checks infinity norm of polynomial against bound B.
 

Variables

static const int32_t mldsa_zetas [MLDSA_N]
 

Detailed Description

ML-DSA polynomial arithmetic (FIPS 204).

Implements NTT, inverse NTT, Montgomery reduction, pointwise multiplication, and related polynomial operations for the ML-DSA ring Z_q[X]/(X^256+1).

Definition in file cx_mldsa_poly.c.

Function Documentation

◆ MLDSA_POLY_add()

void MLDSA_POLY_add ( mldsa_poly a,
const mldsa_poly b 
)

Adds polynomial b to polynomial a in place.

Parameters
[in,out]aAccumulator polynomial.
[in]bPolynomial to add.

Definition at line 104 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_caddq()

int32_t MLDSA_POLY_caddq ( int32_t  a)

Adds q if input is negative.

Parameters
[in]aInput coefficient in (-q, q).
Returns
Coefficient in [0, q).

Definition at line 84 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_caddq_all()

void MLDSA_POLY_caddq_all ( mldsa_poly a)

Applies caddq to all coefficients of a polynomial.

Parameters
[in,out]aPolynomial to make positive.

Definition at line 97 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_chknorm()

int MLDSA_POLY_chknorm ( const mldsa_poly a,
int32_t  B 
)

Checks infinity norm of polynomial against bound B.

Parameters
[in]aPolynomial.
[in]BNorm bound.
Returns
0 if all coefficients within bound, 1 otherwise.

Definition at line 179 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_invntt_tomont()

void MLDSA_POLY_invntt_tomont ( mldsa_poly a)

Inverse NTT and multiply by Montgomery factor.

Parameters
[in,out]aPolynomial to inverse-transform.

Definition at line 141 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_montgomery_reduce()

int32_t MLDSA_POLY_montgomery_reduce ( int64_t  a)

Montgomery reduction: given a 64-bit integer, compute a*q^{-1} mod 2^32.

Parameters
[in]a64-bit input.
Returns
32-bit reduced value in (-q, q).

Definition at line 68 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_ntt()

void MLDSA_POLY_ntt ( mldsa_poly a)

Forward NTT in place.

Parameters
[in,out]aPolynomial to transform.

Definition at line 125 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_pointwise_montgomery()

void MLDSA_POLY_pointwise_montgomery ( mldsa_poly c,
const mldsa_poly a,
const mldsa_poly b,
int  first 
)

Pointwise multiplication (Montgomery) with accumulation.

Parameters
[in,out]cAccumulator polynomial.
[in]aFirst input polynomial.
[in]bSecond input polynomial.
[in]firstIf non-zero, overwrite c; otherwise accumulate.

Definition at line 163 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_reduce()

void MLDSA_POLY_reduce ( mldsa_poly a)

Applies reduce32 to all coefficients of a polynomial.

Parameters
[in,out]aPolynomial to reduce.

Definition at line 90 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_reduce32()

int32_t MLDSA_POLY_reduce32 ( int32_t  a)

Reduce coefficient to representative in about (-6283009, 6283009).

Parameters
[in]aInput coefficient.
Returns
Reduced coefficient.

Definition at line 76 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_shiftl()

void MLDSA_POLY_shiftl ( mldsa_poly a)

Shifts all coefficients left by D bits.

Parameters
[in,out]aPolynomial to shift.

Definition at line 118 of file cx_mldsa_poly.c.

◆ MLDSA_POLY_sub()

void MLDSA_POLY_sub ( mldsa_poly a,
const mldsa_poly b 
)

Subtracts polynomial b from polynomial a in place.

Parameters
[in,out]aAccumulator polynomial.
[in]bPolynomial to subtract.

Definition at line 111 of file cx_mldsa_poly.c.

Variable Documentation

◆ mldsa_zetas

const int32_t mldsa_zetas[MLDSA_N]
static

Definition at line 27 of file cx_mldsa_poly.c.