operator + method

  1. @override
AbstractPoint operator +(
  1. AbstractPoint other
)
override

Overrides the addition operator (+) to perform point addition between this AffinePointt and another AbstractPoint. The result is a new AffinePointt. If one of the points is the point at infinity, it returns the other point. If the x-coordinates of both points are equal, and the sum of their y-coordinates modulo curve.p equals zero, the result is the point at infinity. Otherwise, it computes the sum using the provided addition formula.

Returns a new AffinePointt representing the result of the point addition.

Implementation

@override
AbstractPoint operator +(AbstractPoint other) {
  if (other is! AffinePointt && other is! ProjectiveECCPoint) {
    throw ArgumentException("cannot add with ${other.runtimeType} point");
  }
  if (other is ProjectiveECCPoint) {
    return other + this;
  }
  other as AffinePointt;
  if (other.isInfinity) {
    return this;
  }
  if (isInfinity) {
    return other;
  }
  assert(curve == other.curve);
  if (x == other.x) {
    if ((y + other.y) % curve.p == BigInt.zero) {
      return AffinePointt(curve, BigInt.zero, BigInt.zero);
    } else {
      return doublePoint();
    }
  }

  BigInt p = curve.p;
  BigInt l = (other.y - y) * BigintUtils.inverseMod(other.x - x, p) % p;

  BigInt x3 = (l * l - x - other.x) % p;
  BigInt y3 = (l * (x - x3) - y) % p;

  return AffinePointt(curve, x3, y3, order: null);
}