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), inversion admits a particularly simple closed form. Writing an element as x=x0+x1u, the inverse is obtained by first forming a base-field denominator x02−ηx12 and then multiplying its inverse by the conjugate x0−x1u.
For the cubic extension (Fp3), multiplication by a fixed element defines an Fp -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), the field admits a natural representation as a quadratic extension over Fp2. 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.
1. Inversion in Fp3
1.1 Field Definition
Let
where ξ∈Fp is fixed. Every element x∈Fp3 is written uniquely as
1.2 Multiplication as a Linear Operator
Multiplication by x defines an Fp-linear map Lx:Fp3→Fp3 given by Lx(y)=xy. With respect to the basis {1,u,u2}, this map is represented by
1.3 Inversion via Linear Algebra
Assume x=0. Then Lx is invertible and the inverse element satisfies x−1=Lx−1(1). By Cramer’s rule,
so the coordinates of x−1 are given by the first column of adj(Mx).
1.4 Explicit Inversion Formula
t0,t1,t2: The First Column of the Adjugate Matrix
t0=x02−ξx1x2
This is the cofactor of the Mx[1,1], where Mx[r,c] is the element at row r and coloum c.
It is calculated as the determinant of the 2×2 matrix (x0x1ξx2x0) remaining after crossing out the 1st row and 1st column.
t1=ξx22−x0x1
This is the cofactor for the Mx[1,2].
The sign (−) is already integrated into the simplified formula in the code.
t2=x12−x0x2
This is the cofactor for the Mx[1,3].
These t0,t1,t2 constitute the first column of the adjugate matrix adj(Mx). In extension fields, the matrix has a circulant structure, meaning that knowing the first column is sufficient to determine the entire inverse.
t3: The Determinant
This is the Laplace expansion along the first column of matrix Mx.
It performs Mx[1,1]⋅t0+M[1,2]⋅t1+M[1,3]⋅t3
y=(y0,y1,y2): The Final Inverse
2. Inversion in the Quartic Extension Field
Direct inversion via a 4×4 matrix is inefficient. Instead, Fp4 is viewed as a quadratic extension over Fp2:
2.1 Tower Construction
Let Fp2=Fp[v]/(v2−ξ) and Fp4=Fp2[u]/(u2−v).
Every element x∈Fp4 can be written as x=A+Bu with A,B∈Fp2.
2.2 Quadratic Conjugation
Define the conjugate of x over Fp2 by xˉ=A−Bu. This operation satisfies xxˉ∈Fp2.
2.3 First Level of Rationalization (Removing u)
Our goal is to find x−1=A+Bu1. To remove u from the denominator, we multiply the top and bottom by the conjugate xˉ=A−Bu:
Since u2=v, the denominator becomes D=A2−B2v.
Now, u has been eliminated from the denominator, leaving only v.
2.4 Second Level of Rationalization (Removing v)
Let's look at the new denominator D. Since A and B contain v, D can be expanded into a linear form of v: D=D0+D1v. To remove v, we multiply by its conjugate (D0−D1v):
Since v2=ξ, the final denominator becomes N=D02−D12ξ.
This value N (the Norm) is now a pure scalar (BaseField), free of both u and v.
2.5 Inversion Formula
Assume x=0. Then D=0, and the inverse of x is
Thus inversion in Fp4 reduces to inversion in Fp2.
2.6 Inversion in the Quadratic Subfield
Writing D=D0+D1v with D0,D1∈Fp, one has
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.
Throughout, it is assumed that:
Frobenius applications are free or negligible compared to multiplication,
squaring and multiplication in Fp are counted separately
3.1 Arithmetic Cost Summary
Fp3
Matrix-based inversion
3
9
1
Linear algebra (determinant + adjugate)
Fp3
Itoh–Tsujii
3
≈12
1
Extension-field multiplications
Fp4
Quadratic tower inversion
6
12
1
Two successive quadratic reductions
Fp4
Itoh–Tsujii
≈8
≈18
1
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.
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 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 k, 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=3 and k=4, the specialized algorithms are typically preferred.
A. Possibility of Inversion over a Quadratic Tower
A.1 Setting
Consider an extension field of degree 2n over the prime field Fp. Assume that the field admits a recursive quadratic tower representation of the form
where ηn−1∈Fp2n−1 is a non-square.
A.2 Quadratic Reduction Step
At each level i of the tower, an element of Fp2i+1 can be written as x=x0+x1ui with x0,x1∈Fp2i. The inverse of x is computed by:
forming the denominator x02−ηix12∈Fp2i,
multiplying its inverse by the conjugate x0−x1ui.
This reduces inversion in Fp2i+1 to a single inversion in Fp2i.
A.3 Recursive Structure
By recursively applying the quadratic reduction step, inversion in Fp2n is reduced along the tower
As a result, exactly one inversion in the base field Fp 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 is available at each level of the tower.
If the field is instead given as a flat extension Fp[x]/(f(x)) with degf=2n, 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 n, 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