2.3 LWE & Ring-LWE
Learning With Errors — a deliberately noisy system of equations that is easy to construct but nearly impossible to solve.
Suppose you want to hide a secret number. One approach: multiply your secret by random numbers and give out the products. That’s essentially what public-key cryptography has done for decades. The problem is that if the math is too clean, a quantum computer can unravel it (that’s Shor’s algorithm).
Learning With Errors (LWE), introduced by Oded Regev in 2005 (for which he received the 2018 Gödel Prize), takes a different approach: deliberately introduce random noise into the equations. The equations become just slightly wrong — a small random error is added to each one. This tiny perturbation, it turns out, makes the whole system hard to solve with the best classical and quantum methods known today when parameters are chosen carefully. And yet, someone who knows the secret can still extract information from the noisy equations, because they know which direction to look.
Intuition
Imagine guessing someone’s bank balance by asking them, where every answer is off by a small random amount, like $1 or $2. Ask 100 times and the average gives you the exact number.
Learning With Errors (LWE) is a harder version of this game. The secret is a vector, each answer is a random linear equation in it plus a small error, and all arithmetic wraps around modulo q, so averaging no longer helps. Without the errors, Gaussian elimination would recover the secret from a handful of equations. With them, no efficient algorithm is known, classical or quantum, which is why LWE is used for post-quantum encryption.
The LWE Distribution
The formal definition of LWE pins down every parameter: the dimension, the modulus, and the error distribution. All three must be chosen together — they determine both security and correctness.
Definition 15 — The LWE Distribution
Fix parameters: dimension , modulus , and an error distribution over (typically a discrete Gaussian with standard deviation ).
For a secret , the LWE distribution is the distribution over pairs obtained by:
1. Sample uniformly at random.
2. Sample error .
3. Output the pair .
Equivalently, in matrix form: given samples, the distribution produces where is a random matrix, is the fixed secret, and is a vector of independent errors from .
The parameters fully specify the hardness of the LWE problem: larger and smaller increase security; larger increases correctness margin.
Decision vs Search LWE and the Equivalence
LWE has two natural formulations — one asks you to find the secret, the other asks you to detect whether a given sample is an LWE sample at all. Remarkably, these two problems are computationally equivalent.
Search-LWE
Given polynomially many samples , find the secret .
This is directly analogous to solving a noisy linear system. Without noise, it’s trivial via Gaussian elimination. With noise — believed infeasible in high dimension, even for quantum computers.
Decision-LWE
Given pairs , decide: are they from for some hidden , or are they uniformly random in ?
Security of encryption requires Decision-LWE to be hard: if an attacker can distinguish LWE ciphertexts from random strings, they can recover information about the plaintext.
Theorem — Search-LWE and Decision-LWE Are Equivalent
For prime modulus and any error distribution with polynomially bounded support:
If there exists a polynomial-time algorithm solving Decision-LWE, then there exists a polynomial-time algorithm solving Search-LWE (Regev 2005, refined by Micciancio and Mol 2011).
The reduction works by a hybrid argument: given a Decision-LWE oracle, one can recover each coordinate of independently by querying samples where one row of is shifted by a test vector. The decision oracle detects whether this shift is consistent with the current guess for .
Consequence: to prove a scheme is semantically secure (indistinguishable under chosen-plaintext attack), one assumes Decision-LWE is hard. That is the stronger assumption: Decision-hard trivially implies Search-hard (anyone who can recover can also tell LWE samples from random). The equivalence says the extra strength costs nothing, because Decision-LWE is hard whenever Search-LWE is.
Why LWE Is Hard: The Reduction from SVP
The key result is Regev’s 2005 theorem: if you can solve LWE, you can solve the hardest possible SVP instances using a quantum computer. This is a “worst-case to average-case” reduction. It means that LWE is not just a random hard problem someone cooked up — its hardness is tied, provably, to the hardness of lattice problems that have been studied for over a century.
In practical terms: breaking Kyber or Dilithium implies you can find the shortest vector in arbitrary high-dimensional lattices efficiently using a quantum computer. Since we believe that’s impossible, we believe LWE is hard.
Module-LWE (MLWE) — Used in Kyber
The version of LWE used in Kyber (ML-KEM, FIPS 203) is neither plain LWE nor Ring-LWE but a middle ground called Module-LWE. It combines the efficiency of Ring-LWE with a stronger hardness assumption, and adds a tunable security parameter.
Definition — Module-LWE (MLWE)
Let be the NTRU-style polynomial ring. Fix a module rank .
The Module-LWE distribution over is defined as follows: sample secret (a vector of ring elements with small coefficients), sample uniformly, sample error over , and output .
In matrix form: the public key matrix is and the LWE relation is for vectors in . Each ring element encodes scalar LWE equations, so the full system has equations in unknowns.
Module rank controls security:
— : ML-KEM-512 (~128-bit security, fastest)
— : ML-KEM-768 (~192-bit security, recommended)
— : ML-KEM-1024 (~256-bit security, highest)
Hardness: MLWE with rank reduces to worst-case SVP on module lattices — lattices with rank- module structure over . As , MLWE approaches plain LWE (strongest hardness); at it is Ring-LWE (most efficient).
LWE Parameter Selection for 128-Bit Security
Choosing LWE parameters is a precise engineering task, not a guess. The standard methodology uses the Lattice Estimator tool (Albrecht et al.) to model the cost of all known attacks — primal, dual, and hybrid — and find the parameter set that minimizes key/ciphertext sizes while keeping all attack costs above the target security level.
Parameter Selection for 128-Bit Classical Security
The three parameters must satisfy several constraints simultaneously:
Dimension : Must be large enough that the best BKZ attack on the primal lattice costs operations. For Kyber with , the effective LWE dimension is . The BKZ block size needed to break this (round-3 Kyber specification) is , with Core-SVP cost classically. For comparison, Kyber-512 needs () and Kyber-1024 (). Core-SVP counts only a single SVP call, so it is a conservative lower estimate: Kyber-512’s is still argued to meet NIST Level 1 once the full attack cost is counted.
Modulus : Must be large enough that the message encoding does not get overwhelmed by the accumulated error after decryption. For Kyber: (a prime chosen so that for efficient NTT).
Error parameter : In Kyber, the error distribution is a centered binomial distribution with or , giving . This is much smaller than the Gaussian used in theoretical constructions, optimized for efficiency.
Security vs correctness tradeoff: Larger makes the problem harder (better security) but increases decryption failure probability. The failure probability must be kept below to prevent attacks that exploit decryption failures. This pins in a narrow window.
Quantum security factor: Parameters are chosen with a security margin: classical Core-SVP security ~182 bits, quantum ~165 bits for ML-KEM-768 (a Level 3 parameter set). Both are far above the 128-bit baseline, providing a buffer against algorithmic improvements.
LWE Parameters: The Three Knobs
Three numbers control the security and performance of any LWE-based scheme. Getting them right is the difference between a secure system and one that can be broken in hours.
Definition 16 — LWE Parameter Set (n, q, σ)
Dimension n — the number of unknowns. Bigger means more security (exponentially harder to solve) but larger keys and slower operations. Typical values: to .
Modulus q — all arithmetic is done mod . Must be large enough that the signal (the encrypted message) is not overwhelmed by noise, but not so large that security decreases. Often a prime near to .
Noise width σ — the standard deviation of the error distribution. Smaller makes decryption more accurate; larger makes the problem harder. The ratio is the sweet spot for most schemes.
LWE-Based Encryption: The Basic Construction
Here is the simplest possible LWE encryption scheme, due to Regev. It encrypts one bit at a time and illustrates the core idea behind all LWE-based schemes.
Construction 1 — Regev Encryption
Key generation: Sample a secret . Sample a matrix of random LWE rows and publish as the public key.
Encrypt a bit : Choose a random subset of the published LWE rows, sum them up, and add to the right side. This hides the bit in a random-looking sum.
Decrypt: Compute . The errors cancel approximately, leaving something close to 0 (if ) or close to (if ). Round to recover the bit.
Ring-LWE: The Same Idea, Much More Efficient
Plain LWE has a problem: the public key is a matrix with entries — that’s megabytes of data for cryptographic parameters. Ring-LWE fixes this by doing all the arithmetic inside a polynomial ring instead of plain integers. The key insight: a single ring element encodes the same information as an entire LWE matrix, thanks to the structure of polynomial multiplication.
Definition 17 — Ring-LWE
Replace with the polynomial ring — polynomials of degree less than , with coefficients reduced mod , and the polynomial itself reduced mod .
A Ring-LWE sample is a pair where multiplication is polynomial multiplication in . One ring element encodes scalar LWE equations simultaneously. Key sizes drop from to .
The tradeoff: Ring-LWE operates on ideal lattices (lattices with ring structure), which have more algebraic symmetry than general lattices. Theoretically, this could be exploited. In practice, no attack has broken Ring-LWE at standard parameters, but it’s considered a slight weakening of the hardness assumption compared to plain LWE.
Module-LWE: The Best of Both Worlds
A small worked example of both variants, with the matrix that one polynomial replaces, is in 6.7 Ring-LWE and Module-LWE.
Module-LWE is the version used by Kyber and Dilithium. It’s Ring-LWE but over a module of rank — think of it as a matrix of ring elements instead of a single ring element. This lets you tune security by adjusting without changing the ring structure.
LWE (plain)
Works over integers. Keys: bits. Strongest hardness assumption (general lattices). Slow and large — mainly used for theoretical constructions and FHE, not practical key exchange.
Ring-LWE
Works over one polynomial ring element. Keys: bits. Fast (NTT multiplication). Slight algebraic structure concern. Used in early PQC schemes like NewHope.
Module-LWE (Kyber)
Works over a matrix of ring elements. Keys: bits. Tunable security via . Stronger hardness than Ring-LWE. The NIST-selected standard for key encapsulation.
The NTT: Why Ring-LWE Is Fast
Multiplying two degree- polynomials naively takes multiplications. Ring-LWE schemes would be impractically slow at large without a trick: the Number Theoretic Transform (NTT). The NTT is like a Fourier transform but for integers modulo a prime. It converts a polynomial into its “frequency domain” in operations. Multiplication in the NTT domain is element-wise — just multiply corresponding frequencies — then convert back. Kyber uses the NTT with and , chosen so that the NTT is especially efficient. This is why Kyber key exchange is faster than X25519 despite using larger objects.
Check Your Understanding
Q1. Without the error term, b = As mod q could be solved with Gaussian elimination. What does adding a small random error e change?
Q2. What happens if a designer makes the error σ too large relative to q?
Q3. In Regev encryption, why can the key holder decrypt while an eavesdropper cannot?
Q4. Why does Kyber use Module-LWE instead of plain LWE or Ring-LWE?