Primal LWE Attacks by Hand: Bai–Galbraith Embedding and Core-SVP Block Size
Construct the rescaled primal uSVP lattice, apply the Geometric Series Assumption, and reproduce ML-KEM’s exact BKZ block sizes in 25 lines of Python.
Prerequisite: Parameter Selection
When cryptographers say “ML-KEM-512 has Core-SVP cost at BKZ block size ,” where does actually come from? You do not need a 10,000-line SageMath library to understand parameter estimation: combining the Bai–Galbraith rescaled Kannan embedding with Schnorr's Geometric Series Assumption reproduces the headline block sizes from first principles.
Step 1: Build the rescaled Bai–Galbraith uSVP basis
Given LWE samples with , secret standard deviation , and error standard deviation , reduction algorithms minimize Euclidean length. If (for instance, binary/ternary secrets alongside wide Gaussian errors), rescale the secret coordinates by and set the Kannan homogenization weight to so every coordinate of the target vector has equal variance :
Multiply the row blocks by integer combination where : the resulting lattice vector is , with expected Euclidean length in dimension . Because is block-lower-triangular, its determinant is immediate:
In ML-KEM-768 (), both and come from the centered binomial distribution of variance , so , , , and !
Step 2: Write the Alkim–Ducas–Pöppelmann–Schwabe win condition
Naive intuition compares against the shortest full vector BKZ- produces, . In 2016, the NewHope authors (ADPS16) observed that BKZ recovers much earlier — during the very last SVP call on the trailing -dimensional projected block!
Under the Geometric Series Assumption (GSA), Gram–Schmidt norms decay geometrically across a BKZ- basis as where the root-Hermite factor satisfies:
Projected onto the last orthogonal directions, has expected length , while the start of that final -block (at index ) has Gram–Schmidt length . Recovery succeeds as soon as:
Step 3: Optimize sample count and compute Core-SVP bits
Notice that the attacker chooses how many LWE rows to include! Using too few samples leaves too small; using too many inflates dimension faster than grows. Scanning and converting the winning via BDGL16 classical sieving exponent (or quantum sieving ) yields:
| Instance | Optimal | Lattice dim | BKZ | Classical Core-SVP () | |||
|---|---|---|---|---|---|---|---|
| Toy LWE-128 | 128 | 3329 | 1.000 (η=2) | 136 | 265 | 40 | 11.7 bits |
| ML-KEM-512 | 512 | 3329 | 1.225 (η₁=3) | 488 | 1,001 | 406 | 118.6 bits |
| ML-KEM-768 | 768 | 3329 | 1.000 (η₁=2) | 664 | 1,433 | 624 | 182.2 bits |
| ML-KEM-1024 | 1024 | 3329 | 1.000 (η₁=2) | 872 | 1,897 | 871 | 254.3 bits |
Compare rows 2–4 with Table 3 of the Kyber specification: 406, 624, and 871 match the published primal-attack BKZ block sizes almost to the integer! (Note: in ML-KEM-512, for during KeyGen; full estimators refine asymmetric across KeyGen + ciphertext samples and simulate exact BKZ profiles beyond strict GSA.)
Run the 25-line Primal uSVP Estimator in Python
import math
def delta0(beta: int) -> float:
return (((math.pi * beta) ** (1.0 / beta)) * beta / (2.0 * math.pi * math.e)) ** (1.0 / (2.0 * (beta - 1)))
def estimate_primal_usvp(n: int, q: int, sigma_s: float, sigma_e: float) -> tuple[int, int, float]:
w = sigma_e / sigma_s
best_beta, best_m = 10_000, 0
for m in range(n // 2, 2 * n + 1, 8):
d = m + n + 1
log2_det_root = (m * math.log2(q) + n * math.log2(w) + math.log2(sigma_e)) / d
for beta in range(40, d):
lhs = 0.5 * math.log2(beta) + math.log2(sigma_e)
rhs = (2 * beta - d - 1) * math.log2(delta0(beta)) + log2_det_root
if lhs <= rhs:
if beta < best_beta:
best_beta, best_m = beta, m
break
return best_beta, best_m, round(0.292 * best_beta, 1)
for label, n, s_std, e_std in [
("ML-KEM-512", 512, math.sqrt(1.5), math.sqrt(1.5)),
("ML-KEM-768", 768, 1.0, 1.0),
("ML-KEM-1024", 1024, 1.0, 1.0),
]:
beta, m_opt, bits = estimate_primal_usvp(n, 3329, s_std, e_std)
print(f"{label:12s} -> beta={beta}, m*={m_opt}, Core-SVP={bits} bits")Next, see what happens to and when an attacker obtains side-channel leakage in Integrating Leaked Hints into LWE Lattices, or run real progressive BKZ tours in g6k-rs recipes.