The Handbook of Applied Cryptography states Algorithm 3.39 for solving $x^2\equiv a\pmod p$ (for prime $p\ge5$ and $\left({a\over p}\right)=+1$ ):
- Choose random $b\in\mathbb Z_p$ until $b^2-4a$ is a quadratic non-residue modulo $p$, i.e., $\left({b^2-4a\over p}\right)=-1$ .
- Let $f$ be the polynomial $x^2−bx+a$ in $\mathbb Z_p[x]$ .
- Compute $r=x^{(p+1)/2}\bmod f$ using Algorithm 2.227 (Note: $r$ will be an integer).
- Return $(r,−r)$ .
How can we prove the correctness of this algorithm?
Note: $\left({a\over p}\right)$ is the Legendre symbol; one of several ways to compute it is as $a^{(p-1)/2}\bmod p$ with result $p-1$ replaced by $-1$.
Note: Here is context and a worked-out example.