← Back to section · Foundations of Cryptography

Quadratic Residues and the Legendre Symbol: A Licence for Square Roots

Modulo a prime, not every number has a square root. This article explains the decision problem for quadratic residues, Euler's criterion, the computational rules of the Legendre symbol and quadratic reciprocity, and where this theory sits in proof systems and pseudorandom generation.

Published 22 November 2026 · 6 min read · PQ Frontier

Quadratic Residues and the Legendre Symbol: A Licence for Square Roots
AI-generated site artwork
Video explainer · Number theory: primes and modular arithmetic

Over the reals the boundary is crisp: positive numbers have square roots, negative numbers do not. Modulo a prime pp the question becomes subtler: given aa, does there exist xx with x2≡a(modp)x^2 \equiv a \pmod p? If yes, aa is a quadratic residue; if no, a non-residue. This seemingly pure decision problem is bound up with square-root extraction, pseudorandom generation and even zero-knowledge proofs — one of the deepest points where number theory enters cryptography.

A half-and-half split

First, the scale of things: for an odd prime pp, the squares 12,22,…,(p−1)21^2, 2^2, \dots, (p-1)^2 take only (p−1)/2(p-1)/2 distinct values modulo pp, because x2≡(p−x)2x^2 \equiv (p-x)^2 and the values coincide in pairs. So exactly half of the nonzero elements are residues and half are non-residues, and nothing on the surface marks one half as more “special” — residues and non-residues interleave uniformly through the multiplicative group. Modulo 7, for example, the residues are 1, 2, 4 (since 32=9≡23^2 = 9 \equiv 2, 22=42^2 = 4, 12=11^2 = 1) and the non-residues are 3, 5, 6. Deciding which half a given element belongs to requires tools. One common misconception is worth clearing up: the residues are closed under multiplication (the product of two residues is a residue, a residue times a non-residue is a non-residue, and the product of two non-residues lands back among the residues) — a multiplication table exactly isomorphic to that of signs. This is the real reason the Legendre symbol takes values ±1: it is not an arbitrary notation but the natural compression of this multiplication structure into a single symbol. The structure came first and the notation second, which is why all the computational rules that follow flow so smoothly.

Euler’s criterion and the Legendre symbol

Euler’s criterion supplies the first tool: for an odd prime pp and aa not divisible by pp, a(p−1)/2≡±1(modp)a^{(p-1)/2} \equiv \pm 1 \pmod p, with +1+1 exactly when aa is a quadratic residue. The Legendre symbol (ap)\left(\frac{a}{p}\right) is defined to be this ±1\pm 1 (and 0 when pp divides aa), turning the decision problem into a single modular exponentiation. The symbol also has excellent algebraic properties: it is multiplicative in the numerator, (abp)=(ap)(bp)\left(\frac{ab}{p}\right) = \left(\frac{a}{p}\right)\left(\frac{b}{p}\right), so it suffices to evaluate it at prime numerators. Two supplementary laws give formulas for (−1p)\left(\frac{-1}{p}\right) and (2p)\left(\frac{2}{p}\right), and Gauss’s quadratic reciprocity law is the crown jewel: for distinct odd primes p,qp, q, the symbols (pq)\left(\frac{p}{q}\right) and (qp)\left(\frac{q}{p}\right) differ at most by a sign determined by p,q mod 4p, q \bmod 4. This law lets symbol computation “flip and shrink” repeatedly, exactly like the Euclidean algorithm, reducing a decision modulo a large prime to small cases — feasible by hand and fast in code.

A small example shows reciprocity at work: decide whether 5 is a quadratic residue modulo 11. One could consult a table of squares, but reciprocity offers a programmatic path — multiplicativity reduces everything to prime numerators, and for (511)\left(\frac{5}{11}\right) the two primes are congruent to 1 and 3 modulo 4, so the reciprocity sign rule gives (511)=(115)=(15)=1\left(\frac{5}{11}\right) = \left(\frac{11}{5}\right) = \left(\frac{1}{5}\right) = 1; hence 5 is a residue modulo 11 (indeed 42=16≡54^2 = 16 \equiv 5). For large primes the flipping repeats, each step replacing the larger modulus by a smaller remainder, in lockstep with the Euclidean algorithm — the same motion whether done in a few steps by hand or in microseconds by a machine.

The Jacobi symbol: a bridge toward composite moduli

Generalising the Legendre symbol one step gives the Jacobi symbol: for an odd composite denominator n=p1p2⋯pkn = p_1 p_2 \cdots p_k, the Jacobi symbol (an)\left(\frac{a}{n}\right) is defined as the product of the Legendre symbols (api)\left(\frac{a}{p_i}\right). Its virtue is that reciprocity continues to hold for it, so it can be computed without knowing the factorisation of nn, flipping and shrinking exactly like the Euclidean algorithm. But its semantics are one notch weaker than the Legendre symbol’s: a Jacobi symbol of −1-1 guarantees that aa is a non-residue, while +1+1 leaves both possibilities open — aa may be a residue, or a non-residue in disguise, since the symbols at two prime factors can both be −1-1 and still multiply to +1+1. The bridge is therefore one-way: it yields a computable necessary condition modulo composites while deliberately leaving an ambiguity that cannot be crossed. That ambiguity is not a defect of the theory but the location of the resource: the security of Goldwasser–Micali encryption rests on its irremovability, and any algorithm that removed it would break the scheme on the spot.

A glimpse of root extraction: Tonelli–Shanks

Return to extracting roots modulo a prime. When p≡3(mod4)p \equiv 3 \pmod 4 the formula is simplest: a(p+1)/4a^{(p+1)/4} is a square root of aa, done in one exponentiation. The general case uses the Tonelli–Shanks algorithm: write p−1p - 1 as 2s⋅q2^s \cdot q, take a known quadratic non-residue as an adjusting element, and correct a candidate root into place bit by bit — the process reads like solving for the root one binary digit at a time. It runs in polynomial time but needs a non-residue to start; a random guess hits one in two tries on average (half of all elements are non-residues), which circles back to the decision capability of Euler’s criterion. Decision, extraction and reciprocity thus mesh like gears: the decision tool supplies raw material for the extraction algorithm, and the existence of extraction in turn calibrates where the decision problem sits in difficulty. Modulo a composite, every gear of this machine is jammed by the hardness of factoring, and the whole theory is promoted from a computational toolkit into a source of security assumptions.

Easy to decide, hard to extract: the gap is the resource

Note carefully that deciding and extracting are entirely different difficulty classes. Square roots modulo a prime have polynomial-time algorithms (Tonelli–Shanks; when p≡3(mod4)p \equiv 3 \pmod 4 a single exponentiation does it), so deciding is easy there too. But switch the modulus to a composite n=pqn = pq and the picture flips: extracting square roots modulo nn without knowing the factorisation is as hard as factoring nn itself — the foundation on which the Rabin cryptosystem reduces its security directly to factoring. Deciding residuosity modulo a composite is likewise hard (the Jacobi symbol is computable but cannot distinguish residues from half of the non-residues), and Goldwasser–Micali encryption rests on exactly this “quadratic residuosity assumption”. The Fiat–Shamir identification protocol has a prover repeatedly exhibit square roots modulo nn to prove knowledge of the factorisation — the verifier’s inability to extract roots unaided is the premise of the whole scheme, and after the Fiat–Shamir transform removed the interaction it became one of the design paradigms for signature schemes. The Blum Blum Shub pseudorandom generator, which repeatedly squares and extracts the lowest bit, also reduces its security to problems of this family. Quadratic reciprocity further appears in zero-knowledge proofs and in the constant design of certain signature schemes. A classical theory from Gauss’s Disquisitiones Arithmeticae is still supplying modern cryptography with raw material for one-wayness.

Tags: number theoryquadratic residuesLegendre symbolquadratic reciprocity