Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Hybrid key exchange in TLS 1.3

After this lesson: I can find which key exchange group a TLS 1.3 server agreed and say whether it is hybrid.

65 min lesson7 commandsPost-quantum cryptography lab: ML-KEM, ML-DSA, hybrid TLS and post-quantum SSH with OpenSSL 3.5 and OpenSSH 10

What hybrid post-quantum TLS is

Hybrid post-quantum TLS joins a classical key exchange and ML-KEM in one TLS 1.3 handshake. The group X25519MLKEM768 is already offered by major browsers and servers, so much web traffic is protected this way today.

A padlock does not tell you which group was used. In this lesson you read the group the server agreed, and see what makes it change.

By the end of this lesson

Note

I can find which key exchange group a TLS 1.3 server agreed and say whether it is hybrid.

Key words

WordWhat it meansExample
TLS 1.3the protocol behind HTTPS, in its current version
Groupthe key exchange method a TLS handshake usesX25519MLKEM768
Key sharethe public value each side sends for a group
Hybrida classical and a post-quantum method joined together
s_clientOpenSSL's command-line TLS client

The cells students fill in are left blank in this preview.

Why join two methods?

ML-KEM is new, and new maths sometimes fails. X25519 is old and well tested, but a quantum computer breaks it. A hybrid runs both and mixes their two secrets into the session keys.

An attacker then has to break both. A quantum computer breaks X25519, and a flaw found in ML-KEM would not break X25519, so the connection stays safe if either one holds.

Worked example: the X25519MLKEM768 key shares

Who sendsML-KEM-768 partX25519 partKey share
ClientPublic key, 1184 bytesPublic key, 32 bytes1216 bytes
ServerCiphertext, 1088 bytesPublic key, 32 bytes1120 bytes
BothSecret, 32 bytesSecret, 32 bytesMixed into the session keys

The cells students fill in are left blank in this preview.

How the group is agreed

The client lists the groups it supports and sends a key share for its first choice. If the server has that group, it answers with its own key share. If not, it asks the client again for another group they share.

In the lab, the group agreed is always the first in the client's list that the server has. When they share none, the handshake fails.

List the TLS 1.3 groups OpenSSL knows

Command
docker exec pq openssl list -tls1_3 -tls-groups

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Connect with OpenSSL's defaults

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief 2>&1 | grep -v Connecting"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the default connection prints

LineWhat it means
Protocol version: TLSv1.3The protocol version
Peer certificate: CN=tlsThe server's name in its certificate
Signature type: mldsa65The certificate is signed with ML-DSA, lesson 4
Verification: OKThe certificate chains to the lab's root
Negotiated TLS1.3 group: X25519MLKEM768The hybrid group was agreed

The cells students fill in are left blank in this preview.

Offer only the classical X25519

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief -groups X25519 2>&1 | grep -E 'group|Temp'"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Offer only the pure MLKEM768

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief -groups MLKEM768 2>&1 | grep -E 'group|Temp'"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Put X25519 before the hybrid

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief -groups X25519:X25519MLKEM768 2>&1 | grep -E 'group|Temp'"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A first choice the server lacks

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief -groups secp256r1:MLKEM768:X25519 2>&1 | grep -E 'group|Temp'"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Offer a group the server lacks

Command
docker exec pq sh -c "openssl s_client -connect tls:4433 -servername tls -CAfile /keys/tls-ca.crt -brief -groups secp256r1 2>&1 | grep -o 'alert handshake failure'"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the other Runs print

Client offersWhat it printsKind
X25519Peer Temp Key: X25519, 253 bitsClassical
MLKEM768Negotiated TLS1.3 group: MLKEM768Post-quantum only
X25519:X25519MLKEM768Peer Temp Key: X25519, 253 bitsClassical, by the client's order
secp256r1:MLKEM768:X25519Negotiated TLS1.3 group: MLKEM768The first shared group
secp256r1alert handshake failureNo shared group

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think that if both sides support the hybrid, they always use it. The client's order decides. A client that lists X25519 first gets X25519 from this server, with no warning. Check the group line, not only the padlock.

About this lab and its source: Post-quantum cryptography lab: ML-KEM, ML-DSA, hybrid TLS and post-quantum SSH with OpenSSL 3.5 and OpenSSH 10

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.