operator * method
Multiply an Edwards curve point by a scalar.
This method multiplies an Edwards curve point by a scalar value using an efficient multiplication algorithm. The scalar value is provided as a BigInt, and the result is returned as a new Edwards curve point.
Parameters:
other
: The scalar value to multiply the point by.
Returns:
- A new Edwards curve point resulting from the multiplication.
Implementation
@override
EDPoint operator *(BigInt other) {
final BigInt x2 = _coords[0];
final BigInt t2 = _coords[3];
final BigInt y2 = _coords[1];
final BigInt z2 = _coords[2];
if (other == BigInt.zero) {
return EDPoint.infinity(curve: curve);
}
if (order != null) {
other %= (order! * BigInt.two);
}
_maybePrecompute();
if (_precompute.isNotEmpty) {
return _mulPrecompute(other);
}
BigInt x3 = BigInt.zero;
BigInt y3 = BigInt.one;
BigInt z3 = BigInt.one;
BigInt t3 = BigInt.one;
final nf = BigintUtils.computeNAF(other).reversed.toList();
for (final BigInt i in nf) {
final List<BigInt> resultCoords =
_double(x3, y3, z3, t3, curve.p, curve.a);
x3 = resultCoords[0];
y3 = resultCoords[1];
z3 = resultCoords[2];
t3 = resultCoords[3];
if (i < BigInt.zero) {
final List<BigInt> doubleCoords =
_add(x3, y3, z3, t3, -x2, y2, z2, -t2, curve.p, curve.a);
x3 = doubleCoords[0];
y3 = doubleCoords[1];
z3 = doubleCoords[2];
t3 = doubleCoords[3];
} else if (i > BigInt.zero) {
final List<BigInt> doubleCoords =
_add(x3, y3, z3, t3, x2, y2, z2, t2, curve.p, curve.a);
x3 = doubleCoords[0];
y3 = doubleCoords[1];
z3 = doubleCoords[2];
t3 = doubleCoords[3];
}
}
return EDPoint._(curve, [x3, y3, z3, t3], order: order);
}