Skip to content

Commit 8fe199e

Browse files
committed
CBMC: Add CBMC proof for aarch64 polyz_unpack
Add CBMC contracts for native AArch64 polyz_unpack_17 and polyz_unpack_19 following corresponding HOL-Light specs. Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent f2b5fe9 commit 8fe199e

File tree

7 files changed

+227
-6
lines changed

7 files changed

+227
-6
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,29 @@ __contract__(
108108

109109
#define mld_polyz_unpack_17_asm MLD_NAMESPACE(polyz_unpack_17_asm)
110110
void mld_polyz_unpack_17_asm(int32_t *r, const uint8_t *buf,
111-
const uint8_t *indices);
111+
const uint8_t *indices)
112+
/* This must be kept in sync with the HOL-Light specification
113+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_17.ml */
114+
__contract__(
115+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
116+
requires(memory_no_alias(buf, 576))
117+
requires(indices == mld_polyz_unpack_17_indices)
118+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
119+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 17) - 1), (1 << 17) + 1))
120+
);
112121

113122
#define mld_polyz_unpack_19_asm MLD_NAMESPACE(polyz_unpack_19_asm)
114123
void mld_polyz_unpack_19_asm(int32_t *r, const uint8_t *buf,
115-
const uint8_t *indices);
124+
const uint8_t *indices)
125+
/* This must be kept in sync with the HOL-Light specification
126+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_19.ml */
127+
__contract__(
128+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
129+
requires(memory_no_alias(buf, 640))
130+
requires(indices == mld_polyz_unpack_19_indices)
131+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
132+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 19) - 1), (1 << 19) + 1))
133+
);
116134

117135
#define mld_poly_pointwise_montgomery_asm \
118136
MLD_NAMESPACE(poly_pointwise_montgomery_asm)

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,29 @@ __contract__(
108108

109109
#define mld_polyz_unpack_17_asm MLD_NAMESPACE(polyz_unpack_17_asm)
110110
void mld_polyz_unpack_17_asm(int32_t *r, const uint8_t *buf,
111-
const uint8_t *indices);
111+
const uint8_t *indices)
112+
/* This must be kept in sync with the HOL-Light specification
113+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_17.ml */
114+
__contract__(
115+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
116+
requires(memory_no_alias(buf, 576))
117+
requires(indices == mld_polyz_unpack_17_indices)
118+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
119+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 17) - 1), (1 << 17) + 1))
120+
);
112121

113122
#define mld_polyz_unpack_19_asm MLD_NAMESPACE(polyz_unpack_19_asm)
114123
void mld_polyz_unpack_19_asm(int32_t *r, const uint8_t *buf,
115-
const uint8_t *indices);
124+
const uint8_t *indices)
125+
/* This must be kept in sync with the HOL-Light specification
126+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_19.ml */
127+
__contract__(
128+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
129+
requires(memory_no_alias(buf, 640))
130+
requires(indices == mld_polyz_unpack_19_indices)
131+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
132+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 19) - 1), (1 << 19) + 1))
133+
);
116134

117135
#define mld_poly_pointwise_montgomery_asm \
118136
MLD_NAMESPACE(poly_pointwise_montgomery_asm)

mldsa/src/native/aarch64/src/arith_native_aarch64.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,29 @@ __contract__(
108108

109109
#define mld_polyz_unpack_17_asm MLD_NAMESPACE(polyz_unpack_17_asm)
110110
void mld_polyz_unpack_17_asm(int32_t *r, const uint8_t *buf,
111-
const uint8_t *indices);
111+
const uint8_t *indices)
112+
/* This must be kept in sync with the HOL-Light specification
113+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_17.ml */
114+
__contract__(
115+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
116+
requires(memory_no_alias(buf, 576))
117+
requires(indices == mld_polyz_unpack_17_indices)
118+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
119+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 17) - 1), (1 << 17) + 1))
120+
);
112121

113122
#define mld_polyz_unpack_19_asm MLD_NAMESPACE(polyz_unpack_19_asm)
114123
void mld_polyz_unpack_19_asm(int32_t *r, const uint8_t *buf,
115-
const uint8_t *indices);
124+
const uint8_t *indices)
125+
/* This must be kept in sync with the HOL-Light specification
126+
* in proofs/hol_light/aarch64/proofs/mldsa_polyz_unpack_19.ml */
127+
__contract__(
128+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
129+
requires(memory_no_alias(buf, 640))
130+
requires(indices == mld_polyz_unpack_19_indices)
131+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
132+
ensures(array_bound(r, 0, MLDSA_N, -((1 << 19) - 1), (1 << 19) + 1))
133+
);
116134

117135
#define mld_poly_pointwise_montgomery_asm \
118136
MLD_NAMESPACE(poly_pointwise_montgomery_asm)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 = polyz_unpack_17_native_aarch64_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 = polyz_unpack_17_native_aarch64
12+
13+
# We need to set MLD_CHECK_APIS as otherwise mldsa/src/native/api.h won't be
14+
# included, which contains the CBMC specifications.
15+
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"$(SRCDIR)/mldsa/src/native/aarch64/meta.h\"" -DMLD_CHECK_APIS
16+
INCLUDES +=
17+
18+
REMOVE_FUNCTION_BODY +=
19+
UNWINDSET +=
20+
21+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
22+
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/poly_kl.c $(SRCDIR)/mldsa/src/native/aarch64/src/polyz_unpack_table.c
23+
24+
# polyz_unpack_17 is only used with ML-DSA-44
25+
ifeq ($(MLD_CONFIG_PARAMETER_SET),44)
26+
CHECK_FUNCTION_CONTRACTS=mld_polyz_unpack_17_native
27+
USE_FUNCTION_CONTRACTS = mld_polyz_unpack_17_asm
28+
else
29+
CHECK_FUNCTION_CONTRACTS=
30+
USE_FUNCTION_CONTRACTS =
31+
endif
32+
APPLY_LOOP_CONTRACTS=on
33+
USE_DYNAMIC_FRAMES=1
34+
35+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
36+
EXTERNAL_SAT_SOLVER=
37+
CBMCFLAGS=--smt2
38+
39+
FUNCTION_NAME = polyz_unpack_17_native_aarch64
40+
41+
# If this proof is found to consume huge amounts of RAM, you can set the
42+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
43+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
44+
# documentation in Makefile.common under the "Job Pools" heading for details.
45+
# EXPENSIVE = true
46+
47+
# This function is large enough to need...
48+
CBMC_OBJECT_BITS = 8
49+
50+
# If you require access to a file-local ("static") function or object to conduct
51+
# your proof, set the following (and do not include the original source file
52+
# ("mldsa/poly_kl.c") in PROJECT_SOURCES).
53+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
54+
# include ../Makefile.common
55+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/src/poly_kl.c
56+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
57+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
58+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
59+
# be set before including Makefile.common, but any use of variables on the
60+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
61+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
62+
63+
include ../Makefile.common
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include <stdint.h>
5+
#include "cbmc.h"
6+
#include "params.h"
7+
8+
int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *a);
9+
10+
void harness(void)
11+
{
12+
/* mld_polyz_unpack_17_native is only defined for ML-DSA-44 */
13+
#if MLD_CONFIG_PARAMETER_SET == 44
14+
int32_t *r;
15+
const uint8_t *a;
16+
int t;
17+
t = mld_polyz_unpack_17_native(r, a);
18+
#endif /* MLD_CONFIG_PARAMETER_SET == 44 */
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 = polyz_unpack_19_native_aarch64_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 = polyz_unpack_19_native_aarch64
12+
13+
# We need to set MLD_CHECK_APIS as otherwise mldsa/src/native/api.h won't be
14+
# included, which contains the CBMC specifications.
15+
DEFINES += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_ARITH_BACKEND_FILE="\"$(SRCDIR)/mldsa/src/native/aarch64/meta.h\"" -DMLD_CHECK_APIS
16+
INCLUDES +=
17+
18+
REMOVE_FUNCTION_BODY +=
19+
UNWINDSET +=
20+
21+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
22+
PROJECT_SOURCES += $(SRCDIR)/mldsa/src/poly_kl.c $(SRCDIR)/mldsa/src/native/aarch64/src/polyz_unpack_table.c
23+
24+
# polyz_unpack_19 is only used with ML-DSA-65 and ML-DSA-87
25+
ifeq ($(MLD_CONFIG_PARAMETER_SET),65)
26+
CHECK_FUNCTION_CONTRACTS=mld_polyz_unpack_19_native
27+
USE_FUNCTION_CONTRACTS = mld_polyz_unpack_19_asm
28+
else ifeq ($(MLD_CONFIG_PARAMETER_SET),87)
29+
CHECK_FUNCTION_CONTRACTS=mld_polyz_unpack_19_native
30+
USE_FUNCTION_CONTRACTS = mld_polyz_unpack_19_asm
31+
else
32+
CHECK_FUNCTION_CONTRACTS=
33+
USE_FUNCTION_CONTRACTS =
34+
endif
35+
APPLY_LOOP_CONTRACTS=on
36+
USE_DYNAMIC_FRAMES=1
37+
38+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
39+
EXTERNAL_SAT_SOLVER=
40+
CBMCFLAGS=--smt2
41+
42+
FUNCTION_NAME = polyz_unpack_19_native_aarch64
43+
44+
# If this proof is found to consume huge amounts of RAM, you can set the
45+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
46+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
47+
# documentation in Makefile.common under the "Job Pools" heading for details.
48+
# EXPENSIVE = true
49+
50+
# This function is large enough to need...
51+
CBMC_OBJECT_BITS = 8
52+
53+
# If you require access to a file-local ("static") function or object to conduct
54+
# your proof, set the following (and do not include the original source file
55+
# ("mldsa/poly_kl.c") in PROJECT_SOURCES).
56+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
57+
# include ../Makefile.common
58+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/src/poly_kl.c
59+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
60+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
61+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
62+
# be set before including Makefile.common, but any use of variables on the
63+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
64+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
65+
66+
include ../Makefile.common
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) The mldsa-native project authors
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
#include <stdint.h>
5+
#include "cbmc.h"
6+
#include "params.h"
7+
8+
int mld_polyz_unpack_19_native(int32_t *r, const uint8_t *a);
9+
10+
void harness(void)
11+
{
12+
/* mld_polyz_unpack_19_native is only defined for ML-DSA-65 and ML-DSA-87 */
13+
#if MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87
14+
int32_t *r;
15+
const uint8_t *a;
16+
int t;
17+
t = mld_polyz_unpack_19_native(r, a);
18+
#endif /* MLD_CONFIG_PARAMETER_SET == 65 || MLD_CONFIG_PARAMETER_SET == 87 */
19+
}

0 commit comments

Comments
 (0)