Skip to content

Commit f654c2f

Browse files
committed
Add ABI checker for AArch64, x86_64 (SysV), PowerPC64, Armv8.1-M+MVE
Verify that each assembly kernel preserves the callee-saved registers its platform calling convention requires: - AArch64 (AAPCS64): x19-x28, x29/FP, lower 64 bits of d8-d15. - x86_64 (System V): rbx, rbp, r12-r15. No SIMD register callee-saved. - PowerPC64 (ELFv2): GPRs r14-r31, FPRs f14-f31, VRs v20-v31, CR2-CR4. - Armv8.1-M (AAPCS32): r4-r11 plus MVE Q4-Q7 (= D8-D15). A per-arch assembly call stub loads a random register state, calls the kernel, and captures the result; a checker then confirms the callee-saved set is intact. Pointer arguments are backed by correctly-sized buffers whose layout comes from a per-kernel YAML block; scripts/autogen turns that YAML into the per-kernel checks. A self-test of hand-written corrupters confirms the checker actually fires before kernel verdicts are trusted. Run via `make run_abicheck` or `scripts/tests abicheck`. It needs no library build, so `scripts/tests all` runs it by default. See test/abicheck/README.md for details. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 4872e7a commit f654c2f

213 files changed

Lines changed: 8700 additions & 14 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/mlc_config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
"pattern": "^http://nvlpubs\\.nist\\.gov"
2121
},
2222
{
23+
"_comment": "IACR ePrint rate-limits / 403s automated link-checks.",
2324
"pattern": "^https://eprint\\.iacr\\.org"
25+
},
26+
{
27+
"_comment": "Armv8-M Architecture Reference Manual; the Arm developer site rate-limits / 403s automated link-checks.",
28+
"pattern": "^https://developer\\.arm\\.com"
2429
}
2530
]
2631
}

BIBLIOGRAPHY.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
This file lists the citations made throughout the mlkem-native
88
source code and documentation.
99

10+
### `AAPCS32`
11+
12+
* Procedure Call Standard for the Arm Architecture (AAPCS32)
13+
* Author(s):
14+
- Arm Limited
15+
* URL: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst
16+
* Referenced from:
17+
- [test/abicheck/README.md](test/abicheck/README.md)
18+
- [test/abicheck/armv81m/abicheck_armv81m.c](test/abicheck/armv81m/abicheck_armv81m.c)
19+
20+
### `AAPCS64`
21+
22+
* Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64)
23+
* Author(s):
24+
- Arm Limited
25+
* URL: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
26+
* Referenced from:
27+
- [test/abicheck/README.md](test/abicheck/README.md)
28+
- [test/abicheck/aarch64/abicheck_aarch64.c](test/abicheck/aarch64/abicheck_aarch64.c)
29+
1030
### `ACVP`
1131

1232
* Automated Cryptographic Validation Protocol (ACVP) Server
@@ -30,6 +50,16 @@ source code and documentation.
3050
- [proofs/hol_light/x86_64/mlkem/intt_avx2_asm.S](proofs/hol_light/x86_64/mlkem/intt_avx2_asm.S)
3151
- [proofs/hol_light/x86_64/mlkem/ntt_avx2_asm.S](proofs/hol_light/x86_64/mlkem/ntt_avx2_asm.S)
3252

53+
### `ArmARMv8M`
54+
55+
* Armv8-M Architecture Reference Manual (DDI 0553)
56+
* Author(s):
57+
- Arm Limited
58+
* URL: https://developer.arm.com/documentation/ddi0553/latest/
59+
* Referenced from:
60+
- [test/abicheck/README.md](test/abicheck/README.md)
61+
- [test/abicheck/armv81m/abicheck_armv81m.c](test/abicheck/armv81m/abicheck_armv81m.c)
62+
3363
### `CBMC`
3464

3565
* C Bounded Model Checker
@@ -249,6 +279,16 @@ source code and documentation.
249279
- [proofs/hol_light/aarch64/mlkem/polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S](proofs/hol_light/aarch64/mlkem/polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S)
250280
- [proofs/hol_light/aarch64/mlkem/polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S](proofs/hol_light/aarch64/mlkem/polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S)
251281

282+
### `PPC64ELFv2`
283+
284+
* 64-Bit ELFv2 ABI Specification — Power Architecture
285+
* Author(s):
286+
- OpenPOWER Foundation
287+
* URL: https://openpowerfoundation.org/specifications/64bitelfabi/
288+
* Referenced from:
289+
- [test/abicheck/README.md](test/abicheck/README.md)
290+
- [test/abicheck/ppc64le/abicheck_ppc64le.c](test/abicheck/ppc64le/abicheck_ppc64le.c)
291+
252292
### `REF`
253293

254294
* CRYSTALS-Kyber C reference implementation
@@ -375,6 +415,19 @@ source code and documentation.
375415
- [proofs/hol_light/aarch64/mlkem/intt_aarch64_asm.S](proofs/hol_light/aarch64/mlkem/intt_aarch64_asm.S)
376416
- [proofs/hol_light/aarch64/mlkem/ntt_aarch64_asm.S](proofs/hol_light/aarch64/mlkem/ntt_aarch64_asm.S)
377417

418+
### `SysVAMD64`
419+
420+
* System V Application Binary Interface — AMD64 Architecture Processor Supplement
421+
* Author(s):
422+
- Michael Matz
423+
- Jan Hubička
424+
- Andreas Jaeger
425+
- Mark Mitchell
426+
* URL: https://gitlab.com/x86-psABIs/x86-64-ABI
427+
* Referenced from:
428+
- [test/abicheck/README.md](test/abicheck/README.md)
429+
- [test/abicheck/x86_64/abicheck_x86_64.c](test/abicheck/x86_64/abicheck_x86_64.c)
430+
378431
### `clangover`
379432

380433
* clangover

BIBLIOGRAPHY.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,37 @@
206206
name: tiny_sha3
207207
author: Saarinen, Markku-Juhani O.
208208
url: https://github.com/mjosaarinen/tiny_sha3
209+
210+
- id: AAPCS64
211+
short: AAPCS64
212+
name: "Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64)"
213+
author: Arm Limited
214+
url: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
215+
216+
- id: AAPCS32
217+
short: AAPCS32
218+
name: "Procedure Call Standard for the Arm Architecture (AAPCS32)"
219+
author: Arm Limited
220+
url: https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst
221+
222+
- id: SysVAMD64
223+
short: System V AMD64 psABI
224+
name: "System V Application Binary Interface — AMD64 Architecture Processor Supplement"
225+
author:
226+
- Matz, Michael
227+
- Hubička, Jan
228+
- Jaeger, Andreas
229+
- Mitchell, Mark
230+
url: https://gitlab.com/x86-psABIs/x86-64-ABI
231+
232+
- id: PPC64ELFv2
233+
short: PPC64 ELFv2
234+
name: "64-Bit ELFv2 ABI Specification — Power Architecture"
235+
author: OpenPOWER Foundation
236+
url: https://openpowerfoundation.org/specifications/64bitelfabi/
237+
238+
- id: ArmARMv8M
239+
short: Armv8-M ARM
240+
name: "Armv8-M Architecture Reference Manual (DDI 0553)"
241+
author: Arm Limited
242+
url: https://developer.arm.com/documentation/ddi0553/latest/

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
clean quickcheck check-defined-CYCLES \
1818
size_512 size_768 size_1024 size \
1919
run_size_512 run_size_768 run_size_1024 run_size \
20-
host_info
20+
host_info abicheck run_abicheck
2121

2222
SHELL := /usr/bin/env bash
2323
.DEFAULT_GOAL := build
@@ -46,7 +46,7 @@ quickcheck: test
4646
build: func kat acvp wycheproof
4747
$(Q)echo " Everything builds fine!"
4848

49-
test: run_kat run_func run_acvp run_wycheproof run_unit run_alloc run_rng_fail
49+
test: run_kat run_func run_acvp run_wycheproof run_unit run_alloc run_rng_fail run_abicheck
5050
$(Q)echo " Everything checks fine!"
5151

5252
run_kat_512: kat_512
@@ -245,6 +245,21 @@ run_size: \
245245
run_size_768 \
246246
run_size_1024
247247

248+
# OPT=0: no-op (native asm only built with OPT=1).
249+
# Per-arch gating lives in the sources; x86_64 is also gated on
250+
# MLK_SYSV_ABI_SUPPORTED because the call stub is hand-written SysV asm.
251+
# Unsupported targets get an empty registry and exit success, so this builds
252+
# and runs cleanly on every arch (e.g. riscv64) with no explicit allowlist.
253+
ifeq ($(OPT),1)
254+
abicheck: $(ABICHECK_DIR)/bin/abicheck
255+
256+
run_abicheck: abicheck
257+
$(W) $(ABICHECK_DIR)/bin/abicheck
258+
else
259+
abicheck:
260+
run_abicheck:
261+
endif
262+
248263
# Display host and compiler feature detection information
249264
# Shows which architectural features are supported by both the compiler and host CPU
250265
# Usage: make host_info [AUTO=0|1] [CROSS_PREFIX=...]

dev/aarch64_clean/src/intt_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
Description: AArch64 ML-KEM inverse NTT following @[NeonNTT] and @[SLOTHY_Paper]
2525
Signature: void mlk_intt_aarch64_asm(int16_t p[256], const int16_t twiddles12345[80], const int16_t twiddles56[384])
2626
ABI:
27+
Architecture: aarch64
28+
CallingConvention: AAPCS64
2729
x0:
2830
type: buffer
2931
size_bytes: 512

dev/aarch64_clean/src/ntt_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
Description: AArch64 ML-KEM forward NTT following @[NeonNTT] and @[SLOTHY_Paper]
2525
Signature: void mlk_ntt_aarch64_asm(int16_t p[256], const int16_t twiddles12345[80], const int16_t twiddles56[384])
2626
ABI:
27+
Architecture: aarch64
28+
CallingConvention: AAPCS64
2729
x0:
2830
type: buffer
2931
size_bytes: 512

dev/aarch64_clean/src/poly_mulcache_compute_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Description: Compute multiplication cache for polynomial
99
Signature: void mlk_poly_mulcache_compute_aarch64_asm(int16_t cache[128], const int16_t mlk_poly[256], const int16_t zetas[128], const int16_t zetas_twisted[128])
1010
ABI:
11+
Architecture: aarch64
12+
CallingConvention: AAPCS64
1113
x0:
1214
type: buffer
1315
size_bytes: 256

dev/aarch64_clean/src/poly_reduce_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Description: Barrett reduction of polynomial coefficients
99
Signature: void mlk_poly_reduce_aarch64_asm(int16_t p[256])
1010
ABI:
11+
Architecture: aarch64
12+
CallingConvention: AAPCS64
1113
x0:
1214
type: buffer
1315
size_bytes: 512

dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Description: Convert polynomial to byte representation
99
Signature: void mlk_poly_tobytes_aarch64_asm(uint8_t r[384], const int16_t a[256])
1010
ABI:
11+
Architecture: aarch64
12+
CallingConvention: AAPCS64
1113
x0:
1214
type: buffer
1315
size_bytes: 384

dev/aarch64_clean/src/poly_tomont_aarch64_asm.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Description: Convert polynomial to Montgomery domain
99
Signature: void mlk_poly_tomont_aarch64_asm(int16_t p[256])
1010
ABI:
11+
Architecture: aarch64
12+
CallingConvention: AAPCS64
1113
x0:
1214
type: buffer
1315
size_bytes: 512

0 commit comments

Comments
 (0)