/// <summary> /// Abstract base class for elliptic curves. /// </summary> /// <param name="BasePoint">Base-point.</param> /// <param name="Order">Order of base-point.</param> /// <param name="Cofactor">Cofactor of curve.</param> /// <param name="Secret">Secret.</param> public EllipticCurve(PointOnCurve BasePoint, BigInteger Order, int Cofactor, byte[] Secret) { this.g = BasePoint; this.n = Order; this.cofactor = Cofactor; this.secret = Secret; this.privateKey = null; this.publicKey = null; this.additionalInfo = null; this.orderBits = ModulusP.CalcBits(this.n); this.orderBytes = (this.orderBits + 7) >> 3; this.msbOrderMask = 0xff; int MaskBits = (8 - this.orderBits) & 7; if (MaskBits == 0) { this.orderBytes++; this.msbOrderMask = 0; } else { this.msbOrderMask >>= MaskBits; } }
/// <summary> /// Base class of Elliptic curves over a prime field. /// </summary> /// <param name="Prime">Prime base of field.</param> /// <param name="BasePoint">Base-point.</param> /// <param name="A">a Coefficient in the definition of the curve E: y^2=x^3+a*x+b</param> /// <param name="Order">Order of base-point.</param> /// <param name="OrderBits">Number of bits used to encode order.</param> public CurvePrimeField(BigInteger Prime, PointOnCurve BasePoint, BigInteger A, BigInteger Order, int OrderBits) : base(Prime) { if (Prime <= BigInteger.One) { throw new ArgumentException("Invalid prime base.", nameof(Prime)); } this.g = BasePoint; this.a = A; this.n = Order; this.orderBits = OrderBits; this.orderBytes = (OrderBits + 7) >> 3; this.modN = new ModulusP(Order); this.msbMask = 0xff; int MaskBits = (8 - OrderBits) & 7; if (MaskBits == 0) { this.orderBytes++; this.msbMask = 0; } else { this.msbMask >>= MaskBits; } this.GenerateKeys(); }
/// <summary> /// Base class of Elliptic curves over a prime field. /// </summary> /// <param name="Prime">Prime base of field.</param> /// <param name="BasePoint">Base-point.</param> /// <param name="Order">Order of base-point.</param> /// <param name="Cofactor">Cofactor of curve.</param> /// <param name="Secret">Secret.</param> public PrimeFieldCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger Order, int Cofactor, byte[] Secret) : base(BasePoint, Order, Cofactor, Secret) { if (Prime <= BigInteger.One) { throw new ArgumentException("Invalid prime base.", nameof(Prime)); } this.p = Prime; this.modP = new ModulusP(Prime); this.modN = new ModulusP(Order); }