Skip to content

Commit 25edd79

Browse files
committed
CBMC: Add proof and spec for poly_uniform_gamma1_4x
Resolves #252 Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 3d35081 commit 25edd79

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

mldsa/poly.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ __contract__(
367367
);
368368

369369

370-
#define poly_uniform_gamma1 MLD_NAMESPACE(poly_uniform_gamma1)
370+
#define poly_uniform_gamma1_4x MLD_NAMESPACE(poly_uniform_gamma1_4x)
371371
/*************************************************
372372
* Name: poly_uniform_gamma1_4x
373373
*
@@ -382,7 +382,23 @@ __contract__(
382382
**************************************************/
383383
void poly_uniform_gamma1_4x(poly *r0, poly *r1, poly *r2, poly *r3,
384384
const uint8_t seed[MLDSA_CRHBYTES], uint16_t nonce0,
385-
uint16_t nonce1, uint16_t nonce2, uint16_t nonce3);
385+
uint16_t nonce1, uint16_t nonce2, uint16_t nonce3)
386+
__contract__(
387+
requires(memory_no_alias(r0, sizeof(poly)))
388+
requires(memory_no_alias(r1, sizeof(poly)))
389+
requires(memory_no_alias(r2, sizeof(poly)))
390+
requires(memory_no_alias(r3, sizeof(poly)))
391+
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
392+
assigns(memory_slice(r0, sizeof(poly)))
393+
assigns(memory_slice(r1, sizeof(poly)))
394+
assigns(memory_slice(r2, sizeof(poly)))
395+
assigns(memory_slice(r3, sizeof(poly)))
396+
ensures(array_bound(r0->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
397+
ensures(array_bound(r1->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
398+
ensures(array_bound(r2->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
399+
ensures(array_bound(r3->coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1))
400+
);
401+
386402

387403
#define poly_challenge MLD_NAMESPACE(poly_challenge)
388404
/*************************************************
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 = poly_uniform_gamma1_4x_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 = poly_uniform_gamma1_4x
12+
13+
DEFINES +=
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
18+
19+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
20+
PROJECT_SOURCES += $(SRCDIR)/mldsa/poly.c $(SRCDIR)/mldsa/fips202/fips202x4.c
21+
22+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)poly_uniform_gamma1_4x
23+
USE_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake256x4_absorb_once $(FIPS202_NAMESPACE)shake256x4_squeezeblocks $(MLD_NAMESPACE)polyz_unpack
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
30+
31+
FUNCTION_NAME = poly_uniform_gamma1_4x
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 = 8
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: 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 "poly.h"
5+
6+
void harness(void)
7+
{
8+
poly *r0, *r1, *r2, *r3;
9+
const uint8_t *seed;
10+
uint16_t n0, n1, n2, n3;
11+
12+
poly_uniform_gamma1_4x(r0, r1, r2, r3, seed, n0, n1, n2, n3);
13+
}

0 commit comments

Comments
 (0)