ECFieldF2mpublic class ECFieldF2m extends Object implements ECFieldThe parameters specifying a characteristic 2 finite field of an
elliptic curve. |
Fields Summary |
---|
private static final int | TPB_MID_LEN | private static final int | PPB_MID_LEN | private static final int | TPB_LEN | private static final int | PPB_LEN | private final int | m | private final BigInteger | rp | private final int[] | ks |
Constructors Summary |
---|
public ECFieldF2m(int m)Creates a new {@code ECFieldF2m} with {@code 2^m} elements with a normal
basis.
this.m = m;
if (this.m <= 0) {
throw new IllegalArgumentException(Messages.getString("security.75")); //$NON-NLS-1$
}
this.rp = null;
this.ks = null;
| public ECFieldF2m(int m, BigInteger rp)Creates a new {@code ECFieldF2m} with {@code 2^m} elements with a polynomial
basis and the reduction polynomial based on {@code rp}.
The reduction polynomial must be either trinomial or
pentanomial.
this.m = m;
if (this.m <= 0) {
throw new IllegalArgumentException(Messages.getString("security.75")); //$NON-NLS-1$
}
this.rp = rp;
if (this.rp == null) {
throw new NullPointerException(Messages.getString("security.76")); //$NON-NLS-1$
}
// the leftmost bit must be (m+1)-th one,
// set bits count must be 3 or 5,
// bits 0 and m must be set
int rp_bc = this.rp.bitCount();
if ((this.rp.bitLength() != (m+1)) ||
(rp_bc != TPB_LEN && rp_bc != PPB_LEN) ||
(!this.rp.testBit(0) || !this.rp.testBit(m)) ) {
throw new IllegalArgumentException(Messages.getString("security.77")); //$NON-NLS-1$
}
// setup ks using rp:
// allocate for mid terms only
ks = new int[rp_bc-2];
// find midterm orders and set ks accordingly
BigInteger rpTmp = rp.clearBit(0);
for (int i=ks.length-1; i>=0; i-- ) {
ks[i] = rpTmp.getLowestSetBit();
rpTmp = rpTmp.clearBit(ks[i]);
}
| public ECFieldF2m(int m, int[] ks)Creates a new {@code ECFieldF2m} with {@code 2^m} elements with
a polynomial basis and the reduction polynomial based on {@code ks}.
The reduction polynomial must be either trinomial or
pentanomial.
this.m = m;
if (this.m <= 0) {
throw new IllegalArgumentException(Messages.getString("security.75")); //$NON-NLS-1$
}
// Defensively copies array parameter
// to prevent subsequent modification.
// NPE as specified if ks is null
this.ks = new int[ks.length];
System.arraycopy(ks, 0, this.ks, 0, this.ks.length);
// no need to check for null already
if (this.ks.length != TPB_MID_LEN && this.ks.length != PPB_MID_LEN) {
// must be either trinomial or pentanomial basis
throw new IllegalArgumentException(Messages.getString("security.78")); //$NON-NLS-1$
}
// trinomial basis:
// check that m > k >= 1, where k is ks[0]
// pentanomial basis:
// check that m > k3 > k2 > k1 >= 1
// and kx in descending order, where
// k3 is ks[0], k2 is ks[1], k1 is ks[2]
boolean checkFailed = false;
int prev = this.m;
for (int i=0; i<this.ks.length; i++) {
if (this.ks[i] < prev) {
prev = this.ks[i];
continue;
}
checkFailed = true;
break;
}
if (checkFailed || prev < 1) {
throw new IllegalArgumentException(Messages.getString("security.79")); //$NON-NLS-1$
}
// Setup rp using ks:
// bits 0 and m always set
BigInteger rpTmp = BigInteger.ONE.setBit(this.m);
// set remaining bits according to ks
for (int i=0; i<this.ks.length; i++) {
rpTmp = rpTmp.setBit(this.ks[i]);
}
rp = rpTmp;
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)Returns whether the specified object equals to this finite field.
// object equals to itself
if (this == obj) {
return true;
}
if (obj instanceof ECFieldF2m) {
ECFieldF2m o = (ECFieldF2m)obj;
// check m
if (this.m == o.m) {
// check rp
if (this.rp == null) {
if (o.rp == null) {
// fields both with normal basis
return true;
}
} else {
// at least this field with polynomial basis
// check that rp match
// return this.rp.equals(o.rp);
return Arrays.equals(this.ks, o.ks);
}
}
}
return false;
| public int | getFieldSize()Returns the size of this finite field (in bits).
return m;
| public int | getM()Returns the exponent {@code m} for this finite field, with {@code 2^m} as
the number of elements.
return m;
| public int[] | getMidTermsOfReductionPolynomial()Returns a copy of the integer array containing the order of the middle
term(s) of the reduction polynomial for a polynomial basis.
// Defensively copies private array
// to prevent subsequent modification
// was: return ks == null ? null : (int[])ks.clone();
if (ks == null) {
return null;
} else {
int[] ret = new int[ks.length];
System.arraycopy(ks, 0, ret, 0, ret.length);
return ret;
}
| public java.math.BigInteger | getReductionPolynomial()Returns the base of the reduction polynomial with the n-th bit
corresponding to the n-th coefficient of the reduction polynomial for a
polynomial basis.
return rp;
| public int | hashCode()Returns the hashcode value for this finite field.
return rp == null ? m : m + rp.hashCode();
|
|