Modular Square Root
Presentation: https://youtu.be/wNogfbvrX-s
Introduction
Suppose we want to find the square root , where is an odd prime. That is, we seek some such that the square of is congruent to modulo .
If such an exists, we say that is a quadratic residue modulo ; otherwise, it is a quadratic nonresidue. The trivial case is typically excluded when enumerating quadratic residues, since has a unique square root (itself), and we are often more interested in the structure of the nonzero squares in .
For example, when , the quadratic residues modulo 7 are:
Thus, the quadratic residues modulo 7 are , and the quadratic nonresidues are .
Computing square roots modulo a prime or composite number is a fundamental operation in number theory with important applications in cryptography and computational mathematics. One example is when constructing elliptic curves or decompressing elliptic curve points from compressed form, one must compute square roots modulo a prime field to recover the y-coordinate from the x-coordinate.
To efficiently determine whether a square root exists and to compute it when it does, number theorists use symbolic tools such as the Legendre symbol, Jacobi symbol, and Euler’s criterion, which we now briefly introduce.
Legendre Symbol
The Legendre symbol is a notation that encodes whether is a quadratic residue modulo an odd prime . It is defined as:
The Legendre symbol is a multiplicative function, and is a key component in quadratic reciprocity and in algorithms like the Tonelli–Shanks square root algorithm.
Euler’s Criterion
Euler’s criterion provides a direct method to evaluate the Legendre symbol using modular exponentiation:
This gives a simple way to test whether is a square modulo :
If , then is a quadratic residue.
If , then is a nonresidue.
Generalization to Extension Fields
Euler’s criterion generalizes naturally to extension fields , where , as follows:
That is, an element is a quadratic residue if and only if:
Jacobi Symbol
The Jacobi symbol is a generalization of the Legendre symbol to odd composite moduli , where is the product of odd primes. It is defined as:
Note that, unlike the Legendre symbol, the Jacobi symbol does not determine whether is a square modulo when is composite. For example, it is possible that even though is not a square mod . Nonetheless, the Jacobi symbol is widely used in square root algorithms in composite fields.
Square Root Algorithm Branch

The diagram above is taken from https://eprint.iacr.org/2012/685.pdf and illustrates how different square root algorithms can be selected based on the modulus and the degree of the extension field. In the following subsections, we introduce several of these algorithms in more detail.
Last updated