Skip to content

Commit 7db3610

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

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

mldsa/src/fips202/native/api.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@
4646
*/
4747

4848
#if defined(MLD_USE_FIPS202_X1_NATIVE)
49-
static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state);
50-
#endif
49+
static MLD_INLINE int mld_keccak_f1600_x1_native(uint64_t *state)
50+
__contract__(
51+
requires(memory_no_alias(state, sizeof(uint64_t) * 25 * 1))
52+
assigns(memory_slice(state, sizeof(uint64_t) * 25 * 1))
53+
ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS)
54+
ensures((return_value == MLD_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 1))
55+
);
56+
#endif /* MLD_USE_FIPS202_X1_NATIVE */
5157
#if defined(MLD_USE_FIPS202_X4_NATIVE)
5258
static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state);
5359
#endif
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_FIPS202X1_BACKEND_H
7+
#define MLD_DUMMY_FIPS202X1_BACKEND_H
8+
9+
10+
#define MLD_USE_FIPS202_X1_NATIVE
11+
12+
#include "../../mldsa/src/fips202/native/api.h"
13+
14+
#endif /* !MLD_DUMMY_FIPS202X1_BACKEND_H */
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 = keccakf1600_permute_native_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 = keccakf1600_permute_native
12+
13+
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_FIPS202 -DMLD_CONFIG_FIPS202_BACKEND_FILE="\"dummy_backend_fips202_x1.h\""
14+
INCLUDES +=
15+
16+
REMOVE_FUNCTION_BODY +=
17+
UNWINDSET +=
18+
19+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
20+
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/fips202/keccakf1600.c
21+
22+
CHECK_FUNCTION_CONTRACTS=$(MLD_NAMESPACE)keccakf1600_permute
23+
USE_FUNCTION_CONTRACTS=mld_keccak_f1600_x1_native
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 = mld_keccakf1600_permute_native
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/src/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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include <keccakf1600.h>
5+
6+
void harness(void)
7+
{
8+
uint64_t *a;
9+
mld_keccakf1600_permute(a);
10+
}

0 commit comments

Comments
 (0)