The one-sentence version
A lattice can have many bases: some with long, slanted vectors, others with short, nearly perpendicular ones. The LLL algorithm (1982) turns a "bad basis" into a "fairly good basis" in polynomial time, and so finds quite short vectors. The secret of many cryptosystems happens to be a short vector in some lattice. This is how the 1978 Merkle–Hellman knapsack cryptosystem was broken. Today LLL remains a core tool for attacking ECDSA nonce leaks and evaluating post-quantum lattice parameters.
This article has three layers:
- The intuition: lattices, good and bad bases, the knapsack problem
- Real-world use: the rise and fall of knapsack cryptography, recovering private keys from side-channel leaks, choosing post-quantum parameters
- The mathematics: Gaussian reduction in two dimensions, the idea of LLL, the knapsack cryptosystem and its lattice attack, with worked examples
Layer 1: The Intuition
1.1 Lattices, good bases and bad bases
Take two vectors in the plane. All their integer combinations form a regularly arranged set of points called a lattice.
The same array of points can be generated by different bases. Take the integer lattice (all points with integer coordinates):
- Good basis: and , short and mutually perpendicular;
- Bad basis: and , long and nearly parallel. You can verify that their integer combinations also generate exactly all the integer points (determinant ).
Someone holding the bad basis has a hard time seeing that "the shortest vector in this lattice has length just 1". This is the basic idea of lattice cryptography: the public key gives a bad basis, and the private key is a good one (see "Post-Quantum Cryptography").
1.2 The knapsack problem
You are given a pile of items of different weights, . Which ones add up to exactly ?
This is the subset sum problem. In general it is NP-complete, and with many items you are left with something close to brute force. In 1978 Merkle and Hellman built one of the earliest public-key cryptosystems on it: which items you pick are the plaintext bits, and the total weight is the ciphertext.
1.3 Why it fell
To let the legitimate recipient decrypt, Merkle–Hellman hid a "trapdoor" structure in the item weights. In 1982 Shamir used this structure to break it; soon after, people found a more general method: write the knapsack problem as a lattice, where the secret bit string corresponds to an unusually short vector in the lattice, and run LLL to get it straight out.
Layer 2: Real-World Use
The rise and fall of knapsack cryptography
| Year | Event |
|---|---|
| 1978 | The Merkle–Hellman knapsack cryptosystem is proposed, almost at the same time as RSA |
| 1982 | Shamir gives a polynomial-time attack |
| 1982 | Lenstra, Lenstra and Lovász publish the LLL algorithm (originally for factoring polynomials with rational coefficients) |
| 1985 onward | Lagarias, Odlyzko and others use lattice reduction to attack "low-density" knapsacks; nearly all later improved knapsack variants are wiped out |
What LLL is used for today
- Recovering ECDSA private keys from partial leaks: even if the nonce of ECDSA leaks only a few bits per signature (through a timing side channel, say), collecting a few hundred signatures lets you build a lattice and solve for the private key with LLL or BKZ. This is called the "hidden number problem" (HNP). Attacks such as TPM-Fail (2019) and Minerva (2019) all work this way. (See the extreme case of repeated in "Elliptic Curves".)
- Coppersmith's method: finds small roots of modular polynomial equations, attacking certain uses of small-exponent RSA, or factoring when half the bits of are known.
- Choosing post-quantum parameters: the security parameters of Kyber and Dilithium are estimated from "how long the best lattice reduction algorithm (BKZ) takes". Here LLL is the "enemy", used to measure how high the defenses stand.
- Beyond cryptography: integer relation detection (discovering identities among mathematical constants), integer programming and resolving GPS carrier-phase ambiguity.
Layer 3: The Mathematics
3.1 The definition of a lattice
Given linearly independent vectors , the lattice is
Two bases , generate the same lattice if and only if , where is a unimodular matrix (an integer matrix with determinant ), that is, . So "changing basis" means multiplying by an element of the group .
The determinant of a lattice (the volume of the fundamental parallelepiped), , doesn't change with the basis; it is an invariant of the lattice.
3.2 Two dimensions: Gaussian reduction, the vector version of the Euclidean algorithm
In two dimensions there is an exact algorithm (Lagrange–Gauss): repeatedly use the short vector to "whittle down" the long one, until no more can be removed. This is exactly the same idea as "subtract the smaller from the larger" when computing a greatest common divisor.
A worked example: reducing the bad basis
Each step subtracts one vector from another, a unimodular transformation that leaves the generated lattice unchanged:
| Step | Operation | Basis |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 |
We end with the standard basis, confirming this lattice is . Note that the coordinates are all Fibonacci numbers, exactly matching the Euclidean algorithm computing ; Fibonacci numbers happen to be the "worst case" of the Euclidean algorithm. (Checked with Python. Real Gaussian reduction subtracts the best integer multiple at each step, using fewer steps with the same result.)
3.3 The idea of LLL
In high dimensions there is no algorithm both exact and efficient (the shortest vector problem, SVP, is NP-hard), so LLL settles for an approximation:
- Size reduction: for each , subtract integer multiples of the earlier vectors, making its components along the Gram–Schmidt directions as small as possible (a generalization of two-dimensional Gaussian reduction);
- The Lovász condition: if two adjacent vectors are in a "bad" order (the Gram–Schmidt length of the later one is much shorter than the earlier one's), swap them and return to step 1.
It can be proved that this ends in polynomial time, and the first output vector satisfies
where is the length of the true shortest vector. In the worst case this approximation factor is exponential, but real performance is far better than theory, often finding the shortest vector outright in a few dozen dimensions. The stronger BKZ algorithm builds on LLL by solving blocks exactly, trading time for quality.
3.4 Merkle–Hellman and its lattice attack
Private key: a superincreasing sequence (each term exceeds the sum of all earlier ones), a modulus and a multiplier with .
Public key: , that is, . It looks like a general knapsack, with the superincreasing structure "hidden" by the modular multiplication.
Encryption and decryption
Encrypt the plaintext bits (the ASCII code of the letter a): take items 2, 3 and 8,
Decrypt: and . Then go greedily through the superincreasing sequence:
- : take item 8, leaving
- all exceed : skip
- : take item 3, leaving
- : take item 2, leaving
This gives the bits , recovering a. (Checked with Python.)
The lattice attack: build the lattice whose basis is the following rows (the last column holds the weights):
Taking the plaintext bits as coefficients, adding the first rows and then the last row gives
This is an extremely short vector whose components are only 0 and 1, with length at most , while other vectors in the lattice are usually much longer. When the knapsack's "density" is low, LLL finds it directly, and the bit string is the plaintext.
Summary
| Layer | Key points |
|---|---|
| Intuition | The same lattice has good and bad bases; short vectors hide behind bad bases |
| Algebra | Changing basis multiplying by a unimodular matrix (); two-dimensional reduction is the Euclidean algorithm |
| LLL | Finds a "short enough" vector in polynomial time, with approximation factor |
| Impact | Crushed knapsack cryptography; attacks ECDSA nonce leaks; sets post-quantum parameters |