scale method

EDPoint scale()

Scale the Edwards curve point.

This method scales the point by converting it to projective coordinates (if not already), performing the scaling operation, and then converting it back to extended coordinates.

Returns:

  • A reference to the scaled Edwards curve point.

Implementation

EDPoint scale() {
  BigInt z1 = _coords[2];

  /// If the z-coordinate is already 1, the point is already in projective form, and no scaling is required.
  if (z1 == BigInt.one) {
    return this;
  }
  BigInt x1 = _coords[0];
  BigInt y1 = _coords[1];

  /// Retrieve the prime value (p) of the curve.
  BigInt p = curve.p;

  /// Compute the inverse of z1 modulo p.
  BigInt zInv = BigintUtils.inverseMod(z1, p);
  BigInt x = (x1 * zInv) % p;
  BigInt y = (y1 * zInv) % p;
  BigInt t = (x * y) % p;

  /// Update the coordinates to their scaled values and set z-coordinate to 1 (projective form).
  _coords[0] = x;
  _coords[1] = y;
  _coords[2] = BigInt.one;
  _coords[3] = t;

  return this;
}