Skip to main content
Cipher Visualizers home

Sweet32: Why 64-bit Block Ciphers Fall to the Birthday Bound

In CBC mode, two equal ciphertext blocks leak the XOR of their plaintexts, and for a 64-bit cipher like 3DES such a collision appears after about 2^32 blocks. This guide runs the Sweet32 attack on a reduced-block cipher so the collision actually happens, recovering a secret block from captured ciphertext.

Pashalis Laoutaris 13 min read

Try it

Interactive Sweet32 Birthday Attack

🔐 Sweet32 Birthday Attack on 64-bit Block Ciphers

A reduced 32-bit block cipher in CBC, so the birthday collision appears in tens of thousands of blocks. Real 3DES has a 64-bit block and needs about 2^32.
Enter text and click a button to start!
1. Why a block collision leaks plaintext
2. Capturing ciphertext blocks until two match
3. The collision
4. Recovering the secret block
Click the button to recover a secret from CBC ciphertext using a block collision.

Sweet32: Why 64-bit Block Ciphers Fall to the Birthday Bound

Introduction

A block cipher’s block size is not just a detail. Triple DES and Blowfish have a 64-bit block, half the width of AES. For decades that seemed fine. In 2016 Karthikeyan Bhargavan and Gaëtan Leurent showed it is not, with an attack they called Sweet32. It needs no weakness in the cipher itself. It exploits only the block size, through the birthday paradox, against CBC mode.

The idea is short. In CBC, once two ciphertext blocks happen to be equal, the XOR of their two plaintext blocks is revealed. For a 64-bit block that collision is expected after about 2^32 blocks, which is roughly 32 GB on a single connection, and a long-lived HTTPS or OpenVPN session really does carry that much. Sweet32 recovered secret HTTP cookies this way. This guide runs the attack on a reduced 32-bit block cipher so the collision appears in tens of thousands of blocks, with the exact same mechanism.

Table of Contents

The CBC Collision Leak

CBC mode chains each block into the next. With block cipher E, key k, and previous ciphertext block C_(i-1), each ciphertext block is:

C_i = E(k, P_i xor C_(i-1))

Now suppose two ciphertext blocks are equal, C_i = C_j. Because E is a permutation, equal outputs mean equal inputs:

P_i xor C_(i-1) = P_j xor C_(j-1)

Rearranging gives the leak:

P_i xor P_j = C_(i-1) xor C_(j-1)

The right side is made of ciphertext blocks, which an eavesdropper sees. So a single collision hands the attacker the XOR of two plaintext blocks, with no key and no knowledge of the cipher’s internals. This is the same two-time-pad idea that breaks a reused one-time pad, arriving here through a block collision instead.

The Birthday Bound

Collisions are not rare for a small block. If ciphertext blocks behaved like random 64-bit values, the birthday paradox says a collision is likely after about 2^(64/2) = 2^32 of them. That is the whole attack surface of a 64-bit cipher: not its key, which is strong, but the number of blocks you can safely encrypt under one key before two of them match.

For 3DES at 2^32 blocks of 8 bytes each, that is about 32 GB. A browser kept on a page that quietly makes requests, or a VPN tunnel left open, can push that much through one connection. Sweet32 did exactly this against HTTP over TLS and against OpenVPN. A 128-bit cipher like AES moves the bound to 2^64 blocks, which is astronomically out of reach, which is why block size matters.

Recovering a Secret Block

The XOR of two plaintext blocks is only useful if one of them is known. The practical attack arranges exactly that. The victim’s traffic repeatedly contains a fixed secret block, such as an authentication cookie, and the attacker, running script in the victim’s browser, also injects blocks of chosen known data into the same connection. Both kinds of block stream past under the same key.

The attacker watches every ciphertext block and waits for a collision between a secret-slot block and a known-slot block. When one appears, the algebra gives the secret directly:

secret xor known = C_prev(secret) xor C_prev(known)
secret           = known xor C_prev(secret) xor C_prev(known)

Everything on the right is known, so the secret block is recovered. Collect enough traffic and every secret block falls the same way. A final comparison against the true value confirms it.

Interactive Visualizer

The visualizer above runs the attack on a reduced 32-bit block cipher, a four-round Feistel, in CBC mode. Pick a connection seed; the victim sends a fixed secret block interleaved with attacker-known blocks, and the attacker sees only the ciphertext.

The four cards show why a collision leaks plaintext, the block counter climbing as the attacker captures traffic, the collision when it appears, and the XOR that recovers the secret, checked against the true value. Because the toy block is 32 bits, the collision shows up in tens of thousands of blocks instead of 3DES’s billions. The same code runs in the Python below, and the two agree on the block count and the recovered secret.

A Worked Example

The toy cipher has a 32-bit block, so the birthday bound is about 2^16 blocks. On one CBC connection, with the secret block interleaved with attacker-known blocks, the collision appears after 31,735 blocks for this seed. The secret block is c0ab17a5, which the attacker never sees as plaintext.

At the collision, two ciphertext blocks are equal: one from a secret slot, one from a known slot. The attacker XORs the known block with the two public previous ciphertext blocks and reads off the secret, c0ab17a5, matching the true value. Across 40 connections the attack recovered the secret every time; only the number of blocks varied, averaging about 103,000, right around the birthday bound. A real 64-bit cipher behaves identically, with the counts scaled up to 2^32.

Python Implementation

This is the reduced-block cipher, CBC mode, and the full collision attack. The pseudorandom generator is a small mulberry32, ported identically to the visualizer so both produce the same traffic.

# sweet32.py
#
# Sweet32 (Bhargavan and Leurent, 2016, CVE-2016-2183): a birthday attack on 64-bit block ciphers in
# CBC mode, such as 3DES and Blowfish. In CBC two equal ciphertext blocks reveal the XOR of their
# plaintext blocks, and after about 2^(b/2) blocks such a collision appears by chance. For a 64-bit
# cipher that is ~2^32 blocks (about 32 GB on one connection), which really was reachable over a long
# HTTPS or VPN session. This demo uses a reduced 32-bit block cipher so the collision shows up in a
# few tens of thousands of blocks; the mechanism is identical. Teaching code.

M16 = 0xFFFF
M32 = 0xFFFFFFFF


def _imul(a, b):
    return (a * b) & M32


class Mulberry32:
    """A small deterministic PRNG, ported identically to the visualizer so both produce the same stream."""

    def __init__(self, seed):
        self.a = seed & M32

    def next(self):
        self.a = (self.a + 0x6D2B79F5) & M32
        t = self.a
        t = _imul(t ^ (t >> 15), t | 1) & M32
        t = (t ^ (t + _imul(t ^ (t >> 7), t | 61)) & M32) & M32
        return (t ^ (t >> 14)) & M32


# ---- a toy 32-bit block cipher: a 4-round Feistel on two 16-bit halves (a real permutation) ----
RK = [0x1234, 0x89AB, 0xCDEF, 0x4567]


def round_f(x, rk):
    x = (x * 0x9E37 + rk) & M16
    x ^= x >> 7
    x = (x * 0x85EB) & M16
    x ^= x >> 9
    return x & M16


def encrypt_block(block):
    """32-bit block in, 32-bit block out. Stands in for one 3DES block, but 32 bits wide, not 64."""
    L, R = (block >> 16) & M16, block & M16
    for rk in RK:
        L, R = R, (L ^ round_f(R, rk)) & M16
    return ((L << 16) | R) & M32


def cbc_encrypt_block(plain_block, prev_cipher):
    """One CBC step: C = E(P xor previous C)."""
    return encrypt_block((plain_block ^ prev_cipher) & M32)


def sweet32_attack(seed, cap=5_000_000):
    """A victim repeatedly sends [secret || attacker-known] blocks over one CBC connection.

    The attacker sees every ciphertext block and waits for a collision between a secret-slot block and
    a known-slot block. From C_i = C_j it gets P_i xor P_j = C_(i-1) xor C_(j-1); with one side known,
    the secret block drops out. Returns (blocks_seen, recovered_secret, true_secret).
    """
    rng = Mulberry32(seed)
    secret = rng.next()                        # the fixed secret block, e.g. a session cookie
    prev = rng.next()                          # the IV
    seen = {}                                  # ciphertext block -> (is_secret, plaintext_if_known, prev_cipher)
    idx = 0
    while idx < cap:
        idx += 1
        is_secret = (idx % 2 == 1)             # odd blocks carry the secret, even blocks are attacker data
        pval = secret if is_secret else rng.next()
        c = cbc_encrypt_block(pval, prev)
        if c in seen:
            o_secret, o_pval, o_prev = seen[c]
            if is_secret != o_secret:          # a collision between a secret block and a known block
                known_p = pval if not is_secret else o_pval
                known_prev = prev if not is_secret else o_prev
                secret_prev = o_prev if not is_secret else prev
                recovered = known_p ^ known_prev ^ secret_prev
                return idx, recovered, secret
        seen[c] = (is_secret, pval, prev)
        prev = c
    return idx, None, secret


if __name__ == "__main__":
    # the toy cipher is a genuine permutation (a Feistel always is)
    sample = {encrypt_block(v) for v in range(70000)}
    print("toy 32-bit cipher is a bijection on a 70000-value sample:", len(sample) == 70000)
    print("birthday bound for a 32-bit block: about 2^16 =", 1 << 16, "blocks (3DES, 64-bit, needs ~2^32).")

    seed = 20
    blocks, recovered, secret = sweet32_attack(seed)
    print("\nOne CBC connection, 32-bit-block cipher, seed %d:" % seed)
    print("secret block (the attacker never sees the plaintext):  %08x" % secret)
    print("ciphertext blocks observed until the collision:         %d" % blocks)
    print("recovered secret block from the collision:             %08x" % recovered)
    print("recovered == secret:", recovered == secret)

    # robustness: the attack always works, the only variable is how many blocks it takes
    counts = []
    ok = 0
    for s in range(40):
        b, rec, sec = sweet32_attack(s)
        counts.append(b)
        ok += (rec == sec)
    print("\nover 40 connections: recovered %d/40, mean %d blocks, max %d" % (ok, sum(counts) // len(counts), max(counts)))

Running it prints this:

toy 32-bit cipher is a bijection on a 70000-value sample: True
birthday bound for a 32-bit block: about 2^16 = 65536 blocks (3DES, 64-bit, needs ~2^32).

One CBC connection, 32-bit-block cipher, seed 20:
secret block (the attacker never sees the plaintext):  c0ab17a5
ciphertext blocks observed until the collision:         31735
recovered secret block from the collision:             c0ab17a5
recovered == secret: True

over 40 connections: recovered 40/40, mean 103474 blocks, max 207057

I checked the code several ways. The toy cipher is a Feistel, so it is a genuine permutation, which the code confirms on a sample. The first collision appears right around the 2^16 birthday bound for a 32-bit block, matching the theory. The attack recovers the exact secret block, verified against the true value, and did so for all 40 random connections tested, with only the block count varying. The JavaScript in the visualizer uses the same mulberry32 and the same cipher, and agrees with the Python on the mulberry stream, the cipher outputs, and the recovered secret and block count for every seed tested.

Limitations

A reduced block size. The demo uses a 32-bit block so a real collision appears in tens of thousands of blocks. Sweet32’s targets, 3DES and Blowfish, have 64-bit blocks and need about 2^32 blocks, around 32 GB on one connection. That is reachable in practice but far too much to run here. The mechanism, a CBC block collision leaking a plaintext XOR, is identical at both sizes.

One known block beside the secret. The recovery needs a collision between the secret block and a known block. The attack sets this up by injecting known data into the same connection, as Sweet32 did with script in the browser. A connection carrying only unknown data would leak only XORs of unknowns.

One static key, one connection. The blocks must all be encrypted under the same key, so the attack needs a single long-lived connection or session that does not rekey. Frequent rekeying resets the block count and defeats it.

Teaching code. The cipher is a small Feistel with a cheap round function, enough to behave like a random permutation for the birthday count, not a real cipher. The attack logic is exactly the one that applies to 3DES-CBC.

Security Status

Sweet32 is why 64-bit block ciphers are now deprecated for bulk encryption. After the 2016 disclosure, browsers and servers removed or deprioritized 3DES cipher suites in TLS, OpenVPN changed its defaults and added rekeying guidance, and TLS 1.3 dropped CBC and 3DES entirely. The attack earned CVE-2016-2183. It was not a break of 3DES’s key, which remains strong at its effective key length; it was a break of using a 64-bit block for large amounts of data.

The defenses are clear. Use a 128-bit block cipher, which pushes the collision bound to 2^64 blocks. Where a 64-bit cipher cannot be avoided, strictly limit the data per key and rekey often, well before 2^32 blocks. Modern authenticated modes like AES-GCM and ChaCha20-Poly1305 use large blocks or stream constructions and are the right default. The deeper lesson is that a cipher’s safe data limit is set by its block size, not only its key size.

FAQ

Is 3DES’s key broken by this?

No, its key is not. Sweet32 never attacks the key or the cipher’s internals. It exploits the 64-bit block size, which limits how much data can be encrypted under one key before two ciphertext blocks collide by chance. The key stays as strong as ever; the block size is the problem.

Why does AES not have this problem in practice?

AES has a 128-bit block, so the birthday bound is about 2^64 blocks, which is around 300 exabytes. No connection carries that, so the collision never happens. The attack scales with block size, and doubling the block squares the safe data limit.

Does the cipher mode matter?

Yes, the mode matters. The leak here is specific to CBC, where a ciphertext-block collision reveals a plaintext XOR. Counter-based modes like CTR and GCM have their own data limits from nonce and counter sizes, but they do not leak plaintext from a single ciphertext-block collision the way CBC does.

How much traffic did the real attack need?

About 2^32 blocks, roughly 32 GB, on one connection under one key. Bhargavan and Leurent recovered an HTTP cookie from a browser kept on a page that generated steady requests, and showed the same against OpenVPN. It takes hours, but it is practical.

Why does the demo use a 32-bit block?

So the birthday collision actually happens while you watch. A 64-bit block needs about 2^32 blocks, too many to run in a browser. At 32 bits the bound is about 2^16, so a collision appears in tens of thousands of blocks, and the recovery math is exactly the same.

References

  1. Bhargavan, Karthikeyan, and Gaëtan Leurent. “On the Practical (In-)Security of 64-bit Block Ciphers: Collision Attacks on HTTP over TLS and OpenVPN.” ACM Conference on Computer and Communications Security (CCS), 2016.

  2. CVE-2016-2183. The Sweet32 birthday attack on 64-bit block ciphers in CBC mode.

  3. The Sweet32 project page: https://sweet32.info/.

  4. The 3DES guide on this site, a primary 64-bit-block target: /blog/3des_guide/

  5. The Blowfish guide on this site, the other 64-bit-block target: /blog/blowfish_guide/

A visual representation of the Square attack recovering an AES round key from balanced sets
Modern & Applied Cryptography Breakers Advanced

The Square Attack: Breaking AES Reduced to Four Rounds

Full AES has no practical break, but reduced-round AES does. The Square attack feeds 256 chosen plaintexts through 4-round AES, uses a balance property that survives three rounds, and peels off the last round key one byte at a time, then runs the key schedule backwards to the master key.

16 min read

A visual representation of two files with different prefixes reaching the same MD5 hash
Modern & Applied Cryptography Breakers Advanced

Breaking MD5 with a Chosen-Prefix Collision

A chosen-prefix collision gives two files that start however the attacker likes and still share one MD5 hash. This guide takes a real HashClash pair apart, one starting with yes and one with no, and traces MD5's internal state block by block as nine near-collision blocks cancel the difference to zero.

16 min read

A visual representation of the padding oracle attack recovering AES-CBC plaintext one byte at a time
Modern & Applied Cryptography Breakers Intermediate

Breaking AES-CBC with a Padding Oracle

A server that only tells you whether decrypted padding was valid hands you the whole plaintext. This guide runs the real CBC padding-oracle attack against full AES-128, recovers a secret message one byte at a time, and explains why POODLE and Lucky 13 made authenticated encryption the rule.

16 min read