Only compress ExtendedPoints

This commit is contained in:
Henry de Valence 2017-11-17 13:32:22 -08:00
parent 7f52745770
commit 8337a895d4
2 changed files with 8 additions and 13 deletions

View file

@ -232,18 +232,6 @@ impl ProjectivePoint {
}
}
/// Convert this point to a `CompressedEdwardsY`
pub fn compress(&self) -> CompressedEdwardsY {
let recip = self.Z.invert();
let x = &self.X * &recip;
let y = &self.Y * &recip;
let mut s: [u8; 32];
s = y.to_bytes();
s[31] ^= (x.is_negative() << 7) as u8;
CompressedEdwardsY(s)
}
/// Convert this projective point in the Edwards model to its equivalent
/// projective point on the Montgomery form of the curve.
///

View file

@ -277,7 +277,14 @@ impl ExtendedPoint {
/// Compress this point to `CompressedEdwardsY` format.
pub fn compress(&self) -> CompressedEdwardsY {
self.to_projective().compress()
let recip = self.Z.invert();
let x = &self.X * &recip;
let y = &self.Y * &recip;
let mut s: [u8; 32];
s = y.to_bytes();
s[31] ^= (x.is_negative() << 7) as u8;
CompressedEdwardsY(s)
}
}