TExcelTAD

Lattices

A lattice is a regular grid of points in Rn\mathbb{R}^n: 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 b1,…,bn∈Rn\mathbf{b}_1, \ldots, \mathbf{b}_n \in \mathbb{R}^n (the columns of a basis matrix BB), the lattice they generate is

L(B)={Bz:z∈Zn}={z1b1+⋯+znbn:zi∈Z}L(B) = \{ B\mathbf{z} : \mathbf{z} \in \mathbb{Z}^n \} = \{ z_1\mathbf{b}_1 + \cdots + z_n\mathbf{b}_n : z_i \in \mathbb{Z} \}

The same lattice has infinitely many bases: BB and BUBU generate the same points whenever UU is an integer matrix with det⁡U=±1\det U = \pm 1 (unimodular). The volume of the fundamental parallelepiped, ∣det⁡B∣\lvert \det B \rvert, does not depend on the basis and is the lattice's determinant.

python · try it yourself
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 LL.
  • CVP (closest vector problem): given a target t\mathbf{t}, find the lattice point closest to it.

With a good basis, CVP is easy: write t=Bx\mathbf{t} = B\mathbf{x} with real x\mathbf{x} and round each coordinate (Babai's rounding). With a bad basis of the same lattice, rounding gives a point far from optimal.

python · try it yourself
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 n⋅∣det⁡B∣1/n\sqrt{n} \cdot \lvert \det B \rvert^{1/n}. For random lattices the shortest vector is close to the Gaussian heuristic n/(2πe) ∣det⁡B∣1/n\sqrt{n / (2\pi e)} \, \lvert \det B \rvert^{1/n}. Lattice attacks work when a secret is unusually short compared with this, which is how they break ECDSA with leaked nonce bits.

python · try it yourself
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 {(1,0),(0,1)}\{(1, 0), (0, 1)\} and {(2,1),(1,1)}\{(2, 1), (1, 1)\} generate the same lattice?

Answer

Yes, both generate Z2\mathbb{Z}^2.

Solution

The second basis matrix [2111]\begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} has determinant 2−1=12 - 1 = 1, so it is unimodular and generates the same lattice as the identity.

Exercise 2: Determinant

What is the determinant of the lattice spanned by (3,1)(3, 1) and (1,2)(1, 2), and how many lattice points per unit area does it have?

Answer

det⁡=5\det = 5; one point per 5 units of area.

Solution

det⁡[3112]=6−1=5\det \begin{bmatrix} 3 & 1 \\ 1 & 2 \end{bmatrix} = 6 - 1 = 5. Each fundamental parallelogram has area 5 and contains one lattice point, so the density is 1/51/5.

Exercise 3: Rounding with a good basis (code)

For the lattice with basis (5,0)(5, 0) and (0,5)(0, 5) (multiples of 5 in each coordinate), find the closest lattice point to (13,−7)(13, -7) by rounding.

Answer

(15,−5)(15, -5).

Solution
python · try it yourself
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 BB and B′B' generate the same lattice when…

  1. they have the same first vector
  2. B′=BUB' = BU with UU an integer matrix of determinant ±1\pm 1
  3. they are both orthogonal
  4. det⁡B=det⁡B′\det B = \det B' only

Babai's rounding solves CVP well when the basis is…

  1. long and nearly parallel
  2. short and nearly orthogonal
  3. random
  4. triangular with huge entries

Why are lattice problems interesting for post-quantum cryptography?

  1. they are easy for quantum computers
  2. no efficient quantum algorithm is known for them
  3. they use small primes
  4. they replace hash functions