public CurvePoint(EllypticCurve curve, Point point, BigInteger?orderOfGroup = default(BigInteger?))
        {
            if (curve.IsOnCurve(point))
            {
                Console.WriteLine($"Point {point} is on curve {curve.Coefficient}, {curve.Constant}");
            }
            else
            {
//                throw new ArgumentException($"Point {point} is not on curve {curve.Coefficient}, {curve.Constant}");
                Console.WriteLine($"Point {point} is not on curve {curve.Coefficient}, {curve.Constant}");
            }

            Curve = curve;
            Point = point;

            if (orderOfGroup.HasValue)
            {
                Order = orderOfGroup.Value;
            }
            else
            {
                Order = FindOrderOfGroup();
                Console.WriteLine($"Order of group is calculated {Order}");
            }
        }
        public static CurvePoint SimpleGenerator()
        {
            var curve = EllypticCurve.CreateWeierstrass(0, 7, new BigInteger(199));
            var g     = new Point(
                new BigInteger(2),
                new BigInteger(24));

            return(new CurvePoint(curve, g));
        }
        public static CurvePoint BitCoinGenerator()
        {
            var curve = EllypticCurve.CreateWeierstrass(0, 7, Configurations.MathConfiguration.GenerateSECP256K1());

            var g = new Point(
                BigInteger.Parse("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
                BigInteger.Parse("32670510020758816978083085130507043184471273380659243275938904335757337482424"));

            return(new CurvePoint(curve, g,
                                  BigIntegerExtensions.FromBigEndianHexString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")));
        }
        public static CurvePoint NIST121P192Generator()
        {
            var curve = EllypticCurve.CreateWeierstrass(
                new BigInteger(-3),
                BigIntegerExtensions.FromBigEndianHexString("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1"),
                BigInteger.Parse("6277101735386680763835789423207666416083908700390324961279"));

            var g = new Point(
                BigIntegerExtensions.FromBigEndianHexString("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"),
                BigIntegerExtensions.FromBigEndianHexString("07192b95ffc8da78631011ed6b24cdd573f977a11e794811"));

            return(new CurvePoint(curve, g,
                                  BigInteger.Parse("6277101735386680763835789423176059013767194773182842284081")));
        }
Exemple #5
0
        public static Point CalculateAddition(this EllypticCurve curve, Point p1, Point p2)
        {
            var beta = default(BigInteger);

            if (p1 != null && p1.Equals(p2))
            {
                beta = curve.CalculateBeta(p1);
            }
            else if (p1 != null && p2 != null)
            {
                beta = curve.CalculateBeta(p1, p2);
            }
            else
            {
                throw new ArgumentException();
            }

            var x = curve.CalculateAdditionXCoordinate(beta, p1, p2);
            var y = curve.CalculateAdditionYCoordinate(beta, p1, x);

            return(new Point(x.ToPositiveMod(curve.Modulo), y.ToPositiveMod(curve.Modulo)));
        }
Exemple #6
0
        public static Point CalculateMultiplication(this EllypticCurve curve, Point g, BigInteger scalar)
        {
            var binary = scalar.ToBinaryString();

            binary = binary.TrimStart('0');

            var p = new Point(g.XCoordinate, g.YCoordinate);

            for (var i = 1; i < binary.Length; i++)
            {
                bool add = binary[i] == '1';

                p = curve.CalculateDoubling(p);

                if (add)
                {
                    p = curve.CalculateAddition(p, g);
                }
            }

            return(p);
        }
Exemple #7
0
 public static Point CalculateDoubling(this EllypticCurve curve, Point p)
 {
     return(curve.CalculateAddition(p, p));
 }