Skip to content

Commit 20a32ae

Browse files
mkannwischerrod-chapman
authored andcommitted
CBMC: Add proof and spec for mld_shake256x4_squeezeblocks
Resolves #247 Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 21ec3d8 commit 20a32ae

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

mldsa/fips202/fips202x4.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,20 @@ __contract__(
8080
#define mld_shake256x4_squeezeblocks FIPS202_NAMESPACE(shake256x4_squeezeblocks)
8181
void mld_shake256x4_squeezeblocks(uint8_t *out0, uint8_t *out1, uint8_t *out2,
8282
uint8_t *out3, size_t nblocks,
83-
mld_shake256x4ctx *state);
83+
mld_shake256x4ctx *state)
84+
__contract__(
85+
requires(nblocks <= 8 /* somewhat arbitrary bound */)
86+
requires(memory_no_alias(state, sizeof(mld_shake256x4ctx)))
87+
requires(memory_no_alias(out0, nblocks * SHAKE256_RATE))
88+
requires(memory_no_alias(out1, nblocks * SHAKE256_RATE))
89+
requires(memory_no_alias(out2, nblocks * SHAKE256_RATE))
90+
requires(memory_no_alias(out3, nblocks * SHAKE256_RATE))
91+
assigns(memory_slice(out0, nblocks * SHAKE256_RATE),
92+
memory_slice(out1, nblocks * SHAKE256_RATE),
93+
memory_slice(out2, nblocks * SHAKE256_RATE),
94+
memory_slice(out3, nblocks * SHAKE256_RATE),
95+
object_whole(state))
96+
);
8497

8598
#define mld_shake256x4_init FIPS202_NAMESPACE(shake256x4_init)
8699
void mld_shake256x4_init(mld_shake256x4ctx *state);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) The mldsa-native project authors
2+
# Copyright (c) The mlkem-native project authors
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
5+
include ../Makefile_params.common
6+
7+
HARNESS_ENTRY = harness
8+
HARNESS_FILE = shake256x4_squeezeblocks_harness
9+
10+
# This should be a unique identifier for this proof, and will appear on the
11+
# Litani dashboard. It can be human-readable and contain spaces if you wish.
12+
PROOF_UID = shake256x4_squeezeblocks
13+
14+
DEFINES +=
15+
INCLUDES +=
16+
17+
REMOVE_FUNCTION_BODY +=
18+
UNWINDSET +=
19+
20+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
21+
PROJECT_SOURCES += $(SRCDIR)/mldsa/fips202/fips202x4.c
22+
23+
CHECK_FUNCTION_CONTRACTS=$(FIPS202_NAMESPACE)shake256x4_squeezeblocks
24+
USE_FUNCTION_CONTRACTS=mld_keccak_squeezeblocks_x4
25+
APPLY_LOOP_CONTRACTS=on
26+
USE_DYNAMIC_FRAMES=1
27+
28+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
29+
EXTERNAL_SAT_SOLVER=
30+
CBMCFLAGS=--bitwuzla
31+
32+
FUNCTION_NAME = mld_shake256x4_squeezeblocks
33+
34+
# If this proof is found to consume huge amounts of RAM, you can set the
35+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
36+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
37+
# documentation in Makefile.common under the "Job Pools" heading for details.
38+
# EXPENSIVE = true
39+
40+
# This function is large enough to need...
41+
CBMC_OBJECT_BITS = 8
42+
43+
# If you require access to a file-local ("static") function or object to conduct
44+
# your proof, set the following (and do not include the original source file
45+
# ("mlkem/poly.c") in PROJECT_SOURCES).
46+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
47+
# include ../Makefile.common
48+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/poly.c
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
50+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
51+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
52+
# be set before including Makefile.common, but any use of variables on the
53+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
54+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
55+
56+
include ../Makefile.common
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// Copyright (c) The mlkem-native project authors
3+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
// SPDX-License-Identifier: MIT-0
5+
6+
#include <fips202x4.h>
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
#include <string.h>
10+
11+
void harness(void)
12+
{
13+
uint8_t *output0, output1, output2, output3;
14+
size_t nblocks;
15+
mld_shake256x4ctx *state;
16+
mld_shake256x4_squeezeblocks(output0, output1, output2, output3, nblocks,
17+
state);
18+
}

0 commit comments

Comments
 (0)