FileDocCategorySizeDatePackage
EllipticCurve.javaAPI DocAndroid 1.5 API7256Wed May 06 22:41:06 BST 2009java.security.spec

EllipticCurve

public class EllipticCurve extends Object
An Elliptic Curve with its necessary values.
since
Android 1.0

Fields Summary
private final ECField
field
private final BigInteger
a
private final BigInteger
b
private final byte[]
seed
private volatile int
hash
Constructors Summary
public EllipticCurve(ECField field, BigInteger a, BigInteger b, byte[] seed)
Creates a new {@code EllipticCurve} with the specified field, coefficients and seed.

param
field the finite field of this elliptic curve.
param
a the coefficient {@code a}.
param
b the coefficient {@code b}.
param
seed the seed used for the generation of the curve.
throws
IllegalArgumentException if the specified coefficients are not in the specified field.
since
Android 1.0

        this.field = field;
        if (this.field == null) {
            throw new NullPointerException(Messages.getString("security.7A")); //$NON-NLS-1$
        }
        this.a = a;
        if (this.a == null) {
            throw new NullPointerException(Messages.getString("security.7B")); //$NON-NLS-1$
        }
        this.b = b;
        if (this.b == null) {
            throw new NullPointerException(Messages.getString("security.7C")); //$NON-NLS-1$
        }
        // make defensive copy
        if (seed == null) {
            this.seed = null;
        } else {
            this.seed = new byte[seed.length];
            System.arraycopy(seed, 0, this.seed, 0, this.seed.length);
        }
        // check parameters for ECFieldFp and ECFieldF2m.
        // Check invariant: a and b must be in the field.
        // Check conditions for custom ECField are not specified.
        if (this.field instanceof ECFieldFp) {
            BigInteger p = ((ECFieldFp) this.field).getP();
            if (this.a.signum() < 0 || this.a.compareTo(p) >= 0) {
                throw new IllegalArgumentException(Messages.getString("security.7D")); //$NON-NLS-1$
            }
            if (this.b.signum() < 0 || this.b.compareTo(p) >= 0) {
                throw new IllegalArgumentException(Messages.getString("security.7E")); //$NON-NLS-1$
            }
        } else if (this.field instanceof ECFieldF2m) {
            int fieldSizeInBits = this.field.getFieldSize();
            if (!(this.a.bitLength() <= fieldSizeInBits)) {
                throw new IllegalArgumentException(Messages.getString("security.7D")); //$NON-NLS-1$
            }
            if (!(this.b.bitLength() <= fieldSizeInBits)) {
                throw new IllegalArgumentException(Messages.getString("security.7E")); //$NON-NLS-1$
            }
        }
    
public EllipticCurve(ECField field, BigInteger a, BigInteger b)
Creates a new {@code EllipticCurve} with the specified field and coefficients.

param
field the finite field of this elliptic curve.
param
a the coefficient {@code a}.
param
b the coefficient {@code b}.
throws
IllegalArgumentException if the specified coefficients are not in the specified field.
since
Android 1.0

        this(field, a, b, null);
    
Methods Summary
public booleanequals(java.lang.Object other)
Returns whether the specified object equals to this elliptic curve.

param
other the object to compare.
return
{@code true} if the specified object is equal to this elliptic curve, otherwise {@code false}.
since
Android 1.0

        if (this == other) {
            return true;
        }
        if (!(other instanceof EllipticCurve)) {
            return false;
        }
        EllipticCurve otherEc = (EllipticCurve) other;
        return this.field.equals(otherEc.field) && this.a.equals(otherEc.a)
                && this.b.equals(otherEc.b)
                && Arrays.equals(this.seed, otherEc.seed);
    
public java.math.BigIntegergetA()
Returns the coefficient {@code a} of this elliptic curve.

return
the coefficient {@code a} of this elliptic curve.
since
Android 1.0

        return a;
    
public java.math.BigIntegergetB()
Returns the coefficient {@code b} of this elliptic curve.

return
the coefficient {@code b} of this elliptic curve.
since
Android 1.0

        return b;
    
public java.security.spec.ECFieldgetField()
Returns the finite field of this elliptic curve.

return
the finite field of this elliptic curve.
since
Android 1.0

        return field;
    
public byte[]getSeed()
Returns a copy of the seed that was used to generate this elliptic curve.

return
a copy of the seed that was used to generate this elliptic curve, or {@code null} if none specified.
since
Android 1.0

        if (seed == null) {
            return null;
        } else {
            // return copy
            byte[] ret = new byte[seed.length];
            System.arraycopy(seed, 0, ret, 0, ret.length);
            return ret;
        }
    
public inthashCode()
Returns the hashcode of this elliptic curve.

return
the hashcode of this elliptic curve.
since
Android 1.0

        // hash init is delayed
        if (hash == 0) {
            int hash0 = 11;
            hash0 = hash0 * 31 + field.hashCode();
            hash0 = hash0 * 31 + a.hashCode();
            hash0 = hash0 * 31 + b.hashCode();
            if (seed != null) {
                for (int i = 0; i < seed.length; i++) {
                    hash0 = hash0 * 31 + seed[i];
                }
            } else {
                hash0 = hash0 * 31;
            }
            hash = hash0;
        }
        return hash;