Skip to content

Commit 1d4f674

Browse files
committed
CBMC: Prove AArch64 mlk_intt_native based on HOL-Light spec
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 2df2a55 commit 1d4f674

File tree

6 files changed

+114
-3
lines changed

6 files changed

+114
-3
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ __contract__(
4747
);
4848

4949
#define mlk_intt_asm MLK_NAMESPACE(intt_asm)
50-
void mlk_intt_asm(int16_t *, const int16_t *, const int16_t *);
50+
void mlk_intt_asm(int16_t *p, const int16_t *twiddles12345,
51+
const int16_t *twiddles56)
52+
/* This must be kept in sync with the HOL-Light specification
53+
* in proofs/hol_light/arm/proofs/mlkem_intt.ml */
54+
__contract__(
55+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
56+
requires(twiddles12345 == mlk_aarch64_invntt_zetas_layer12345)
57+
requires(twiddles56 == mlk_aarch64_invntt_zetas_layer67)
58+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
59+
/* check-magic: off */
60+
ensures(array_abs_bound(p, 0, MLKEM_N, 26625))
61+
/* check-magic: on */
62+
);
5163

5264
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
5365
void mlk_poly_reduce_asm(int16_t *);

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ __contract__(
4747
);
4848

4949
#define mlk_intt_asm MLK_NAMESPACE(intt_asm)
50-
void mlk_intt_asm(int16_t *, const int16_t *, const int16_t *);
50+
void mlk_intt_asm(int16_t *p, const int16_t *twiddles12345,
51+
const int16_t *twiddles56)
52+
/* This must be kept in sync with the HOL-Light specification
53+
* in proofs/hol_light/arm/proofs/mlkem_intt.ml */
54+
__contract__(
55+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
56+
requires(twiddles12345 == mlk_aarch64_invntt_zetas_layer12345)
57+
requires(twiddles56 == mlk_aarch64_invntt_zetas_layer67)
58+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
59+
/* check-magic: off */
60+
ensures(array_abs_bound(p, 0, MLKEM_N, 26625))
61+
/* check-magic: on */
62+
);
5163

5264
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
5365
void mlk_poly_reduce_asm(int16_t *);

mlkem/native/aarch64/src/arith_native_aarch64.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ __contract__(
4747
);
4848

4949
#define mlk_intt_asm MLK_NAMESPACE(intt_asm)
50-
void mlk_intt_asm(int16_t *, const int16_t *, const int16_t *);
50+
void mlk_intt_asm(int16_t *p, const int16_t *twiddles12345,
51+
const int16_t *twiddles56)
52+
/* This must be kept in sync with the HOL-Light specification
53+
* in proofs/hol_light/arm/proofs/mlkem_intt.ml */
54+
__contract__(
55+
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
56+
requires(twiddles12345 == mlk_aarch64_invntt_zetas_layer12345)
57+
requires(twiddles56 == mlk_aarch64_invntt_zetas_layer67)
58+
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
59+
/* check-magic: off */
60+
ensures(array_abs_bound(p, 0, MLKEM_N, 26625))
61+
/* check-magic: on */
62+
);
5163

5264
#define mlk_poly_reduce_asm MLK_NAMESPACE(poly_reduce_asm)
5365
void mlk_poly_reduce_asm(int16_t *);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) The mlkem-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 = intt_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 = intt_native_aarch64
12+
13+
# We need to set MLK_CHECK_APIS as otherwise mlkem/native/api.h won't be
14+
# included, which contains the CBMC specifications.
15+
DEFINES += -DMLK_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLK_CONFIG_ARITH_BACKEND_FILE="\"$(SRCDIR)/mlkem/native/aarch64/meta.h\"" -DMLK_CHECK_APIS
16+
INCLUDES +=
17+
18+
REMOVE_FUNCTION_BODY +=
19+
UNWINDSET +=
20+
21+
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
22+
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c $(SRCDIR)/mlkem/native/aarch64/src/aarch64_zetas.c
23+
24+
CHECK_FUNCTION_CONTRACTS=mlk_intt_native
25+
USE_FUNCTION_CONTRACTS=mlk_intt_asm
26+
APPLY_LOOP_CONTRACTS=on
27+
USE_DYNAMIC_FRAMES=1
28+
29+
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
30+
EXTERNAL_SAT_SOLVER=
31+
CBMCFLAGS=--smt2
32+
33+
FUNCTION_NAME = intt_native_aarch64
34+
35+
# If this proof is found to consume huge amounts of RAM, you can set the
36+
# EXPENSIVE variable. With new enough versions of the proof tools, this will
37+
# restrict the number of EXPENSIVE CBMC jobs running at once. See the
38+
# documentation in Makefile.common under the "Job Pools" heading for details.
39+
# EXPENSIVE = true
40+
41+
# This function is large enough to need...
42+
CBMC_OBJECT_BITS = 8
43+
44+
# If you require access to a file-local ("static") function or object to conduct
45+
# your proof, set the following (and do not include the original source file
46+
# ("mlkem/poly.c") in PROJECT_SOURCES).
47+
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i
48+
# include ../Makefile.common
49+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/poly.c
50+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar
51+
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz
52+
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must
53+
# be set before including Makefile.common, but any use of variables on the
54+
# left-hand side requires those variables to be defined. Hence, _SOURCE,
55+
# _FUNCTIONS, _OBJECTS is set after including Makefile.common.
56+
57+
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 mlkem-native project authors
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: MIT-0
4+
5+
#include <stdint.h>
6+
#include "cbmc.h"
7+
#include "params.h"
8+
9+
void mlk_intt_native(int16_t data[MLKEM_N]);
10+
11+
void harness(void)
12+
{
13+
int16_t *r;
14+
mlk_intt_native(r);
15+
}

proofs/hol_light/arm/proofs/mlkem_intt.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ let intt_constants = define
482482
(* Correctness proof. *)
483483
(* ------------------------------------------------------------------------- *)
484484

485+
(* NOTE: This must be kept in sync with the CBMC specification
486+
* in mlkem/native/aarch64/src/arith_native_aarch64.h *)
487+
485488
let MLKEM_INTT_CORRECT = prove
486489
(`!a z_12345 z_67 x pc.
487490
ALL (nonoverlapping (a,512))

0 commit comments

Comments
 (0)