You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -13,11 +13,12 @@
13
13
mlkem-native is a secure, fast, and portable C90 implementation of [ML-KEM](https://doi.org/10.6028/NIST.FIPS.203).
14
14
It is a fork of the ML-KEM [reference implementation](https://github.com/pq-crystals/kyber/tree/main/ref).
15
15
16
+
Large parts of mlkem-native are formally verified: All C code in [mlkem/*](mlkem) and [mlkem/fips202/*](mlkem/fips202) is verified
17
+
using [CBMC](https://github.com/diffblue/cbmc) to be free of various classes of undefined behaviour. [HOL-Light](https://github.com/jrh13/hol-light) is used to verify
18
+
the functional correctness of core AArch64 assembly routines.
19
+
16
20
mlkem-native includes native backends for AArch64 and AVX2, offering competitive performance on most Arm, Intel, and AMD platforms
17
-
(see [benchmarks](https://pq-code-package.github.io/mlkem-native/dev/bench/)). The frontend and the C backend (i.e., all C code in [mlkem/*](mlkem) and [mlkem/fips202/*](mlkem/fips202)) are verified
18
-
using [CBMC](https://github.com/diffblue/cbmc) to be free of various classes of undefined behaviour. In particular, there are no out of
19
-
bounds accesses, nor integer overflows during optimized modular arithmetic.
20
-
[HOL-Light](https://github.com/jrh13/hol-light) is used to verify the functional correctness of core AArch64 assembly routines.
21
+
(see [benchmarks](https://pq-code-package.github.io/mlkem-native/dev/bench/)).
21
22
22
23
mlkem-native is supported by the [Post-Quantum Cryptography Alliance](https://pqca.org/) as part of the [Linux Foundation](https://linuxfoundation.org/).
This directory contains material related to the formal verification of the source code of mlkem-native.
6
+
7
+
## C verification: CBMC
8
+
9
+
We use the [C Bounded Model Checker (CBMC)](https://github.com/diffblue/cbmc) to show the absence of various classes of undefined behaviour in the mlkem-native C source, including out of bounds memory accesses and integer overflows. See [proofs/cbmc](cbmc).
10
+
11
+
## Assembly verification: HOL-Light
12
+
13
+
We use the [HOL-Light](https://github.com/jrh13/hol-light) interactive theorem prover alongside the verification infrastructure from [s2n-bignum](https://github.com/awslabs/s2n-bignum) to show the functional correctness of various highly optimized assembly routines in mlkem-native at the object-code level. See [proofs/hol_light/arm](hol_light/arm).
Copy file name to clipboardExpand all lines: proofs/hol_light/arm/README.md
+61-20Lines changed: 61 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,52 @@ prover, utilizing the assembly verification infrastructure from [s2n-bignum](htt
9
9
10
10
Each function is proved in a separate `.ml` file in [proofs/](proofs). Each file
11
11
contains the byte code being verified, as well as the specification that is being
12
-
proved. Specifications are essentially Hoare triples, with the noteworthy difference
13
-
that the program is implicit as the content of memory at the PC; which is asserted to
14
-
be the code under verification as part of the precondition.
12
+
proved.
15
13
16
-
## What is covered?
14
+
## Primer
17
15
18
-
At present, this directory contains functional correctness proofs for the following functions:
16
+
Proofs are 'post-hoc' in the sense that HOL-Light/s2n-bignum operate on the final object code. In particular, the means by which the code was generated (including the [SLOTHY](https://github.com/slothy-optimizer/slothy/) superoptimizer) need not be trusted.
* AArch64 base multiplications: [mlkem_poly_basemul_acc_montgomery_cached_k2.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k2.S)[mlkem_poly_basemul_acc_montgomery_cached_k3.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k3.S)[mlkem_poly_basemul_acc_montgomery_cached_k4.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k4.S)
24
-
* AArch64 conversion to Montgomery form: [mlkem_poly_tomont.S](mlkem/mlkem_poly_tomont.S)
* Keccak-F1600 using lazy rotations (see [this paper](https://eprint.iacr.org/2022/1243)): [keccak_f1600_x1_scalar.S](mlkem/keccak_f1600_x1_scalar.S)
29
-
* Keccak-F1600 using v8.4-A SHA3 instructions: [keccak_f1600_x1_v84a.S](mlkem/keccak_f1600_x1_v84a.S)
30
-
* 2-fold Keccak-F1600 using v8.4-A SHA3 instructions: [keccak_f1600_x2_v84a.S](mlkem/keccak_f1600_x2_v84a.S)
31
-
* 'Hybrid' 4-fold Keccak-F1600 using scalar and v8-A Neon instructions: [keccak_f1600_x4_v8a_scalar.S](mlkem/keccak_f1600_x4_v8a_scalar.S)
32
-
* 'Triple hybrid' 4-fold Keccak-F1600 using scalar, v8-A Neon and v8.4-A+SHA3 Neon instructions:[keccak_f1600_x4_v8a_v84a_scalar.S](mlkem/keccak_f1600_x4_v8a_v84a_scalar.S)
18
+
Specifications are essentially [Hoare triples](https://en.wikipedia.org/wiki/Hoare_logic), with the noteworthy difference that the program is implicit as the content of memory at the PC; which is asserted to
19
+
be the code under verification as part of the precondition. For example, the following is the specification of the `poly_reduce` function:
33
20
34
-
The NTT and invNTT functions are super-optimized using [SLOTHY](https://github.com/slothy-optimizer/slothy/).
21
+
```ocaml
22
+
(* For all (abbreviated by `!` in HOL):
23
+
- a: Source pointer
24
+
- pc: Current value of Program Counter (PC)
25
+
- returnaddress: Return address in the link register *)
26
+
`!a x pc returnaddress.
27
+
(* Assume that the program and the source pointer don't overlap *)
28
+
nonoverlapping (word pc,0x124) (a,512)
29
+
==> ensures arm
30
+
(* Precondition *)
31
+
(\s. (* The memory at the current PC is the byte-code of poly_reduce() *)
32
+
aligned_bytes_loaded s (word pc) mlkem_poly_reduce_mc /\
33
+
read PC s = word pc /\
34
+
(* The return address is stored in the link register (LR) *)
35
+
read X30 s = returnaddress /\
36
+
(* The source pointer is in X0 *)
37
+
C_ARGUMENTS [a] s /\
38
+
(* Give a name to the memory contents at the source pointer *)
39
+
!i. i < 256
40
+
==> read(memory :> bytes16(word_add a (word(2 * i)))) s = x i)
41
+
(* Postcondition: Eventually we reach a state where ... *)
42
+
(\s.
43
+
(* The PC is the original value of the link register *)
44
+
read PC s = returnaddress /\
45
+
(* The integers represented by the final memory contents
46
+
* are the unsigned canonical reductions mod 3329
47
+
* of the integers represented by the original memory contents. *)
* AArch64 base multiplications: [mlkem_poly_basemul_acc_montgomery_cached_k2.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k2.S)[mlkem_poly_basemul_acc_montgomery_cached_k3.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k3.S)[mlkem_poly_basemul_acc_montgomery_cached_k4.S](mlkem/mlkem_poly_basemul_acc_montgomery_cached_k4.S)
83
+
* AArch64 conversion to Montgomery form: [mlkem_poly_tomont.S](mlkem/mlkem_poly_tomont.S)
0 commit comments