Skip to content

Commit 53aebb3

Browse files
committed
CBMC:Add proof and contract for mldsa_shake128_stream_init
Signed-off-by: Jake Massimo <[email protected]>
1 parent 7f1d91a commit 53aebb3

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

mldsa/symmetric-shake.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void mldsa_shake128_stream_init(keccak_state *state,
1212
uint16_t nonce)
1313
{
1414
uint8_t t[2];
15-
t[0] = nonce;
15+
16+
t[0] = nonce & 0xFF;
1617
t[1] = nonce >> 8;
1718

1819
shake128_init(state);

mldsa/symmetric.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define MLD_SYMMETRIC_H
77

88
#include <stdint.h>
9+
#include "cbmc.h"
10+
#include "common.h"
911

1012
#include "fips202/fips202.h"
1113

@@ -15,7 +17,12 @@ typedef keccak_state stream256_state;
1517
#define mldsa_shake128_stream_init MLD_NAMESPACE(mldsa_shake128_stream_init)
1618
void mldsa_shake128_stream_init(keccak_state *state,
1719
const uint8_t seed[MLDSA_SEEDBYTES],
18-
uint16_t nonce);
20+
uint16_t nonce)
21+
__contract__(
22+
requires(memory_no_alias(state, sizeof(keccak_state)))
23+
requires(memory_no_alias(seed, MLDSA_SEEDBYTES))
24+
assigns(memory_slice(state, sizeof(keccak_state)))
25+
);
1926

2027
#define mldsa_shake256_stream_init MLD_NAMESPACE(mldsa_shake256_stream_init)
2128
void mldsa_shake256_stream_init(keccak_state *state,
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_shake128_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_shake128_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_shake128_stream_init
22+
USE_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake128_init $(FIPS202_NAMESPACE)shake128_absorb $(FIPS202_NAMESPACE)shake128_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_shake128_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_shake128_stream_init(s, seed, nonce);
14+
}

0 commit comments

Comments
 (0)