multiply static method
Multiplies an elliptic curve point with another number usind the efficient double and add scheme. NOTE: This is not secure against side-channel-attacks. If you need security against side-channel-attacks, change the if statement so that both clauses consume the same amount of CPU cycles and energy in any case.
Implementation
static EllipticCurvePoint multiply(
EllipticCurvePoint ellipticCurvePoint, BigInt n) {
BigInt done_additions = BigInt.zero;
EllipticCurvePoint result = ellipticCurvePoint;
while (done_additions < n) {
if ((n - done_additions).isEven) {
result = add(result, result);
done_additions += ((n - done_additions) ~/ BigInt.two);
} else {
result = add(result, ellipticCurvePoint);
done_additions += BigInt.one;
}
}
return result;
}