Square Roots in Finite Fields

In a field, x + x = 0 for all x iff the field is of characteristic 2. Among finite fields only GF(2n) are like this. In any field we consider how many square roots of some value there are. But first when do squares of distinct values collide? Suppose that p2 = q2.
p2 − q2 = 0
(p + q)(p − q) = 0
but fields have no zero divisors and thus: p = q or p = −q. It is thus impossible for three distinct values to have the same square. If characteristic is not 2 and p2 = x and p≠0 then (−p) is distinct from p and (−p)2 = x and thus x has just two distinct square roots. In a finite field with characteristic > 2 exactly half of the non zero elements have square roots simply because those that do have two. Fortunately such fields have an odd number of elements and an even number of non zero elements.

For even characteristics (just 2) p = −p and each element has at most one square root and thus every element has exactly one root.

For sqrt code in a finite field GF(p), see this in this context.