← LibraryTesting Quadratic Residuosity: Prime ModulusEngineering · MathematicsLesson 141/385← PrevNext →
ArticlePublished 7 Aug 20263 min readBy Kevin Jogin

Engineering  /  Mathematics  — Quadratic Residues

Testing Quadratic Residuosity: Prime Modulus

Deciding quadratic residuosity modulo a prime, and why the problem is easy in this case.

Page KV-MATH-0413Reading time 3 minReviewed 2026-08-07Author Kevin Jogin

Executive summary

Modulo a prime, quadratic residuosity is decided in polynomial time by Euler's criterion or, faster, by the Legendre symbol algorithm.

The problem is easy precisely because the modulus has no hidden structure, which is what changes when the modulus is composite.

Learning objectives

  1. State the decision procedure for a prime modulus.
  2. Compare the available methods.
  3. Explain why primality makes the problem tractable.

01The decision procedure

Two methods decide the question, and both are polynomial time.

Algorithm

Decide residuosity mod a prime

Inputprime p, integer a
Outputresidue or non-residue
  1. Given odd prime p and integer a with p not dividing a.
  2. Compute the Legendre symbol (a|p) by the Euclid-style algorithm.
  3. Return residue if the symbol is 1, non-residue if −1.
Cost  O(len(p)²) bit operations

The alternative, Euler's criterion, computes a^{(p−1)/2} mod p and reads off the result. It is a cubic-time method giving the same answer, and it is preferred only where fixed control flow matters.

02Why primality makes it easy

Modulo a prime, the units form a cyclic group and the residues are exactly the even powers of a generator — a subgroup of index 2. The quotient by that subgroup is the two-element group, and the quotient map is the Legendre symbol, which is efficiently computable.

  • Prime modulus

    One subgroup of index 2, and the quotient map is computable. Residuosity is decided directly.

  • Composite modulus

    Several subgroups of index 2. The Jacobi symbol computes one quotient; the residues are a strictly smaller set, and identifying them requires the factorisation.

03Consequences

Prime versus composite
TaskPrime modulusComposite modulus
Decide residuosityPolynomial timeBelieved hard without the factorisation
Compute a square rootPolynomial time (randomised)Equivalent to factoring
Count square rootsExactly 24 for pq; 2^k in general

Every row changes in the same direction, and the reason is the same in each case: the composite modulus hides a decomposition that the prime modulus does not have. Knowing the decomposition restores all three to the easy column.

This is the structural fact that Goldwasser–Micali encryption and several related constructions are built on.

04Frequently asked questions

Is there any advantage to Euler's criterion here?

Constant-time behaviour. The Legendre algorithm branches on the operand values, so where the argument is secret the fixed exponentiation ladder is preferable despite being slower.

Does deciding residuosity give the square root?

No. The Legendre symbol answers yes or no without producing a witness. Extracting the root is a separate computation, and for p ≡ 1 (mod 4) it requires a randomised algorithm.

What about prime power moduli?

Residuosity modulo p^e for odd p reduces to residuosity modulo p, because the unit group is cyclic in both cases. The root is then lifted by Hensel's method.

Sources and method

Structural reference: Victor Shoup, A Computational Introduction to Number Theory and Algebra, Version 1, Cambridge University Press, 2005 — book pages 291.

This page carries the durable method layer only: definitions, constructions, algorithms, complexity results and selection criteria, authored originally for KEVOS. No text is transcribed or paraphrased from the source, and no numeric tables or benchmark data are reproduced — these are routed to live authoritative sources instead.

Author: Kevin Jogin. Last reviewed 2026-08-07.

Continue learning

Computing the Jacobi SymbolArticle · MathematicsNEXT LESSON →Testing Quadratic Residuosity: Prime Power and Composite ModulusArticle · MathematicsThe Jacobi SymbolArticle · MathematicsComputing Modular Square Roots: Prime ModulusArticle · Mathematics