3

I'm would like to find a few polynomials of degree 127 irreducible over $\mathbb{F}_2$ for use in constructing $GF(2^{127})$. This is because I'm thinking of trying to make my own version of AES-GCM that doesn't have the small-subgroup problem (because it currently uses $GF(2^{128})$). And since $2^{127}-1$ is a Mersenne Prime, every element except 1 and 0 will be a generator for the whole field under multiplication.

Are there any good techniques for discovering such polynomials quickly? I've been picking polynomials randomly and testing with Fermat's Little Theorem on a few randomly chosen field elements (aka does $a^{2^{127}-1} \mod p = 1$ where $a$ is a polynomial with degree < 127 over $\mathbb{F}_2[x]), a \notin \{0,1\}$ and $p$ is my candidate polynomial?). Is there a better way? Are there any pitfalls for my way?

Please forgive me if I've stated things imprecisely or used the wrong terminology. I'm primarily a software engineer who's learned some abstract algebra because I like knowing the math stuff is based on rather than blindly implementing it.

  • For what it's worth you have an explicit formula for the number of irreducible polynomials of degree $n$ over a field of order $q$ which involves Moebius function. From this, if you pick random polynomial of high degree then you have a fairly good change to end up with an irreducible polynomial. What is the degree of the polynomial you are picking? If this is low degree, maybe it is a good idea to directly make the list of all polynomials. – Clément Guérin Mar 14 '18 at 03:30
  • @ClémentGuérin - In order to construct a field that contains all the elements of $GF(2^{127})$ I need a polynomial of degree 128, correct? – Omnifarious Mar 14 '18 at 03:35
  • Ah okay, I thought you were looking for an irreducible polynomial over $GF(2^{127})$. If you are looking for an irreducible polynomial of degree $127$ over $\mathbb{F}_2$ by picking it up randomly, then you have a probability of $0.007874015748031482$ not to be irreducible (I just made the computation). – Clément Guérin Mar 14 '18 at 03:47
  • @ClémentGuérin - But, how do I know if I've made a bad choice (even though most choices won't be)? – Omnifarious Mar 14 '18 at 03:50
  • 2
    Ok, to test if a polynomial over a finite field is irreducible you can use Cantor-Zassenhaus algorithm see the Wikipedia page. You also have Berlekamp algorithm. – Clément Guérin Mar 14 '18 at 03:53
  • @ClémentGuérin - That might make a good answer. :-) Is there anything wrong with my approach? – Omnifarious Mar 14 '18 at 04:14
  • 2
    @ClémentGuérin Your computation is incorrect. I tried a simulation, with 1000 random polynomials of degree 127 over $\mathbb F_2$, and only $8$ were irreducible. So maybe that $0.00787...$ should be the probability that it is irreducible. Well, I can see right away that the probability of being irreducible must be less than half, since if the constant term is $0$ it's certainly reducible. – Robert Israel Mar 14 '18 at 04:52
  • @RobertIsrael - I suspected that was the case. There is a formula that I've forgotten for determining the number of irreducible polynomials of degree $n$ over $\mathbb{F}_p$. The percentage gets smaller as $n$ gets larger if I recall. I think it's related to $\phi(p^{n-1})$ or something like that. – Omnifarious Mar 14 '18 at 05:36
  • 1
    @RobertIsrael, the formula I have in mind is this one : https://math.stackexchange.com/questions/152880/how-many-irreducible-polynomials-of-degree-n-exist-over-mathbbf-p. You are right, thanks for checking! The number of irreducible polynomials is equivalent to $q^n/n$ when $n$ goes to infinity. Which obviously make the probability goes to $0$ when $n$ gets bigger. Sorry Omnifarious. – Clément Guérin Mar 14 '18 at 07:08

2 Answers2

3

In general this is difficult (in the sense that I don't know a general method for finding one), but with degree $127$ the following special trick springs to mind.

Consider the polynomial $L(x)=x^{128}+x^2+x\in GF(2)[x]$. It is the linearized associate of the polynomial $m(x)=x^7+x+1$ (replace exponent $\ell$ with $2^\ell$ throughout to get the linearized associate). It is easy to verify that $m(x)$ is irreducible:

  • It has no zeros in $GF(2)$ and hence no linear factors in $GF(2)[x]$.
  • It is not divisible by the one and only irreducible quadratic $x^2+x+1$, because that is a factor of $x^3+1$ and hence also of $x^6+1$ and $x^7+x$.
  • It is not divisible by either of the irreducible cubics, because those are factors of $x^7+1$.

The zeros of $m(x)$ are thus elements of $GF(2^7)$, and because $2^7-1=127$ is a prime those zeros have order $127$. Therefore $m(x)\mid x^{127}-1$ in $GF(2)[x]$. Again, by the theory of linearized and conventional associates this implies that $$ L(x)\mid x^{2^{127}}-x. $$ Namely, if a polynomial divides another, then its linearized associate divides the linearized associate of the other even symbolically (= as an innermost composition factor), and hence also in the polynomial ring.

But, $GF(2^{127})$ is well known to consist of the zeros of $p(x)=x^{2^{127}}-x$. Again, as $127$ is a prime, this implies that apart from the trivial factors $x$ and $x-1$ all the irreducible factors of $p(x)$ have degree $127$.

Drums, please. We just saw that $$f(x)=L(x)/x=x^{127}+x+1$$ is a degree $127$ factor of $p(x)$. Hence it must be irreducible.


Repeating the dose, we arrive at the curious conclusion that because $M=2^{127}-1$ is a prime number, it follows that $$ F(x)=x^M+x+1 $$ is also irreducible in $GF(2)[x]$. By the properties of linearized associates $x^{2^{127}}+x^2+x$ is a factor of $x^{2^M}+x$. As all the non-linear irreducible factors of that polynomial have degree $M$ (because $M$ is prime) we can conclude that $F(x)$ is irreducible!

I wonder whether this "Mersenne tower" continues. It is beyond the existing technology, see a relevant Wikipedia page for more information.

Jyrki Lahtonen
  • 133,153
  • Because $x^7+x^3+1$ is also irreducible, a similar argument shows that $$x^{127}+x^7+1=\frac1x(x^{2^7}+x^{2^3}+x^{2^0})$$ is another irreducible polynomial of degree $127$. – Jyrki Lahtonen Mar 14 '18 at 15:35
  • For basic facts about linearized polynomials I refer the interested reader to Chapter 3.4 of Lidl & Niederreiter. – Jyrki Lahtonen Mar 14 '18 at 15:41
  • It's going to take me a little while to wrap my head around this. Is there anything wrong with my "Femat's Little Theorem" based method of testing? I realize it's probabilistic, but shouldn't it generally work well if you try enough different values for $a$? – Omnifarious Mar 14 '18 at 16:05
  • According to Maple, $x^{127} + x^k + 1$ is irreducible over $\mathbb F_2$ for $k = 1, 7, 15, 30, 63, 64, 97, 112, 120$, and $126$. – Robert Israel Mar 14 '18 at 18:15
  • See also OEIS sequence A278573 and references there. – Robert Israel Mar 14 '18 at 18:30
  • @RobertIsrael $k=15$ and $k=63$ also come from the same recipe by replacing $m(x)$ with its reciprocal in the above examples. We can then also take reciprocals of $f(x)$ explaining $k=126,120,112$ and $64$. Only the pair $30=127-97$ doesn't come from a linearized polynomial in this way. – Jyrki Lahtonen Mar 14 '18 at 19:31
  • I'm willing to accept this as an answer when you've commented on my use of an approach based on Fermat's little theorem to arrive at a probabilistic answer. I'm really curious as to if it's even in the tiniest bit valid, or if there is some serious flaw with it. – Omnifarious Mar 14 '18 at 23:00
  • There is a general method, but it involves factoring polynomials of very large degrees, so it is probably not practical. The idea is that all irreducible factors of the $(2^n-1)$st cyclotomic polynomial will have degree $n$. – Tobias Kildetoft Mar 15 '18 at 06:16
  • @TobiasKildetoft Sure, I oversimplified. I meant: "I don't know a general method I'm willing to carry out with paper & pencil" :-) – Jyrki Lahtonen Mar 15 '18 at 06:28
3

I'm not sure whether this is what the OP had in mind, but here is one way of testing whether a given polynomial of degree $127$ from $GF(2)[x]$ is irreducible. This relies on $127$ being a prime number, but some modifications could be made to work for other for non-primes also, I think. This is not for paper & pencil work, just a simple test you can do, if you have implemented arithmetic of polynomials with coefficients in $GF(2)$.

Input: A polynomial $p(x)\in GF(2)[x]$ of degree $127$.

Goal: Determine whether $p(x)$ is irreducible over $GF(2)$.

Assumptions:

  • I assume that $p(x)$ is square-free. In other words, there are no non-constant polynomials $q(x)\in GF(2)[x]$ such that $q(x)^2\mid p(x)$. This is easy to test. All you need to do is to calculate $\gcd(p(x),p'(x))$ with the Euclidean algorithm. Here $p'(x)$ is the (formal) derivative of $p(x)$. If $q(x)^2\mid p(x)$, then also $q(x)\mid p'(x)$, and hence $q(x)$ is a common factor of $p(x)$ and $p'(x)$. So if the gcd is equal to one, then $p(x)$ is square-free. Otherwise we can immediately conclude that $p(x)$ is not irreducible.
  • For simplicity we can also assume that $p(0)=1$. For otherwise $p(0)=0$, $x$ is a factor, and $p(x)$ is trivially not irreducible.

Claim (or the algorithm): The input polynomial $p(x)$ is irreducible in $GF(2)[x]$ if and only if $$ x^{2^{127}}\equiv x\pmod {p(x)}. $$ Here the remainder of $x^{2^{127}}$ modulo $p(x)$ can be efficiently calculated with repeated squaring. In other words we recursively define the sequence of polynomials $(r_n)$ of degrees $<127$ as follows:

  • $r_0(x)=x$,

  • if we have calculated $r_k(x)$, we then calculate $r_{k+1}(x)$ as the remainder of $r_k(x)^2$ modulo $p(x)$,

  • then $r_{127}(x)$ is the desired remainder.

Proof. This test shows that $p(x)$ is a factor of $S(x):=x^{2^{127}}-x$. Because $127$ is a prime, this implies that $p(x)$ is irreducible. All factors of $S(x)$ of degree $127$ are irreducible because $S(x)$ is known to be the product of all the irreducible polynomials of degrees that are factors of $127$. In the present case, the degrees of irreducible factors of $S(x)$ are thus $1$ or $127$, and all such irreducible polynomials appear.


Remarks. This is mostly about generalizing the above test to non-prime degrees.

  1. In the case of degree $127$ the square-free test was superfluous. It becomes necessary, if instead of degree $127$ we study the irreducibility of polynomials of non-prime degrees. See the next item.
  2. If, in the general case, $p(x)$ is a square-free polynomial of degree $m$, then it is a product of distinct irreducible factors, say $$p(x)=p_1(x)p_2(x)\cdots p_k(x).$$ In this case the Chinese Remainder Theorem tells us that the quotient ring $$GF(2)[x]/\langle p(x)\rangle\simeq \bigoplus_{i=1}^kGF(2)[x]/\langle p_i(x)\rangle.$$ Consequently $x^{2^\ell}\equiv x\pmod {p(x)}$ if and only if $x^{2^\ell}\equiv x\pmod{p_i(x)}$ for all $i=1,2,\ldots,k$ if and only if $\ell$ is divisible by the degrees $\deg p_i(x)$ of all the irreducible factors.
  3. From the previous remark we see that that if $m$ is the least common multiple of the degrees $\deg p_i(x), i=1,2,\ldots,k$, then the polynomial $p(x)$ passes the simple test of the main algorithm. We can soup up the algorithm by testing whether the polynomial $r_d(x)-x$ has a common factor with $p(x)$ for those values of $d$ such that $d\mid m$. This will then catch $p(x)$ is reducible. Namely, if $p_i(x)$ is a factor of degree $d$, then $p_i(x)$ is a common factor of $p(x)$ and $x^{2^d}-x$, and will thus be a factor of $r_d(x)-x$.
  4. The OP discussed testing the remainder of $a^{2^{127}-1}$ modulo $p(x)$ for some generic element $a\in GF(2^{127})\setminus GF(2)$. I'm not sure what they wanted to do here, because without the irreducible polynomial $p(x)$ we may not have implemented the field $GF(2^{127})$ yet. The main algorithm uses the coset of $x$ modulo $p(x)$ as a generic element of a "candidate field" $GF(2)[x]/\langle p(x)\rangle$ much the same way, so in that sense the method works. Indeed, because $2^{127}-1$ is also a prime, the order of $x$ must be precisely $2^{127}-1$ in the positive cases.
Jyrki Lahtonen
  • 133,153
  • @Omnifarious I chose to post this as another answer. It is quite distinct from the trickery of the other answer, so I think it is ok to keep it separate. I hope this answers your actual question. At least this is how I understood (or made sense of) the algorithm you proposed. – Jyrki Lahtonen Mar 15 '18 at 22:21
  • Thank you. :-) I tried to clarify what I meant since you're right, I didn't get my statement of what I was doing quite right. :-) – Omnifarious Mar 16 '18 at 01:13