Given that p is congruent to 3 mod 4, we can compute the square root of a mod p as the (p+1)/4'th power of a.
As (p+1)/4 is an even number, it will have the same result for a and for (-a). Only one of these two numbers actually has a square root however, so we test at the end by squaring and comparing to the input. Also because (p+1)/4 is an even number, the computed square root is itself always a square (a ** ((p+1)/4) is the square of a ** ((p+1)/8)).
The binary representation of (p + 1)/4 has 3 blocks of 1s, with lengths in { 2, 22, 223 }. Use an addition chain to calculate 2^n - 1 for each block: 1, [2], 3, 6, 9, 11, [22], 44, 88, 176, 220, [223]
Definition at line 37 of file field_impl.h.