Skip to content

Commit 9fd0d76

Browse files
committed
HOL-Light/x86_64: Replace Keccakx4 intrinsics with AVX2 assembly and prove correct
- Ports pq-code-package/mlkem-native#1576 Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 339e496 commit 9fd0d76

33 files changed

+3905
-531
lines changed

.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: keccak_f1600_x4_avx2
169+
needs: ["keccak_utils.ml", "keccak_spec.ml", "keccak_f1600_x4_avx2_constants.ml", "keccak_constants.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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ HOL-Light functional correctness proofs can be found in [proofs/hol_light](proof
6565

6666
- AArch64 poly_caddq [poly_caddq_asm.S](mldsa/src/native/aarch64/src/poly_caddq_asm.S)
6767
- x86_64 NTT [ntt.S](mldsa/src/native/x86_64/src/ntt.S)
68+
- x86_64 4-fold Keccak-F1600 using AVX2 [keccak_f1600_x4_avx2.S](mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S)
6869

6970
These proofs utilize the verification infrastructure in [s2n-bignum](https://github.com/awslabs/s2n-bignum).
7071

dev/fips202/aarch64/src/keccakf1600_round_constants.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/*
2-
* Copyright (c) The mlkem-native project authors
32
* Copyright (c) The mldsa-native project authors
43
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
54
*/
65

6+
/*
7+
* WARNING: This file is auto-generated from scripts/autogen
8+
* in the mldsa-native repository.
9+
* Do not modify it directly.
10+
*/
11+
712
#include "../../../../common.h"
813

914
#if (defined(MLD_FIPS202_AARCH64_NEED_X1_SCALAR) || \
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@
44
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
55
*/
66

7-
#ifndef MLD_FIPS202_NATIVE_X86_64_XKCP_H
8-
#define MLD_FIPS202_NATIVE_X86_64_XKCP_H
7+
#ifndef MLD_DEV_FIPS202_X86_64_KECCAK_F1600_X4_AVX2_H
8+
#define MLD_DEV_FIPS202_X86_64_KECCAK_F1600_X4_AVX2_H
99

1010
#include "../../../common.h"
1111

12-
#define MLD_FIPS202_X86_64_XKCP
12+
#define MLD_FIPS202_X86_64_NEED_X4_AVX2
13+
14+
/* Part of backend API */
15+
#define MLD_USE_FIPS202_X4_NATIVE
1316

1417
#if !defined(__ASSEMBLER__)
1518
#include "../api.h"
16-
#include "src/KeccakP_1600_times4_SIMD256.h"
17-
18-
#define MLD_USE_FIPS202_X4_NATIVE
19+
#include "src/fips202_native_x86_64.h"
1920
MLD_MUST_CHECK_RETURN_VALUE
2021
static MLD_INLINE int mld_keccak_f1600_x4_native(uint64_t *state)
2122
{
2223
if (!mld_sys_check_capability(MLD_SYS_CAP_AVX2))
2324
{
2425
return MLD_NATIVE_FUNC_FALLBACK;
2526
}
26-
mld_keccakf1600x4_permute24(state);
27+
28+
mld_keccak_f1600_x4_avx2(state, mld_keccakf1600_round_constants,
29+
mld_keccak_rho8, mld_keccak_rho56);
2730
return MLD_NATIVE_FUNC_SUCCESS;
2831
}
2932
#endif /* !__ASSEMBLER__ */
3033

31-
#endif /* !MLD_FIPS202_NATIVE_X86_64_XKCP_H */
34+
#endif /* !MLD_DEV_FIPS202_X86_64_KECCAK_F1600_X4_AVX2_H */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) The mlkem-native project authors
3+
* Copyright (c) The mldsa-native project authors
4+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
5+
*/
6+
7+
#ifndef MLD_DEV_FIPS202_X86_64_SRC_FIPS202_NATIVE_X86_64_H
8+
#define MLD_DEV_FIPS202_X86_64_SRC_FIPS202_NATIVE_X86_64_H
9+
10+
#include "../../../../cbmc.h"
11+
#include "../../../../common.h"
12+
13+
/* TODO: Reconsider whether this check is needed -- x86_64 is always
14+
* little-endian, so the backend selection already implies this. */
15+
#ifndef MLD_SYS_LITTLE_ENDIAN
16+
#error Expecting a little-endian platform
17+
#endif
18+
19+
#define mld_keccakf1600_round_constants \
20+
MLD_NAMESPACE(keccakf1600_round_constants)
21+
extern const uint64_t mld_keccakf1600_round_constants[];
22+
23+
#define mld_keccak_rho8 MLD_NAMESPACE(keccak_rho8)
24+
extern const uint64_t mld_keccak_rho8[];
25+
26+
#define mld_keccak_rho56 MLD_NAMESPACE(keccak_rho56)
27+
extern const uint64_t mld_keccak_rho56[];
28+
29+
#define mld_keccak_f1600_x4_avx2 MLD_NAMESPACE(keccak_f1600_x4_avx2)
30+
void mld_keccak_f1600_x4_avx2(uint64_t states[100], const uint64_t rc[24],
31+
const uint64_t rho8[4], const uint64_t rho56[4])
32+
/* This must be kept in sync with the HOL-Light specification
33+
* in proofs/hol_light/x86_64/proofs/keccak_f1600_x4_avx2.ml */
34+
__contract__(
35+
requires(memory_no_alias(states, sizeof(uint64_t) * 25 * 4))
36+
requires(rc == mld_keccakf1600_round_constants)
37+
requires(rho8 == mld_keccak_rho8)
38+
requires(rho56 == mld_keccak_rho56)
39+
assigns(memory_slice(states, sizeof(uint64_t) * 25 * 4))
40+
);
41+
42+
#endif /* !MLD_DEV_FIPS202_X86_64_SRC_FIPS202_NATIVE_X86_64_H */

0 commit comments

Comments
 (0)