Skip to content

Commit e86480b

Browse files
committed
Serial FIPS202: Adapt mld_polyvecl_uniform_gamma1
This commit changes mld_polyvecl_uniform_gamma1 to only use mld_poly_uniform_gamma1 in case MLD_CONFIG_SERIAL_FIPS202_ONLY is set. An additional CBMC proof is added that proves the function in case the option is enabled. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 7e5c9ea commit e86480b

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

mldsa/poly_kl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ void mld_poly_uniform_gamma1(mld_poly *a, const uint8_t seed[MLDSA_CRHBYTES],
432432
mld_zeroize(extseed, sizeof(extseed));
433433
}
434434

435+
436+
#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
435437
MLD_INTERNAL_API
436438
void mld_poly_uniform_gamma1_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
437439
mld_poly *r3,
@@ -480,6 +482,7 @@ void mld_poly_uniform_gamma1_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
480482
mld_zeroize(buf, sizeof(buf));
481483
mld_zeroize(extseed, sizeof(extseed));
482484
}
485+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
483486

484487
MLD_INTERNAL_API
485488
void mld_poly_challenge(mld_poly *c, const uint8_t seed[MLDSA_CTILDEBYTES])

mldsa/polyvec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,20 @@ void mld_polyvecl_uniform_gamma1(mld_polyvecl *v,
157157
const uint8_t seed[MLDSA_CRHBYTES],
158158
uint16_t nonce)
159159
{
160+
#if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
161+
int i;
162+
#endif
163+
160164
/* Safety: nonce is at most ((UINT16_MAX - MLDSA_L) / MLDSA_L), and, hence,
161165
* this cast is safe. See NONCE_UB comment in sign.c. */
162166
nonce = (uint16_t)(MLDSA_L * nonce);
163167
/* Now, nonce <= UINT16_MAX - (MLDSA_L - 1), so the casts below are safe. */
168+
#if defined(MLD_CONFIG_SERIAL_FIPS202_ONLY)
169+
for (i = 0; i < MLDSA_L; i++)
170+
{
171+
mld_poly_uniform_gamma1(&v->vec[i], seed, (uint16_t)(nonce + i));
172+
}
173+
#else /* MLD_CONFIG_SERIAL_FIPS202_ONLY */
164174
#if MLDSA_L == 4
165175
mld_poly_uniform_gamma1_4x(&v->vec[0], &v->vec[1], &v->vec[2], &v->vec[3],
166176
seed, nonce, (uint16_t)(nonce + 1),
@@ -179,6 +189,7 @@ void mld_polyvecl_uniform_gamma1(mld_polyvecl *v,
179189
seed, (uint16_t)(nonce + 3), (uint16_t)(nonce + 4),
180190
(uint16_t)(nonce + 5), (uint16_t)(nonce + 6));
181191
#endif /* MLDSA_L == 7 */
192+
#endif /* !MLD_CONFIG_SERIAL_FIPS202_ONLY */
182193

183194
mld_assert_bound_2d(v->vec, MLDSA_L, MLDSA_N, -(MLDSA_GAMMA1 - 1),
184195
MLDSA_GAMMA1 + 1);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 = polyvecl_uniform_gamma1_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 = polyvecl_uniform_gamma1_serial
12+
13+
DEFINES += -DMLD_CONFIG_SERIAL_FIPS202_ONLY
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
18+
UNWINDSET += $(MLD_NAMESPACE)polyvecl_uniform_gamma1.0:7 # Largest value of MLDSA_L
19+
20+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
21+
PROJECT_SOURCES += $(SRCDIR)/mldsa/polyvec.c
22+
23+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)polyvecl_uniform_gamma1
24+
USE_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)poly_uniform_gamma1
25+
26+
APPLY_LOOP_CONTRACTS=on
27+
USE_DYNAMIC_FRAMES=1
28+
29+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
30+
EXTERNAL_SAT_SOLVER=
31+
CBMCFLAGS=--smt2
32+
33+
FUNCTION_NAME = polyvecl_uniform_gamma1_serial
34+
35+
# If this proof is found to consume huge amounts of RAM, you can set the
36+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
37+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
38+
# documentation in Makefile.common under the "Job Pools" heading for details.
39+
# EXPENSIVE = true
40+
41+
# This function is large enough to need...
42+
CBMC_OBJECT_BITS = 10
43+
44+
# If you require access to a file-local ("static") function or object to conduct
45+
# your proof, set the following (and do not include the original source file
46+
# ("mldsa/poly.c") in PROJECT_SOURCES).
47+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
48+
# include ../Makefile.common
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/poly.c
50+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
51+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
52+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
53+
# be set before including Makefile.common, but any use of variables on the
54+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
55+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
56+
57+
include ../Makefile.common
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 *v;
9+
const uint8_t *seed;
10+
uint16_t nonce;
11+
12+
mld_polyvecl_uniform_gamma1(v, seed, nonce);
13+
}

0 commit comments

Comments
 (0)