Skip to content

Commit 4f75982

Browse files
mkannwischerrod-chapman
authored andcommitted
CBMC: Add proof and spec for polyvecl_uniform_gamma1
Resolves #115 Adapted from #250. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 9f4e9e1 commit 4f75982

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

mldsa/polyvec.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,28 @@ typedef struct
1717
} polyvecl;
1818

1919
#define polyvecl_uniform_gamma1 MLD_NAMESPACE(polyvecl_uniform_gamma1)
20+
/*************************************************
21+
* Name: polyvecl_uniform_gamma1
22+
*
23+
* Description: Sample vector of polynomials with uniformly random coefficients
24+
* in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] by unpacking output
25+
* stream of SHAKE256(seed|nonce)
26+
*
27+
* Arguments: - polyvecl *v: pointer to output vector
28+
* - const uint8_t seed[]: byte array with seed of length
29+
* MLDSA_CRHBYTES
30+
* - uint16_t nonce: 16-bit nonce
31+
*************************************************/
2032
void polyvecl_uniform_gamma1(polyvecl *v, const uint8_t seed[MLDSA_CRHBYTES],
21-
uint16_t nonce);
33+
uint16_t nonce)
34+
__contract__(
35+
requires(memory_no_alias(v, sizeof(polyvecl)))
36+
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
37+
requires(nonce <= (UINT16_MAX - MLDSA_L) / MLDSA_L)
38+
assigns(memory_slice(v, sizeof(polyvecl)))
39+
ensures(forall(k0, 0, MLDSA_L,
40+
array_bound(v->vec[k0].coeffs, 0, MLDSA_N, -(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1 + 1)))
41+
);
2242

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

0 commit comments

Comments
 (0)