Skip to content

Commit 44afe49

Browse files
committed
HOL-Light: Add x86 AVX2 nttunpack proof
Signed-off-by: Jake Massimo <jakemas@amazon.com>
1 parent fdfe6ae commit 44afe49

15 files changed

Lines changed: 890 additions & 9 deletions

File tree

.github/workflows/hol_light.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ jobs:
165165
needs: ["mldsa_specs.ml", "mldsa_utils.ml", "mldsa_zetas.ml"]
166166
- name: mldsa_intt
167167
needs: ["mldsa_specs.ml", "mldsa_utils.ml", "mldsa_zetas.ml"]
168+
- name: mldsa_nttunpack
169+
needs: ["mldsa_specs.ml", "mldsa_utils.ml"]
168170
name: x86_64 HOL Light proof for ${{ matrix.proof.name }}.S
169171
runs-on: pqcp-x64
170172
if: github.repository_owner == 'pq-code-package' && !github.event.pull_request.head.repo.fork

BIBLIOGRAPHY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ source code and documentation.
250250
- [mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c](mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c)
251251
- [proofs/hol_light/x86_64/mldsa/mldsa_intt.S](proofs/hol_light/x86_64/mldsa/mldsa_intt.S)
252252
- [proofs/hol_light/x86_64/mldsa/mldsa_ntt.S](proofs/hol_light/x86_64/mldsa/mldsa_ntt.S)
253+
- [proofs/hol_light/x86_64/mldsa/mldsa_nttunpack.S](proofs/hol_light/x86_64/mldsa/mldsa_nttunpack.S)
253254

254255
### `Round3_Spec`
255256

dev/x86_64/src/arith_native_x86_64.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ __contract__(
6161
);
6262

6363
#define mld_nttunpack_avx2 MLD_NAMESPACE(nttunpack_avx2)
64-
void mld_nttunpack_avx2(int32_t *r);
64+
void mld_nttunpack_avx2(int32_t *r)
65+
__contract__(
66+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
67+
requires(array_abs_bound(r, 0, MLDSA_N, 8380417))
68+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
69+
/* Output is a permutation of input: every output coefficient
70+
* is some input coefficient */
71+
ensures(forall(i, 0, MLDSA_N, exists(j, 0, MLDSA_N,
72+
r[i] == old(*(int32_t (*)[MLDSA_N])r)[j])))
73+
);
6574

6675
#define mld_rej_uniform_avx2 MLD_NAMESPACE(mld_rej_uniform_avx2)
6776
MLD_MUST_CHECK_RETURN_VALUE

dev/x86_64/src/nttunpack.S

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
* https://github.com/pq-crystals/dilithium/tree/master/avx2
1414
*/
1515

16-
/*
16+
/*
1717
* This file is derived from the public domain
1818
* AVX2 Dilithium implementation @[REF_AVX2].
1919
*/
2020

21-
#include "../../../common.h"
22-
21+
#include "../../../common.h"
2322
#if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \
2423
!defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
2524
/* simpasm: header-end */

mldsa/src/native/x86_64/src/arith_native_x86_64.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ __contract__(
6161
);
6262

6363
#define mld_nttunpack_avx2 MLD_NAMESPACE(nttunpack_avx2)
64-
void mld_nttunpack_avx2(int32_t *r);
64+
void mld_nttunpack_avx2(int32_t *r)
65+
__contract__(
66+
requires(memory_no_alias(r, sizeof(int32_t) * MLDSA_N))
67+
requires(array_abs_bound(r, 0, MLDSA_N, 8380417))
68+
assigns(memory_slice(r, sizeof(int32_t) * MLDSA_N))
69+
/* Output is a permutation of input: every output coefficient
70+
* is some input coefficient */
71+
ensures(forall(i, 0, MLDSA_N, exists(j, 0, MLDSA_N,
72+
r[i] == old(*(int32_t (*)[MLDSA_N])r)[j])))
73+
);
6574

6675
#define mld_rej_uniform_avx2 MLD_NAMESPACE(mld_rej_uniform_avx2)
6776
MLD_MUST_CHECK_RETURN_VALUE

mldsa/src/native/x86_64/src/nttunpack.S

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
* https://github.com/pq-crystals/dilithium/tree/master/avx2
1414
*/
1515

16-
/*
16+
/*
1717
* This file is derived from the public domain
1818
* AVX2 Dilithium implementation @[REF_AVX2].
1919
*/
2020

21-
#include "../../../common.h"
22-
21+
#include "../../../common.h"
2322
#if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \
2423
!defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
2524

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 = nttunpack_native_x86_64_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 = nttunpack_native_x86_64
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/x86_64/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/polyvec.c
23+
24+
CHECK_FUNCTION_CONTRACTS=mld_poly_permute_bitrev_to_custom
25+
USE_FUNCTION_CONTRACTS=mld_nttunpack_avx2 mld_sys_check_capability
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 = nttunpack_native_x86_64
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+
# ("mldsa/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)/mldsa/src/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: 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 <stdlib.h>
6+
#include "cbmc.h"
7+
#include "params.h"
8+
9+
void mld_poly_permute_bitrev_to_custom(int32_t p[MLDSA_N]);
10+
11+
void harness(void)
12+
{
13+
{
14+
/* Dummy use of `free` to work around CBMC issue #8814. */
15+
free(NULL);
16+
}
17+
int32_t *r;
18+
mld_poly_permute_bitrev_to_custom(r);
19+
}

proofs/hol_light/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ echo '1+1;;' | nc -w 5 127.0.0.1 2012
5454
- AArch64 poly_caddq: [mldsa_poly_caddq.S](aarch64/mldsa/mldsa_poly_caddq.S)
5555
- x86_64 forward NTT: [mldsa_ntt.S](x86_64/mldsa/mldsa_ntt.S)
5656
- x86_64 inverse NTT: [mldsa_intt.S](x86_64/mldsa/mldsa_intt.S)
57+
- x86_64 NTT unpack: [mldsa_nttunpack.S](x86_64/mldsa/mldsa_nttunpack.S)

proofs/hol_light/x86_64/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ endif
5050

5151
SPLIT=tr ';' '\n'
5252

53-
OBJ = mldsa/mldsa_ntt.o mldsa/mldsa_intt.o
53+
OBJ = mldsa/mldsa_ntt.o \
54+
mldsa/mldsa_intt.o \
55+
mldsa/mldsa_nttunpack.o
5456

5557
# Build object files from assembly sources
5658
$(OBJ): %.o : %.S

0 commit comments

Comments
 (0)