コード例 #1
0
 public override ECFieldElement Sqrt()
 {
     uint[] x = this.x;
     if (Nat192.IsZero(x) || Nat192.IsOne(x))
     {
         return(this);
     }
     uint[] z         = Nat192.Create();
     uint[] numArray3 = Nat192.Create();
     SecP192R1Field.Square(x, z);
     SecP192R1Field.Multiply(z, x, z);
     SecP192R1Field.SquareN(z, 2, numArray3);
     SecP192R1Field.Multiply(numArray3, z, numArray3);
     SecP192R1Field.SquareN(numArray3, 4, z);
     SecP192R1Field.Multiply(z, numArray3, z);
     SecP192R1Field.SquareN(z, 8, numArray3);
     SecP192R1Field.Multiply(numArray3, z, numArray3);
     SecP192R1Field.SquareN(numArray3, 0x10, z);
     SecP192R1Field.Multiply(z, numArray3, z);
     SecP192R1Field.SquareN(z, 0x20, numArray3);
     SecP192R1Field.Multiply(numArray3, z, numArray3);
     SecP192R1Field.SquareN(numArray3, 0x40, z);
     SecP192R1Field.Multiply(z, numArray3, z);
     SecP192R1Field.SquareN(z, 0x3e, z);
     SecP192R1Field.Square(z, numArray3);
     return(!Nat192.Eq(x, numArray3) ? null : new SecP192R1FieldElement(z));
 }
コード例 #2
0
 public override ECFieldElement Sqrt()
 {
     uint[] y = x;
     if (Nat192.IsZero(y) || Nat192.IsOne(y))
     {
         return(this);
     }
     uint[] array  = Nat192.Create();
     uint[] array2 = Nat192.Create();
     SecP192R1Field.Square(y, array);
     SecP192R1Field.Multiply(array, y, array);
     SecP192R1Field.SquareN(array, 2, array2);
     SecP192R1Field.Multiply(array2, array, array2);
     SecP192R1Field.SquareN(array2, 4, array);
     SecP192R1Field.Multiply(array, array2, array);
     SecP192R1Field.SquareN(array, 8, array2);
     SecP192R1Field.Multiply(array2, array, array2);
     SecP192R1Field.SquareN(array2, 16, array);
     SecP192R1Field.Multiply(array, array2, array);
     SecP192R1Field.SquareN(array, 32, array2);
     SecP192R1Field.Multiply(array2, array, array2);
     SecP192R1Field.SquareN(array2, 64, array);
     SecP192R1Field.Multiply(array, array2, array);
     SecP192R1Field.SquareN(array, 62, array);
     SecP192R1Field.Square(array, array2);
     return((!Nat192.Eq(y, array2)) ? null : new SecP192R1FieldElement(array));
 }
コード例 #3
0
        /**
         * return a sqrt root - the routine verifies that the calculation returns the right value - if
         * none exists it returns null.
         */
        public override ECFieldElement Sqrt()
        {
            // Raise this element to the exponent 2^190 - 2^62

            uint[] x1 = this.x;
            if (Nat192.IsZero(x1) || Nat192.IsOne(x1))
            {
                return(this);
            }

            uint[] t1 = Nat192.Create();
            uint[] t2 = Nat192.Create();

            SecP192R1Field.Square(x1, t1);
            SecP192R1Field.Multiply(t1, x1, t1);

            SecP192R1Field.SquareN(t1, 2, t2);
            SecP192R1Field.Multiply(t2, t1, t2);

            SecP192R1Field.SquareN(t2, 4, t1);
            SecP192R1Field.Multiply(t1, t2, t1);

            SecP192R1Field.SquareN(t1, 8, t2);
            SecP192R1Field.Multiply(t2, t1, t2);

            SecP192R1Field.SquareN(t2, 16, t1);
            SecP192R1Field.Multiply(t1, t2, t1);

            SecP192R1Field.SquareN(t1, 32, t2);
            SecP192R1Field.Multiply(t2, t1, t2);

            SecP192R1Field.SquareN(t2, 64, t1);
            SecP192R1Field.Multiply(t1, t2, t1);

            SecP192R1Field.SquareN(t1, 62, t1);
            SecP192R1Field.Square(t1, t2);

            return(Nat192.Eq(x1, t2) ? new SecP192R1FieldElement(t1) : null);
        }