Generalized Shanks Algorithm for Quadratic Extension Field

This section explains how to compute square roots in the quadratic extension field Fp2\mathbb{F}_{p^2}, particularly when the base field Fp\mathbb{F}_p satisfies p3(mod4)p \equiv 3 \pmod 4. The method is based on Algorithm 9 from ePrint 2012/685.


Goal

Given aFp2a \in \mathbb{F}_{p^2}, find xFp2x \in \mathbb{F}_{p^2} such that:

x2=ax^2 = a

where x=x0+x1ix = x_0 + x_1 \cdot i and i2=1i^2 = -1.


Algorithm

The algorithm proceeds as follows:

  1. Compute a1=a(p3)/4a_1 = a^{(p - 3)/4}

  2. Compute α=a12a=a(p1)/2\alpha = a_1^2 \cdot a = a^{(p-1)/2}

  3. Check whether αp+1=a(p21)/2=1\alpha^{p + 1} = a^{(p^2-1)/2} = -1. If so, then aa is a non-residue, and no square root exists.

  4. Compute β=a1a=a(p+1)/4\beta = a_1 \cdot a = a^{(p+1)/4}

  5. If α=1\alpha = -1, return x=βi=a(p+1)/4ix = \beta \cdot i = a^{(p+1)/4} \cdot i

  6. Otherwise:

    • Compute b=(α+1)(p1)/2=(1+a(p1)/2)(p1)/2b = (\alpha + 1)^{(p - 1)/2} = \left(1 + a^{(p-1)/2} \right)^{(p - 1)/2}

    • Return x=bβ=(1+a(p1)/2)(p1)/2a(p+1)/4x = b \cdot \beta = \left( 1 + a^{(p-1)/2} \right)^{(p - 1)/2} \cdot a^{(p+1)/4}


Intuition Behind the Algorithm

To compute a square root of aFp2a \in \mathbb{F}_{p^2}, we can find an element bFp2b \in \mathbb{F}_{p^2} and an odd integer ss such that:

b2as=1b^2 \cdot a^s = 1

In this case, a square root of aa is given by:

x=ba(s+1)/2x = b \cdot a^{(s + 1)/2}

because:

x2=(ba(s+1)/2)2=b2as+1=(b2as)a=ax^2 = \left( b \cdot a^{(s+1)/2} \right)^2 = b^2 \cdot a^{s+1} = (b^2 \cdot a^s) \cdot a = a

To find such bb and ss, we set:

  • s=p12s = \frac{p - 1}{2}

  • b=(1+a(p1)/2)(p1)/2b = \left( 1 + a^{(p-1)/2} \right)^{(p - 1)/2}

Case 1: b0b \ne 0

We can verify:

b2as=(1+a(p1)/2)(p1)a(p1)/2=(1+a(p1)/2)p(1+a(p1)/2)1a(p1)/2=(1+ap(p1)/2)(1+a(p1)/2)1a(p1)/2=(a(p1)/2+1)(1+a(p1)/2)1=1\begin{aligned} b^2 \cdot a^s &= \left(1 + a^{(p-1)/2}\right)^{(p-1)} \cdot a^{(p-1)/2} \\ &= \left(1 + a^{(p-1)/2}\right)^p \cdot \left(1 + a^{(p-1)/2}\right)^{-1} \cdot a^{(p-1)/2} \\ &= \left(1 + a^{p(p-1)/2}\right) \cdot \left(1 + a^{(p-1)/2}\right)^{-1} \cdot a^{(p-1)/2} \\ &= \left(a^{(p-1)/2} + 1\right) \cdot \left(1 + a^{(p-1)/2}\right)^{-1} = 1 \end{aligned}

So, x=ba(p+1)/4x = b \cdot a^{(p+1)/4} is a valid square root of aa.

Explanations

This step works due to the properties of the Frobenius endomorphism, which states that:

(1+a(p1)/2)p=1+ap(p1)/2\left(1 + a^{(p-1)/2}\right)^p = 1 + a^{p \cdot (p-1)/2}

since exponentiation by pp acts as an automorphism over Fp2\mathbb{F}_{p^2}, and in particular, fixes elements in the base field Fp\mathbb{F}_p.

In addition, every nonzero element aFp2a \in \mathbb{F}_{p^2} satisfies:

ap21=1a^{p^2 - 1} = 1

because the multiplicative group Fp2\mathbb{F}_{p^2}^* has order p21p^2 - 1. This ensures that all powers used in the algorithm, including a(p21)/2a^{(p^2 - 1)/2}, are well-defined and lie within the group.

Case 2: b=0b = 0

Then, by definition of bb, we must have:

1+a(p1)/2=0a(p1)/2=11 + a^{(p-1)/2} = 0 \quad \Rightarrow \quad a^{(p-1)/2} = -1

In this case, define x=a(p+1)/4ix = a^{(p+1)/4} \cdot i, where i2=1i^2 = -1. Then:

x2=(a(p+1)/4i)2=a(p+1)/2i2=a(p+1)/2(1)=aa(p1)/2(1)=a(1)(1)=a\begin{aligned} x^2 &= \left( a^{(p+1)/4} \cdot i \right)^2 = a^{(p+1)/2} \cdot i^2 \\ &= a^{(p+1)/2} \cdot (-1) = a \cdot a^{(p-1)/2} \cdot (-1) = a \cdot (-1) \cdot (-1) = a \end{aligned}

Thus, xx is again a valid square root of aa.


Final Formula

We can summarize the square root of aFp2a \in \mathbb{F}_{p^2}, for p3(mod4)p \equiv 3 \pmod 4, as:

x={a(p+1)/4iif a(p1)/2=1(1+a(p1)/2)(p1)/2a(p+1)/4otherwisex = \begin{cases} a^{(p+1)/4} \cdot i & \text{if } a^{(p-1)/2} = -1 \\ \left( 1 + a^{(p-1)/2} \right)^{(p - 1)/2} \cdot a^{(p+1)/4} & \text{otherwise} \end{cases}

This elegant formula generalizes the classic Shanks algorithm from Fp\mathbb{F}_p to quadratic extensions Fp2\mathbb{F}_{p^2}, and avoids iterative procedures entirely.

Written by ryan Kim from A41

Last updated