mul method

Point mul(
  1. BigInt n, [
  2. bool safe = true
])

Point scalar multiplication.

Implementation

Point mul(BigInt n, [bool safe = true]) {
  if (!safe && n == BigInt.zero) {
    // in unsafe mode, allow zero
    return I;
  }
  if (!Utilities.ge(n)) {
    // must be 0 < n < CURVE.n
    throw Exception('invalid scalar');
  }
  if (equals(G)) {
    // use precomputes for base point
    return WNAF.wNAF(n).p;
  }
  // init result point & fake point
  var p = I, f = G;
  for (var d = this; n > BigInt.zero; d = d.double(), n >>= 1) {
    // double-and-add ladder
    if ((n & BigInt.one) == BigInt.one) {
      // if bit is present, add to point
      p = p.add(d);
    } else if (safe) {
      // if not, add to fake for timing safety
      f = f.add(d);
    }
  }
  return p;
}