Skip to content

Commit e736dda

Browse files
mkannwischerrod-chapman
authored andcommitted
Serial FIPS202 3/3: Adapt mld_polyvec_matrix_expand
This commit changes mld_polyvec_matrix_expand to use only poly_uniform in case MLD_CONFIG_SERIAL_FIPS202_ONLY is set. A CBMC proof is added. This change closely follows pq-code-package/mlkem-native@c670e1d Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 6052009 commit e736dda

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

mldsa/poly.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ void mld_poly_uniform(mld_poly *a, const uint8_t seed[MLDSA_SEEDBYTES + 2])
352352
mld_zeroize(buf, sizeof(buf));
353353
}
354354

355+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
355356
MLD_INTERNAL_API
356357
void mld_poly_uniform_4x(mld_poly *vec0, mld_poly *vec1, mld_poly *vec2,
357358
mld_poly *vec3,
@@ -416,6 +417,7 @@ void mld_poly_uniform_4x(mld_poly *vec0, mld_poly *vec1, mld_poly *vec2,
416417
mld_zeroize(buf, sizeof(buf));
417418
}
418419

420+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
419421

420422
MLD_INTERNAL_API
421423
void mld_polyt1_pack(uint8_t *r, const mld_poly *a)

mldsa/polyvec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void mld_polyvec_matrix_expand(mld_polyvecl mat[MLDSA_K],
5454
{
5555
mld_memcpy(seed_ext[j], rho, MLDSA_SEEDBYTES);
5656
}
57+
58+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
5759
/* Sample 4 matrix entries a time. */
5860
for (i = 0; i < (MLDSA_K * MLDSA_L / 4) * 4; i += 4)
5961
__loop__(
@@ -86,6 +88,9 @@ void mld_polyvec_matrix_expand(mld_polyvecl mat[MLDSA_K],
8688
&mat[(i + 3) / MLDSA_L].vec[(i + 3) % MLDSA_L],
8789
seed_ext);
8890
}
91+
#else /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
92+
i = 0;
93+
#endif /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
8994

9095
/* For MLDSA_K=6, MLDSA_L=5, process the last two entries individually */
9196
while (i < MLDSA_K * MLDSA_L)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) The mldsa-native project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
include ../Makefile_params.common
5+
6+
HARNESS_ENTRY = harness
7+
HARNESS_FILE = polyvec_matrix_expand_harness
8+
9+
# This should be a unique identifier for this proof, and will appear on the
10+
# Litani dashboard. It can be human-readable and contain spaces if you wish.
11+
PROOF_UID = polyvec_matrix_expand_serial
12+
13+
DEFINES += -DMLD_CONFIG_SERIAL_FIPS202_ONLY
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
18+
19+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
20+
PROJECT_SOURCES += $(SRCDIR)/mldsa/polyvec.c
21+
22+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)polyvec_matrix_expand
23+
USE_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)poly_uniform
24+
APPLY_LOOP_CONTRACTS=on
25+
USE_DYNAMIC_FRAMES=1
26+
27+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
28+
EXTERNAL_SAT_SOLVER=
29+
CBMCFLAGS=--smt2 --arrays-uf-always --slice-formula
30+
31+
FUNCTION_NAME = polyvec_matrix_expand_serial
32+
33+
# If this proof is found to consume huge amounts of RAM, you can set the
34+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
35+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
36+
# documentation in Makefile.common under the "Job Pools" heading for details.
37+
# EXPENSIVE = true
38+
39+
# This function is large enough to need...
40+
CBMC_OBJECT_BITS = 11
41+
42+
# If you require access to a file-local ("static") function or object to conduct
43+
# your proof, set the following (and do not include the original source file
44+
# ("mldsa/poly.c") in PROJECT_SOURCES).
45+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
46+
# include ../Makefile.common
47+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/poly.c
48+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
50+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
51+
# be set before including Makefile.common, but any use of variables on the
52+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
53+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
54+
55+
include ../Makefile.common
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include "polyvec.h"
5+
6+
void harness(void)
7+
{
8+
mld_polyvecl *mat;
9+
uint8_t *rho;
10+
11+
mld_polyvec_matrix_expand(mat, rho);
12+
}

0 commit comments

Comments
 (0)