From 8337a895d46fd1d4e00a7d39dd2e858997e2bc3d Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 17 Nov 2017 13:32:22 -0800 Subject: [PATCH] Only compress ExtendedPoints --- src/curve_models/mod.rs | 12 ------------ src/edwards.rs | 9 ++++++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/curve_models/mod.rs b/src/curve_models/mod.rs index 7669a5e..aba35fe 100644 --- a/src/curve_models/mod.rs +++ b/src/curve_models/mod.rs @@ -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. /// diff --git a/src/edwards.rs b/src/edwards.rs index 58970e7..b2fb397 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -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) } }