Skip to content

Commit 6bc95ba

Browse files
committed
CBMC: Prove AArch64 mlk_poly_mulcache_compute_native based on HOL-Light spec
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 242eccb commit 6bc95ba

File tree

6 files changed

+115
-6
lines changed

6 files changed

+115
-6
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,19 @@ __contract__(
8282
);
8383

8484
#define mlk_poly_mulcache_compute_asm MLK_NAMESPACE(poly_mulcache_compute_asm)
85-
void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
86-
const int16_t *);
85+
void mlk_poly_mulcache_compute_asm(int16_t *cache, const int16_t *mlk_poly,
86+
const int16_t *zetas,
87+
const int16_t *zetas_twisted)
88+
/* This must be kept in sync with the HOL-Light specification
89+
* in proofs/hol_light/arm/proofs/mlkem_poly_mulcache_compute.ml */
90+
__contract__(
91+
requires(memory_no_alias(cache, sizeof(int16_t) * (MLKEM_N / 2)))
92+
requires(memory_no_alias(mlk_poly, sizeof(int16_t) * MLKEM_N))
93+
requires(zetas == mlk_aarch64_zetas_mulcache_native)
94+
requires(zetas_twisted == mlk_aarch64_zetas_mulcache_twisted_native)
95+
assigns(object_whole(cache))
96+
ensures(array_abs_bound(cache, 0, MLKEM_N / 2, MLKEM_Q))
97+
);
8798

8899
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
89100
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,19 @@ __contract__(
8282
);
8383

8484
#define mlk_poly_mulcache_compute_asm MLK_NAMESPACE(poly_mulcache_compute_asm)
85-
void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
86-
const int16_t *);
85+
void mlk_poly_mulcache_compute_asm(int16_t *cache, const int16_t *mlk_poly,
86+
const int16_t *zetas,
87+
const int16_t *zetas_twisted)
88+
/* This must be kept in sync with the HOL-Light specification
89+
* in proofs/hol_light/arm/proofs/mlkem_poly_mulcache_compute.ml */
90+
__contract__(
91+
requires(memory_no_alias(cache, sizeof(int16_t) * (MLKEM_N / 2)))
92+
requires(memory_no_alias(mlk_poly, sizeof(int16_t) * MLKEM_N))
93+
requires(zetas == mlk_aarch64_zetas_mulcache_native)
94+
requires(zetas_twisted == mlk_aarch64_zetas_mulcache_twisted_native)
95+
assigns(object_whole(cache))
96+
ensures(array_abs_bound(cache, 0, MLKEM_N / 2, MLKEM_Q))
97+
);
8798

8899
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
89100
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)

mlkem/native/aarch64/src/arith_native_aarch64.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,19 @@ __contract__(
8282
);
8383

8484
#define mlk_poly_mulcache_compute_asm MLK_NAMESPACE(poly_mulcache_compute_asm)
85-
void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
86-
const int16_t *);
85+
void mlk_poly_mulcache_compute_asm(int16_t *cache, const int16_t *mlk_poly,
86+
const int16_t *zetas,
87+
const int16_t *zetas_twisted)
88+
/* This must be kept in sync with the HOL-Light specification
89+
* in proofs/hol_light/arm/proofs/mlkem_poly_mulcache_compute.ml */
90+
__contract__(
91+
requires(memory_no_alias(cache, sizeof(int16_t) * (MLKEM_N / 2)))
92+
requires(memory_no_alias(mlk_poly, sizeof(int16_t) * MLKEM_N))
93+
requires(zetas == mlk_aarch64_zetas_mulcache_native)
94+
requires(zetas_twisted == mlk_aarch64_zetas_mulcache_twisted_native)
95+
assigns(object_whole(cache))
96+
ensures(array_abs_bound(cache, 0, MLKEM_N / 2, MLKEM_Q))
97+
);
8798

8899
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
89100
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)
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 = poly_mulcache_compute_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_mulcache_compute_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_poly_mulcache_compute_native
25+
USE_FUNCTION_CONTRACTS=mlk_poly_mulcache_compute_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 = poly_mulcache_compute_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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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_poly_mulcache_compute_native(int16_t cache[MLKEM_N / 2],
10+
const int16_t mlk_poly[MLKEM_N]);
11+
12+
void harness(void)
13+
{
14+
int16_t *r, *c;
15+
mlk_poly_mulcache_compute_native(c, r);
16+
}

proofs/hol_light/arm/proofs/mlkem_poly_mulcache_compute.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ let have_mulcache_zetas = define
9595
iword (EL i mulcache_zetas_twisted))
9696
`;;
9797

98+
(* NOTE: This must be kept in sync with the CBMC specification
99+
* in mlkem/native/aarch64/src/arith_native_aarch64.h *)
100+
98101
let poly_mulcache_compute_GOAL = `forall pc src dst zetas zetas_twisted x y returnaddress.
99102
ALL (nonoverlapping (dst, 256))
100103
[(word pc, LENGTH poly_mulcache_compute_mc); (src, 512); (zetas, 256); (zetas_twisted, 256)]

0 commit comments

Comments
 (0)