Quadratic Residues

Let aZn. We say a is a quadratic residue if there exists some x such that x2=a. Otherwise a is a quadratic nonresidue.

Efficiently distinguishing a quadratic residue from a nonresidue modulo N=pq for primes p,q is an open problem. This is exploited by several cryptosystems, such as Goldwassser-Micali encryption, or Cocks identity-based encryption. More general variants of this problem underlie other cryptosystems such as Paillier encryption.

Let p be an odd prime, as the case p=2 is trivial. Let g be a generator of Zp. Any aZp can be written as gk for some k[0..p2].

Say k is even. Write k=2m. Then (gm)2=a, so a is a quadratic residue. Exactly half of [0..p2] is even (since p is odd), hence at least half of the elements of Zp are quadratic residues.

Suppose we have b2=a. Then (b)2=a as well, and since bb (since p>2) every quadratic residue has at least two square roots (in fact, we know from studying polynomials there can be at most two), thus at most half the elements of Zp are quadratic residues. (Otherwise there are more square roots than elements!)

Thus exactly half of Zp are quadratic residues, and they are the even powers of g.

Given a=gk, consider the effect of exponentiating by (p1)/2. If k is odd, say k=2m+1, we get

a(p1)/2=g(2m+1)(p1)/2=g(p1)mg(p1)/2=g(p1)/2

The square of g(p1)/2 is gp1=1, so g(p1)/2 is 1 or 1. But g has order p1 (g is a generator) thus we must have g(p1)/2=1.

If k is even, say k=2m, then a(p1)/2=g(p1)m=1.

In other words, we have proved Euler’s Criterion, which states a is a quadratic residue if and only if a(p1)/2=1, and a is a quadratic nonresidue if and only if a(p1)/2=1.

Example: We have 1 is a quadratic residue in Zp if and only if p=1(mod4).

The Legendre Symbol

We define the Legendre symbol for odd primes p and integers a by

(ap)=a(p1)/2.

The symbol can also be written as (a|p).

Thus:

  • (ap)=1 if a is a quadratic residue of p

  • (ap)=1 if a is a quadratic nonresidue of p

  • (ap)=0 if a=0 modulo p

For any integer b

(ap)(bp)=(abp)

and for any r coprime to p

(ar2p)=(ap)

Ben Lynn blynn@cs.stanford.edu 💡