Skip to content

Commit 64afc15

Browse files
authored
Merge pull request #32 from h2parson/set_adrs
2 parents d2b14a4 + b5f04d3 commit 64afc15

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

cbmc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
#define array_abs_bound(arr, lb, ub, k) \
139139
array_bound((arr), (lb), (ub), -((int)(k)) + 1, (k))
140140

141+
#define VALID_SLH_VAR_T(var) \
142+
(memory_no_alias(var, sizeof(slh_var_t)) && memory_no_alias(var->prm, sizeof(slh_param_t)) && \
143+
memory_no_alias(var->adrs, sizeof(adrs_t)))
144+
141145
#endif /* CBMC */
142146

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

slh_adrs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ static SLH_INLINE uint32_t adrs_get_tree_index(const slh_var_t *var)
126126

127127
/* === Set WOTS+ hash address. */
128128
static SLH_INLINE void adrs_set_hash_address(slh_var_t *var, uint32_t x)
129+
__contract__(
130+
requires(VALID_SLH_VAR_T(var))
131+
assigns(var->adrs->u32[7])
132+
)
129133
{
130134
var->adrs->u32[7] = rev8_be32(x);
131135
}

0 commit comments

Comments
 (0)