Libjade is a formally verified cryptographic library written in the Jasmin programming language, with machine-checked proofs in EasyCrypt. Libjade is part of Formosa Crypto. Its focus is high-assurance implementations of standardized cryptographic algorithms, with a special emphasis on the NIST post-quantum standards.
Libjade aims to be on par with other cryptographic libraries with respect to common validation techniques for basic safety and correctness properties: the CI checks the code for known-answer tests for correctness/compliance and Valgrind for memory safety.
We use high-assurance to mean that machine-checked proofs come on top of the above validation steps. ASSURANCE.md explains in more detail what properties the machine-checked proofs establish and under what assumptions (i.e., what is the Trusted Code Base).
In particular, ASSURANCE.md clarifies the meaning of the following terms used in this README:
- Validation: KAT, Memcheck
- High assurance
- End-to-end proofs:
- security of the specification: the security theorem of the EasyCrypt specification of the standard;
- correctness, compilation, safety, CT and SCT;
- ProvSec: how far the security theorem of the specification carries over to the implementation.
- Trusted computing base
Each algorithm has an EasyCrypt specification of its standard, with the security theorem of the specification, stated once for all parameter sets and instantiated for each set it covers:
-
ML-KEM (FIPS 203), parameter sets 512, 768 and 1024: MLKEM.ec; IND-CCA in the ROM (MLKEMSecurity.ec), for 768 (Security768.ec) and 1024 (Security1024.ec);
-
ML-DSA (FIPS 204), parameter sets 44, 65 and 87: MLDSA.ec; EUF-CMA in the ROM, hedged signing, with leakage (MLDSA_Security.ec), for 44, 65 and 87 (
Security<set>.ecin the same directory). -
SHA-3 (FIPS 202), SHA3-224/256/384/512 and SHAKE128/256: FIPS202_SHA3.ec, with no security theorem. Its implementation, the Jasmin Keccak Code Package (JKCP), covers every function at once (see src/fips202/README.md); its building blocks, under
src/fips202/<target>/common/, are also what ML-KEM and ML-DSA use.
Each implementation is a self-contained assembly file and an accompanying C header:
asm/<algorithm>/<target>/<algorithm><parameter set>_<target>_<profile>.s
src/include/<algorithm><parameter set>.h
The assembly is compiled from
src/<algorithm>/<target>/<profile>/<parameter set>/ by make -C src extract-asm;
CI fails if a committed file differs from the assembly it compiles.
SHA-3 is one implementation of every function, in two assembly files, single lane and 4-way, with one header:
asm/fips202/avx2/fips202x1_avx2_sct.s (from src/fips202/ref/JKCP.jazz)
asm/fips202/avx2/fips202x4_avx2_sct.s (from src/fips202/avx2/JKCP.jazz)
src/include/JKCP.h
An implementation of an algorithm is fixed by two choices:
- its target, the instruction set it runs on:
avx2is x86-64 with AVX2; - its profile, what it is optimised for beyond computing the right result:
sctis optimised for speed and protected against timing side channels, with CT and SCT countermeasures.
Every algorithm has one implementation, avx2 / sct. The sources of ML-KEM and
ML-DSA are in src/<algorithm>/avx2/sct/, one directory per parameter set; those of
SHA-3 are the two JKCP programs of src/fips202/.
Each parameter set of an implementation states what it guarantees in
src/<algorithm>/<target>/<profile>/<parameter set>/meta.toml:
claims = ["kat", "memcheck", "ct", "sct", "safety", "correctness"]
provsec = "functional"An implementation of every parameter set at once, as JKCP, states it in
src/<algorithm>/meta.toml, with its target, its profile and the name of its scheme
in bench/; it claims checks only, for now:
target = "avx2"
profile = "sct"
scheme = "FIPS-202"
claims = ["kat", "memcheck", "ct", "sct"]-
kat,memcheck,ctandsctare checks: the CI runs each of them on the implementations that claim it, and only on them. -
safetyandcorrectnessare proofs: each has its evidence inproofs/<algorithm>/<target>/<profile>/<property>/<parameter set>/meta.toml, the EasyCrypt lemma that proves it for each operation of the algorithm, stated for the parameter set in that directory:keygen = { file = "correctness65.ec", lemma = "keygen_correct" } sign = { file = "correctness65.ec", lemma = "sign_correct" } verify = { file = "correctness65.ec", lemma = "verify_correct" }
-
provsecis the ProvSec kind of the implementation: how far the security theorem of the specification carries over to the implementation. functional means that the correctness of the implementation and the security of the specification are proved separately and there is no explicit reduction from specification security to implementation security; reduction and leakage-aware reduction mean that an EasyCrypt theorem states the security of the implementation, in the latter case showing that the constant-time leakage has a theoretical justification.
scripts/claims.py checks the claims on every pull request: every entry point of
src/ has its meta.toml, every proved claim has the lemma of each operation, in a
file that the proofs CI checks, and functional has the correctness proof and the
instance of the security theorem of the specification for the parameter set.
The assembly follows the System V AMD64 ABI, in AT&T syntax, for Linux (ELF). Target
avx2 runs on x86-64 with AVX2.
The API follows libsodium and NaCl: objects are byte arrays passed by pointer, and
the header gives their sizes. The functions take their randomness as an argument.
The exported functions of each algorithm, with <p> the parameter set:
- ML-KEM,
jade_kem_mlkem_mlkem<p>_amd64_avx2_<function>:keypair_derand: key generation from 64 bytes of coins (Algorithm 16 in FIPS 203). Returns 0.enc_derand: modulus check of the public key (Section 7.2 in FIPS 203), then encapsulation with 32 bytes of coins (Algorithm 17 in FIPS 203). Returns 0, or -1 with an all-zero ciphertext and shared secret when the check fails.dec: hash check of the secret key (Section 7.3 in FIPS 203), then decapsulation (Algorithm 18 in FIPS 203). Returns 0, or -1 with an all-zero shared secret when the check fails.check_pk: modulus check of the public key (Section 7.2 in FIPS 203). Returns 0, or -1 when the check fails.check_sk: hash check of the secret key (Section 7.3 in FIPS 203). Returns 0, or -1 when the check fails.
- ML-DSA,
ml_dsa_<p>_<function>:keygen: key generation from 32 bytes of randomness (Algorithm 6 in FIPS 204). No return value.sign: signature of a message with a context and 32 bytes of randomness (Algorithm 2 in FIPS 204). Returns 0; -1 when the context is longer than 255 bytes; -1 with an all-zero signature when the signing loop reaches its iteration bound.verify: verification of a signature on a message with a context (Algorithm 3 in FIPS 204). Returns 0 when the signature verifies, -1 when the context is longer than 255 bytes, and a nonzero value otherwise.
- SHA-3 (JKCP,
src/include/JKCP.h), with<f>one ofjkcp_sha3_224,jkcp_sha3_256,jkcp_sha3_384,jkcp_sha3_512,jkcp_shake128,jkcp_shake256:- one-shot,
<f>: the hash of a message (jkcp_shake*take the output length too); - incremental, single lane:
<f>_init, thenjkcp_keccak_absorbany number of times, thenjkcp_keccak_squeezeany number of times (the first squeeze of a positive length applies the padding); the caller owns the 208-byte state; - incremental, 4-way:
<f>x4_init, thenjkcp_keccakx4_absorb_bcast(the same input in every lane) andjkcp_keccakx4_absorb(four inputs of the same length), thenjkcp_keccakx4_squeezeinto four outputs; the state has 808 bytes.
- one-shot,
The header of each implementation describes informally the contract of each function: what it requires from the caller, what it ensures, and what the code declassifies.
The caller may pass unaligned pointers, but must adhere to the following restrictions:
- pass memory regions that do not overlap;
- avoid data races on the memory regions passed to a call.
Jasmin has no global mutable variables, so the code keeps no state between calls, and concurrent calls are thread safe under the rules above.
The headers are not verified: the proofs are about the Jasmin functions, and the C
declarations of src/include/ are part of the trusted computing base.
CI runs these checks on every pull request and every commit on main
(checks.yml):
- KAT: the known-answer tests of the parameter set (
bench/vectors/), from NIST ACVP and post-quantum-cryptography/KAT; for SHA-3, every NIST ACVP test with a byte-aligned message, through the one-shot, incremental and 4-way functions; - memcheck: Valgrind's memcheck on every operation;
- CT and SCT:
jasmin-cton the entry point (for SHA-3, on both JKCP programs); - extraction: the committed EasyCrypt models and assembly are the extraction of
src/, and the claims are consistent (scripts/claims.py, see Claims).
KAT, memcheck, CT and SCT run on the implementations that claim them (scripts/checks.py).
Checks dashboard: the results of
every commit on main.
Results dashboard: proof-checking times
and cycle benchmarks for every commit on main.
See CONTRIBUTORS.md.
Libjade is dual-licensed under CC0 1.0 or
Apache 2.0, at your option
(SPDX-License-Identifier: CC0-1.0 OR Apache-2.0, see LICENSE). The
submodules of bench/third_party/ keep their own licenses.