subMod method

Secp256r1Fr subMod()

Implementation

Secp256r1Fr subMod() {
  var t = Uint64.sbb(limbs[0], Secp256r1FrConst.modulusLimbs[0], Uint64.zero);
  Uint64 d0 = t.$1;
  Uint64 b = t.$2;
  t = Uint64.sbb(limbs[1], Secp256r1FrConst.modulusLimbs[1], b);
  Uint64 d1 = t.$1;
  b = t.$2;
  t = Uint64.sbb(limbs[2], Secp256r1FrConst.modulusLimbs[2], b);
  Uint64 d2 = t.$1;
  b = t.$2;
  t = Uint64.sbb(limbs[3], Secp256r1FrConst.modulusLimbs[3], b);
  Uint64 d3 = t.$1;
  b = t.$2;
  // Keep d iff no borrow (limbs >= mod), else keep limbs — mask blend,
  // no early return.
  final d = Secp256r1Fr([d0, d1, d2, d3]);
  return Secp256r1Fr.conditionalSelectMask(this, d, (~b) & Uint64.one);
}