← Back to section · Tutorials & Labs
Hands-On: Local TLS with ML-KEM + ML-DSA Using OpenSSL 3.5
No research libraries needed: use the OpenSSL 3.5 shipped by mainstream distributions to issue an ML-DSA certificate, serve local TLS, and verify hybrid key exchange negotiation yourself.
The previous two labs used liboqs to learn the algorithms themselves. This one switches to the production tool: OpenSSL 3.5. Released in April 2025, 3.5 is OpenSSL’s turning point — ML-KEM, ML-DSA and SLH-DSA are built in natively, and the default TLS 1.3 group list carries the hybrid X25519MLKEM768. The same post-quantum TLS that browsers and CDNs are deploying, reproducible on your own machine.
Step 0: Check the version
openssl version
openssl list -kem-algorithms | grep -i ml-kem
openssl list -signature-algorithms | grep -i ml-dsa
You need ≥ 3.5. If your distribution ships 3.0–3.4, upgrade the distribution or install a newer package (don’t hand-build for production machines; lab machines are fair game).
Step 1: Generate an ML-DSA certificate
openssl genpkey -algorithm ML-DSA-65 -out mldsa-key.pem
openssl req -new -x509 -key mldsa-key.pem -out mldsa-cert.pem -days 30 \
-subj "/CN=localhost"
openssl x509 -in mldsa-cert.pem -noout -text | grep "Signature Algorithm"
The last line should read Signature Algorithm: ML-DSA-65. While you are here, ls -l mldsa-cert.pem — roughly 4–5 KB; set that against the size arithmetic in our PKI migration article and the numbers become tangible.
Step 2: Serve and connect
Terminal A (keep it running):
openssl s_server -accept 4433 -key mldsa-key.pem -cert mldsa-cert.pem \
-tls1_3 -www
Terminal B:
openssl s_client -connect localhost:4433 -groups X25519MLKEM768
Step 3: Verify the negotiation
Check the s_client output line by line:
Negotiated TLS1.3 group: X25519MLKEM768— hybrid key exchange succeeded; half of the KEM is ML-KEM-768;- In the certificate block,
Signature Algorithm: ML-DSA-65andPublic Key Algorithm: ML-DSA-65— the server presented a post-quantum certificate; - Protocol is
TLSv1.3.
Run the control experiment: change -groups to X25519 and reconnect — the negotiated group falls back to purely classical. Same server, same client, one flag: that is crypto-agility at the command line.
How the Hybrid Group Actually Works
Once the checklist passes, it is worth looking one layer deeper: the name X25519MLKEM768 encodes an entire design. Under the hybrid group, the TLS 1.3 key_share extension carries two pieces of material at once — a classical X25519 public key (32 bytes) and an ML-KEM-768 encapsulation key (1,184 bytes). The server computes the classical shared secret with its X25519 private key and, in parallel, runs Encaps against the ML-KEM key, producing a post-quantum shared secret and a 1,088-byte ciphertext that travels back in the server’s key_share. Both sides then concatenate the two secrets and feed them together into the TLS key schedule (HKDF) to derive the session keys.
This “concatenate and derive together” structure means: the session keys are safe as long as either channel remains unbroken. The classical channel insures against ML-KEM — an algorithm finalized only in 2024 — falling to classical cryptanalysis; the ML-KEM channel insures against “harvest now, decrypt later”, where an attacker records today’s handshake traffic and decrypts it once a quantum computer exists. The hybrid is not a transitional compromise but a hedge in both directions at once, which is why browsers and CDNs have made it the default.
The cost is equally concrete: the ClientHello carries 1,184 extra bytes of encapsulation key, and the server’s first flight carries 1,088 bytes of ciphertext. Add this to the certificate-size bill in our PKI migration article and you have the bulk of the post-quantum TLS handshake overhead — the root cause of the record-layer fragmentation and middlebox quirks that show up in deployments.
Seeing the Handshake: -msg and -trace
The default s_client output gives conclusions, not the flow. To watch those bytes move, reconnect with -msg:
openssl s_client -connect localhost:4433 -groups X25519MLKEM768 -msg
-msg prints each handshake message with its type and length: watch the total ClientHello size (against a pure X25519 run, the roughly 1.2 KB delta is the ML-KEM encapsulation key), then the ServerHello coming back, which carries the ciphertext. For a field-level breakdown, replace -msg with -trace, which expands every extension, including the group name and length inside key_share.
Run both variants and record the numbers: pure X25519 versus X25519MLKEM768, ClientHello and ServerHello sizes for each. Those four numbers are your own post-quantum handshake cost table — more trustworthy than any second-hand article.
While You Are Here: Dissect an ML-DSA Certificate
Before using the certificate from Step 1, read it end to end with x509 -text — the post-quantum PKI size bill hides in its fields:
openssl x509 -in mldsa-cert.pem -noout -text | less
Look at three places. First, the Subject Public Key Info block: an ML-DSA-65 public key is 1,952 bytes of raw data — against 32 bytes for Ed25519 or 294 bytes for RSA-2048 (structure included), the public key alone adds roughly 1.9 KB to the certificate. Second, the signature value at the end: one ML-DSA-65 signature is 3,309 bytes, where an Ed25519 signature is 64. Third, the total: add the two, plus subject, validity, and extension fields, and a self-signed ML-DSA-65 certificate lands around 5 KB — about five times a classical self-signed certificate (roughly 1 KB).
Now multiply by chain length: a production chain of leaf + intermediate + root in ML-DSA-65 pushes more than 10 KB of certificates through every handshake — before an OCSP response attaches yet another signature. This is why our PKI migration article keeps insisting that size is the first engineering gate of the post-quantum migration: the algorithms are fine; what is expensive is fitting them into the byte budgets of existing protocols. The 5 KB you just measured by hand is the smallest sample of that gate.
Variations to Try
- Swap the parameter set: issue certificates with
ML-DSA-44andML-DSA-87, repeat steps 1–3, and compare certificate file sizes and total handshake bytes — the three-way trade between security level, certificate size, and handshake cost becomes visible at once; - Pure post-quantum group: with
-groups MLKEM768the negotiated group readsMLKEM768, with no classical component — this needs both ends to support pure groups and does not interoperate with current browsers, so keep it in the lab; - Turn post-quantum off: start the server with
-groups X25519so it offers only the classical group, then request the hybrid group from the client and watch how negotiation fails or falls back — understanding “the intersection of both ends decides” beats memorizing definitions.
Troubleshooting
s_clientfails with “no suitable signature algorithm” — usually OpenSSL older than 3.5, or a system policy (some distributions’ crypto-policies) disabling new algorithms; checkopenssl versionfirst, then the policy;- Pure ML-KEM group — use
-groups MLKEM768(both ends on 3.5); browser interop requires the hybrid group; - Chain size — issue an intermediate and stack it, repeat step 2, and watch the handshake bytes (the
-msgflag) — measure the PKI size bill yourself.
What separates this lab from production
A local self-signed setup proves algorithm and protocol viability, not a deployment: production additionally needs publicly issued ML-DSA certificates (the ecosystem is early — see our PKI article), a client compatibility matrix, and performance testing. But keep the order right: run this handshake at home and learn the checklist now, and when the ecosystem arrives you will be missing only a certificate, not the understanding.
Sources and further reading
- OpenSSL, 3.5 Release Notes (ML-KEM/ML-DSA/SLH-DSA support and default group changes), 2025-04. https://openssl-library.org/news/openssl-3.5-notes/
- OpenSSL man pages:
s_server,s_client,genpkey(3.5). - On this site: “Hybrid Key Exchange: How TLS Moves First” and “Migrating PKI and Certificates to Post-Quantum”
Tags: OpenSSLTLSML-KEMML-DSAlab