Ejemplo n.º 1
0
 protected bool Equals(
     F2mFieldElement other)
 {
     return(m == other.m &&
            k1 == other.k1 &&
            k2 == other.k2 &&
            k3 == other.k3 &&
            representation == other.representation &&
            base.Equals(other));
 }
Ejemplo n.º 2
0
        static F2mFieldElement halfTrace(F2mFieldElement x)
        {
            F2mFieldElement t = x;

            for (int i = 1; i <= ((x.M - 1) / 2); i++)
            {
                t = (F2mFieldElement)t.Square().Square().Add(x);
            }

            return(t);
        }
Ejemplo n.º 3
0
        // 6.5 Вычисляем след элемента
        static F2mFieldElement trace(F2mFieldElement x)
        {
            F2mFieldElement t = x;

            for (int i = 1; i < x.M; i++)
            {
                t = (F2mFieldElement)t.Square().Add(x);
            }

            return(t);
        }
Ejemplo n.º 4
0
 /**
  * Creates the points on the curve with literature values.
  */
 internal static void createPoints()
 {
     for (int i = 0; i < pointSource.Length / 2; i++)
     {
         F2mFieldElement x = new F2mFieldElement(m, k1,
                                                 new BigInteger(pointSource[2 * i], 16));
         F2mFieldElement y = new F2mFieldElement(m, k1,
                                                 new BigInteger(pointSource[2 * i + 1], 16));
         p[i] = new F2mPoint(curve, x, y);
     }
 }
Ejemplo n.º 5
0
        public override ECFieldElement Add(
            ECFieldElement b)
        {
            // No check performed here for performance reasons. Instead the
            // elements involved are checked in ECPoint.F2m
            // checkFieldElements(this, b);
            IntArray        iarrClone = (IntArray)this.x.Clone();
            F2mFieldElement bF2m      = (F2mFieldElement)b;

            iarrClone.AddShifted(bF2m.x, 0);
            return(new F2mFieldElement(m, k1, k2, k3, iarrClone));
        }
Ejemplo n.º 6
0
    public override bool Equals(object obj)
    {
        if (obj == this)
        {
            return(true);
        }
        F2mFieldElement f2mFieldElement = obj as F2mFieldElement;

        if (f2mFieldElement == null)
        {
            return(false);
        }
        return(Equals(f2mFieldElement));
    }
        public static int GetByteLength(
            ECFieldElement fe)
        {
            if (fe is FpFieldElement)
            {
                FpFieldElement ep = (FpFieldElement)fe;

                return((ep.Q.BitLength + 7) / 8);
            }

            F2mFieldElement em = (F2mFieldElement)fe;

            return((em.M + 7) / 8);
        }
Ejemplo n.º 8
0
        public override ECFieldElement Multiply(
            ECFieldElement b)
        {
            // Right-to-left comb multiplication in the IntArray
            // Input: Binary polynomials a(z) and b(z) of degree at most m-1
            // Output: c(z) = a(z) * b(z) mod f(z)

            // No check performed here for performance reasons. Instead the
            // elements involved are checked in ECPoint.F2m
            // checkFieldElements(this, b);
            F2mFieldElement bF2m = (F2mFieldElement)b;
            IntArray        mult = x.Multiply(bF2m.x, m);

            mult.Reduce(m, new int[] { k1, k2, k3 });
            return(new F2mFieldElement(m, k1, k2, k3, mult));
        }
Ejemplo n.º 9
0
    public static void CheckFieldElements(ECFieldElement a, ECFieldElement b)
    {
        if (!(a is F2mFieldElement) || !(b is F2mFieldElement))
        {
            throw new ArgumentException("Field elements are not both instances of F2mFieldElement");
        }
        F2mFieldElement f2mFieldElement  = (F2mFieldElement)a;
        F2mFieldElement f2mFieldElement2 = (F2mFieldElement)b;

        if (f2mFieldElement.representation != f2mFieldElement2.representation)
        {
            throw new ArgumentException("One of the F2m field elements has incorrect representation");
        }
        if (f2mFieldElement.m != f2mFieldElement2.m || !Arrays.AreEqual(f2mFieldElement.ks, f2mFieldElement2.ks))
        {
            throw new ArgumentException("Field elements are not elements of the same field F2m");
        }
    }
Ejemplo n.º 10
0
        // 6.8. Вычисление случайной точки эллиптической кривой
        static F2mPoint computeRandomPoint(F2mCurve curve)
        {
            // 1. Вычислим случайный элемент основного поля
            BigInteger u = RNG.GetRandomInteger(curve.M);

            var u__element = new F2mFieldElement(curve.M, curve.K1, curve.K2, curve.K3, u);


            var a__element = new F2mFieldElement(curve.M, curve.K1, curve.K2, curve.K3, curve.A.ToBigInteger());
            var b__element = new F2mFieldElement(curve.M, curve.K1, curve.K2, curve.K3, curve.B.ToBigInteger());

            var au__element = u__element.Multiply(u__element).Multiply(a__element);

            // 2. Вычисляем элемент основного поля w = u ^ 3 + A u ^ 2 + B
            var w__element = u__element.Multiply(u__element).Multiply(u__element).Add(au__element).Add(b__element);

            // 3. Решаем квадратное уравнение z^2 + uz = w
            var z__element = quadraticEquation(curve, u__element.ToBigInteger(), w__element.ToBigInteger());

            // 5. Принимают x = u, y = z
            var point = new F2mPoint(curve, u__element, z__element);

            return(point);
        }
Ejemplo n.º 11
0
 protected bool Equals(
  F2mFieldElement other)
 {
     return m == other.m
         && k1 == other.k1
         && k2 == other.k2
         && k3 == other.k3
         && representation == other.representation
         && base.Equals(other);
 }