FileDocCategorySizeDatePackage
ECFieldF2m.javaAPI DocJava SE 5 API7365Fri Aug 26 14:57:18 BST 2005java.security.spec

ECFieldF2m

public class ECFieldF2m extends Object implements ECField
This immutable class defines an elliptic curve (EC) characteristic 2 finite field.
see
ECField
author
Valerie Peng
version
1.3, 12/19/03
since
1.5

Fields Summary
private int
m
private int[]
ks
private BigInteger
rp
Constructors Summary
public ECFieldF2m(int m)
Creates an elliptic curve characteristic 2 finite field which has 2^m elements with normal basis.

param
m with 2^m being the number of elements.
exception
IllegalArgumentException if m is not positive.

	if (m <= 0) {
	    throw new IllegalArgumentException("m is not positive");
	}
	this.m = m;
	this.ks = null;
	this.rp = null;
    
public ECFieldF2m(int m, BigInteger rp)
Creates an elliptic curve characteristic 2 finite field which has 2^m elements with polynomial basis. The reduction polynomial for this field is based on rp whose i-th bit correspondes to the i-th coefficient of the reduction polynomial.

Note: A valid reduction polynomial is either a trinomial (X^m + X^k + 1 with m > k >= 1) or a pentanomial (X^m + X^k3 + X^k2 + X^k1 + 1 with m > k3 > k2 > k1 >= 1).

param
m with 2^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 rp is null.
exception
IllegalArgumentException if m is not positive, or rp does not represent a valid reduction polynomial.

	// 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);
	}
    
public ECFieldF2m(int m, int[] ks)
Creates an elliptic curve characteristic 2 finite field which has 2^m elements with polynomial basis. The reduction polynomial for this field is based on ks whose content contains the order of the middle term(s) of the reduction polynomial. Note: A valid reduction polynomial is either a trinomial (X^m + X^k + 1 with m > k >= 1) or a pentanomial (X^m + X^k3 + X^k2 + X^k1 + 1 with m > k3 > k2 > k1 >= 1), so ks should have length 1 or 3.

param
m with 2^m being the number of elements.
param
ks the order of the middle term(s) of the reduction polynomial. Contents of this array are copied to protect against subsequent modification.
exception
NullPointerException if ks is null.
exception
IllegalArgumentException ifm is not positive, or the length of ks is neither 1 nor 3, or values in ks are not between m-1 and 1 (inclusive) and in descending order.

	// check m and ks
        this.m = m;
        this.ks = (int[]) ks.clone();
	if (m <= 0) {
	    throw new IllegalArgumentException("m is not positive");
	}
	if ((this.ks.length != 1) && (this.ks.length != 3)) {
	    throw new IllegalArgumentException
		("length of ks is neither 1 nor 3");
	}
	for (int i = 0; i < this.ks.length; i++) {
	    if ((this.ks[i] < 1) || (this.ks[i] > m-1)) {
		throw new IllegalArgumentException
		    ("ks["+ i + "] is out of range");
	    }
	    if ((i != 0) && (this.ks[i] >= this.ks[i-1])) {
		throw new IllegalArgumentException
		    ("values in ks are not in descending order");
	    }
	}
	// convert ks into rp
	this.rp = BigInteger.ONE;
	this.rp = rp.setBit(m);
	for (int j = 0; j < this.ks.length; j++) {
	    rp = rp.setBit(this.ks[j]);
	}
    
Methods Summary
public booleanequals(java.lang.Object obj)
Compares this finite field for equality with the specified object.

param
obj the object to be compared.
return
true if obj is an instance of ECFieldF2m and both m and the reduction polynomial match, false otherwise.

	if (this == obj) return true;
	if (obj instanceof ECFieldF2m) {
	    // no need to compare rp here since ks and rp 
  	    // should be equivalent
	    return ((m == ((ECFieldF2m)obj).m) &&
		    (Arrays.equals(ks, ((ECFieldF2m) obj).ks)));
	}
	return false;
    
public intgetFieldSize()
Returns the field size in bits which is m for this characteristic 2 finite field.

return
the field size in bits.

	return m;
    
public intgetM()
Returns the value m of this characteristic 2 finite field.

return
m with 2^m being the number of elements.

	return m;
    
public int[]getMidTermsOfReductionPolynomial()
Returns an integer array which contains the order of the middle term(s) of the reduction polynomial for polynomial basis or null for normal basis.

return
an integer array which contains the order of the middle term(s) of the reduction polynomial for polynomial basis or null for normal basis. A new array is returned each time this method is called.

	if (ks == null) { 
	    return null; 
	} else {
	    return (int[]) ks.clone();
	}
    
public java.math.BigIntegergetReductionPolynomial()
Returns a BigInteger whose i-th bit corresponds to the i-th coefficient of the reduction polynomial for polynomial basis or null for normal basis.

return
a BigInteger whose i-th bit corresponds to the i-th coefficient of the reduction polynomial for polynomial basis or null for normal basis.

	return rp;
    
public inthashCode()
Returns a hash code value for this characteristic 2 finite field.

return
a hash code value.

	int value = m << 5;
	value += (rp==null? 0:rp.hashCode());
	// no need to involve ks here since ks and rp 
	// should be equivalent.
	return value;