From 0d8f33153c144632e97b5a49cefe1e66a292463a Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 20 Apr 2021 23:58:29 +0000 Subject: [PATCH 1/2] Implement Identity for MontgomeryPoint. This can be used in checks for non-contributory behaviour in protocols where that is a concern. --- src/montgomery.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/montgomery.rs b/src/montgomery.rs index de0f8b7..867496c 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -94,6 +94,13 @@ impl PartialEq for MontgomeryPoint { impl Eq for MontgomeryPoint {} +impl Identity for MontgomeryPoint { + /// Return the group identity element, which has order 4. + fn identity() -> MontgomeryPoint { + MontgomeryPoint([0u8; 32]) + } +} + impl Zeroize for MontgomeryPoint { fn zeroize(&mut self) { self.0.zeroize(); @@ -351,6 +358,14 @@ mod test { use rand_core::OsRng; + #[test] + fn identity_in_different_coordinates() { + let id_projective = ProjectivePoint::identity(); + let id_montgomery = id_projective.to_affine(); + + assert!(id_montgomery == MontgomeryPoint::identity()); + } + #[test] #[cfg(feature = "serde")] fn serde_bincode_basepoint_roundtrip() { From d7c2a1394f6b1ba2aaa8152b563cb221f7d4c710 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Wed, 21 Apr 2021 00:06:44 +0000 Subject: [PATCH 2/2] Add another test for equivalence with the Edwards identity. --- src/montgomery.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/montgomery.rs b/src/montgomery.rs index 867496c..ef4d0f5 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -366,6 +366,11 @@ mod test { assert!(id_montgomery == MontgomeryPoint::identity()); } + #[test] + fn identity_in_different_models() { + assert!(EdwardsPoint::identity().to_montgomery() == MontgomeryPoint::identity()); + } + #[test] #[cfg(feature = "serde")] fn serde_bincode_basepoint_roundtrip() {