Implement Identity for MontgomeryPoint.

This can be used in checks for non-contributory behaviour in protocols
where that is a concern.
This commit is contained in:
Isis Lovecruft 2021-04-20 23:58:29 +00:00
parent 032a14cfa5
commit 0d8f33153c
No known key found for this signature in database
GPG key ID: AB41313533E8E812

View file

@ -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() {