/// <summary> /// Creates an elliptic curve with the specified elliptic field /// {@code field}, the coefficients {@code a} and /// {@code b}, and the {@code seed} used for curve generation. </summary> /// <param name="field"> the finite field that this elliptic curve is over. </param> /// <param name="a"> the first coefficient of this elliptic curve. </param> /// <param name="b"> the second coefficient of this elliptic curve. </param> /// <param name="seed"> the bytes used during curve generation for later /// validation. Contents of this array are copied to protect against /// subsequent modification. </param> /// <exception cref="NullPointerException"> if {@code field}, /// {@code a}, or {@code b} is null. </exception> /// <exception cref="IllegalArgumentException"> if {@code a} /// or {@code b} is not null and not in {@code field}. </exception> public EllipticCurve(ECField field, System.Numerics.BigInteger a, System.Numerics.BigInteger b, sbyte[] seed) { if (field == null) { throw new NullPointerException("field is null"); } if (a == null) { throw new NullPointerException("first coefficient is null"); } if (b == null) { throw new NullPointerException("second coefficient is null"); } CheckValidity(field, a, "first coefficient"); CheckValidity(field, b, "second coefficient"); this.Field_Renamed = field; this.a = a; this.b = b; if (seed != null) { this.Seed_Renamed = seed.clone(); } else { this.Seed_Renamed = null; } }
// Check coefficient c is a valid element in ECField field. private static void CheckValidity(ECField field, System.Numerics.BigInteger c, String cName) { // can only perform check if field is ECFieldFp or ECFieldF2m. if (field is ECFieldFp) { System.Numerics.BigInteger p = ((ECFieldFp)field).P; if (p.CompareTo(c) != 1) { throw new IllegalArgumentException(cName + " is too large"); } else if (c.signum() < 0) { throw new IllegalArgumentException(cName + " is negative"); } } else if (field is ECFieldF2m) { int m = ((ECFieldF2m)field).M; if (c.bitLength() > m) { throw new IllegalArgumentException(cName + " is too large"); } } }
/// <summary> /// Creates an elliptic curve with the specified elliptic field /// {@code field} and the coefficients {@code a} and /// {@code b}. </summary> /// <param name="field"> the finite field that this elliptic curve is over. </param> /// <param name="a"> the first coefficient of this elliptic curve. </param> /// <param name="b"> the second coefficient of this elliptic curve. </param> /// <exception cref="NullPointerException"> if {@code field}, /// {@code a}, or {@code b} is null. </exception> /// <exception cref="IllegalArgumentException"> if {@code a} /// or {@code b} is not null and not in {@code field}. </exception> public EllipticCurve(ECField field, System.Numerics.BigInteger a, System.Numerics.BigInteger b) : this(field, a, b, null) { }