subMod method

Ed25519Fr subMod()

Implementation

Ed25519Fr subMod() {
  var t = Uint64.sbb(limbs[0], Ed25519FrConst.modulusLimbs[0], Uint64.zero);
  Uint64 d0 = t.$1;
  Uint64 b = t.$2;
  t = Uint64.sbb(limbs[1], Ed25519FrConst.modulusLimbs[1], b);
  Uint64 d1 = t.$1;
  b = t.$2;
  t = Uint64.sbb(limbs[2], Ed25519FrConst.modulusLimbs[2], b);
  Uint64 d2 = t.$1;
  b = t.$2;
  t = Uint64.sbb(limbs[3], Ed25519FrConst.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. t.$2 is a borrow mask (all-ones iff borrow).
  final d = Ed25519Fr([d0, d1, d2, d3]);
  return Ed25519Fr.conditionalSelectMask(this, d, (~b) & Uint64.one);
}