twice method

  1. @override
ECPoint? twice()
override

Implementation

@override
ECPoint? twice() {
  if (isInfinity) {
    // Twice identity element (point at infinity) is identity
    return this;
  }

  if (y!.toBigInteger() == BigInt.zero) {
    // if y1 == 0, then (x1, y1) == (x1, -y1)
    // and hence this = -this and thus 2(x1, y1) == infinity
    return curve.infinity as ECPoint?;
  }

  var two = curve.fromBigInteger(BigInt.two);
  var three = curve.fromBigInteger(BigInt.from(3));
  var gamma = ((x!.square() * three) + curve.a!) / (y! * two);

  var x3 = gamma.square() - (x! * two);
  var y3 = (gamma * (x! - x3)) - y!;

  return ECPoint(curve as ECCurve, x3 as ECFieldElement?,
      y3 as ECFieldElement?, isCompressed);
}