Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
cx_mldsa_polymat.c
Go to the documentation of this file.
1/*****************************************************************************
2 * (c) 2026 Ledger SAS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
21#include "cx_mldsa_polymat.h"
22#include "cx_mldsa_sample.h"
23
25 const uint8_t rho[MLDSA_SEEDBYTES],
26 const MLDSA_param_info_t *p)
27{
28 for (uint8_t i = 0U; i < p->k; i++) {
29 for (uint8_t j = 0U; j < p->l; j++) {
30 uint16_t nonce = ((uint16_t) i << 8U) | (uint16_t) j;
31 MLDSA_SAMPLE_uniform(&mat[i].vec[j], rho, nonce);
32 }
33 }
34}
35
37 const mldsa_polyvecl *mat,
38 const mldsa_polyvecl *s,
39 const MLDSA_param_info_t *p)
40{
41 for (uint8_t i = 0U; i < p->k; i++) {
42 MLDSA_POLYVEC_pointwise_acc_montgomery(&t->vec[i], &mat[i], s, p->l);
43 }
44}
45
47 const uint8_t rho[MLDSA_SEEDBYTES],
48 const mldsa_polyvecl *s,
49 const MLDSA_param_info_t *p)
50{
51 mldsa_poly aij;
52 for (uint8_t i = 0U; i < p->k; i++) {
53 for (uint8_t j = 0U; j < p->l; j++) {
54 uint16_t nonce = ((uint16_t) i << 8U) | (uint16_t) j;
55 MLDSA_SAMPLE_uniform(&aij, rho, nonce);
56 MLDSA_POLY_pointwise_montgomery(&t->vec[i], &aij, &s->vec[j], (j == 0U) ? 1 : 0);
57 }
58 }
59}
void MLDSA_POLY_pointwise_montgomery(mldsa_poly *c, const mldsa_poly *a, const mldsa_poly *b, int first)
Pointwise multiplication (Montgomery) with accumulation.
void MLDSA_POLYMAT_expand_and_multiply(mldsa_polyveck *t, const uint8_t rho[MLDSA_SEEDBYTES], const mldsa_polyvecl *s, const MLDSA_param_info_t *p)
On-the-fly A expansion with matrix-vector multiply.
void MLDSA_POLYMAT_expand(mldsa_polyvecl *mat, const uint8_t rho[MLDSA_SEEDBYTES], const MLDSA_param_info_t *p)
Expand the k x l matrix A from a seed rho using SHAKE128. Each polynomial A[i][j] is stored as mat[i]...
void MLDSA_POLYMAT_pointwise_montgomery(mldsa_polyveck *t, const mldsa_polyvecl *mat, const mldsa_polyvecl *s, const MLDSA_param_info_t *p)
Matrix-vector multiply: t = A * s (in NTT domain). Both A and s must already be in NTT domain....
void MLDSA_POLYVEC_pointwise_acc_montgomery(mldsa_poly *w, const mldsa_polyvecl *u, const mldsa_polyvecl *v, uint8_t l)
Inner product of L-vectors in NTT domain with accumulation.
void MLDSA_SAMPLE_uniform(mldsa_poly *a, const uint8_t seed[MLDSA_SEEDBYTES], uint16_t nonce)
Sample polynomial with uniformly random coefficients in [0, q-1] by performing rejection sampling on ...
#define MLDSA_SEEDBYTES
Definition lcx_mldsa.h:40
ML-DSA parameter set descriptor holding all derived sizes.
Definition lcx_mldsa.h:179
Polynomial with MLDSA_N int32_t coefficients.
Polynomial vector of up to MLDSA_MAX_K polynomials.
mldsa_poly vec[MLDSA_MAX_K]
Polynomial vector of up to MLDSA_MAX_L polynomials.
mldsa_poly vec[MLDSA_MAX_L]