operator + method

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

Addition operator for two Edwards curve points.

This operator performs point addition on the Edwards curve. It checks if the points are on the same curve and not at infinity, then calculates the result of the addition operation and returns a new Edwards curve point.

Parameters:

  • other: The other Edwards curve point to add to this point.

Returns:

  • A new Edwards curve point representing the result of the addition.

Throws:

  • ArgumentException: If the 'other' point is on a different curve or at infinity.

Implementation

@override
EDPoint operator +(AbstractPoint other) {
  if (other is! EDPoint || curve != other.curve) {
    throw ArgumentException("The other point is on a different curve.");
  }
  if (other.isInfinity) {
    return this;
  }
  BigInt p = curve.p;
  BigInt a = curve.a;

  BigInt x1 = _coords[0];
  BigInt y1 = _coords[1];
  BigInt z1 = _coords[2];
  BigInt t1 = _coords[3];

  BigInt x2 = other._coords[0];
  BigInt y2 = other._coords[1];
  BigInt z2 = other._coords[2];
  BigInt t2 = other._coords[3];

  List<BigInt> result = _add(x1, y1, z1, t1, x2, y2, z2, t2, p, a);
  if (result[0] == BigInt.zero || result[3] == BigInt.zero) {
    return EDPoint.infinity(curve: curve);
  }

  return EDPoint(
      curve: curve,
      x: result[0],
      y: result[1],
      z: result[2],
      t: result[3],
      order: order);
}