EllipticCurvepublic class EllipticCurve extends Object An Elliptic Curve with its necessary values. |
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.
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.
this(field, a, b, null);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object other)Returns whether the specified object equals to this elliptic curve.
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.BigInteger | getA()Returns the coefficient {@code a} of this elliptic curve.
return a;
| public java.math.BigInteger | getB()Returns the coefficient {@code b} of this elliptic curve.
return b;
| public java.security.spec.ECField | getField()Returns the finite field of this elliptic curve.
return field;
| public byte[] | getSeed()Returns a copy of the seed that was used to generate this elliptic curve.
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 int | hashCode()Returns the hashcode of this elliptic curve.
// 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;
|
|