Optimized Inversion Algorithm

Presentation: https://www.youtube.com/watch?v=QNxgKYcc-A0

Finite-field inversion can be optimized when the extension degree is small and the field's algebraic structure is well-defined. Specifically, extension fields of degrees three and four enable inversion to be formulated in closed form, leveraging low-dimensional linear algebra and quadratic subextensions.

For the quadratic extension (Fp2\mathbb{F}_{p^2}), inversion admits a particularly simple closed form. Writing an element as x=x0+x1ux = x_0 + x_1 u, the inverse is obtained by first forming a base-field denominator x02ηx12x_0^2 - \eta x_1^2 and then multiplying its inverse by the conjugate x0x1ux_0 - x_1 u.

For the cubic extension (Fp3\mathbb{F}_{p^3}), multiplication by a fixed element defines an Fp\mathbb{F}_p -linear endomorphism of a three-dimensional vector space. Inversion can therefore be obtained by inverting this linear transformation, leading to explicit formulas involving determinants and adjugate matrices.

For the quartic extension (Fp4\mathbb{F}_{p^4}), the field admits a natural representation as a quadratic extension over Fp2\mathbb{F}_{p^2}. This tower structure enables inversion via conjugation with respect to the intermediate field, reducing the problem to the inversion of a single element in Fp2\mathbb{F}_{p^2}.

1. Inversion in Fp3\mathbb{F}_{p^3}

1.1 Field Definition

Let

Fp3=Fp[u]/(u3ξ),\mathbb{F}_{p^3} = \mathbb{F}_p[u] / (u^3 - \xi),

where ξFp\xi \in \mathbb{F}_p is fixed. Every element xFp3x \in \mathbb{F}_{p^3} is written uniquely as

x=x0+x1u+x2u2,x0,x1,x2Fp.x = x_0 + x_1 u + x_2 u^2, \qquad x_0, x_1, x_2 \in \mathbb{F}_p.

1.2 Multiplication as a Linear Operator

Multiplication by xx defines an Fp\mathbb{F}_p-linear map Lx:Fp3Fp3L_x : \mathbb{F}_{p^3} \to \mathbb{F}_{p^3} given by Lx(y)=xyL_x(y) = x y. With respect to the basis {1,u,u2}\{1, u, u^2\}, this map is represented by

Mx=(x0ξx2ξx1x1x0ξx2x2x1x0).M_x = \begin{pmatrix} x_0 & \xi x_2 & \xi x_1 \\ x_1 & x_0 & \xi x_2 \\ x_2 & x_1 & x_0 \end{pmatrix}.

1.3 Inversion via Linear Algebra

Assume x0x \neq 0. Then LxL_x is invertible and the inverse element satisfies x1=Lx1(1)x^{-1} = L_x^{-1}(1). By Cramer’s rulearrow-up-right,

Mx1=det(Mx)1adj(Mx),M_x^{-1} = \det(M_x)^{-1} \operatorname{adj}(M_x),

so the coordinates of x1x^{-1} are given by the first column of adj(Mx)\operatorname{adj}(M_x).

1.4 Explicit Inversion Formula

  1. t0,t1,t2t_0, t_1, t_2: The First Column of the Adjugate Matrix

  • t0=x02ξx1x2t_0 = x_0^2 - \xi x_1 x_2

    • This is the cofactor of the Mx[1,1]M_x[1, 1], where Mx[r,c]M_x[r, c] is the element at row rr and coloum cc.

    • It is calculated as the determinant of the 2×22 \times 2 matrix (x0ξx2x1x0)\begin{pmatrix} x_0 & \xi x_2 \\ x_1 & x_0 \end{pmatrix} remaining after crossing out the 1st row and 1st column.

  • t1=ξx22x0x1t_1 = \xi x_2^2 - x_0 x_1

    • This is the cofactor for the Mx[1,2]M_x[1, 2].

    • The sign ()(-) is already integrated into the simplified formula in the code.

  • t2=x12x0x2t_2 = x_1^2 - x_0 x_2

    • This is the cofactor for the Mx[1,3]M_x[1, 3].

These t0,t1,t2t_0, t_1, t_2 constitute the first column of the adjugate matrix adj(Mx)\text{adj}(M_x). In extension fields, the matrix has a circulant structure, meaning that knowing the first column is sufficient to determine the entire inverse.

  1. t3t_3: The Determinant

t3=x0t0+ξ(x2t1+x1t2)t_3 = x_0 t_0 + \xi (x_2 t_1 + x_1 t_2)
  • This is the Laplace expansionarrow-up-right along the first column of matrix MxM_x.

  • It performs Mx[1,1]t0+M[1,2]t1+M[1,3]t3M_x[1, 1] \cdot t_0 + M[1, 2] \cdot t_1 + M[1,3] \cdot t_3

  1. y=(y0,y1,y2)y = (y_0, y_1, y_2): The Final Inverse

(y0,y1,y2)=t31(t0,t1,t2)(y_0, y_1, y_2) = t_3^{-1} \cdot (t_0, t_1, t_2)

2. Inversion in the Quartic Extension Field

Direct inversion via a 4×44 \times 4 matrix is inefficient. Instead, Fp4\mathbb{F}_{p^4} is viewed as a quadratic extension over Fp2\mathbb{F}_{p^2}:

Fp  v2=ξ  Fp2  u2=v  Fp4.\mathbb{F}_p \;\xrightarrow{\, v^2 = \xi \,}\; \mathbb{F}_{p^2} \;\xrightarrow{\, u^2 = v \,}\; \mathbb{F}_{p^4}.

2.1 Tower Construction

Let Fp2=Fp[v]/(v2ξ)\mathbb{F}_{p^2} = \mathbb{F}_p[v]/(v^2 - \xi) and Fp4=Fp2[u]/(u2v)\mathbb{F}_{p^4} = \mathbb{F}_{p^2}[u]/(u^2 - v).

Every element xFp4x \in \mathbb{F}_{p^4} can be written as x=A+Bux = A + B u with A,BFp2A, B \in \mathbb{F}_{p^2}.

x=x0+x1u+x2u2+x3u3=(x0+x2u2)+(x1+x3u2)u=(x0+x2v)+(x1+x3v)u\begin{align*} x &= x_0 + x_1u + x_2u^2 + x_3u^3 \\ &= (x_0 + x_2u^2) + (x_1 + x_3u^2)u \\ &= (x_0 + x_2v) + (x_1 + x_3v)u \end{align*}

2.2 Quadratic Conjugation

Define the conjugate of xx over Fp2\mathbb{F}_{p^2} by xˉ=ABu\bar{x} = A - B u. This operation satisfies xxˉFp2x \bar{x} \in \mathbb{F}_{p^2}.

2.3 First Level of Rationalization (Removing uu)

Our goal is to find x1=1A+Bux^{-1} = \frac{1}{A+Bu}. To remove uu from the denominator, we multiply the top and bottom by the conjugate xˉ=ABu\bar{x} = A - Bu:

x1=1A+BuABuABu=ABuA2B2u2x^{-1} = \frac{1}{A+Bu} \cdot \frac{A-Bu}{A-Bu} = \frac{A-Bu}{A^2 - B^2u^2}

Since u2=vu^2 = v, the denominator becomes D=A2B2vD = A^2 - B^2v.

Now, uu has been eliminated from the denominator, leaving only vv.

2.4 Second Level of Rationalization (Removing vv)

Let's look at the new denominator DD. Since AA and BB contain vv, DD can be expanded into a linear form of vv: D=D0+D1vD = D_0 + D_1v. To remove vv, we multiply by its conjugate (D0D1v)(D_0 - D_1v):

x1=ABuD0+D1vD0D1vD0D1v=(ABu)(D0D1v)D02D12v2x^{-1} = \frac{A - Bu}{D_0 + D_1v} \cdot \frac{D_0 - D_1v}{D_0 - D_1v} = \frac{(A - Bu) \cdot (D_0 - D_1v)}{D_0^2 - D_1^2v^2}

Since v2=ξv^2 = \xi, the final denominator becomes N=D02D12ξN = D_0^2 - D_1^2\xi.

This value NN (the Norm) is now a pure scalar (BaseField), free of both uu and vv.

2.5 Inversion Formula

Assume x0x \neq 0. Then D0D \neq 0, and the inverse of xx is

x1=D1(ABu).x^{-1} = D^{-1} (A - B u).

Thus inversion in Fp4\mathbb{F}_{p^4} reduces to inversion in Fp2\mathbb{F}_{p^2}.

2.6 Inversion in the Quadratic Subfield

Writing D=D0+D1vD = D_0 + D_1 v with D0,D1FpD_0, D_1 \in \mathbb{F}_p, one has

D1=(D02ξD12)1(D0D1v).D^{-1} = (D_0^2 - \xi D_1^2)^{-1} (D_0 - D_1 v).

This completes the inversion algorithm using only base-field arithmetic.

3. Performance Comparison with the Itoh–Tsujii Algorithm

This section compares the specialized inversion methods for low-degree extension fields with the Itoh–Tsujii algorithm from the perspective of arithmetic cost. The comparison is expressed in terms of operations over the prime field Fp\mathbb{F}_p.

Throughout, it is assumed that:

  • Frobenius applications are free or negligible compared to multiplication,

  • squaring and multiplication in Fp\mathbb{F}_p are counted separately


3.1 Arithmetic Cost Summary

Field
Method
Square
Multiplication
Inversion
Structural Cost

Fp3\mathbb{F}_{p^3}

Matrix-based inversion

33

99

11

Linear algebra (determinant + adjugate)

Fp3\mathbb{F}_{p^3}

Itoh–Tsujii

33

12\approx 12

11

Extension-field multiplications

Fp4\mathbb{F}_{p^4}

Quadratic tower inversion

66

1212

11

Two successive quadratic reductions

Fp4\mathbb{F}_{p^4}

Itoh–Tsujii

8\approx 8

18\approx 18

11

Flat exponentiation in full extension

3.2 Interpretation

For both cubic and quartic extensions, the specialized inversion formulas reduce the number of base-field multiplications by avoiding full extension-field multiplication.

  • In the cubic case, inversion is obtained via explicit determinant and adjugate computation, keeping all arithmetic in Fp\mathbb{F}_p.

  • In the quartic case, inversion proceeds through a quadratic tower, so that all intermediate inversions occur in proper subfields.

In contrast, the Itoh–Tsujii algorithm operates uniformly on the full extension field Fpk\mathbb{F}_{p^k} and requires additional extension-field multiplications, which expand to a larger number of base-field operations.

3.3 Asymptotic Perspective

However, for small values of kk, the constant factors dominate:

  • Specialized methods achieve lower arithmetic cost by exploiting explicit low-degree structure.

  • Itoh–Tsujii trades higher constant factors for generality and uniformity across extension degrees.

As a result, for extension degrees k=3k = 3 and k=4k = 4, the specialized algorithms are typically preferred.

A. Possibility of Inversion over a Quadratic Tower

A.1 Setting

Consider an extension field of degree 2n2^n over the prime field Fp\mathbb{F}_p. Assume that the field admits a recursive quadratic tower representation of the form

Fp2n=Fp2n1[un1]/(un12ηn1),\mathbb{F}_{p^{2^n}} = \mathbb{F}_{p^{2^{n-1}}}[u_{n-1}] / (u_{n-1}^2 - \eta_{n-1}),

where ηn1Fp2n1\eta_{n-1} \in \mathbb{F}_{p^{2^{n-1}}} is a non-square.

A.2 Quadratic Reduction Step

At each level ii of the tower, an element of Fp2i+1\mathbb{F}_{p^{2^{i+1}}} can be written as x=x0+x1uix = x_0 + x_1 u_i with x0,x1Fp2ix_0, x_1 \in \mathbb{F}_{p^{2^i}}. The inverse of xx is computed by:

  • forming the denominator x02ηix12Fp2ix_0^2 - \eta_i x_1^2 \in \mathbb{F}_{p^{2^i}},

  • multiplying its inverse by the conjugate x0x1uix_0 - x_1 u_i.

This reduces inversion in Fp2i+1\mathbb{F}_{p^{2^{i+1}}} to a single inversion in Fp2i\mathbb{F}_{p^{2^i}}.

A.3 Recursive Structure

By recursively applying the quadratic reduction step, inversion in Fp2n\mathbb{F}_{p^{2^n}} is reduced along the tower

Fp2nFp2n1Fp2Fp.\mathbb{F}_{p^{2^n}} \rightarrow \mathbb{F}_{p^{2^{n-1}}} \rightarrow \cdots \rightarrow \mathbb{F}_{p^2} \rightarrow \mathbb{F}_p.

As a result, exactly one inversion in the base field Fp\mathbb{F}_p is required, together with a bounded number of multiplications and squarings in intermediate subfields.

A.4 Applicability Conditions

This approach is applicable if and only if:

  • the extension field is explicitly represented as a quadratic tower,

  • a suitable non-residue ηi\eta_i is available at each level of the tower.

If the field is instead given as a flat extension Fp[x]/(f(x))\mathbb{F}_p[x]/(f(x)) with degf=2n\deg f = 2^n, a compatible quadratic tower representation may not be immediately available and may require nontrivial basis transformations.

A.5 Limitations

Although quadratic tower inversion is structurally simple and implementation-friendly, it is not universally optimal. For large values of nn, the accumulated cost of intermediate multiplications may outweigh the benefits of avoiding extension-field exponentiation. Moreover, the existence of suitable non-residues is field-dependent and must be ensured by construction.

Written by Soowon Jeong of Fractalyze

Last updated