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);
     if (!Nat192.Eq(y, array2))
     {
         return(null);
     }
     return(new SecP192R1FieldElement(array));
 }
 public override ECFieldElement Divide(ECFieldElement b)
 {
     uint[] z = Nat192.Create();
     Mod.Invert(SecP192R1Field.P, ((SecP192R1FieldElement)b).x, z);
     SecP192R1Field.Multiply(z, x, z);
     return(new SecP192R1FieldElement(z));
 }
 public SecP192R1FieldElement(BigInteger x)
 {
     if (x == null || x.SignValue < 0 || x.CompareTo(Q) >= 0)
     {
         throw new ArgumentException("value invalid for SecP192R1FieldElement", "x");
     }
     this.x = SecP192R1Field.FromBigInteger(x);
 }
 public override ECFieldElement Square()
 {
     uint[] z = Nat192.Create();
     SecP192R1Field.Square(x, z);
     return(new SecP192R1FieldElement(z));
 }
 public override ECFieldElement Multiply(ECFieldElement b)
 {
     uint[] z = Nat192.Create();
     SecP192R1Field.Multiply(x, ((SecP192R1FieldElement)b).x, z);
     return(new SecP192R1FieldElement(z));
 }
 public override ECFieldElement Subtract(ECFieldElement b)
 {
     uint[] z = Nat192.Create();
     SecP192R1Field.Subtract(x, ((SecP192R1FieldElement)b).x, z);
     return(new SecP192R1FieldElement(z));
 }
    public override ECPoint Add(ECPoint b)
    {
        if (base.IsInfinity)
        {
            return(b);
        }
        if (b.IsInfinity)
        {
            return(this);
        }
        if (this == b)
        {
            return(Twice());
        }
        ECCurve curve = Curve;
        SecP192R1FieldElement secP192R1FieldElement  = (SecP192R1FieldElement)base.RawXCoord;
        SecP192R1FieldElement secP192R1FieldElement2 = (SecP192R1FieldElement)base.RawYCoord;
        SecP192R1FieldElement secP192R1FieldElement3 = (SecP192R1FieldElement)b.RawXCoord;
        SecP192R1FieldElement secP192R1FieldElement4 = (SecP192R1FieldElement)b.RawYCoord;
        SecP192R1FieldElement secP192R1FieldElement5 = (SecP192R1FieldElement)base.RawZCoords[0];
        SecP192R1FieldElement secP192R1FieldElement6 = (SecP192R1FieldElement)b.RawZCoords[0];

        uint[] array  = Nat192.CreateExt();
        uint[] array2 = Nat192.Create();
        uint[] array3 = Nat192.Create();
        uint[] array4 = Nat192.Create();
        bool   isOne  = secP192R1FieldElement5.IsOne;

        uint[] array5;
        uint[] array6;
        if (isOne)
        {
            array5 = secP192R1FieldElement3.x;
            array6 = secP192R1FieldElement4.x;
        }
        else
        {
            array6 = array3;
            SecP192R1Field.Square(secP192R1FieldElement5.x, array6);
            array5 = array2;
            SecP192R1Field.Multiply(array6, secP192R1FieldElement3.x, array5);
            SecP192R1Field.Multiply(array6, secP192R1FieldElement5.x, array6);
            SecP192R1Field.Multiply(array6, secP192R1FieldElement4.x, array6);
        }
        bool isOne2 = secP192R1FieldElement6.IsOne;

        uint[] array7;
        uint[] array8;
        if (isOne2)
        {
            array7 = secP192R1FieldElement.x;
            array8 = secP192R1FieldElement2.x;
        }
        else
        {
            array8 = array4;
            SecP192R1Field.Square(secP192R1FieldElement6.x, array8);
            array7 = array;
            SecP192R1Field.Multiply(array8, secP192R1FieldElement.x, array7);
            SecP192R1Field.Multiply(array8, secP192R1FieldElement6.x, array8);
            SecP192R1Field.Multiply(array8, secP192R1FieldElement2.x, array8);
        }
        uint[] array9 = Nat192.Create();
        SecP192R1Field.Subtract(array7, array5, array9);
        uint[] array10 = array2;
        SecP192R1Field.Subtract(array8, array6, array10);
        if (Nat192.IsZero(array9))
        {
            if (Nat192.IsZero(array10))
            {
                return(Twice());
            }
            return(curve.Infinity);
        }
        uint[] array11 = array3;
        SecP192R1Field.Square(array9, array11);
        uint[] array12 = Nat192.Create();
        SecP192R1Field.Multiply(array11, array9, array12);
        uint[] array13 = array3;
        SecP192R1Field.Multiply(array11, array7, array13);
        SecP192R1Field.Negate(array12, array12);
        Nat192.Mul(array8, array12, array);
        uint x = Nat192.AddBothTo(array13, array13, array12);

        SecP192R1Field.Reduce32(x, array12);
        SecP192R1FieldElement secP192R1FieldElement7 = new SecP192R1FieldElement(array4);

        SecP192R1Field.Square(array10, secP192R1FieldElement7.x);
        SecP192R1Field.Subtract(secP192R1FieldElement7.x, array12, secP192R1FieldElement7.x);
        SecP192R1FieldElement secP192R1FieldElement8 = new SecP192R1FieldElement(array12);

        SecP192R1Field.Subtract(array13, secP192R1FieldElement7.x, secP192R1FieldElement8.x);
        SecP192R1Field.MultiplyAddToExt(secP192R1FieldElement8.x, array10, array);
        SecP192R1Field.Reduce(array, secP192R1FieldElement8.x);
        SecP192R1FieldElement secP192R1FieldElement9 = new SecP192R1FieldElement(array9);

        if (!isOne)
        {
            SecP192R1Field.Multiply(secP192R1FieldElement9.x, secP192R1FieldElement5.x, secP192R1FieldElement9.x);
        }
        if (!isOne2)
        {
            SecP192R1Field.Multiply(secP192R1FieldElement9.x, secP192R1FieldElement6.x, secP192R1FieldElement9.x);
        }
        ECFieldElement[] zs = new ECFieldElement[1]
        {
            secP192R1FieldElement9
        };
        return(new SecP192R1Point(curve, secP192R1FieldElement7, secP192R1FieldElement8, zs, base.IsCompressed));
    }
    public override ECPoint Twice()
    {
        if (base.IsInfinity)
        {
            return(this);
        }
        ECCurve curve = Curve;
        SecP192R1FieldElement secP192R1FieldElement = (SecP192R1FieldElement)base.RawYCoord;

        if (secP192R1FieldElement.IsZero)
        {
            return(curve.Infinity);
        }
        SecP192R1FieldElement secP192R1FieldElement2 = (SecP192R1FieldElement)base.RawXCoord;
        SecP192R1FieldElement secP192R1FieldElement3 = (SecP192R1FieldElement)base.RawZCoords[0];

        uint[] array  = Nat192.Create();
        uint[] array2 = Nat192.Create();
        uint[] array3 = Nat192.Create();
        SecP192R1Field.Square(secP192R1FieldElement.x, array3);
        uint[] array4 = Nat192.Create();
        SecP192R1Field.Square(array3, array4);
        bool isOne = secP192R1FieldElement3.IsOne;

        uint[] array5 = secP192R1FieldElement3.x;
        if (!isOne)
        {
            array5 = array2;
            SecP192R1Field.Square(secP192R1FieldElement3.x, array5);
        }
        SecP192R1Field.Subtract(secP192R1FieldElement2.x, array5, array);
        uint[] array6 = array2;
        SecP192R1Field.Add(secP192R1FieldElement2.x, array5, array6);
        SecP192R1Field.Multiply(array6, array, array6);
        uint x = Nat192.AddBothTo(array6, array6, array6);

        SecP192R1Field.Reduce32(x, array6);
        uint[] array7 = array3;
        SecP192R1Field.Multiply(array3, secP192R1FieldElement2.x, array7);
        x = Nat.ShiftUpBits(6, array7, 2, 0u);
        SecP192R1Field.Reduce32(x, array7);
        x = Nat.ShiftUpBits(6, array4, 3, 0u, array);
        SecP192R1Field.Reduce32(x, array);
        SecP192R1FieldElement secP192R1FieldElement4 = new SecP192R1FieldElement(array4);

        SecP192R1Field.Square(array6, secP192R1FieldElement4.x);
        SecP192R1Field.Subtract(secP192R1FieldElement4.x, array7, secP192R1FieldElement4.x);
        SecP192R1Field.Subtract(secP192R1FieldElement4.x, array7, secP192R1FieldElement4.x);
        SecP192R1FieldElement secP192R1FieldElement5 = new SecP192R1FieldElement(array7);

        SecP192R1Field.Subtract(array7, secP192R1FieldElement4.x, secP192R1FieldElement5.x);
        SecP192R1Field.Multiply(secP192R1FieldElement5.x, array6, secP192R1FieldElement5.x);
        SecP192R1Field.Subtract(secP192R1FieldElement5.x, array, secP192R1FieldElement5.x);
        SecP192R1FieldElement secP192R1FieldElement6 = new SecP192R1FieldElement(array6);

        SecP192R1Field.Twice(secP192R1FieldElement.x, secP192R1FieldElement6.x);
        if (!isOne)
        {
            SecP192R1Field.Multiply(secP192R1FieldElement6.x, secP192R1FieldElement3.x, secP192R1FieldElement6.x);
        }
        return(new SecP192R1Point(curve, secP192R1FieldElement4, secP192R1FieldElement5, new ECFieldElement[1]
        {
            secP192R1FieldElement6
        }, base.IsCompressed));
    }