mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Add 2p to avoid underflows
This commit is contained in:
parent
a9cbca668b
commit
24f11427a1
1 changed files with 5 additions and 5 deletions
10
src/field.rs
10
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];
|
||||
|
|
|
|||
Loading…
Reference in a new issue