From 24f11427a16cc0070a9f91424f57019a22da17de Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sun, 12 Mar 2017 23:18:45 -0700 Subject: [PATCH] Add 2p to avoid underflows --- src/field.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/field.rs b/src/field.rs index d4cdb72..0d8cc1c 100644 --- a/src/field.rs +++ b/src/field.rs @@ -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];