Skip to content

Commit d702136

Browse files
willieyzmkannwischer
authored andcommitted
CBMC: Add proofs on top of native functions (keccakf1600x4_permute_native)
- This commit adds CBMC proofs for following the native function: `mld_keccak_f1600_x4_native`, called `keccakf1600x4_permute_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `keccakf1600x4_permute`. - Use the following function contracts: - `mld_keccak_f1600_x4_native` - Add `MLD_USE_FIPS202_X4_NATIVE` in dummy_backend_fips202_x4.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent 7db3610 commit d702136

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

mldsa/src/fips202/native/api.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ __contract__(
5555
);
5656
#endif /* MLD_USE_FIPS202_X1_NATIVE */
5757
#if defined(MLD_USE_FIPS202_X4_NATIVE)
58-
static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state);
59-
#endif
58+
static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
59+
__contract__(
60+
requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 4))
61+
assigns(memory_slice(state, sizeof(uint64_t) * 25 * 4))
62+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
63+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 4))
64+
);
65+
#endif /* MLD_USE_FIPS202_X4_NATIVE */
6066

6167
#endif /* !MLD_FIPS202_NATIVE_API_H */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) The mldsa-native project authors
3+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
*/
5+
6+
#ifndef MLD_DUMMY_FIPS202X4_BACKEND_H
7+
#define MLD_DUMMY_FIPS202X4_BACKEND_H
8+
9+
10+
#define MLD_USE_FIPS202_X4_NATIVE
11+
12+
#include "../../mldsa/src/fips202/native/api.h"
13+
14+
#endif /* !MLD_DUMMY_FIPS202X4_BACKEND_H */
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 = keccakf1600x4_permute_native_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 = keccakf1600x4_permute_native
13+
14+
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 -DMLD_CONFIG_FIPS202_BACKEND_FILE="\"dummy_backend_fips202_x4.h\""
15+
INCLUDES +=
16+
17+
REMOVE_FUNCTION_BODY +=
18+
UNWINDSET +=
19+
20+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
21+
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/fips202/keccakf1600.c
22+
23+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)keccakf1600x4_permute
24+
USE_FUNCTION_CONTRACTS=mld_keccak_f1600_x4_native
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=--smt2
31+
32+
# For this proof we tell CBMC to
33+
# - not decompose arrays into their individual cells
34+
# - to slice constraints that are not in the cone of influence of the proof obligations
35+
# These options simplify them modelling of arrays and produce much more compact
36+
# SMT files, leaving all array-type reasoning to the SMT solver.
37+
#
38+
# For functions that use large and multi-dimensional arrays, this yields
39+
# a substantial improvement in proof performance.
40+
CBMCFLAGS += --no-array-field-sensitivity
41+
CBMCFLAGS += --slice-formula
42+
43+
FUNCTION_NAME = mld_keccakf1600x4_permute_native
44+
45+
# If this proof is found to consume huge amounts of RAM, you can set the
46+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
47+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
48+
# documentation in Makefile.common under the "Job Pools" heading for details.
49+
# EXPENSIVE = true
50+
51+
# This function is large enough to need...
52+
CBMC_OBJECT_BITS = 8
53+
54+
# If you require access to a file-local ("static") function or object to conduct
55+
# your proof, set the following (and do not include the original source file
56+
# ("mlkem/poly.c") in PROJECT_SOURCES).
57+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
58+
# include ../Makefile.common
59+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/poly.c
60+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
61+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
62+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
63+
# be set before including Makefile.common, but any use of variables on the
64+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
65+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
66+
67+
include ../Makefile.common
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 <keccakf1600.h>
7+
8+
void harness(void)
9+
{
10+
uint64_t *s;
11+
mld_keccakf1600x4_permute(s);
12+
}

0 commit comments

Comments
 (0)