Lattices
A lattice is a regular grid of points in : all integer combinations of a few basis vectors. Finding the shortest nonzero vector, or the lattice point closest to a target, is easy in two dimensions and believed hard in hundreds, even for quantum computers. That hardness underlies the new post-quantum standards, and lattice algorithms are also a powerful attack tool against biased ECDSA nonces and weak RSA variants.
Definition
Given linearly independent vectors (the columns of a basis matrix ), the lattice they generate is
The same lattice has infinitely many bases: and generate the same points whenever is an integer matrix with (unimodular). The volume of the fundamental parallelepiped, , does not depend on the basis and is the lattice's determinant.
import numpy as np
B = np.array([[2, 1], [0, 3]]) # columns b1 = (2, 0), b2 = (1, 3)
U = np.array([[5, 3], [3, 2]]) # det U = 1: unimodular
B2 = B @ U
print("good basis columns:", B.T.tolist(), " det:", round(np.linalg.det(B)))
print("bad basis columns: ", B2.T.tolist(), " det:", round(np.linalg.det(B2)))
pts = {tuple(B @ z) for z in np.array(np.meshgrid(range(-4, 5), range(-4, 5))).reshape(2, -1).T}
pts2 = {tuple(B2 @ z) for z in np.array(np.meshgrid(range(-40, 41), range(-40, 41))).reshape(2, -1).T}
window = lambda S: sorted(p for p in S if abs(p[0]) <= 4 and abs(p[1]) <= 4)
print("same points near the origin:", window(pts) == window(pts2))good basis columns: [[2, 0], [1, 3]] det: 6
bad basis columns: [[13, 9], [8, 6]] det: 6
same points near the origin: True
Both bases generate exactly the same points, but one has short, nearly orthogonal vectors and the other long, nearly parallel ones.
The hard problems
- SVP (shortest vector problem): find the shortest nonzero vector of .
- CVP (closest vector problem): given a target , find the lattice point closest to it.
With a good basis, CVP is easy: write with real and round each coordinate (Babai's rounding). With a bad basis of the same lattice, rounding gives a point far from optimal.
import numpy as np
B_good = np.array([[2.0, 1.0], [0.0, 3.0]])
B_bad = B_good @ np.array([[5.0, 3.0], [3.0, 2.0]])
t = np.array([7.3, 5.2])
def babai(B, t):
z = np.round(np.linalg.solve(B, t))
return B @ z
for name, B in (("good", B_good), ("bad", B_bad)):
v = babai(B, t)
print(f"{name} basis: lattice point {v.round(6).tolist()}, distance {np.linalg.norm(t - v):.3f}")good basis: lattice point [8.0, 6.0], distance 1.063
bad basis: lattice point [0.0, 0.0], distance 8.963
This is the GGH idea for a trapdoor: publish a bad basis, keep a good one. Anyone can encode a message as a lattice point plus small noise; only the holder of the good basis can round away the noise.
Minkowski's bound
How short can the shortest vector be? Minkowski's theorem guarantees a nonzero lattice vector of length at most . For random lattices the shortest vector is close to the Gaussian heuristic . Lattice attacks work when a secret is unusually short compared with this, which is how they break ECDSA with leaked nonce bits.
import numpy as np, itertools
rng = np.random.default_rng(5)
B = rng.integers(-50, 51, size=(3, 3)).astype(float)
det = abs(np.linalg.det(B))
best = min(np.linalg.norm(B @ np.array(z)) for z in itertools.product(range(-6, 7), repeat=3) if any(z))
n = 3
print(f"det = {det:.0f} shortest found = {best:.2f}")
print(f"Minkowski bound = {np.sqrt(n) * det ** (1 / n):.2f} Gaussian heuristic = {np.sqrt(n / (2 * np.pi * np.e)) * det ** (1 / n):.2f}")det = 16158 shortest found = 15.10
Minkowski bound = 43.79 Gaussian heuristic = 10.60
(The brute-force search over small coefficients is only feasible in tiny dimensions; in dimension 500 the number of candidates is astronomical.)
In software
- Post-quantum ML-KEM (Kyber) and ML-DSA (Dilithium) rely on module-lattice problems (Learning With Errors); Falcon (FN-DSA) uses a GGH-like trapdoor done right.
- Lattice reduction (LLL) attacks: Coppersmith's method for small RSA roots, hidden-number attacks on ECDSA nonce bias.
Exercises
Exercise 1: Same lattice?
Do the bases and generate the same lattice?
Answer
Yes, both generate .
Solution
The second basis matrix has determinant , so it is unimodular and generates the same lattice as the identity.
Exercise 2: Determinant
What is the determinant of the lattice spanned by and , and how many lattice points per unit area does it have?
Answer
; one point per 5 units of area.
Solution
. Each fundamental parallelogram has area 5 and contains one lattice point, so the density is .
Exercise 3: Rounding with a good basis (code)
For the lattice with basis and (multiples of 5 in each coordinate), find the closest lattice point to by rounding.
Answer
.
Solution
import numpy as np
B = np.array([[5.0, 0.0], [0.0, 5.0]])
t = np.array([13.0, -7.0])
v = B @ np.round(np.linalg.solve(B, t))
print(v.tolist(), np.linalg.norm(t - v))[15.0, -5.0] 2.8284271247461903
With an orthogonal basis rounding is exact: each coordinate is rounded to the nearest multiple of 5 independently.
Test yourself
Two bases and generate the same lattice when…
- they have the same first vector
- with an integer matrix of determinant
- they are both orthogonal
- only
Babai's rounding solves CVP well when the basis is…
- long and nearly parallel
- short and nearly orthogonal
- random
- triangular with huge entries
Why are lattice problems interesting for post-quantum cryptography?
- they are easy for quantum computers
- no efficient quantum algorithm is known for them
- they use small primes
- they replace hash functions