Skip to content

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

Libjade

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.

Assurance

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:

Algorithms

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>.ec in 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.

Assembly files

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

Implementations

An implementation of an algorithm is fixed by two choices:

  • its target, the instruction set it runs on: avx2 is x86-64 with AVX2;
  • its profile, what it is optimised for beyond computing the right result: sct is 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/.

Claims

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, ct and sct are checks: the CI runs each of them on the implementations that claim it, and only on them.

  • safety and correctness are proofs: each has its evidence in proofs/<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" }
  • provsec is 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.

API and ABI

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 of jkcp_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, then jkcp_keccak_absorb any number of times, then jkcp_keccak_squeeze any 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, then jkcp_keccakx4_absorb_bcast (the same input in every lane) and jkcp_keccakx4_absorb (four inputs of the same length), then jkcp_keccakx4_squeeze into four outputs; the state has 808 bytes.

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.

Validation

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-ct on 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.

Performance

Results dashboard: proof-checking times and cycle benchmarks for every commit on main.

Contributors

See CONTRIBUTORS.md.

License

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.

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages