Add 2p to avoid underflows

This commit is contained in:
Henry de Valence 2017-03-12 23:18:45 -07:00
parent a9cbca668b
commit 24f11427a1

View file

@ -146,11 +146,11 @@ impl<'b> SubAssign<&'b FieldElement> for FieldElement {
fn sub_assign(&mut self, _rhs: &'b FieldElement) {
// To avoid underflow, first add p
// XXX how many copies should we add to preserve headroom?
self.0[0] += constants::p.0[0];
self.0[1] += constants::p.0[1];
self.0[2] += constants::p.0[2];
self.0[3] += constants::p.0[3];
self.0[4] += constants::p.0[4];
self.0[0] += 2*constants::p.0[0];
self.0[1] += 2*constants::p.0[1];
self.0[2] += 2*constants::p.0[2];
self.0[3] += 2*constants::p.0[3];
self.0[4] += 2*constants::p.0[4];
// then subtract _rhs
self.0[0] -= _rhs.0[0];
self.0[1] -= _rhs.0[1];