If f is an irreducible polynomial then Zp[x]/f(x) is the Galois field GF(pn), so that every nonzero polynomial a(x) has a multiplicative inverse a−1(x). Given two polynomials
a variant of the extended Euclidean algorithm (Chapter 2, Section 2.1.2) allows the expression of the greatest common divider of f and a in the form
In particular, if gcd(f, a) = 1 then a−1(x) = b(x) mod f.
The following formal algorithm, in which degree(a) returns the degree of a and swap(a, b) interchanges a and b, computes z(x) = a−1(x).
Example 8.7
As p = 2, Algorithm 8.23 can be simplified; in particular, u(m) = υ−1(t) = υ(0) = 1.
Compute a−1(x):
In order to execute Algorithm 8.23, the following procedures must be defined:
procedure degree (a: in polynomial; deg: out natural);
computes the degree deg of a;
procedure invert (a: in coefficient; p: in module; b: out coefficient);
computes a−1 mod p; Algorithm 8.16 could be used;
procedure add (a, b: in polynomial; p: in module; c: out polynomial);
computes the sum of two polynomials; Algorithm 8.17 could be used;
procedure sub (a, b: in polynomial; p: in module; c: out polynomial);
computes the difference of two polynomials; Algorithm 8.18 could be used;
procedure shift (a: in polynomial; k: in natural; c: out polynomial);
computes c(x) = a(x).xk; it is equivalent to a k-position right-shift of the coefficients of a, with the k lower-degree coefficients set to 0.
The following algorithm is deduced from Algorithm 8.23 and from the previous procedure definitions (zero and one stand for the polynomials 0 and 1, respectively):
Algorithm 8.24 Inversion in GF(pn)
A different method, based on a modification of the Itoh–Tsujii algorithm ([ITO1988]), can be used if f(x) is a binomial ([WOO2000], [BAI2001]). First observe that if r = 1 + p + p2 + … + pn−1, then (Chapter 2, Section 2.2.4) (a(x))r is an element of Zp (a 0-degree polynomial). As
the problem is reduced to the computation of exponential functions in GF(pn) and to the inversion in GF(p).
The following formal algorithm computes z(x) = a−1(x).
Algorithm 8.25
In order to execute the preceding algorithm the following procedures must be defined:
procedure multiply (a, b, f: in polynomial; p: in module; z: out polynomial);
computes the product of a by b modulo f; Algorithm 8.20, 8.21, or 8.22 could be used;
procedure exponentiation (a, f: in polynomial; p: in module; i: in natural; b: out polynomial);
computes ar(i) modulo f, where r(i) = pi.
It remains to generate the preceding procedure. First recall (Chapter 2, Section 2.2.5) that if α, β, …, γ are elements of GF(pn), then
More generally, if r(i) = pi, then
Observe also that, given a coefficient ak (an element of Zp), then
and, more generally,
From (8.17) and (8.18) the following relation is deduced:
Assume now that f is a binomial
and that n divides p − 1 (p mod n = 1), so that
Then
The values of
can be computed in advance (an algorithm for computing fki is given in Appendix 8.1), so that
The corresponding exponentiation procedure is the following:
procedure exponentiation (a, f: in polynomial; p: in module; i: in natural; b: out polynomial) is begin b(0):=a(0); for k in 1..n−1 loop modular_product (f(k,i), a(k), p, b(k)); end loop; end procedure;
The complete inversion algorithm is deduced from Algorithm 8.25.
Algorithm 8.26 Inversion, Second Version
In order to reduce the number of calls to the exponentiation procedure the following property can be used.
Property 8.1 If s = 1 + p + p2 + … + pk and t = 1 + p + p2 + … + pl, where k is odd and l = (k − 1)/2, then
where u = pk−l.
Proof
where
so that
If k+1 is a power of 2, that is, k = 2m − 1, then l = 2m−1 − 1, and the same decomposition can be recursively applied. The following algorithm computes z(x) = (a(x))s, where s = 1 + p + p2 + · · · + pk with k = 2m − 1.
Algorithm 8.27
b(0):=a; for j in 0..m−1 loop exponentiation (b(2*j), f, p, 2**j, b(2*j+1)); multiply (b(2*j), b(2*j+1), f, p, b(2*(j+1))); end loop; z:=b(2*m);
Example 8.8 k = 7, m = 3; in the following computation scheme r(i) stands for pi, so that r(i).r(j) = r(i + j).
Assume now that n−1 is a power of 2, that is,
Then
and
The preceding algorithm can be used for computing
It remains to compute
and
The complete inversion algorithm, when
is the following.
Algorithm 8.28 Inversion, Third Version
Observe that the main iteration is executed m times instead of n − 1 = 2m times as in Algorithm 8.26.
Example 8.9 If p = 239 and f(x) = x17 − 2, then Algorithm 828 can be applied:
the coefficients fki can be computed with Algorithm A 8.1.
Another example is the binomial x6−2 with
As n − 1 is not a power of 2, Algorithm 8.28 must be slightly modified.