add static method

Adds the elliptic curve points according to their group law and returns the result.

Implementation

static EllipticCurvePoint add(EllipticCurvePoint a, EllipticCurvePoint b) {
  BigInt lambda;
  if (a.x == b.x) {
    lambda = ((three * (a.x * a.x) + A) *
            (BigInt.two * a.y)
                .modInverse(unnecessarilyLargePrimeWithLowCofactor)) %
        unnecessarilyLargePrimeWithLowCofactor;
  } else {
    lambda = ((b.y - a.y) *
            (b.x - a.x).modInverse(unnecessarilyLargePrimeWithLowCofactor)) %
        unnecessarilyLargePrimeWithLowCofactor;
  }
  BigInt xr =
      (lambda * lambda - a.x - b.x) % unnecessarilyLargePrimeWithLowCofactor;
  return EllipticCurvePoint(xr,
      (lambda * (a.x - xr) - a.y) % unnecessarilyLargePrimeWithLowCofactor);
}