예제 #1
0
 /**
  * Creates an elliptic curve characteristic 2 finite field which has 2^{@code m} elements with
  * polynomial basis. The reduction polynomial for this field is based on {@code rp} whose i-th bit
  * corresponds to the i-th coefficient of the reduction polynomial.
  *
  * <p>Note: A valid reduction polynomial is either a trinomial (X^{@code m} + X^{@code k} + 1 with
  * {@code m} &gt; {@code k} &gt;= 1) or a pentanomial (X^{@code m} + X^{@code k3} + X^{@code k2} +
  * X^{@code k1} + 1 with {@code m} &gt; {@code k3} &gt; {@code k2} &gt; {@code k1} &gt;= 1).
  *
  * @param m with 2^{@code m} being the number of elements.
  * @param rp the BigInteger whose i-th bit corresponds to the i-th coefficient of the reduction
  *     polynomial.
  * @exception NullPointerException if {@code rp} is null.
  * @exception IllegalArgumentException if {@code m} is not positive, or {@code rp} does not
  *     represent a valid reduction polynomial.
  */
 public ECFieldF2m(int m, BigInteger rp) {
   // check m and rp
   this.m = m;
   this.rp = rp;
   if (m <= 0) {
     throw new IllegalArgumentException("m is not positive");
   }
   int bitCount = this.rp.bitCount();
   if (!this.rp.testBit(0) || !this.rp.testBit(m) || ((bitCount != 3) && (bitCount != 5))) {
     throw new IllegalArgumentException("rp does not represent a valid reduction polynomial");
   }
   // convert rp into ks
   BigInteger temp = this.rp.clearBit(0).clearBit(m);
   this.ks = new int[bitCount - 2];
   for (int i = this.ks.length - 1; i >= 0; i--) {
     int index = temp.getLowestSetBit();
     this.ks[i] = index;
     temp = temp.clearBit(index);
   }
 }