Exemplo n.º 1
0
 public override ECFieldElement Add(ECFieldElement b)
 {
     uint[] z = Nat160.Create();
     SecP160R2Field.Add(x, ((SecP160R2FieldElement)b).x, z);
     return(new SecP160R2FieldElement(z));
 }
Exemplo n.º 2
0
    public override ECPoint Twice()
    {
        if (base.IsInfinity)
        {
            return(this);
        }
        ECCurve curve = Curve;
        SecP160R2FieldElement secP160R2FieldElement = (SecP160R2FieldElement)base.RawYCoord;

        if (secP160R2FieldElement.IsZero)
        {
            return(curve.Infinity);
        }
        SecP160R2FieldElement secP160R2FieldElement2 = (SecP160R2FieldElement)base.RawXCoord;
        SecP160R2FieldElement secP160R2FieldElement3 = (SecP160R2FieldElement)base.RawZCoords[0];

        uint[] array  = Nat160.Create();
        uint[] array2 = Nat160.Create();
        uint[] array3 = Nat160.Create();
        SecP160R2Field.Square(secP160R2FieldElement.x, array3);
        uint[] array4 = Nat160.Create();
        SecP160R2Field.Square(array3, array4);
        bool isOne = secP160R2FieldElement3.IsOne;

        uint[] array5 = secP160R2FieldElement3.x;
        if (!isOne)
        {
            array5 = array2;
            SecP160R2Field.Square(secP160R2FieldElement3.x, array5);
        }
        SecP160R2Field.Subtract(secP160R2FieldElement2.x, array5, array);
        uint[] array6 = array2;
        SecP160R2Field.Add(secP160R2FieldElement2.x, array5, array6);
        SecP160R2Field.Multiply(array6, array, array6);
        uint x = Nat160.AddBothTo(array6, array6, array6);

        SecP160R2Field.Reduce32(x, array6);
        uint[] array7 = array3;
        SecP160R2Field.Multiply(array3, secP160R2FieldElement2.x, array7);
        x = Nat.ShiftUpBits(5, array7, 2, 0u);
        SecP160R2Field.Reduce32(x, array7);
        x = Nat.ShiftUpBits(5, array4, 3, 0u, array);
        SecP160R2Field.Reduce32(x, array);
        SecP160R2FieldElement secP160R2FieldElement4 = new SecP160R2FieldElement(array4);

        SecP160R2Field.Square(array6, secP160R2FieldElement4.x);
        SecP160R2Field.Subtract(secP160R2FieldElement4.x, array7, secP160R2FieldElement4.x);
        SecP160R2Field.Subtract(secP160R2FieldElement4.x, array7, secP160R2FieldElement4.x);
        SecP160R2FieldElement secP160R2FieldElement5 = new SecP160R2FieldElement(array7);

        SecP160R2Field.Subtract(array7, secP160R2FieldElement4.x, secP160R2FieldElement5.x);
        SecP160R2Field.Multiply(secP160R2FieldElement5.x, array6, secP160R2FieldElement5.x);
        SecP160R2Field.Subtract(secP160R2FieldElement5.x, array, secP160R2FieldElement5.x);
        SecP160R2FieldElement secP160R2FieldElement6 = new SecP160R2FieldElement(array6);

        SecP160R2Field.Twice(secP160R2FieldElement.x, secP160R2FieldElement6.x);
        if (!isOne)
        {
            SecP160R2Field.Multiply(secP160R2FieldElement6.x, secP160R2FieldElement3.x, secP160R2FieldElement6.x);
        }
        return(new SecP160R2Point(curve, secP160R2FieldElement4, secP160R2FieldElement5, new ECFieldElement[1]
        {
            secP160R2FieldElement6
        }, base.IsCompressed));
    }