FileDocCategorySizeDatePackage
ECFieldF2m.javaAPI DocAndroid 1.5 API9688Wed May 06 22:41:06 BST 2009java.security.spec

ECFieldF2m

public class ECFieldF2m extends Object implements ECField
The parameters specifying a characteristic 2 finite field of an elliptic curve.
since
Android 1.0

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.

param
m the exponent {@code m} for the number of elements.
throws
IllegalArgumentException if {@code m <= zero}.
since
Android 1.0


                                                                   
       
        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.

param
m the exponent {@code m} for the number of elements.
param
rp the base of the reduction polynomial with the n-th bit corresponding to the n-th coefficient of the reduction polynomial.
throws
IllegalArgumentException if {@code m <= zero} or the {@code rp} is invalid.
since
Android 1.0

        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.

param
m the exponent {@code m} for the number of elements.
param
ks the base of the reduction polynomial with coefficients given in descending order.
throws
IllegalArgumentException if {@code m <= zero} or the reduction polynomial is not valid.
since
Android 1.0

        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 booleanequals(java.lang.Object obj)
Returns whether the specified object equals to this finite field.

param
obj the object to compare to this finite field.
return
{@code true} if the specified object is equal to this finite field, otherwise {@code false}.
since
Android 1.0

        // 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 intgetFieldSize()
Returns the size of this finite field (in bits).

return
the size of this finite field (in bits).
since
Android 1.0

        return m;
    
public intgetM()
Returns the exponent {@code m} for this finite field, with {@code 2^m} as the number of elements.

return
the exponent {@code m} for this finite field
since
Android 1.0

        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.

return
a copy of the integer array containing the order of the middle term(s) of the reduction polynomial for a polynomial basis or {@code null} for a normal basis.
since
Android 1.0

        // 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.BigIntegergetReductionPolynomial()
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
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 or {@code null} for a normal basis.
since
Android 1.0

        return rp;
    
public inthashCode()
Returns the hashcode value for this finite field.

return
the hashcode value for this finite field.
since
Android 1.0

        return rp == null ? m : m + rp.hashCode();