Exemple #1
0
        public static void Invert(ulong[] x, ulong[] z)
        {
            if (Nat256.IsZero64(x))
            {
                throw new InvalidOperationException();
            }

            // Itoh-Tsujii inversion

            ulong[] t0 = Nat256.Create64();
            ulong[] t1 = Nat256.Create64();

            Square(x, t0);
            Multiply(t0, x, t0);
            Square(t0, t0);
            Multiply(t0, x, t0);
            SquareN(t0, 3, t1);
            Multiply(t1, t0, t1);
            Square(t1, t1);
            Multiply(t1, x, t1);
            SquareN(t1, 7, t0);
            Multiply(t0, t1, t0);
            SquareN(t0, 14, t1);
            Multiply(t1, t0, t1);
            Square(t1, t1);
            Multiply(t1, x, t1);
            SquareN(t1, 29, t0);
            Multiply(t0, t1, t0);
            SquareN(t0, 58, t1);
            Multiply(t1, t0, t1);
            SquareN(t1, 116, t0);
            Multiply(t0, t1, t0);
            Square(t0, z);
        }
Exemple #2
0
 public static void Invert(ulong[] x, ulong[] z)
 {
     if (Nat256.IsZero64(x))
     {
         throw new InvalidOperationException();
     }
     ulong[] array  = Nat256.Create64();
     ulong[] array2 = Nat256.Create64();
     Square(x, array);
     Multiply(array, x, array);
     Square(array, array);
     Multiply(array, x, array);
     SquareN(array, 3, array2);
     Multiply(array2, array, array2);
     Square(array2, array2);
     Multiply(array2, x, array2);
     SquareN(array2, 7, array);
     Multiply(array, array2, array);
     SquareN(array, 14, array2);
     Multiply(array2, array, array2);
     Square(array2, array2);
     Multiply(array2, x, array2);
     SquareN(array2, 29, array);
     Multiply(array, array2, array);
     Square(array, array);
     Multiply(array, x, array);
     SquareN(array, 59, array2);
     Multiply(array2, array, array2);
     Square(array2, array2);
     Multiply(array2, x, array2);
     SquareN(array2, 119, array);
     Multiply(array, array2, array);
     Square(array, z);
 }
Exemple #3
0
        public static void Invert(ulong[] x, ulong[] z)
        {
            if (Nat256.IsZero64(x))
            {
                throw new InvalidOperationException();
            }

            // Itoh-Tsujii inversion with bases { 2, 3 }

            ulong[] t0 = Nat256.Create64();
            ulong[] t1 = Nat256.Create64();

            Square(x, t0);

            // 3 | 192
            SquareN(t0, 1, t1);
            Multiply(t0, t1, t0);
            SquareN(t1, 1, t1);
            Multiply(t0, t1, t0);

            // 2 | 64
            SquareN(t0, 3, t1);
            Multiply(t0, t1, t0);

            // 2 | 32
            SquareN(t0, 6, t1);
            Multiply(t0, t1, t0);

            // 2 | 16
            SquareN(t0, 12, t1);
            Multiply(t0, t1, t0);

            // 2 | 8
            SquareN(t0, 24, t1);
            Multiply(t0, t1, t0);

            // 2 | 4
            SquareN(t0, 48, t1);
            Multiply(t0, t1, t0);

            // 2 | 2
            SquareN(t0, 96, t1);
            Multiply(t0, t1, z);
        }