operator + method
Implementation
@override
Secp256k1Point operator +(Secp256k1Point other) {
// Branch-free style: always compute formula + double, select via masks.
final z1z1 = z.square();
final z2z2 = other.z.square();
final u1 = x * z2z2;
final u2 = other.x * z1z1;
var s1 = y * z2z2 * other.z;
var s2 = other.y * z1z1 * z;
final h = u2 - u1;
final i = (h + h).square();
final j = h * i;
var r = (s2 - s1);
r = r + r;
final v = u1 * i;
final x3 = r.square() - j - v - v;
final s1j = s1 * j;
final y3 = r * (v - x3) - s1j - s1j;
final z3 = ((z + other.z).square() - z1z1 - z2z2) * h;
var sum = from(x: x3, y: y3, z: z3);
// All comparisons below fold to 0/1 masks: no bool branches on the
// (secret) point data.
final eqU = Uint64.ctEqualsMask(u1.limbs, u2.limbs) & Uint64.one;
final eqS = Uint64.ctEqualsMask(s1.limbs, s2.limbs) & Uint64.one;
sum = conditionalSelectMask(sum, double(), eqU & eqS);
sum = conditionalSelectMask(sum, identity(), eqU & ~eqS);
final inf1 =
Uint64.isZeroMask(z.limbs[0] | z.limbs[1] | z.limbs[2] | z.limbs[3]) &
Uint64.one;
final inf2 =
Uint64.isZeroMask(
other.z.limbs[0] |
other.z.limbs[1] |
other.z.limbs[2] |
other.z.limbs[3],
) &
Uint64.one;
sum = conditionalSelectMask(sum, other, inf1);
sum = conditionalSelectMask(sum, this, inf2);
return sum;
}