You are in a cafe and want to send a message from your laptop to your friend's computer.
Your friend John is sitting in another cafe, and a copper wire runs from your laptop to his computer.
A wire carries a voltage
Your laptop can only raise or lower the voltage on the wire, and John's computer can only measure that voltage at its end a moment later.
High means 1, low means 0
Both computers follow one rule, which is that a high voltage stands for 1 and a low voltage stands for 0. Each 1 or 0 is called a bit, and anything at all can be written as a string of bits.
One bit per time slice
A long stretch of low voltage could be one 0 or several, so both sides share a clock that cuts time into equal slices, and the sender holds one level for each slice.
John reads each slice
John's computer measures the voltage in the middle of every slice and writes down 1 for high and 0 for low.
Letters are numbers
Both computers use the same table, called ASCII, which gives every character a number, so a capital H is 72 and a lowercase i is 105.
Each number is eight bits
Each position in a binary number is worth twice the one to its right, so 72 is 01001000 and 105 is 01101001. A group of eight bits like this is called a byte.
"Hi" on the wire
Send the two bytes one bit per slice and the voltage traces this shape, which John's computer turns back into Hi. Type any two characters to redraw it.
The wire runs from your laptop to John's computer and nowhere else.
Is John the only one who can see this wave?
Anyone touching the wire can read it
A wire delivers its voltage to everything connected to it, so if someone we will call Mallory clips a probe onto the copper, her readout fills in letter for letter alongside John's. Nothing in the signal says who it is meant for.
One wire per machine is impossible
You also want to reach your bank, your email and millions of other machines, and nobody can lay a separate wire from your laptop to each of them.
Routers pass messages along
Instead, each computer is wired to a nearby box called a router, routers are wired to other routers, and each router hands a message to a neighbour that is closer to its destination.
Messages travel as packets
Every link also carries other people's traffic, so a message is cut into small pieces called packets. Each packet starts with a header that holds the destination address and the piece's position in the message.
Packets can arrive out of order
Each router picks the next hop for each packet on its own, so packets can take different routes and overtake each other, and John's computer uses the positions in the headers to rebuild the message.
A router reads every packet
To forward a packet a router has to read the address in its header, and it holds the whole packet in memory while it does, so nothing stops it from reading the rest.
Follow one message
A real trip passes through ten or more machines run by different organisations, and every one of them can read the packet.
John's computer now has all the right bits in the right order, but how does it know which of them spell a name and which of them are an amount of money?
Bits need agreed formats
On its own the stream is just 1s and 0s. It means something only because the software at both ends implements the same published standards, which stack in layers.
Layer one: bytes
The first layer cuts the stream into bytes. Engineers write each byte as two hexadecimal digits, a base-16 notation that uses 0 to 9 and then a to f, so 01111011 is written 7b.
Layer two: characters
A text encoding called UTF-8 turns bytes into characters. It keeps the ASCII table for ordinary letters and digits, so 7b is { and 74 is t.
Layer three: JSON
Most web services arrange those characters as JSON, which writes data as names paired with values, so a payment to John can be written like this.
Layer four: an HTTP request
The JSON travels inside an HTTP request, the format browsers and servers use to talk. Its first lines say what to do (POST), which address on the server should handle it (/transfer) and how many bytes of JSON follow.
All the layers at once
Change the name or the amount, then step through the tabs to see that one edit at every layer.
A wire carries bits as voltages, the internet carries those bits as packets through many routers, and standard formats turn them into characters, JSON and HTTP requests. Every machine on the path can read all of it, because none of these layers hides anything.
That hardly matters for "Hello, John", but what changes when the message is an instruction to move $5,000 out of your bank account?
Now the other computer is a bank
The machine at the other end is now your bank's server, a computer whose job is to answer requests. From the cafe, you open your banking app to send $5,000 to John.
Your transfer becomes a request
When you press Send, the app writes a small JSON message with your account, the recipient and the amount, and sends it inside an HTTP request to the bank.
The first hop is radio
Your laptop reaches the cafe's Wi-Fi router by radio, and every device in range receives the same signal, as if they were all touching one wire. From the cafe the request goes router by router to the bank.
Who can read your transfer
Press Play to follow the request. Every machine on the way can read your account number, John's name and the amount.
None of those machines is doing anything wrong, because reading a packet is part of forwarding it.
But what if someone on that path, perhaps a stranger on the same cafe Wi-Fi, decides to use that position against you?
Mallory joins the Wi-Fi
Mallory, who clipped the probe onto the wire in chapter 1, now sits at the next table on the same Wi-Fi. Every packet between you and the bank passes through a network she can reach.
She can read it
She copies each packet and reads it, and because she changes nothing, neither you nor the bank can tell. This breaks confidentiality, the promise that only you and the bank can read the message.
She can change it
She can edit a packet as it passes, so the bank receives a normal-looking request to pay Mallory $50,000. This breaks integrity, the promise that any change on the way will be noticed.
She can pose as the bank
She can steer your connection to a copy of the bank's site that she runs herself, so you type your PIN into her machine. This breaks authentication, the promise that you know who is at the other end.
She can pose as you
She can also write her own request to pay $5,000 to Mallory, put your account number on it and send it, and the bank has no way to tell who wrote it. Authentication has to work in both directions.
Three guarantees
Each move breaks a different promise, so a safe connection to the bank needs all three at once.
Anyone on the path can read your messages, change them, or pretend to be you or the bank, which breaks confidentiality, integrity and authentication.
The padlock is TLS
To protect connections like this, the web uses a mechanism called TLS, short for Transport Layer Security. Your browser shows it as the padlock next to the address, and as the https at the start of the address.
From here on we go deep into how it works, one piece at a time.
Of the three, reading is the one Mallory can do without leaving a trace, so it is the natural place to start.
Nobody can stop the packets from being copied on the way, so is there any way to make it harmless that Mallory gets a copy of everything we send?
Encryption with a shared key
Encryption turns a message into scrambled bytes, called ciphertext, using a secret value called a key, and only someone with the key can turn it back. When both sides use the same key, it is called symmetric encryption.
Caesar's cipher
Julius Caesar shifted every letter along the alphabet by a fixed number, and that number was the key. With a key of 3, SEND becomes VHQG, and the receiver shifts back by 3.
Mallory tries every key
Caesar's cipher has only 25 useful keys, so Mallory can try them all in a moment and keep the one that gives readable text. Trying every possible key like this is called brute force.
AES
Modern ciphers such as AES, the Advanced Encryption Standard, keep the idea of one shared key but mix the bits far more thoroughly, using keys of 128 or 256 bits. Processors have dedicated AES instructions, so one core encrypts gigabytes per second.
Brute force no longer works
A 128-bit key has 2128, about 3.4 × 1038, possible values. Even at a billion billion guesses per second, trying them all would take about ten trillion years.
The tag catches changes
The way AES is used on the web, called AES-GCM, also attaches a 16-byte tag computed from the key and the ciphertext. If anyone changes even one bit on the way, the bank's recomputed tag no longer matches and the message is thrown away.
Symmetric encryption scrambles data with one key that both sides hold. It is fast, and with its tag it gives confidentiality and integrity, but only once both sides already have the same key.
You and the bank have never met. How did the two of you come to hold the same secret key without Mallory getting a copy of it on the way?
Sending the key gives it away
The obvious move is to pick a key on your laptop and send it to the bank. The key travels as ordinary bytes, so Mallory copies it and can decrypt everything that follows, however strong the cipher is.
Meeting in person does not scale
You could hand over a key in person, but every pair of people who want to talk privately needs its own key. A bank with ten million customers cannot meet them all, and you cannot meet every website you visit.
The number of keys explodes
With n people the number of keys is n(n − 1)/2, so 1,000 people need 499,500 keys and a million people need about 500 billion.
The key cannot travel in the open, and it cannot be delivered in person.
Is there any way at all to get a secret to the bank when the two of you share nothing yet and Mallory hears every byte you send?
Two keys instead of one
In the 1970s researchers found a way to use a pair of keys, where whatever one key locks only the other can unlock. The public key is handed to everyone, the private key never leaves its owner, and because the two keys differ this is called asymmetric encryption.
The padlock picture
Imagine the bank handing out open padlocks to anyone while keeping the only key. You snap one shut on a box holding your message, and Mallory, with as many padlocks as she likes, still cannot open it.
A padlock is a physical object, and the network only carries numbers.
What kind of calculation could anyone perform with a public number, yet nobody could undo without a private number that only the bank knows?
Two ideas RSA is built from
RSA is built from two small ideas, remainders (written mod) and prime numbers. If you already know both, you can skip straight to RSA.
Otherwise the next three slides cover them in about a minute.
Remainders, written mod
x mod n means the remainder when x is divided by n, which is where you land after counting x steps around a clock with n positions. So 17 mod 5 is 2, and on a 12-hour clock 25 mod 12 is 1.
Remainders hide the laps
Powers work the same way, so 34 mod 7 means 81 mod 7, which is 4. The answer never grows past n, and the remainder alone does not tell you how many laps were made.
Primes
A prime is a number divisible only by 1 and itself, such as 53 or 61. Multiplying two primes takes one step, but finding them again from their product is slow, and for large primes it is hopelessly slow.
RSA, step 1: the public number n
RSA, named after Rivest, Shamir and Adleman, starts with the bank choosing two secret primes, here p = 61 and q = 53. It publishes their product n = 3233 and keeps p and q to itself. From here on each of these numbers keeps its colour, and a dotted underline marks a value worked out from others.
What φ(n) counts
The private key in the next step is built from a number called φ(n), read "phi of n", which only someone who knows p and q can work out. It counts the whole numbers from 1 to n − 1 that have no factor in common with n, apart from 1.
For n = 15 that leaves 1, 2, 4, 7, 8, 11, 13 and 14, so φ(15) = 8. When n = p × q there is a shortcut, φ(n) = (p − 1) × (q − 1), which gives 2 × 4 = 8 for 15 = 3 × 5.
RSA, step 2: φ(n) and e
The bank applies the shortcut: φ(n) = (p − 1) × (q − 1) = 60 × 52 = 3120, with no need to count 3232 numbers. It then picks a public exponent e = 17, which shares no factor with 3120, so that a matching private number exists in the next step.
RSA, step 3: the private key d
The private key is the number d for which e × d leaves remainder 1 when divided by φ(n). Here d = 2753, because 17 × 2753 = 46,801 = 15 × 3120 + 1, and finding d requires φ(n), which requires p and q.
Locking and unlocking
To lock the message 65, anyone computes 6517 mod 3233 = 2790, and the bank unlocks it with 27902753 mod 3233 = 65. A result called Euler's theorem guarantees that the two powers cancel, because e × d is one more than a multiple of φ(n).
Why n must be two primes
Anyone who knows p and q can compute φ(n) instantly. If n were itself prime, φ(n) would simply be n − 1, so everyone could work out d and the private key would be public.
Compare what Mallory can do with each kind of public key.
What Mallory can try
Mallory has n, e and the locked number. Guessing d is hopeless because a real d is about as large as n, so her only route is to split n into p and q, which takes 52 trial divisions for 3233 and roughly 10308 for a real 617-digit n.
Real RSA
Real keys use primes of about 300 digits each, which the bank can find in a fraction of a second with fast probabilistic tests. Real systems also add random padding, a scheme called OAEP, so that locking the same message twice gives different results.
The price of RSA
RSA is thousands of times slower than AES, and one operation with a 2048-bit key can lock only about 190 bytes.
Each family has a job
So secure systems use asymmetric encryption briefly at the start to set up a symmetric key, and then let the fast symmetric cipher carry the data.
Asymmetric encryption uses a public key that locks and a private key that unlocks, so a secret can reach the bank without any earlier meeting. It is slow and handles small amounts of data, so it sets up a symmetric key and AES carries the traffic.
Early versions of TLS did exactly this: your browser picked a key, locked it with the bank's RSA public key and sent it.
The bank uses the same private key for every visitor. What if Mallory got hold of that key just once, say as an employee of the bank with access to it?
How older TLS shared the key
In TLS before version 1.3, your browser could invent a fresh symmetric key for the connection, called the session key, lock it with the bank's RSA public key and send it. The bank unlocked it with its private key, and both sides then used AES.
The flaw: one key opens every recording
Mallory can record those encrypted connections today and keep them. If the bank's private key ever leaks, even years later, she can unlock the session key in every recording, because that one long-lived key protected all of them.
A better design would have each connection create its own secret without ever sending it, and delete it afterwards, so there is nothing left to steal. TLS 1.3 removed RSA key transport for this reason.
But how can two parties end up holding the same secret if neither of them ever sends it, while Mallory hears every byte they exchange?
Diffie-Hellman key exchange
The answer is Diffie-Hellman key exchange, published in 1976, a year before RSA. It cannot encrypt or sign anything, and its one job is to let two parties agree on a secret, while in TLS 1.3 RSA keeps the separate job of proving the bank's identity with a signature (chapter 10).
Paint: the public base
Alice and Bob want to end up with the same colour while Mallory watches. They agree in public on a yellow base paint, and each picks a secret colour that they never show anyone.
Paint: swapping blends
Each mixes their secret colour into the base and sends the blend, so Mallory sees both blends.
Paint: the same colour
Each then adds their own secret colour to the blend they received. Both buckets now hold the base, Alice's colour and Bob's colour, and Mallory cannot pull a secret colour back out of a blend.
The same trick with numbers
Real paint can be roughly unmixed by eye, so the real version uses remainders instead. Alice and Bob agree in public on a prime p = 23 and a base g = 5, then Alice secretly picks a = 6 and Bob picks b = 15.
Each letter keeps its own colour from here on, so you can always tell which number is which. A dotted underline marks a value worked out from others, and hovering or tapping it shows how.
Swapping the numbers
Alice sends A = 56 mod 23 = 8, and Bob sends B = 515 mod 23 = 19. These are the blends, and Mallory sees both.
The shared secret
Alice computes 196 mod 23 and Bob computes 815 mod 23, and both get 2. Both have calculated 56 × 15 mod 23, with the exponents applied in a different order.
The discrete logarithm
To find the secret, Mallory needs a or b, which means solving 5x mod 23 = 8 for x, a problem called the discrete logarithm. With p = 23 she tries all 22 values, but with a 2048-bit p there is no known fast method, while Alice and Bob need only a few thousand multiplications.
That answers the last chapter's question: a and b live for one connection and are then deleted, so a bank key stolen later cannot reopen a recording.
How big the clock version has to be
Every public number in the clock version is as large as p, and staying safe for decades needs a p of about 3,072 bits, so Alice and Bob each send a 384-byte number.
It must be that large because Mallory does not try every value. Whole numbers mod p have a structure, the same one the best factoring methods use, that shortens her search, so each extra bit adds less protection than you would hope.
Measuring protection in bits
We measure protection by the number of steps Mallory needs, and 128 bits of protection means about 2128 steps, more than all the computers on Earth could perform. With the shortcut above, the clock version reaches 128 bits only at 3,072 bits of p, so the question is whether another kind of arithmetic gives the same protection with a smaller number.
The same exchange on a curve
The exchange keeps its steps: a public starting point, two secret numbers, a swap and a shared result, with the clock multiplication replaced by adding points on an elliptic curve, built over the next slides. Nobody has found a shortcut for a good curve, so a 256-bit key already needs about 2128 steps to break.
This gives the same protection as the clock version, not a stronger promise, in keys twelve times smaller and with much faster arithmetic.
What we need to build
The clock exchange works because Alice and Bob each repeat the same operation, and repeating it b times and then a times gives the same result as a times and then b times: (gb)a = (ga)b. A curve offers another operation that can be repeated, and we will build it in three steps: the curve itself, a rule for adding two points, and adding a point to itself again and again. Then we will see why Alice and Bob end at the same point.
An elliptic curve
An elliptic curve is the set of points (x, y) that satisfy an equation such as y² = x³ − 3x + 5. At x = 2, for example, y² = 8 − 6 + 5 = 7, so the points (2, 2.65) and (2, −2.65) lie on the curve.
The form is not free: y is squared, x is cubed, and the numbers in y² = x³ + ax + b must avoid a curve with a sharp point or a self-crossing, which means 4a³ + 27b² ≠ 0. Squaring y makes the curve a mirror image across the horizontal axis, which the next slides rely on, so an equation such as y = x³ + 126 does not qualify.
Adding two points
We need a rule that turns two points on the curve into a third. It is a recipe, not arithmetic on the coordinates: draw the straight line through P and Q, find the one other point where it meets the curve, and reflect that point across the horizontal axis. The result is called P + Q, and the name fits because the rule behaves like addition, as the next slides show. Swapping P and Q gives the same line, so P + Q = Q + P.
So the x-values are not added: with P at x = −1.4 and Q at x = 1.2, the result lands at x = 2.95, because the line decides where it goes.
When the line is vertical
If Q is the mirror image of P, the line through them is vertical and never meets the curve a third time. To cover this case, mathematicians add one extra point to the curve, called O or the point at infinity, and define P + Q = O.
O works like zero: adding it to any point leaves that point unchanged. The same happens when a point is added to itself and its tangent is vertical.
Adding a point to itself
Repeated adding starts with adding a point to itself, because a × G means G added to itself a times. There is no second point, so use the tangent line at P instead. At P = (−1, 2.65) the tangent is flat, it meets the curve again at (2, 2.65), and reflecting gives 2P = (2, −2.65).
Multiples of a point
Adding P again gives 3P = P + 2P = (2.11, 2.84), and repeating gives 4P, 5P and so on, written k × P, meaning P added to itself k times.
Why Alice and Bob end at the same point
Take a point G that everyone knows, and let Alice pick a = 3 and Bob pick b = 2. Each adds G to itself that many times and sends the result, then adds the point they received to itself their own number of times, so each has added G a total of 3 × 2 = 6 times and both reach 6 × G.
This works because each step is the line recipe from earlier, which hops to a new point on the curve, and the rule has two properties: P + Q = Q + P, and it does not matter which pair is added first, so only the total number of G counts. With O as zero and mirror images as negatives, this is why it is called adding.
Moving to whole numbers
The curve we have drawn uses real numbers such as 2.65, which a computer cannot store exactly, and tiny rounding errors would stop Alice's and Bob's points from matching exactly. So cryptography keeps the same idea with whole numbers only.
Every calculation is done mod a prime, which has about 77 digits in real systems, so after each step only the remainder is kept. Lines, third points and reflections still work with the same formulas, and the points become a scattered cloud instead of a smooth curve.
A small example modulo 97
To follow every number, we use a small example: the curve y² = x³ + 2x + 3 with everything taken mod 97. We pick G = (0, 10) as the starting point. It lies on the curve because 10² = 100 and 100 mod 97 = 3, which equals 0³ + 2 × 0 + 3.
Adding G to itself again and again gives 2G, 3G, 4G and so on, and these points jump around with no visible pattern.
Fast forwards, hopeless backwards
To get 13 × G you need not add G twelve times, because you can double to get 2G, 4G and 8G and then add 8G + 4G + G, so a 256-bit number needs only about 256 doublings. Going back from 13 × G to 13 has no known method much faster than searching through the multiples, and finding the number is called the elliptic-curve discrete logarithm problem.
Three hard problems side by side
RSA, the clock exchange and the curve exchange all rest on a calculation that is easy forwards and hard backwards, but they are not the same problem, and only the curve has no shortcut beyond a generic search.
Key exchange on the curve
Alice picks a secret a = 13 and publishes A = 13 × G = (87, 70), and Bob picks b = 29 and publishes B = 29 × G = (47, 18). Alice computes 13 × B and Bob computes 29 × A, and both land on the same point, (49, 63).
What Mallory faces on a real curve
Mallory sees G, A and B, and on this tiny curve she finds a = 13 after 13 tries. X25519, the curve browsers use, is computed modulo the prime 2255 − 19, and its G has about 2252 multiples, so the same search would never finish.
Forward secrecy
The secret numbers a and b are made fresh for every connection and deleted afterwards. A key stolen from the bank next year therefore cannot unlock last month's traffic, and this property is called forward secrecy.
Diffie-Hellman lets two parties build a shared secret in public without ever sending it, because the calculation is easy forwards and impractical to undo. Browsers use the elliptic-curve version for its small keys, and fresh secrets for each connection give forward secrecy.
Mallory can no longer read the traffic, but key exchange will agree a secret with whoever answers. How can you be sure that whoever answered is really the bank, and how can the bank be sure a request really came from you?
Encryption does not say who wrote it
Everything so far hides messages, but none of it proves who sent them. Asymmetric keys can be used the other way round, so the owner produces a signature with the private key and anyone checks it with the public key.
A hash is a fingerprint
Signing a long message directly would be slow, so we sign a short fingerprint of it called a hash. A hash function takes data of any length and returns a fixed-size value, 256 bits for the widely used SHA-256. For example, the SHA-256 hash of "Pay John 5000" is f0e7c9a0 followed by 56 more hexadecimal digits, and anyone who hashes that text gets the same result.
One letter changes everything
Hashing the same message always gives the same result, while changing a single character gives a completely different one.
Fixed size and one-way
A million-character message still hashes to 64 hexadecimal digits. Nobody knows how to go from a hash back to a message except by guessing messages and hashing each guess.
Signing
To sign, the bank hashes the message into its fixed-size fingerprint, reduces the hash to a number below n, and raises it to its private power d. With the toy key from chapter 8, where n = 3233 and d = 2753, the result is a number below 3233, and that number is the signature.
Checking a signature
Anyone can raise the signature to the public power e = 17, keep the remainder after dividing by n = 3233, and compare it with the hash of the message they received. A match shows the message came from the holder of d and has not changed.
Try it: sign and check by hand
Signing is a power followed by a remainder, and one pass by hand makes it stick. This tiny key has n = 33, e = 3 and d = 7, and the message's fingerprint is 5.
The trick is to keep only the remainder after every multiplication, so the numbers never grow: 57 is built as 52, then 54, 56 and 57.
Tampering breaks the signature
If Mallory changes 5000 to 5001 the hash changes, so the check fails, and she cannot make a new signature because she does not have d.
Signatures in practice
Real systems sign with RSA or with ECDSA, a signature scheme built on elliptic curves, and both follow the same pattern of signing with a private key and checking with the public key.
A hash is a short, fixed-size fingerprint that changes completely when the message changes. A signature is that fingerprint processed with a private key, so anyone with the public key can confirm who produced the message and that nobody altered it.
A signature only proves that the holder of a particular private key wrote the message. When your laptop first connects, the bank simply sends you its public key, so what stops Mallory from sending you hers instead?
A key does not carry a name
When you connect, the bank sends its public key, and since you have never seen that key before, you have nothing to compare it with.
Mallory swaps the key
Mallory intercepts the request and replies with her own public key, claiming it belongs to the bank.
The man in the middle
You lock your secret to her key, she opens it, reads it and locks it again with the bank's real key, so both ends see a working connection while she reads everything. This is called a man-in-the-middle attack.
Key exchange has the same problem
Diffie-Hellman falls to the same trick, because Mallory can run one key exchange with you and a second one with the bank. She then decrypts each message with the first secret and encrypts it again with the second.
The only defence is a way to confirm that a public key really belongs to the name it claims.
You have never met the bank and share nothing with it, so who could possibly vouch for its key in a way that Mallory cannot fake?
A certificate
A certificate is a signed statement saying that a given public key belongs to a given name, such as bank.example, between two dates. It is signed by a certificate authority (CA), an organisation that checks who is asking before it signs.
Your device already trusts a few CAs
Your device ships with a short list of CAs that it trusts, called the trust store, and the CAs on that list are called root CAs.
Roots sign intermediates
A root's private key is too valuable to keep online, so the root signs an intermediate CA, and the intermediate signs the bank's certificate.
Checking the chain
The bank sends its certificate together with the intermediate's, and your device checks each signature up to a root in its trust store, then checks the name and the dates.
When a check fails
If any check fails, the browser shows a warning and refuses to continue. Step through four common failures.
Why this stops Mallory
Mallory can still send her own key, but no CA will sign a certificate binding it to bank.example, and she cannot forge a CA's signature. The bank also has to prove it holds the private key that matches its certificate, as the next chapter shows.
Certificates expire on purpose
Certificates are valid only for a limited time, so a stolen key stops being useful once its certificate expires, and the industry keeps shortening those lifetimes.
A certificate is a signed statement that ties a public key to a name, and trust flows down a chain of signatures from a root that your device already holds. That leaves Mallory no way to pass off her key as the bank's.
We now have every piece: AES, key exchange, signatures and certificates. How does a browser fit all of them together before it sends a single byte of your request?
The handshake
The handshake is the short exchange at the start of a connection in which the browser and server agree on keys and check identity. TLS 1.3 completes it in one round trip.
ClientHello
The browser's first message, called ClientHello, lists the versions and ciphers it supports and already carries its key share, the public half of a Diffie-Hellman exchange. Mallory can read it, but a key share is public.
ServerHello
The server replies with its own key share in ServerHello. Both sides now compute the same secret and derive session keys from it, the symmetric keys that protect only this one connection. They are unrelated to the login session or token, such as a cookie or a JWT, which an app uses later inside the encrypted connection. Mallory has seen only public values.
Certificate and signature, already encrypted
Everything after this is encrypted, including the certificate chain. The server also signs the handshake so far with its private key, which proves it holds the key named in its certificate.
The browser checks
The browser checks the chain up to a trusted root, the signature and the name. The Finished messages then confirm that neither side's view of the handshake was altered.
Your request, protected
Now your request travels encrypted with AES-GCM and protected by its tag. Mallory can see only that roughly 200 bytes went by.
Three guarantees, three tools
Each guarantee from chapter 5 now has a mechanism behind it.
TLS 1.3 sets up a connection in one round trip. The key shares create the secret, the certificate and the server's signature prove who is answering, and AES-GCM protects everything after that.
Where else can we see this in play? You probably run systems that never open a browser, such as internal services, VPNs and SSH sessions, so do they use this same recipe, or something different?
The same three ingredients
Whenever two programs talk privately, the same ingredients appear: a key agreement, a cipher and a way to know who is on the other side. What changes from system to system is mostly how identity is established.
Internal services: mutual TLS
Inside a company, services often use mutual TLS, where the company runs its own CA, issues each service a short-lived certificate, and both sides present one during the handshake.
VPNs
A VPN, which tunnels a device's traffic into a private network, usually skips CAs, because each peer's public key is written into the other's configuration. An elliptic-curve key exchange then makes fresh keys for each session.
Signed tokens
A signed token such as a JWT (JSON Web Token) has no handshake at all. The issuer signs the claims with its private key and any service verifies them with the published public key, though anyone holding the token can read it, since it is signed and not encrypted.
SSH
SSH, the usual way engineers log in to remote machines, remembers a server's host key the first time you connect and warns loudly if it ever changes. You log in by signing a challenge with your private key.
One recipe, different sources of identity
Only the source of identity really differs.
Every one of these systems rests on calculations that are easy to do and believed to be hard to undo. How hard are they really, and what would it take to undo one?
Factoring
RSA rests on multiplication being easy and its reverse being hard. Multiplying two large primes is instant, while finding them again from the product, called factoring, has no known fast method on an ordinary computer, one that works with plain 0 and 1 bits. We say ordinary on purpose, because a different kind of computer is about to enter this story.
Watch the work double
Pick a prime size and the page factors the product by dividing by every number in turn. Each extra bit in the primes doubles the work, and RSA-2048 uses primes of about 1,024 bits.
Cleverer methods still fall short
The best known method, the number field sieve, is far faster than trial division, but its cost still grows so steeply that RSA-2048 stays out of reach. The largest RSA challenge number factored in public, RSA-250 with 829 bits, took about 2,700 core-years in 2020.
The discrete logarithm
Diffie-Hellman and elliptic curves rest on the discrete logarithm from chapter 9, which has the same shape of easy forwards and apparently infeasible backwards. For about fifty years these problems have resisted every attack on ordinary computers, which is strong evidence and still not a proof.
That is enough for now.
You now know how a message stays secret, unchanged and attributable on the internet. A fast cipher protects the data, a key exchange creates the secret, signatures prove who is speaking, and certificates vouch for the keys.
It seems like we have covered everything, doesn't it?
This is how it has worked for more than twenty years, and it would take billions to trillions of years of computing to break it.
But is that really true?
Is there a machine that could actually break this, or some new technology that could mess up the whole system?
AI
Breaking a cipher means finding a shortcut that nobody has noticed, and finding what people missed is exactly what AI is now being pointed at. There is no public evidence that AI can break RSA, elliptic curves or the newer post-quantum schemes. People still ask, because locks like these have sometimes fallen to a single new idea with no extra computing power at all, as chapter 20 shows.
A different kind of computer
The second suspect changes the machine itself. Mathematicians have taken it seriously since 1994, when it was shown that such a machine would open exactly the locks this story depends on.
Computers that follow quantum rules
Quantum computing began as physics. In 1981 Richard Feynman pointed out that ordinary computers simulate quantum systems hopelessly slowly, and suggested building computers that follow quantum rules themselves.
Shor's discovery
In 1994 Peter Shor showed that such a machine could factor large numbers and solve discrete logarithms efficiently. That turned an idea about physics into a threat to RSA, Diffie-Hellman and elliptic curves.
Single particles that make stripes
Physicists fired electrons at a screen through two narrow slits, one electron at a time, and each one landed as a single dot. After thousands of dots the screen showed bright and dark stripes, the pattern two overlapping waves make, and closing one slit made the stripes vanish and lit up places that had been dark.
Amplitudes: chances that can cancel
Physics gives each route a number called an amplitude, which can be positive or negative. At each spot the amplitudes of all routes that reach it are added, and the chance of a dot there is that sum squared, so +0.5 and −0.5 add to 0 and make a dark stripe, while +0.5 and +0.5 add to 1.0 and make a bright one.
A qubit
Engineers build tiny systems with two states labelled 0 and 1, such as an ion held by lasers or a small superconducting circuit, and give each state one amplitude. Amplitudes of about 0.6 and 0.8 mean a 36% chance of reading 0 and a 64% chance of reading 1, and measuring returns one bit and leaves the qubit holding that value.
Stray contact with the surroundings, such as heat or a passing particle of light, acts like a small measurement, which is why qubits are kept cold and isolated and still make errors.
Using cancellation to compute
Ten qubits have an amplitude for each of the 1,024 possible answers, but a measurement still returns only one of them. A quantum algorithm steers the amplitudes so that each wrong answer receives contributions that cancel, such as +0.5 and −0.5, while the right answer receives contributions that add, such as +0.5 and +0.5, so measuring returns it almost every time.
This works only for problems with hidden structure, such as a repeating pattern, and only while noise leaves the amplitudes undisturbed.
What Shor was asking
In 1994 Peter Shor, a researcher at Bell Labs, was looking for a problem where a quantum computer would beat an ordinary one by a wide margin. He knew that interference suits repeating patterns, because contributions that line up with the repeat add together while the rest cancel, and Daniel Simon had just shown this for a different problem.
He also knew that factoring can be turned into the search for a repeating pattern, and putting the two facts together gave him a fast way to factor.
What a period is
A period here is a length, not a time. It is the number of steps before a list of numbers starts repeating, so the list 1, 7, 4, 13, 1, 7, 4, 13 and so on has period 4, because after four numbers it is back at the start.
Shor's method needs this length for one particular list, which the next slide builds.
Shor's list and its period
To factor a number N, Shor picks any number a and makes the list ax mod N for x = 0, 1, 2 and so on. For N = 15 and a = 7 the list is 1, 7, 4, 13, and then it repeats, so its period is r = 4.
From the period to the factors
Knowing r = 4, we compute 7r/2 = 72 = 49, and 49 mod 15 = 4. The largest number that divides both 4 − 1 = 3 and 15, called their greatest common divisor, is 3, and for 4 + 1 = 5 and 15 it is 5, which gives 15 = 3 × 5.
Where the quantum computer helps
For a 2048-bit N the sequence is far too long to list, and no ordinary computer can find its period. A quantum computer can, using interference, and a similar trick solves discrete logarithms, which is why Shor's algorithm breaks RSA, Diffie-Hellman and elliptic curves.
What about AES? Grover's search
Shor attacks the number-theory problems behind RSA, Diffie-Hellman and elliptic curves, but AES and hashes rest on plain guessing instead. Against guessing, a second quantum algorithm, Grover's algorithm from 1996, speeds up brute-force search by a square root, so a 128-bit key offers roughly the protection of a 64-bit key. AES itself is not broken, and long-lived secrets move to 256-bit keys.
How big a machine is needed
Today's quantum chips have roughly a hundred to a thousand noisy qubits, far too few to attack RSA-2048, which is therefore not broken. In 2025 Craig Gidney estimated that RSA-2048 would need fewer than a million noisy qubits running for under a week, about twenty times fewer than the roughly twenty million in his 2019 estimate with Martin Ekerå.
The estimates keep falling
Since Shor's paper a seven-qubit machine has factored 15, and NIST, the US standards body, has published replacement algorithms. Meanwhile the estimated size of a machine that breaks RSA has kept falling.
A quantum computer is good at a few special tasks, and Shor's algorithm uses one of them to factor numbers and solve discrete logarithms quickly, which would break RSA, Diffie-Hellman and elliptic curves. Grover only weakens symmetric keys by a square root, and no machine today is large enough, though the estimates keep falling.
If no such machine exists yet and nobody knows when one will, why would anyone spend effort replacing cryptography that works today?
Harvest now, decrypt later
Recording encrypted traffic is cheap and so is storing it, so a patient attacker can record today and decrypt once a capable machine exists. This is called harvest now, decrypt later.
What the recording contains
A recording holds the handshake, which includes both public key shares, and the data encrypted with AES under session keys that neither side ever sent. Those keys were computed from the key exchange, so whoever can undo the key exchange can recompute them.
Why nobody harvests AES itself
AES does not rest on factoring or discrete logarithms, so Shor's algorithm does not apply to it, and Grover's search only cuts a key's strength to about half its bits. AES-128 keeps about 64 bits against such a machine, whose steps must run one after another, and AES-256 keeps about 128, so the weak link is the key exchange that produced the keys.
If AES itself were broken, recorded data would be exposed in the same way, which is why long-lived secrets move to AES-256 as a precaution.
Forward secrecy does not help here
Forward secrecy protects against a stolen server key, but a quantum computer does not need that key, because it can solve each recorded key exchange directly.
Signatures can wait a little
A forged signature only helps an attacker who has the machine at the moment of the attack, so there is no stockpile of old signatures to exploit, with one exception: things signed to be trusted for years, such as firmware, need care sooner. That is why key exchange is being upgraded first.
Does harvesting matter to you? Mosca's inequality
Whether harvesting hurts depends on timing, and a simple comparison called Mosca's inequality captures it. Three numbers decide whether you are already late: x, how long the data must stay secret, y, how long your migration will take, and z, how long until a capable machine exists. If x + y is greater than z, data you send today will still be sensitive when the machine arrives.
Try it with your own data
Nobody knows z, so try the presets with your own guesses. Health records that must stay secret for 25 years are already 18 years late if migration takes five years and the machine arrives in twelve.
An attacker can record traffic now and decrypt it later, so key exchange is at risk whenever data must stay secret for longer than the time until a capable machine arrives. Forged signatures only matter once the machine exists, so they come second.
What could replace Diffie-Hellman and elliptic curves with a hard problem that even Shor's algorithm cannot touch?
Looking for a problem Shor cannot touch
Shor's algorithm works because factoring and discrete logarithms hide a repeating pattern that a quantum computer can find. So the replacements need a hard problem with no such pattern, and the leading candidates come from an unexpected place: grids of dots.
A grid of dots
Picture graph paper that has been tilted a little, with a dot at every crossing. Mathematicians call a regular grid of dots like this a lattice, the same word as for the criss-cross wooden strips of a garden trellis.
Two arrows build the whole grid
Start at one dot and walk some whole number of steps along each of two arrows, and you reach every other dot. Those two arrows are called the basis of the lattice, and they are all you need to describe the whole grid.
The closest-dot puzzle
Now put a target somewhere on the sheet, away from the dots, and ask which dot is closest to it. In two dimensions you can see the answer at a glance, but the version used in cryptography has hundreds of dimensions, where nobody can see anything and no known method, ordinary or quantum, finds the closest dot quickly.
A tidy basis makes it easy
With short, nearly perpendicular basis arrows, simple rounding finds the closest point straight away.
A skewed basis hides the answer
The same grid can also be described by long, skewed arrows, and then rounding lands far from the right point. In lattice cryptography the tidy basis plays the role of the private key and the skewed one the public key.
ML-KEM
ML-KEM, the standard that NIST built from this idea, works in hundreds of dimensions and adds a little random noise to the points. No known algorithm, classical or quantum, finds the closest point efficiently there.
We say known on purpose, because nobody has proved that a fast method cannot exist. A candidate called SIKE was broken in 2022 on a single processor core in about an hour at first and about ten minutes in later versions, which chapter 20 returns to, and that is one reason browsers pair ML-KEM with X25519 instead of trusting it alone.
How ML-KEM shares a secret
The browser makes a fresh ML-KEM key pair and sends the public half, called the encapsulation key, and the server uses it to wrap a new random secret and sends back the ciphertext. The key pair is new for every connection and deleted afterwards, so unlike old RSA key transport this keeps forward secrecy.
Hybrid: both at once
ML-KEM is young, so browsers do not rely on it alone. They run X25519, the elliptic-curve exchange from chapter 9, and ML-KEM-768 side by side and mix both secrets into the session key. A quantum computer breaks X25519 but not ML-KEM, and a flaw found in ML-KEM would leave X25519 standing against today's computers, so an attacker needs something that defeats both at once.
Already in use
The browser's key share grows from 32 bytes to 1,216, which is 32 for X25519 plus 1,184 for ML-KEM. Chrome and large content-delivery networks already negotiate this hybrid, called X25519MLKEM768.
Lattice schemes such as ML-KEM rest on problems with no known quantum shortcut, and browsers run them alongside X25519 so a session stays safe if either one holds.
That protects the secrecy of traffic recorded from now on, but the bank's certificate and signature still use RSA or ECDSA. What happens to authentication?
Post-quantum signatures are big
ML-DSA is NIST's standard post-quantum signature scheme, and its main drawback is size. An ML-DSA-65 signature is 3,309 bytes and its public key 1,952 bytes, against about 64 bytes each for ECDSA on the standard P-256 curve.
A whole chain adds up
A handshake carries three signatures and two public keys, about 1.3 kilobytes with RSA-2048. With ML-DSA-65 the same items come to about 13.8 kilobytes on every connection.
Every connection would carry about ten times more bytes just to prove who the server is, so is there a way to prove it without sending a fresh pile of large signatures each time?
Merkle Tree Certificates
Merkle Tree Certificates avoid most of that cost by making one signature serve many certificates. The CA hashes many certificates, hashes those results in pairs into a tree, and signs only the single hash at the top, called the tree's root, which is a different thing from a root CA.
A short proof
Each certificate travels with the sibling hashes on its path to the top, so the browser can recompute the root and compare it with the signed one. A million certificates need a proof of only about twenty hashes.
Tampering shows
Change the certificate and the recomputed root no longer matches the signed one, so the check fails.
Chrome's plan
On 3 December 2026 the Chrome Security Team said Chrome will support Merkle Tree Certificates, expected very early in 2027, and intends to stop trusting CA keys that use ECDSA P-256 from 15 March 2027. It also recommends that sites adopt hybrid ML-KEM key exchange.
Post-quantum signatures are many times larger, and Merkle Tree Certificates keep handshakes small by having the CA sign one root and sending each certificate with a short proof.
We are swapping locks studied for decades for new ones studied for far less time. What happens if one of the new ones turns out to have a flaw?
A belief is not a proof
Every lock in this story depends on a problem that people believe is hard, and nobody has proved that any of them is.
The story of SIKE
SIKE was a compact post-quantum key exchange that reached the last round of NIST's competition after years of study. In July 2022 Wouter Castryck and Thomas Decru published an attack that recovered SIKEp434 keys in about 62 minutes on a single processor core, with no quantum computer involved.
What broke SIKE
A later reimplementation did it in about ten minutes. SIKE fell to a mathematical insight that nobody had found in all those years, which is exactly the kind of break the AI question in the interlude was about.
Where that leaves us
RSA and X25519 will probably fall to quantum computers on a date nobody knows. ML-KEM and ML-DSA are the best replacements available and have no known break, though SIKE shows that a break can arrive without warning.
Crypto agility
Because nobody can promise how long an algorithm will last, systems need crypto agility, which means being able to replace an algorithm without redesigning the system.
Crypto agility in practice
In practice that means running hybrid modes so that one broken algorithm is not fatal, and keeping keys and certificates short-lived. It also means keeping an inventory of where each algorithm is used, so you know what to change when one falls.
Cheat sheet
The whole story fits in one table.
Check yourself, 1 of 4
What are the three guarantees TLS provides, and which tool provides each of them?
Show answerHide answer
Confidentiality comes from the key exchange, which makes the secret, and AES, which uses it. Integrity comes from the AES-GCM tag and the Finished messages. Authentication comes from the certificate chain and the server's signature.
Check yourself, 2 of 4
Why does forward secrecy not protect you against a quantum computer?
Show answerHide answer
Forward secrecy means a stolen server key cannot decrypt old traffic. A quantum computer does not need the server key, because it breaks each recorded X25519 exchange directly, so old recordings still open.
Check yourself, 3 of 4
Why is the certificate migration happening after the key exchange migration?
Show answerHide answer
Breaking key exchange works backwards in time, since anything recorded now can be read later. Breaking signatures reveals no secret, so a recording gains the attacker nothing to read. A forged signature only helps in a live attack, when the machine already exists, or in faking something meant to be trusted for years, such as signed firmware. Post-quantum signatures are also much larger.
Check yourself, 4 of 4
Why do browsers use hybrid key exchange instead of ML-KEM alone?
Show answerHide answer
ML-KEM is young, and having no known attack is not a proof, as SIKE showed when it fell in about ten minutes of computing after years of study. With a hybrid, an attacker has to break both X25519 and ML-KEM.
In short
Two parties agree on a secret in public, use it to encrypt their traffic, prove who they are through a chain of signatures, and keep every part replaceable, because nobody can say how long the hard problems will stay hard.