Skip to content

Commit 26d81ad

Browse files
committed
CBMC: Prove AArch64 mlk_poly_tobytes_native based on HOL-Light spec
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 96eeed1 commit 26d81ad

File tree

6 files changed

+105
-4
lines changed

6 files changed

+105
-4
lines changed

dev/aarch64_clean/src/arith_native_aarch64.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
7979
const int16_t *);
8080

8181
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
82-
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a);
82+
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)
83+
/* This must be kept in sync with the HOL-Light specification
84+
* in proofs/hol_light/arm/proofs/mlkem_poly_tobytes.ml */
85+
__contract__(
86+
requires(memory_no_alias(r, MLKEM_POLYBYTES))
87+
requires(memory_no_alias(a, sizeof(int16_t) * MLKEM_N))
88+
requires(array_bound(a, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))
89+
assigns(object_whole(r))
90+
);
8391

8492
#define mlk_polyvec_basemul_acc_montgomery_cached_asm_k2 \
8593
MLK_NAMESPACE(polyvec_basemul_acc_montgomery_cached_asm_k2)

dev/aarch64_opt/src/arith_native_aarch64.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ __contract__(
6565
void mlk_poly_reduce_asm(int16_t *);
6666

6767
#define mlk_poly_tomont_asm MLK_NAMESPACE(poly_tomont_asm)
68+
void mlk_poly_tomont_asm(int16_t *p)
6869
/* This must be kept in sync with the HOL-Light specification
6970
* in proofs/hol_light/arm/proofs/mlkem_poly_tomont.ml */
70-
void mlk_poly_tomont_asm(int16_t *p)
7171
__contract__(
7272
requires(memory_no_alias(p, sizeof(int16_t) * MLKEM_N))
7373
assigns(memory_slice(p, sizeof(int16_t) * MLKEM_N))
@@ -79,7 +79,15 @@ void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
7979
const int16_t *);
8080

8181
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
82-
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a);
82+
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)
83+
/* This must be kept in sync with the HOL-Light specification
84+
* in proofs/hol_light/arm/proofs/mlkem_poly_tobytes.ml */
85+
__contract__(
86+
requires(memory_no_alias(r, MLKEM_POLYBYTES))
87+
requires(memory_no_alias(a, sizeof(int16_t) * MLKEM_N))
88+
requires(array_bound(a, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))
89+
assigns(object_whole(r))
90+
);
8391

8492
#define mlk_polyvec_basemul_acc_montgomery_cached_asm_k2 \
8593
MLK_NAMESPACE(polyvec_basemul_acc_montgomery_cached_asm_k2)

mlkem/native/aarch64/src/arith_native_aarch64.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ void mlk_poly_mulcache_compute_asm(int16_t *, const int16_t *, const int16_t *,
7979
const int16_t *);
8080

8181
#define mlk_poly_tobytes_asm MLK_NAMESPACE(poly_tobytes_asm)
82-
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a);
82+
void mlk_poly_tobytes_asm(uint8_t *r, const int16_t *a)
83+
/* This must be kept in sync with the HOL-Light specification
84+
* in proofs/hol_light/arm/proofs/mlkem_poly_tobytes.ml */
85+
__contract__(
86+
requires(memory_no_alias(r, MLKEM_POLYBYTES))
87+
requires(memory_no_alias(a, sizeof(int16_t) * MLKEM_N))
88+
requires(array_bound(a, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))
89+
assigns(object_whole(r))
90+
);
8391

8492
#define mlk_polyvec_basemul_acc_montgomery_cached_asm_k2 \
8593
MLK_NAMESPACE(polyvec_basemul_acc_montgomery_cached_asm_k2)
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_tobytes_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_tobytes_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
23+
24+
CHECK_FUNCTION_CONTRACTS=mlk_poly_tobytes_native
25+
USE_FUNCTION_CONTRACTS=mlk_poly_tobytes_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_tobytes_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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
10+
const int16_t a[MLKEM_N]);
11+
12+
void harness(void)
13+
{
14+
uint8_t *r;
15+
int16_t *a;
16+
mlk_poly_tobytes_native(r, a);
17+
}

proofs/hol_light/arm/proofs/mlkem_poly_tobytes.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ let lemma =
168168
CONV_RULE(EXPAND_CASES_CONV THENC
169169
DEPTH_CONV (NUM_RED_CONV ORELSEC EL_CONV)) th';;
170170

171+
(* NOTE: This must be kept in sync with the CBMC specification
172+
* in mlkem/native/aarch64/src/arith_native_aarch64.h *)
173+
171174
let MLKEM_POLY_TOBYTES_CORRECT = prove
172175
(`!r a (l:int16 list) pc.
173176
ALL (nonoverlapping (r,384)) [(word pc,0x158); (a,512)]

0 commit comments

Comments
 (0)