mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Add p constant for subtraction
This commit is contained in:
parent
08ef9e5d1e
commit
3eab4acbd8
2 changed files with 17 additions and 5 deletions
|
|
@ -26,6 +26,9 @@ use curve::CompressedEdwardsY;
|
|||
use curve::EdwardsBasepointTable;
|
||||
use scalar::Scalar;
|
||||
|
||||
#[cfg(feature="radix_51")]
|
||||
pub const p: FieldElement = FieldElement([2251799813685229, 2251799813685247, 2251799813685247, 2251799813685247, 2251799813685247]);
|
||||
|
||||
#[cfg(feature="radix_25_5")]
|
||||
pub const d: FieldElement = FieldElement([
|
||||
-10913610, 13857413, -15372611, 6949391, 114729,
|
||||
|
|
|
|||
19
src/field.rs
19
src/field.rs
|
|
@ -244,11 +244,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] += 2251799813685229;
|
||||
self.0[1] += 2251799813685247;
|
||||
self.0[2] += 2251799813685247;
|
||||
self.0[3] += 2251799813685247;
|
||||
self.0[4] += 2251799813685247;
|
||||
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];
|
||||
// then subtract _rhs
|
||||
self.0[0] -= _rhs.0[0];
|
||||
self.0[1] -= _rhs.0[1];
|
||||
|
|
@ -338,6 +338,15 @@ impl FieldElement {
|
|||
self[i] = -self[i];
|
||||
}
|
||||
}
|
||||
#[cfg(feature="radix_51")]
|
||||
pub fn negate(&mut self) {
|
||||
// XXX how many copies of p
|
||||
self.0[0] = constants::p.0[0] - self.0[0];
|
||||
self.0[1] = constants::p.0[1] - self.0[1];
|
||||
self.0[2] = constants::p.0[2] - self.0[2];
|
||||
self.0[3] = constants::p.0[3] - self.0[3];
|
||||
self.0[4] = constants::p.0[4] - self.0[4];
|
||||
}
|
||||
|
||||
/// Construct the additive identity
|
||||
#[cfg(feature="radix_25_5")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue