From 0d8f33153c144632e97b5a49cefe1e66a292463a Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Tue, 20 Apr 2021 23:58:29 +0000 Subject: [PATCH] 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() {