Exemple #1
0
        static FieldElement halfTrace(FieldElement x)
        {
            int          m = 163;
            FieldElement t = x;

            for (int i = 1; i <= ((m - 1) / 2); i++)
            {
                t = (FieldElement)t.Square().Square().Add(x);
            }
            return(t);
        }
Exemple #2
0
        static FieldElement trace(FieldElement x)
        {
            int          m = 163;
            FieldElement t = x;

            for (int i = 1; i < m; i++)
            {
                t = (FieldElement)t.Square().Add(x);
            }
            return(t);
        }
Exemple #3
0
        static FieldElement quadraticEquation(BigInteger u, BigInteger w)
        {
            int m  = 163;
            int k1 = 3;
            int k2 = 6;
            int k3 = 7;
            var w1 = new FieldElement(m, k1, k2, k3, w);
            var u1 = new FieldElement(m, k1, k2, k3, u);
            var u2 = u1.Invert().Square();
            var v  = (FieldElement)w1.Multiply(u2);
            var tr = trace(v);
            var t  = halfTrace(v);
            var z  = (FieldElement)t.Multiply(u1);

            return(z);
        }
Exemple #4
0
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            FieldElement other = obj as FieldElement;

            if (other == null)
            {
                return(false);
            }

            return(Equals(other));
        }
Exemple #5
0
        public override ECPoint Twice()
        {
            if (this.IsInfinity)
            {
                return(this);
            }

            if (this.x.ToBigInteger().SignValue == 0)
            {
                return(this.curve.Infinity);
            }

            FieldElement bX2 = (FieldElement)x.Invert().Square().Multiply(this.curve.B);
            FieldElement x2  = (FieldElement)x.Square().Add(bX2);

            FieldElement ydX = (FieldElement)x.Invert().Multiply(y);
            FieldElement by2 = (FieldElement)x.Add(ydX).Multiply(x2);
            FieldElement y2  = (FieldElement)x.Square().Add(by2).Add(x2);

            return(new FPoint(this.curve, x2, y2));
        }
Exemple #6
0
        static FPoint computeRandomPoint()
        {
            int m  = 163;
            int k1 = 3;
            int k2 = 6;
            int k3 = 7;

            var        a     = new BigInteger("1", 16);
            var        b     = new BigInteger("5FF6108462A2DC8210AB403925E638A19C1455D21", 16);
            var        curve = new FCurve(m, k1, k2, k3, a, b);
            BigInteger u     = getRandom();

            var u_element = new FieldElement(m, k1, k2, k3, u);
            var a_element = new FieldElement(m, k1, k2, k3, a);
            var b_element = new FieldElement(m, k1, k2, k3, b);

            var au    = u_element.Multiply(u_element).Multiply(a_element);
            var w     = u_element.Multiply(u_element).Multiply(u_element).Add(au).Add(b_element);
            var z     = quadraticEquation(u_element.ToBigInteger(), w.ToBigInteger());
            var point = new FPoint(curve, u_element, z);

            return(point);
        }