pow method

JubJubFq pow(
  1. List<BigInt> by
)

Implementation

JubJubFq pow(List<BigInt> by) {
  JubJubFq res = JubJubFq.one();

  // Loop over exponent words, from high → low
  for (final e in by.reversed) {
    // Loop bits from highest to lowest
    for (int i = 63; i >= 0; i--) {
      res = res.square();

      JubJubFq tmp = res;
      tmp = tmp * this;

      // Extract bit: ((e >> i) & 1)
      final bit = ((e >> i) & BigInt.one) == BigInt.one;

      // Constant-time conditional assign
      res = bit ? tmp : res;
    }
  }

  return res;
}