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

Free lesson

Post-Quantum Crypto Basics

The whole lesson is free and interactive. Read it here, or press Start lab to run it for real in a live lab, with no account needed.

Container lab12 min read11 commands

Can a message sent today be read in 2040?

Someone can record your encrypted traffic today and keep it. If a large quantum computer is built later, it could break the key exchange and read the recording. Post-quantum cryptography is new maths that a quantum computer is not known to break.

By the end of this lesson

Note

I can use OpenSSL and OpenSSH to make a post-quantum key exchange and see which one a server agreed.

Key words

  • Quantum computer: a machine that could break today's public-key maths.
  • KEM: a way to send a fresh secret using someone's public key.
  • ML-KEM: the post-quantum KEM chosen as a standard in 2024.
  • Hybrid: a classical and a post-quantum method used together.
  • Key exchange: how two computers agree a secret over an open network.

Starter: what you already know

Note

Answer in your head. 1. What does a public key let a stranger do? 2. Why does HTTPS need a shared secret? 3. What is a padlock in a browser telling you? Answers: send you something only you can open; to encrypt quickly with one key; the connection is encrypted to the site named in its certificate.

Before you start

Note

Press Start the lab on the bar at the top of this lesson and wait until it says it is running. Your workstation is a service called pq, and each Run reaches it with docker exec pq. The TLS server is called tls and the SSH server sshd. Each Run button below types its command into your lab's terminal, one after another in the same session. To watch them, or to type your own, press Open terminal on the bar.

1. OpenSSL 3.5 knows ML-KEM

The command prints OpenSSL 3.5.7, the version in this lab. Version 3.5 was the first to include ML-KEM and ML-DSA without any add-on.

Command
docker exec pq openssl version

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

2. A KEM sends a secret in one step

The first command makes an ML-KEM-768 key pair for Ana, and the second copies out her public key. The third is the sender: it uses only the public key and writes two files, a ciphertext and a 32-byte secret. The fourth is Ana: her private key turns the ciphertext back into a secret. diff -qs prints Files sender.bin and ana.bin are identical. wc -c shows the sizes: 1088 bytes of ciphertext and 32 of secret each. Those 32 bytes become the key that encrypts the real data.

Command
docker exec pq openssl genpkey -algorithm ML-KEM-768 -out ana.pem

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

Command
docker exec pq openssl pkey -in ana.pem -pubout -out ana.pub

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

Command
docker exec pq openssl pkeyutl -encap -inkey ana.pub -pubin -out wrapped.bin -secret sender.bin

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

Command
docker exec pq openssl pkeyutl -decap -inkey ana.pem -in wrapped.bin -secret ana.bin

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

Command
docker exec pq diff -qs sender.bin ana.bin

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

Command
docker exec pq wc -c wrapped.bin sender.bin ana.bin

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

3. A TLS server agrees a hybrid group

The first command connects to the TLS server with OpenSSL's defaults and keeps the line that names the group: Negotiated TLS1.3 group: X25519MLKEM768. That is a hybrid, X25519 and ML-KEM-768 together. The second offers only the classical X25519 and prints Peer Temp Key: X25519, 253 bits. Both connections work, but only the first is protected against a future quantum computer.

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

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

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 Temp"

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

4. SSH chooses a post-quantum key exchange by default

With -v, SSH explains each step, and grep keeps the line that names the key exchange. The first prints debug1: kex: algorithm: mlkem768x25519-sha256: OpenSSH 10 picks the hybrid without being asked. The second asks the old-style server on port 2200, which only knows classical methods, and prints curve25519-sha256.

Command
docker exec pq sh -c "ssh -v sshd true 2>&1 | grep 'kex: algorithm'"

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

Command
docker exec pq sh -c "ssh -v legacy true 2>&1 | grep 'kex: algorithm'"

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

Exit check

Tip

Answer without looking back. 1. What does a KEM send, besides the ciphertext? 2. How many bytes is an ML-KEM-768 ciphertext? 3. What makes X25519MLKEM768 a hybrid? 4. Why does a recording made today matter? Answers: a shared secret, 32 bytes; 1088; it joins classical X25519 with post-quantum ML-KEM; it could be broken later by a quantum computer.

For teachers

Tip

This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. The lab is three small services and one named volume, and nothing here marks itself: the student hands in a short report of their own copy, the TLS group for three client lists they chose, the ML-KEM-512 and ML-KEM-1024 sizes, a three-level ML-DSA chain that verifies, and the SSH key exchange with sntrup761x25519-sha512 forced, none of which this lesson does for them. Key learning points: 1. A recording made today can be broken later, so key exchange moves first. 2. A KEM sends a fresh secret with the public key alone. 3. A hybrid joins a classical and a post-quantum method. 4. OpenSSL 3.5 and OpenSSH 10 choose the hybrid by default. Common mistake: thinking a connection that works is post-quantum. Equipment: the lab and its terminal. Tip: ask students to predict the group before each Run. WireGuard with Rosenpass is not in the lab, as it needs kernel rights a lab does not have. The module Post-quantum cryptography in practice goes further in six lessons. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.

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 these lessons for your students with marking and a lab for every student.