Skip to content

Commit 1b732cf

Browse files
jakemasmkannwischer
authored andcommitted
CBMC: Add proof and contract for mldsa_shake256_stream_init
Signed-off-by: Jake Massimo <[email protected]>
1 parent 13fa708 commit 1b732cf

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

mldsa/symmetric-shake.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void mldsa_shake256_stream_init(keccak_state *state,
2727
uint16_t nonce)
2828
{
2929
uint8_t t[2];
30-
t[0] = nonce;
30+
t[0] = nonce & 0xFF;
3131
t[1] = nonce >> 8;
3232

3333
shake256_init(state);

mldsa/symmetric.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ __contract__(
2727
#define mldsa_shake256_stream_init MLD_NAMESPACE(mldsa_shake256_stream_init)
2828
void mldsa_shake256_stream_init(keccak_state *state,
2929
const uint8_t seed[MLDSA_CRHBYTES],
30-
uint16_t nonce);
30+
uint16_t nonce)
31+
__contract__(
32+
requires(memory_no_alias(state, sizeof(keccak_state)))
33+
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
34+
assigns(memory_slice(state, sizeof(keccak_state)))
35+
);
3136

3237
#define STREAM128_BLOCKBYTES SHAKE128_RATE
3338
#define STREAM256_BLOCKBYTES SHAKE256_RATE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
include ../Makefile_params.common
4+
5+
HARNESS_ENTRY = harness
6+
HARNESS_FILE = mldsa_shake256_stream_init_harness
7+
8+
# This should be a unique identifier for this proof, and will appear on the
9+
# Litani dashboard. It can be human-readable and contain spaces if you wish.
10+
PROOF_UID = mldsa_shake256_stream_init
11+
12+
DEFINES +=
13+
INCLUDES +=
14+
15+
REMOVE_FUNCTION_BODY +=
16+
UNWINDSET +=
17+
18+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
19+
PROJECT_SOURCES += $(SRCDIR)/mldsa/symmetric-shake.c
20+
21+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)mldsa_shake256_stream_init
22+
USE_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake256_init $(FIPS202_NAMESPACE)shake256_absorb $(FIPS202_NAMESPACE)shake256_finalize
23+
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 = mldsa_shake256_stream_init
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2025 The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#include "params.h"
5+
#include "symmetric.h"
6+
7+
void harness(void)
8+
{
9+
keccak_state *s;
10+
const uint8_t *seed;
11+
uint16_t nonce;
12+
13+
mldsa_shake256_stream_init(s, seed, nonce);
14+
}

0 commit comments

Comments
 (0)