public override ECPoint Add(ECPoint b) { if (base.IsInfinity) { return(b); } if (b.IsInfinity) { return(this); } if (this == b) { return(Twice()); } ECCurve curve = Curve; Curve25519FieldElement curve25519FieldElement = (Curve25519FieldElement)base.RawXCoord; Curve25519FieldElement curve25519FieldElement2 = (Curve25519FieldElement)base.RawYCoord; Curve25519FieldElement curve25519FieldElement3 = (Curve25519FieldElement)base.RawZCoords[0]; Curve25519FieldElement curve25519FieldElement4 = (Curve25519FieldElement)b.RawXCoord; Curve25519FieldElement curve25519FieldElement5 = (Curve25519FieldElement)b.RawYCoord; Curve25519FieldElement curve25519FieldElement6 = (Curve25519FieldElement)b.RawZCoords[0]; uint[] array = Nat256.CreateExt(); uint[] array2 = Nat256.Create(); uint[] array3 = Nat256.Create(); uint[] array4 = Nat256.Create(); bool isOne = curve25519FieldElement3.IsOne; uint[] array5; uint[] array6; if (isOne) { array5 = curve25519FieldElement4.x; array6 = curve25519FieldElement5.x; } else { array6 = array3; Curve25519Field.Square(curve25519FieldElement3.x, array6); array5 = array2; Curve25519Field.Multiply(array6, curve25519FieldElement4.x, array5); Curve25519Field.Multiply(array6, curve25519FieldElement3.x, array6); Curve25519Field.Multiply(array6, curve25519FieldElement5.x, array6); } bool isOne2 = curve25519FieldElement6.IsOne; uint[] array7; uint[] array8; if (isOne2) { array7 = curve25519FieldElement.x; array8 = curve25519FieldElement2.x; } else { array8 = array4; Curve25519Field.Square(curve25519FieldElement6.x, array8); array7 = array; Curve25519Field.Multiply(array8, curve25519FieldElement.x, array7); Curve25519Field.Multiply(array8, curve25519FieldElement6.x, array8); Curve25519Field.Multiply(array8, curve25519FieldElement2.x, array8); } uint[] array9 = Nat256.Create(); Curve25519Field.Subtract(array7, array5, array9); uint[] array10 = array2; Curve25519Field.Subtract(array8, array6, array10); if (Nat256.IsZero(array9)) { if (Nat256.IsZero(array10)) { return(Twice()); } return(curve.Infinity); } uint[] array11 = Nat256.Create(); Curve25519Field.Square(array9, array11); uint[] array12 = Nat256.Create(); Curve25519Field.Multiply(array11, array9, array12); uint[] array13 = array3; Curve25519Field.Multiply(array11, array7, array13); Curve25519Field.Negate(array12, array12); Nat256.Mul(array8, array12, array); uint x = Nat256.AddBothTo(array13, array13, array12); Curve25519Field.Reduce27(x, array12); Curve25519FieldElement curve25519FieldElement7 = new Curve25519FieldElement(array4); Curve25519Field.Square(array10, curve25519FieldElement7.x); Curve25519Field.Subtract(curve25519FieldElement7.x, array12, curve25519FieldElement7.x); Curve25519FieldElement curve25519FieldElement8 = new Curve25519FieldElement(array12); Curve25519Field.Subtract(array13, curve25519FieldElement7.x, curve25519FieldElement8.x); Curve25519Field.MultiplyAddToExt(curve25519FieldElement8.x, array10, array); Curve25519Field.Reduce(array, curve25519FieldElement8.x); Curve25519FieldElement curve25519FieldElement9 = new Curve25519FieldElement(array9); if (!isOne) { Curve25519Field.Multiply(curve25519FieldElement9.x, curve25519FieldElement3.x, curve25519FieldElement9.x); } if (!isOne2) { Curve25519Field.Multiply(curve25519FieldElement9.x, curve25519FieldElement6.x, curve25519FieldElement9.x); } uint[] zSquared = (isOne && isOne2) ? array11 : null; Curve25519FieldElement curve25519FieldElement10 = CalculateJacobianModifiedW(curve25519FieldElement9, zSquared); ECFieldElement[] zs = new ECFieldElement[2] { curve25519FieldElement9, curve25519FieldElement10 }; return(new Curve25519Point(curve, curve25519FieldElement7, curve25519FieldElement8, zs, base.IsCompressed)); }
public override ECFieldElement Negate() { uint[] z = Nat256.Create(); Curve25519Field.Negate(x, z); return(new Curve25519FieldElement(z)); }