From 20ace8da48da63fd2730f192f705f013778e2fb5 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Sat, 4 Mar 2017 02:26:36 +0000 Subject: [PATCH] Rename compress() to compress_edwards(). --- src/curve.rs | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/curve.rs b/src/curve.rs index 92457c5..a05f90b 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -449,7 +449,7 @@ impl CTAssignable for AffineNielsPoint { impl CTEq for ExtendedPoint { fn ct_eq(&self, other: &ExtendedPoint) -> u8 { - arrays_equal_ct(&self.compress().0, &other.compress().0) + arrays_equal_ct(&self.compress_edwards().0, &other.compress_edwards().0) } } @@ -498,7 +498,7 @@ impl ProjectivePoint { } /// Convert this point to a `CompressedEdwardsY` - pub fn compress(&self) -> CompressedEdwardsY { + pub fn compress_edwards(&self) -> CompressedEdwardsY { let recip = self.Z.invert(); let x = &self.X * &recip; let y = &self.Y * &recip; @@ -563,11 +563,6 @@ impl ExtendedPoint { } } - /// Compress this point to `CompressedEdwardsY` format - pub fn compress(&self) -> CompressedEdwardsY { - self.to_projective().compress() - } - /// Dehomogenize to a AffineNielsPoint. /// Mainly for testing. pub fn to_precomputed(&self) -> AffineNielsPoint { @@ -582,6 +577,11 @@ impl ExtendedPoint { } } + /// Compress this point to `CompressedEdwardsY` format. + pub fn compress_edwards(&self) -> CompressedEdwardsY { + self.to_projective().compress_edwards() + } + /// Convert this point to a `CompressedMontgomeryU`. /// Note that this discards the sign. /// @@ -1160,7 +1160,7 @@ mod test { #[test] fn test_basepoint_from_montgomery() { let bp = BASE_CMPRSSD_MONTY.decompress().unwrap(); - let bp_compressed_edwards = bp.compress(); + let bp_compressed_edwards = bp.compress_edwards(); assert_eq!(bp_compressed_edwards, BASE_CMPRSSD); } @@ -1193,8 +1193,8 @@ mod test { let bp2 = BASE2_CMPRSSD.decompress().unwrap(); assert!( bp.is_valid()); assert!(bp2.is_valid()); - let compressed = bp.compress(); - let compressed2 = bp2.compress(); + let compressed = bp.compress_edwards(); + let compressed2 = bp2.compress_edwards(); // Check that decompression actually gives the correct X coordinate assert_eq!(base_X, bp.X); assert_eq!(compressed, BASE_CMPRSSD); @@ -1219,7 +1219,7 @@ mod test { #[test] fn test_basepoint_mult_one_vs_basepoint() { let bp = ExtendedPoint::basepoint_mult(&Scalar::one()); - let compressed = bp.compress(); + let compressed = bp.compress_edwards(); assert_eq!(compressed, BASE_CMPRSSD); } @@ -1229,7 +1229,7 @@ mod test { fn test_basepoint_plus_basepoint() { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp_added = &bp + &bp; - assert_eq!( bp_added.compress(), BASE2_CMPRSSD); + assert_eq!( bp_added.compress_edwards(), BASE2_CMPRSSD); } /// Test `impl Add for ExtendedPoint` @@ -1238,7 +1238,7 @@ mod test { fn test_basepoint_plus_basepoint_cached() { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp_added = (&bp + &bp.to_cached()).to_extended(); - assert_eq!( bp_added.compress(), BASE2_CMPRSSD); + assert_eq!( bp_added.compress_edwards(), BASE2_CMPRSSD); } /// Test `impl Add for ExtendedPoint` @@ -1253,7 +1253,7 @@ mod test { xy2d: &bp.T * &constants::d2, }; let bp_added = (&bp + &bp_precomputed).to_extended(); - assert_eq!( bp_added.compress(), BASE2_CMPRSSD); + assert_eq!( bp_added.compress_edwards(), BASE2_CMPRSSD); } #[test] @@ -1278,14 +1278,14 @@ mod test { let aB_pc = aB.to_precomputed(); let id = ExtendedPoint::identity(); let P = &id + &aB_pc; - assert_eq!(P.to_extended().compress(), aB.compress()) + assert_eq!(P.to_extended().compress_edwards(), aB.compress_edwards()) } /// Test basepoint_mult versus a known scalar multiple from ed25519.py #[test] fn test_basepoint_mult() { let aB = ExtendedPoint::basepoint_mult(&A_SCALAR); - assert_eq!(aB.compress(), A_TIMES_BASEPOINT); + assert_eq!(aB.compress_edwards(), A_TIMES_BASEPOINT); } /// Test scalar_mult versus a known scalar multiple from ed25519.py @@ -1293,7 +1293,7 @@ mod test { fn test_scalar_mult() { let bp = BASE_CMPRSSD.decompress().unwrap(); let aB = bp.scalar_mult(&A_SCALAR); - assert_eq!(aB.compress(), A_TIMES_BASEPOINT); + assert_eq!(aB.compress_edwards(), A_TIMES_BASEPOINT); } /// Test double_scalar_mult_vartime vs ed25519.py @@ -1301,7 +1301,7 @@ mod test { fn test_double_scalar_mult_vartime() { let A = A_TIMES_BASEPOINT.decompress().unwrap(); let result = double_scalar_mult_vartime(&A_SCALAR, &A, &B_SCALAR); - assert_eq!(result.compress(), DOUBLE_SCALAR_MULT_RESULT); + assert_eq!(result.compress_edwards(), DOUBLE_SCALAR_MULT_RESULT); } /// Test basepoint.double() versus the 2*basepoint constant. @@ -1309,7 +1309,7 @@ mod test { fn test_basepoint_double() { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp_doubled = bp.double(); - assert_eq!(bp_doubled.compress(), BASE2_CMPRSSD); + assert_eq!(bp_doubled.compress_edwards(), BASE2_CMPRSSD); } /// Test that computing 2*basepoint is the same as basepoint.double() @@ -1322,7 +1322,7 @@ mod test { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp_doubled = bp.double(); let bp2 = ExtendedPoint::basepoint_mult(&two); - assert_eq!(bp_doubled.compress(), bp2.compress()); + assert_eq!(bp_doubled.compress_edwards(), bp2.compress_edwards()); } #[test] @@ -1330,7 +1330,7 @@ mod test { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp_roundtrip = bp.to_projective().to_extended(); - assert_eq!(BASE_CMPRSSD, bp_roundtrip.compress()); + assert_eq!(BASE_CMPRSSD, bp_roundtrip.compress_edwards()); } /// Test computing 16*basepoint vs mult_by_pow_2 @@ -1338,7 +1338,7 @@ mod test { fn test_mult_by_pow_2() { let bp = BASE_CMPRSSD.decompress().unwrap(); let bp16 = bp.mult_by_pow_2(4); - assert_eq!(bp16.compress(), BASE16_CMPRSSD); + assert_eq!(bp16.compress_edwards(), BASE16_CMPRSSD); } /// The basepoint, doubled, minus the basepoint should equal the basepoint. @@ -1348,7 +1348,7 @@ mod test { let p2: ExtendedPoint = BASE2_CMPRSSD.decompress().unwrap(); let p3: ExtendedPoint = (&p2 - &p1.to_cached()).to_extended(); - assert_eq!(p1.compress(), p3.compress()); + assert_eq!(p1.compress_edwards(), p3.compress_edwards()); } /// The basepoint plus the identity should equal the basepoint. @@ -1358,7 +1358,7 @@ mod test { let p2: ExtendedPoint = ExtendedPoint::identity(); let p3: ExtendedPoint = (&p1 + &p2.to_cached()).to_extended(); - assert_eq!(p1.compress(), p3.compress()); + assert_eq!(p1.compress_edwards(), p3.compress_edwards()); } #[test] @@ -1484,7 +1484,7 @@ mod test { let mut rng: OsRng = OsRng::new().unwrap(); let p1: ExtendedPoint = ExtendedPoint::basepoint_mult(&Scalar::random(&mut rng)); - b.iter(| | p1.compress() ); + b.iter(| | p1.compress_edwards() ); } #[bench]