• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.bouncycastle.math.field;
2 
3 import java.math.BigInteger;
4 
5 public abstract class FiniteFields
6 {
7     static final FiniteField GF_2 = new PrimeField(BigInteger.valueOf(2));
8     static final FiniteField GF_3 = new PrimeField(BigInteger.valueOf(3));
9 
getBinaryExtensionField(int[] exponents)10     public static PolynomialExtensionField getBinaryExtensionField(int[] exponents)
11     {
12         if (exponents[0] != 0)
13         {
14             throw new IllegalArgumentException("Irreducible polynomials in GF(2) must have constant term");
15         }
16         for (int i = 1; i < exponents.length; ++i)
17         {
18             if (exponents[i] <= exponents[i - 1])
19             {
20                 throw new IllegalArgumentException("Polynomial exponents must be montonically increasing");
21             }
22         }
23 
24         return new GenericPolynomialExtensionField(GF_2, new GF2Polynomial(exponents));
25     }
26 
27 //    public static PolynomialExtensionField getTernaryExtensionField(Term[] terms)
28 //    {
29 //        return new GenericPolynomialExtensionField(GF_3, new GF3Polynomial(terms));
30 //    }
31 
getPrimeField(BigInteger characteristic)32     public static FiniteField getPrimeField(BigInteger characteristic)
33     {
34         int bitLength = characteristic.bitLength();
35         if (characteristic.signum() <= 0 || bitLength < 2)
36         {
37             throw new IllegalArgumentException("'characteristic' must be >= 2");
38         }
39 
40         if (bitLength < 3)
41         {
42             switch (characteristic.intValue())
43             {
44             case 2:
45                 return GF_2;
46             case 3:
47                 return GF_3;
48             }
49         }
50 
51         return new PrimeField(characteristic);
52     }
53 }
54