Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
cx_mlkem_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 *****************************************************************************/
23#include "lcx_mlkem.h"
24#include "cx_mlkem_polymat.h"
25#include "cx_mlkem_sample.h"
26
27void MLKEM_POLYMAT_gen_matrix(polymat *a, const uint8_t *seed, int32_t transposed, uint8_t k)
28{
29 for (uint32_t i = 0U; i < k; i++) {
30 for (uint32_t j = 0U; j < k; j++) {
31 if (transposed != 0) {
32 MLKEM_SAMPLE_rej_uniform(&a->vec[i].vec[j], seed, (uint8_t) i, (uint8_t) j);
33 }
34 else {
35 MLKEM_SAMPLE_rej_uniform(&a->vec[i].vec[j], seed, (uint8_t) j, (uint8_t) i);
36 }
37 }
38 }
39}
40
42 const uint8_t *seed,
43 int32_t transposed,
44 uint8_t i,
45 uint8_t k)
46{
47 for (uint32_t j = 0U; j < k; j++) {
48 if (transposed != 0) {
49 MLKEM_SAMPLE_rej_uniform(&row->vec[j], seed, i, (uint8_t) j);
50 }
51 else {
52 MLKEM_SAMPLE_rej_uniform(&row->vec[j], seed, (uint8_t) j, i);
53 }
54 }
55}
void MLKEM_POLYMAT_gen_matrix(polymat *a, const uint8_t *seed, int32_t transposed, uint8_t k)
Generates a matrix of polynomials from a seed using rejection sampling.
void MLKEM_POLYMAT_gen_matrix_row(polyvec *row, const uint8_t *seed, int32_t transposed, uint8_t i, uint8_t k)
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.
ML-KEM (Module-Lattice Key Encapsulation Mechanism) public API.
Matrix of polynomial vectors with up to MLKEM_MAX_K rows.
polyvec vec[MLKEM_MAX_K]
Vector of polynomials with up to MLKEM_MAX_K elements.
poly vec[MLKEM_MAX_K]