Esempio n. 1
0
        /// <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;
            }
        }
Esempio n. 2
0
        /// <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);
        }