Skip to content

Commit d174a34

Browse files
committed
Add CBMC spec and proof for aarch64 poly_caddq native function
Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 95a638f commit d174a34

File tree

5 files changed

+103
-3
lines changed

5 files changed

+103
-3
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define MLD_NATIVE_AARCH64_SRC_ARITH_NATIVE_AARCH64_H
99

1010
#include <stdint.h>
11+
#include "../../../cbmc.h"
1112
#include "../../../common.h"
1213

1314
#define mld_aarch64_ntt_zetas_layer123456 \
@@ -74,7 +75,15 @@ void mld_poly_decompose_32_asm(int32_t *a1, int32_t *a0);
7475
void mld_poly_decompose_88_asm(int32_t *a1, int32_t *a0);
7576

7677
#define mld_poly_caddq_asm MLD_NAMESPACE(poly_caddq_asm)
77-
void mld_poly_caddq_asm(int32_t *a);
78+
void mld_poly_caddq_asm(int32_t *a)
79+
/* This must be kept in sync with the HOL-Light specification
80+
* in proofs/hol_light/aarch64/proofs/mldsa_poly_caddq.ml */
81+
__contract__(
82+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
83+
requires(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
84+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
85+
ensures(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
86+
);
7887

7988
#define mld_poly_use_hint_32_asm MLD_NAMESPACE(poly_use_hint_32_asm)
8089
void mld_poly_use_hint_32_asm(int32_t *b, const int32_t *a, const int32_t *h);

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define MLD_NATIVE_AARCH64_SRC_ARITH_NATIVE_AARCH64_H
99

1010
#include <stdint.h>
11+
#include "../../../cbmc.h"
1112
#include "../../../common.h"
1213

1314
#define mld_aarch64_ntt_zetas_layer123456 \
@@ -74,7 +75,15 @@ void mld_poly_decompose_32_asm(int32_t *a1, int32_t *a0);
7475
void mld_poly_decompose_88_asm(int32_t *a1, int32_t *a0);
7576

7677
#define mld_poly_caddq_asm MLD_NAMESPACE(poly_caddq_asm)
77-
void mld_poly_caddq_asm(int32_t *a);
78+
void mld_poly_caddq_asm(int32_t *a)
79+
/* This must be kept in sync with the HOL-Light specification
80+
* in proofs/hol_light/aarch64/proofs/mldsa_poly_caddq.ml */
81+
__contract__(
82+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
83+
requires(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
84+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
85+
ensures(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
86+
);
7887

7988
#define mld_poly_use_hint_32_asm MLD_NAMESPACE(poly_use_hint_32_asm)
8089
void mld_poly_use_hint_32_asm(int32_t *b, const int32_t *a, const int32_t *h);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define MLD_NATIVE_AARCH64_SRC_ARITH_NATIVE_AARCH64_H
99

1010
#include <stdint.h>
11+
#include "../../../cbmc.h"
1112
#include "../../../common.h"
1213

1314
#define mld_aarch64_ntt_zetas_layer123456 \
@@ -74,7 +75,15 @@ void mld_poly_decompose_32_asm(int32_t *a1, int32_t *a0);
7475
void mld_poly_decompose_88_asm(int32_t *a1, int32_t *a0);
7576

7677
#define mld_poly_caddq_asm MLD_NAMESPACE(poly_caddq_asm)
77-
void mld_poly_caddq_asm(int32_t *a);
78+
void mld_poly_caddq_asm(int32_t *a)
79+
/* This must be kept in sync with the HOL-Light specification
80+
* in proofs/hol_light/aarch64/proofs/mldsa_poly_caddq.ml */
81+
__contract__(
82+
requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N))
83+
requires(array_abs_bound(a, 0, MLDSA_N, MLDSA_Q))
84+
assigns(memory_slice(a, sizeof(int32_t) * MLDSA_N))
85+
ensures(array_bound(a, 0, MLDSA_N, 0, MLDSA_Q))
86+
);
7887

7988
#define mld_poly_use_hint_32_asm MLD_NAMESPACE(poly_use_hint_32_asm)
8089
void mld_poly_use_hint_32_asm(int32_t *b, const int32_t *a, const int32_t *h);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 = poly_caddq_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 = poly_caddq_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.c
23+
24+
CHECK_FUNCTION_CONTRACTS=mld_poly_caddq_native
25+
USE_FUNCTION_CONTRACTS = $(MLD_NAMESPACE)poly_caddq_asm
26+
USE_FUNCTION_CONTRACTS += mld_sys_check_capability
27+
APPLY_LOOP_CONTRACTS=on
28+
USE_DYNAMIC_FRAMES=1
29+
30+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
31+
EXTERNAL_SAT_SOLVER=
32+
CBMCFLAGS=--smt2
33+
34+
FUNCTION_NAME = poly_caddq_native_aarch64
35+
36+
# If this proof is found to consume huge amounts of RAM, you can set the
37+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
38+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
39+
# documentation in Makefile.common under the "Job Pools" heading for details.
40+
# EXPENSIVE = true
41+
42+
# This function is large enough to need...
43+
CBMC_OBJECT_BITS = 8
44+
45+
# If you require access to a file-local ("static") function or object to conduct
46+
# your proof, set the following (and do not include the original source file
47+
# ("mldsa/src/poly.c") in PROJECT_SOURCES).
48+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
49+
# include ../Makefile.common
50+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mldsa/src/poly.c
51+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
52+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
53+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
54+
# be set before including Makefile.common, but any use of variables on the
55+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
56+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
57+
58+
include ../Makefile.common
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_poly_caddq_native(int32_t a[MLDSA_N]);
9+
10+
void harness(void)
11+
{
12+
int32_t *a;
13+
int t;
14+
t = mld_poly_caddq_native(a);
15+
}

0 commit comments

Comments
 (0)