SparkTLS is a TLS 1.3 and TLS 1.2 implementation in SPARK/Ada. The library contains no C code; the accelerated crypto paths in SPARKTLSCrypto use x86 inline assembly.
Note: this project is pre-release and not yet suitable for production use.
- TLS 1.3 client and server: full handshake, HelloRetryRequest, PSK
resumption (
psk_dhe_keonly, forward secret), KeyUpdate, exporters, mutual authentication, SNI-based identity selection, and a server-side identity set (Config.Identities) chosen by the client's signature algorithms, cipher-suite family, curves and certificate_authorities. - TLS 1.2 client and server: ECDHE suites only (RSA and ECDSA authentication), extended master secret, mutual authentication, RFC 5077 session-ticket resumption.
- Key exchange: X25519, secp256r1 (P-256), secp384r1 (P-384), and the
post-quantum hybrid X25519MLKEM768 (TLS 1.3, on by default; ML-KEM-768
from the
sparkmlkemcrate, itself derived from AWS LibFormalPQC). - Cipher suites: ChaCha20-Poly1305-SHA256, AES-128-GCM-SHA256, AES-256-GCM-SHA384.
- Signatures: Ed25519, ECDSA P-256/P-384, RSA-PSS and RSA-PKCS#1 v1.5
(SHA-256/384/512). Peer RSA keys from
Min_RSA_Bits(default 2048) up to 8192 bits are verified on both versions, including TLS 1.2 ServerKeyExchange signatures; a local RSA identity may be up to 4096 bits. RSA public keys are checked for a sane exponent (odd, at least 3). - X.509 parsing and RFC 5280 chain validation via SPARKx509, with name constraints (including CN-only leaves), EKU chaining, and a WebPKI policy mode.
- Certificate revocation: stapled OCSP (TLS 1.3 and 1.2) and
application-supplied CRLs, evaluated for every certificate below the
trust anchor, with
Ignore/Soft_Fail/Hard_Failpolicies and RFC 7633 must-staple. AVerify_Staplehook lets the application apply its own OCSP policy on top. - OCSP stapling on the server: an identity carries its OCSP response
(
Set_OCSP_Staple/Credentials.Load_Staple) and the server staples it for clients that sendstatus_request, as a TLS 1.3 CertificateEntry extension or a TLS 1.2 CertificateStatus message. - Stateless session tickets on both versions: the resumption secret is sealed under a server ticket-encryption key (AES-256-GCM) and the ticket is the identity, so no server-side session store exists.
- ALPN with strict echo checking (RFC 7301).
- Key material is scrubbed when a handshake context is released and when
a connection closes or fails; private keys handed to
Set_Identityare checked against the certificate's public key. - RecordFlux-generated message serialization and parsing with SPARK contracts; crypto from SPARKNaCl and SPARKTLSCrypto (AES-NI, VAES, VPCLMULQDQ and AVX-512 ChaCha20 fast paths).
ATTACK_COVERAGE.md lists every known TLS implementation attack class with
the mechanism that closes it here and the test or proof that shows so, plus
the behaviour differences documented as intentional and the features not
implemented. It is the reference for what the numbers below do and do not
claim.
- Every unit in
sparktls,sparkx509andsparktlscryptodischarges undergnatprove --level=1with no unproved checks; the whole-project run (ci/prove.sh) is the release gate and is expected to report only the handful of known findings in upstream SPARKNaCl and in RecordFlux-generated code. - Constant-time behaviour of the crypto kernels is checked in CI by
ci/timing.sh all: a valgrind/ctgrind lane that poisons secrets — and, for the signature verifiers, the attacker-controlled inputs — and fails on any data-dependent branch or index, plus a dudect statistical lane run against the optimised build (so the AVX-512 and AES-NI paths that valgrind cannot execute are covered). Both lanes carry a canary with a planted leak that must be flagged, so a harness that loses sensitivity fails the build rather than passing silently. - Conformance suites (2026-09-14): BoringSSL's BoGo runner passes
1464 of 1534 cases, with the 70 failures each documented in
tests/bogo/EXPECTED_FAILURES.txtand nothing left unimplemented (seetests/bogo/CLASSIFICATION.mdfor the out-of-scope list); tlsfuzzer runs 2600+ conversations across 90 scripts with every failing script classified intests/protocol/run.sh; TLS-Anvil passes 181 of the 218 tests its scan enables, with the 37 failures grouped and dispositioned intests/tlsanvil/EXPECTED_FAILURES.txt(all three groups are documented decisions, none an open bug); x509-limbo 9752/9778 and NIST PKITS 189/249 with the deviations listed undertests/x509/; Wycheproof and NIST CAVP vectors pass in full.tests/README.mddescribes every lane, its baseline file and how to reproduce one case. - The example programs and
sparktls_cliare covered by the test lanes (integration andtests/cli) and were reviewed for the failure modes that get CVEs filed against sample code: path traversal, unbounded reads, ignored short writes, missing timeouts, world-readable key files, silently overwritten files, unverified CSRs and exit codes that hide failures.
- TLS 1.3 0-RTT / early data. Intentionally not implemented on either
side. The
early_dataextension is never emitted or accepted. A peer that offers 0-RTT is interoperable: the server skips up to 32 undecryptable early-data records without disturbing its handshake read counter, then proceeds with a normal 1-RTT handshake. - Renegotiation (TLS 1.2), including the
renegotiation_infoextension: not offered; an unsolicited server echo is rejected. - TLS 1.1 and earlier, SSL, RSA key exchange, static DH, compression.
- DTLS, QUIC, ECH, certificate compression, SCTs, delegated credentials.
- TLS 1.2 session-ID resumption (tickets only) and Ed25519 client
authentication in TLS 1.2 (the client declines with an empty
Certificate: PureEdDSA needs the raw transcript, which this stack does
not keep). In TLS 1.2 an ECDSA key signs only with the hash of its own
curve (P-256 with SHA-256, P-384 with SHA-384), so a peer that offers
ecdsa_secp256r1_sha256alone cannot use a P-384 identity. - Fetching revocation data. The library never performs network I/O of its own: OCSP evidence arrives stapled from the server and CRLs are attached by the application.
- Active GREASE emission. SparkTLS aims for deterministic ClientHello serialization. It tolerates unknown or reserved values where the TLS RFCs require extensibility, but does not intentionally emit reserved cipher suites, groups, signature schemes, versions, or extensions.
A session ends in one of two ways. Close_Notify is the orderly path: it
queues the close_notify alert and the session keeps being driven through
Advance until the peer has answered, at which point the handshake slot is
freed. Drop is the other one: the transport died, a timeout fired, or the
application is done with the connection. It scrubs every key and handshake
secret and frees the slot without touching the wire, and it is safe and
idempotent in every state. Call it on every path that stops driving a
session; a server that forgets does not answer anyone once as many peers
as its Handshake_Pool has slots have disconnected mid-handshake, which
scanners and browsers' speculative connections do routinely. Close_Notify only has meaning once the
handshake is complete, and a peer that never answers it is finished with
Drop as well.
Neither is a callback. The library never calls the application about a
session's lifetime; everything it has to say arrives as the Action that
Advance returns (Has_Output, Need_Input, Handshake_Done,
Plaintext_Ready, Error_Alert, Shutdown), and the application drives
the socket. The only callbacks are the hooks the application installs in
Config: the random source, the clock, the peer-verification veto, the
client-identity selector, the OCSP-staple policy hooks and the ticket-key
ring accessors.
Set Config.Sign to a SPARKTLS.Sign_Fn and load the identity with
Credentials.Load_Identity_Public (certificate only). SPARKTLS then never
holds the private key: at each handshake signature it calls your callback
with the negotiated scheme, the to-be-signed message and its digest, and
verifies the signature you return against the certificate before sending
it. SPARKTLS.External_Signing.ECDSA_Raw_To_DER converts the r || s
that PKCS#11, TPM2 and secure elements return. examples/software_signer.adb
is a complete callback over a software key; tls_blocking_server --external-sign runs the server through it, and tls_yubikey_server does
the same with a YubiKey PIV slot via the sparkpiv crate.
Tickets on both versions are sealed under the server's ticket-encryption
key ring (SPARKTLS.Ticket_Keys), which the application owns: a single
process rotates it in place, a fleet shares the key material through its
own channel. The ring is the only long-lived copy of the keys; call
Ticket_Keys.Reset before the process exits.
TLS 1.3 tickets are hostname-scoped by default. Servers mark
NewSessionTicket with the resumption_across_names flag only when
Config.TLS13_Resumption_Across_Names is set. Leave it off unless the
deployment intentionally shares a ticket key ring and resumption policy
across the relevant hostnames inside one trust boundary. TLS 1.2 tickets
never resume across names; both versions bind the ticket to the cipher
suite, the client-authentication status and (TLS 1.2) the
extended-master-secret state of the original session.
A client that is configured with a resumption ticket must also supply
Get_Time: ticket lifetimes are enforced, and a ticket whose age cannot
be known is refused at configuration time rather than offered forever.
Mode_WebPKI is the default validation mode for public web-style TLS. It
applies RFC 5280 chain validation plus the CA/Browser Forum leaf policy
checks. Mode_RFC5280 is for private PKI and development certificates
where WebPKI issuance policy is not the right target.
Config.Min_RSA_Bits (default 2048) is enforced in every mode. Lower it
only for a legacy PKI you control.
Skip_Verify is only a chain-validation opt-out. When Server_Name is
set, hostname verification still runs even with Skip_Verify => True, so
a self-signed development certificate for the wrong hostname is rejected.
Skip_Hostname_Verify => True is the separate, explicit opt-out.
Revocation is governed by Config.Revocation. Soft_Fail (the default)
fails on a revoked certificate and proceeds when no evidence is
available; Hard_Fail also fails without evidence, which with
intermediates in the chain means their issuers' CRLs must be attached; a
malformed CRL from the application's own store fails in every mode.
Request_OCSP_Staple independently controls whether status_request is
sent. The known x509-limbo and PKITS deviations are listed in
tests/x509/ alongside the runners.
- None open in the realworld matrix (
tests/realworld/run.sh). Note thatrevoked.badssl.comis only refused when the runner attaches the issuer's CRL: the library never fetches revocation data, so without a stapled OCSP response or an application-supplied CRL a revoked leaf is accepted under the defaultSoft_Failpolicy, exactly as curl accepts it. UseHard_Failwhere that is unacceptable.
- TLS-Anvil and tlsfuzzer conformance runs with documented intentional gaps.
- Post-quantum: the
X25519MLKEM768hybrid key exchange is implemented (TLS 1.3, on by default). Pure ML-KEM groups (MLKEM768, MLKEM1024) and ML-DSA certificates wait on the follow-on standards; thesparkmlkemcrate already instantiates ML-KEM-1024.
| Dependency | Source | Notes |
|---|---|---|
| SPARKNaCl | git | Core crypto (SPARK proven) |
| SPARKTLSCrypto | git | AES-GCM, ChaCha20-Poly1305, P-256/P-384, RSA, SHA-2, HKDF, SHA-1 (OCSP CertID only) |
| SPARKx509 | git | X.509, CRL and OCSP parsing |
| sparkentropy | git | Entropy source for examples/ and tests only (brings libkeccak) |
| RecordFlux | pip / GitHub | Only needed to regenerate generated/ from specs/ |
Two of these are not pulled automatically. SPARKTLSCrypto and
SPARKx509 are not in the Alire community index; alire.toml pins them by
relative path (../sparkx509, ../sparktlscrypto) so they can be developed
side by side. sparknacl resolves from the Alire index. A checkout of
sparktls on its own will not resolve.
Prerequisites: Alire 2.x with GNAT 16 and gnatprove 16 (Alire fetches the toolchain), OpenSSL for the test fixtures, and Go for the BoGo runner (downloaded on first run). The repository ships a Nix flake that provides all of this reproducibly:
# sibling checkouts git clone https://github.com/docandrew/sparkx509 git clone https://github.com/docandrew/sparktlscrypto git clone https://github.com/docandrew/sparkentropy git clone https://github.com/docandrew/sparktls cd sparktls alr build # the library (cd examples && alr build) # example clients and servers nix develop --command bash ci/check.sh # the CI lane: versions + full test suite
Test suites can be run individually with tests/run_all.sh unit|integration|protocol|x509|bogo|fuzz;
tests/bogo/run.sh -test "Pattern" runs a subset of BoGo. Proofs:
nix develop --command bash ci/prove.sh # whole project, level 1 (the release gate) nix develop --command bash ci/prove.sh -u sparktls-client.adb # one unit
sparktlscrypto/ci/timing.sh ctgrind runs the constant-time lane. The
cli/ directory holds sparktls_cli, a development tool for generating
keys, certificates and CSRs and for inspecting and verifying chains.
Thank you to Chris Allen (@bitemyapp) for a set of performance and constant-time contributions, each with differential test and benchmark evidence.
In SparkTLS:
- Prepared AES-GCM keys reused for TLS 1.3 application writes
- TLS 1.3 plaintext passed to the record builder without a staging copy
Send_Ciphertext, which sends queued ciphertext directly through a scoped transport callback- Fixed-base X25519 for classical and hybrid key shares
In SPARKTLSCrypto:
- A precomputed fixed-base Curve25519 table, with a constant-time row scan and cached mixed addition, for X25519 key generation and Ed25519 signing
- Prepared AES-GCM keys
- A shorter AVX-512 GHASH reduction
- Fused sixteen-block VAES/GHASH
- 64-bit carries in Curve25519 field multiplication
- Removal of secret-dependent branches from the portable GHASH
Chris also traced the GCC 14+ array-slice miscompile that led every crate to
build its optimized modes with -fno-tree-vrp.
SparkTLS is provided "as is" without any warranty. Use at your own risk.