mapToPoint static method

EDPoint mapToPoint(
  1. BigInt r0
)

Maps a BigInt 'r0' to an Edwards curve point (EDPoint).

This static method maps a given 'r0' value to an Edwards curve point using a series of calculations and modular arithmetic. The resulting point is returned as an instance of EDPoint.

Parameters:

  • r0: The input BigInt 'r0' value to be mapped to a point.

Returns:

  • EDPoint: The Edwards curve point mapped from the input 'r0'.

Details:

  • The method performs calculations to derive various intermediate values, computes the coordinates of the Edwards curve point, and ensures that the final point is correctly mapped from the input 'r0'.

Implementation

static EDPoint mapToPoint(BigInt r0) {
  final curveD = Curves.generatorED25519.curve.d;
  final primeP = Curves.curveEd25519.p;

  final rSquared =
      ristretto_tools.positiveMod(ristretto_tools.sqrtM1 * r0 * r0, primeP);
  final numeratorS = ristretto_tools.positiveMod(
      (rSquared + BigInt.one) * ristretto_tools.oneMinusDSq, primeP);

  var c = BigInt.from(-1);

  final D = ristretto_tools.positiveMod(
      (c - curveD * rSquared) *
          ristretto_tools.positiveMod(rSquared + curveD, primeP),
      primeP);

  final uvRatio = ristretto_tools.sqrtUV(numeratorS, D);

  final useSecondRoot = uvRatio.item1;
  BigInt sValue = uvRatio.item2;

  BigInt sComputed = ristretto_tools.positiveMod(sValue * r0, primeP);

  if (!ristretto_tools.isOdd(sComputed, primeP)) {
    sComputed = ristretto_tools.positiveMod(-sComputed, primeP);
  }

  if (!useSecondRoot) {
    sValue = sComputed;
  }

  if (!useSecondRoot) {
    c = rSquared;
  }

  final ntValue = ristretto_tools.positiveMod(
      c * (rSquared - BigInt.one) * ristretto_tools.minusOneSq - D, primeP);

  final sSquared = sValue * sValue;
  final w0 = ristretto_tools.positiveMod((sValue + sValue) * D, primeP);
  final w1 = ristretto_tools.positiveMod(
      ntValue * ristretto_tools.sqrtAdMinusOne, primeP);
  final w2 = ristretto_tools.positiveMod(BigInt.one - sSquared, primeP);
  final w3 = ristretto_tools.positiveMod(BigInt.one + sSquared, primeP);

  return EDPoint(
      curve: Curves.curveEd25519,
      x: ristretto_tools.positiveMod(w0 * w3, primeP),
      y: ristretto_tools.positiveMod(w2 * w1, primeP),
      z: ristretto_tools.positiveMod(w1 * w3, primeP),
      t: ristretto_tools.positiveMod(w0 * w2, primeP));
}