Пример #1
0
        private static bool TrySqrt(uint[] nc, uint[] r, uint[] t)
        {
            uint[] d1 = Nat224.Create();
            Nat224.Copy(r, d1);
            uint[] e1 = Nat224.Create();
            e1[0] = 1;
            uint[] f1 = Nat224.Create();
            RP(nc, d1, e1, f1, t);

            uint[] d0 = Nat224.Create();
            uint[] e0 = Nat224.Create();

            for (int k = 1; k < 96; ++k)
            {
                Nat224.Copy(d1, d0);
                Nat224.Copy(e1, e0);

                RS(d1, e1, f1, t);

                if (Nat224.IsZero(d1))
                {
                    Mod.Invert(SecP224R1Field.P, e0, t);
                    SecP224R1Field.Multiply(t, d0, t);
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
 private static void RM(uint[] nc, uint[] d0, uint[] e0, uint[] d1, uint[] e1, uint[] f1, uint[] t)
 {
     SecP224R1Field.Multiply(e1, e0, t);
     SecP224R1Field.Multiply(t, nc, t);
     SecP224R1Field.Multiply(d1, d0, f1);
     SecP224R1Field.Add(f1, t, f1);
     SecP224R1Field.Multiply(d1, e0, t);
     Nat224.Copy(f1, d1);
     SecP224R1Field.Multiply(e1, d0, e1);
     SecP224R1Field.Add(e1, t, e1);
     SecP224R1Field.Square(e1, f1);
     SecP224R1Field.Multiply(f1, nc, f1);
 }
Пример #3
0
        private static bool IsSquare(uint[] x)
        {
            uint[] t1 = Nat224.Create();
            uint[] t2 = Nat224.Create();
            Nat224.Copy(x, t1);

            for (int i = 0; i < 7; ++i)
            {
                Nat224.Copy(t1, t2);
                SecP224R1Field.SquareN(t1, 1 << i, t1);
                SecP224R1Field.Multiply(t1, t2, t1);
            }

            SecP224R1Field.SquareN(t1, 95, t1);
            return(Nat224.IsOne(t1));
        }
Пример #4
0
        private static void RP(uint[] nc, uint[] d1, uint[] e1, uint[] f1, uint[] t)
        {
            Nat224.Copy(nc, f1);

            uint[] d0 = Nat224.Create();
            uint[] e0 = Nat224.Create();

            for (int i = 0; i < 7; ++i)
            {
                Nat224.Copy(d1, d0);
                Nat224.Copy(e1, e0);

                int j = 1 << i;
                while (--j >= 0)
                {
                    RS(d1, e1, f1, t);
                }

                RM(nc, d0, e0, d1, e1, f1, t);
            }
        }