TLS 1.3 for QUIC, in Lean 4.
This library has not been audited by any third party.
lean_tls is the TLS 1.3 handshake (RFC 8446) as QUIC carries it (RFC 9001): handshake messages over three encryption levels and the key schedule that yields each level's secrets. There is no record layer, no TLS 1.2 and no DTLS; QUIC protects its own packets. The handshake is a pure state machine with no IO and no randomness of its own: it is given CRYPTO stream bytes and a 32-byte seed per connection, and answers with bytes to send and secrets to install. Its primitives come from Cryptlib.
- Key exchange:
X25519MLKEM768(0x11ec, draft-ietf-tls-ecdhe-mlkem), the hybrid of ML-KEM-768 and X25519.x25519andMLKEM768are also defined. - Cipher suites:
TLS_CHACHA20_POLY1305_SHA256, preferred, andTLS_AES_128_GCM_SHA256. - Authentication: the server signs with Ed25519 (0x0807) or, for post-quantum authentication,
ML-DSA-65 (0x0905, draft-ietf-tls-mldsa;
Server.Config.scheme). The client lists the schemes it accepts (Client.Config.schemes, both by default) and pinsSHA-256(SubjectPublicKeyInfo)of the certificate, as katzenpost's QUIC transport does. Certificates are self-signed in the shape of katzenpost'sepochCertificate(X509.certificateFor). No chain validation, no client certificates. - 1-RTT only: no PSK, no resumption, no 0-RTT, no HelloRetryRequest. Session tickets from the server are ignored.
As in Cryptlib, the correctness of a building block is a field of its type, so a composition carries the laws of its parts.
KeyShareis a named group with the lawagree: an honest client completes the secret the server derived from its share.KeyShare.ofNIKEtakesagreefrom a NIKE's commutativity,KeyShare.ofKEMfrom a KEM's round trip, andKeyShare.concatassembles it from two groups'.x25519mlkem768isconcat mlkem768 x25519and needs no proof of its own.Agreement.keys_agree: when the key exchange isReliableand the server accepts the client's share, the client derives exactly the server's handshake and application traffic secrets.Handshake.handshake_correct: an honest client and server, run against each other on each other's output, both end established with each other's transport parameters, and every level's keys match: what the client reads the server writes, and the other way round. Honest means compatible configurations (group, a common cipher suite, ALPN, sizes), aReliablekey exchange the server accepts, a server random that is not a HelloRetryRequest's, and a certificate that holds the server's signing key and is pinned by the client.CipherSuitecarries a CryptlibAEADand with it that AEAD's laws.WireLaws,MessageLaws: parsers read back what writers write.RT w p x nsays the writerwwrites at mostnbytes from whichpreadsx; it composes like the do-blocks it describes, and holds for extensions, ClientHello, ServerHello, Certificate, CertificateVerify, key shares and ALPN lists.splitMessages_framessplits framed messages back apart.Client.Establishedis the client's evidence that the server is authenticated: its constructor is private to the client handshake, and it holds a proof that the server's SPKI hash is one of the pins and that the CertificateVerify signature verified.Server.Establishedlikewise holds the check of the client's Finished.- Handshake phases carry only what has been established so far, so a message out of order has no transition.
make axioms lists the axioms every theorem depends on. Beyond Lean's own, those built on X25519 use
Cryptlib's p_prime and liftX_isSome_of_exists.
make testLeanTLS.Tests.RFC8448: the RFC 8448 §3 trace byte for byte: the X25519 exchange, every secret of the key schedule, both Finished messages, and a parse and re-encode of every message.testdata/rfc8448_1rtt.jsonis extracted from the RFC's text byscripts/extract_rfc8448.py.LeanTLS.Tests.Handshake: a client and a server run against each other over X25519MLKEM768, with whole flights and one byte at a time; refusals of a wrong pin, wrong ALPN, a tampered Finished and signature, truncated, malformed and oversized messages; and the certificate check against one produced by katzenpost's GoepochCertificate.
The handshake is exercised against Go's crypto/tls and quic-go by lean_quic's interop tests.
make benchLeanBench benchmarks, their own Lake project in bench/: the
whole in-process handshake for X25519MLKEM768 and X25519 with an Ed25519 or ML-DSA-65 server; each
side's step on its own; key shares, CertificateVerify signing and checking, certificate parsing, the
transcript hash and the key schedule; and QUIC packet keys, header protection and AEAD seal/open of
a 1200-byte and 16 KiB payload for both cipher suites. Pass LeanBench flags with BENCH_ARGS.