Add impl of Identity for DecafPoint and CompressedDecaf

This commit is contained in:
Henry & Isis 2017-02-20 03:45:49 -08:00 committed by Henry de Valence
parent f06afbc493
commit ea5efcdc29

View file

@ -30,6 +30,7 @@ use core::ops::{Add, Sub, Neg};
use curve::ExtendedPoint; use curve::ExtendedPoint;
use curve::BasepointMult; use curve::BasepointMult;
use curve::ScalarMult; use curve::ScalarMult;
use curve::Identity;
use scalar::Scalar; use scalar::Scalar;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -79,6 +80,12 @@ impl CompressedDecaf {
} }
} }
impl Identity for CompressedDecaf {
fn identity() -> CompressedDecaf {
CompressedDecaf([0u8;32])
}
}
/// A point in a prime-order group. /// A point in a prime-order group.
/// ///
/// XXX think about how this API should work /// XXX think about how this API should work
@ -165,6 +172,12 @@ impl DecafPoint {
} }
} }
impl Identity for DecafPoint {
fn identity() -> DecafPoint {
DecafPoint(ExtendedPoint::identity())
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Equality // Equality
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -262,7 +275,7 @@ mod test {
#[test] #[test]
fn test_decaf_decompress_id() { fn test_decaf_decompress_id() {
let compressed_id = CompressedDecaf([0u8; 32]); let compressed_id = CompressedDecaf::identity();
let id = compressed_id.decompress().unwrap(); let id = compressed_id.decompress().unwrap();
// This should compress (as ed25519) to the following: // This should compress (as ed25519) to the following:
let mut bytes = [0u8; 32]; bytes[0] = 1; let mut bytes = [0u8; 32]; bytes[0] = 1;
@ -271,8 +284,8 @@ mod test {
#[test] #[test]
fn test_decaf_compress_id() { fn test_decaf_compress_id() {
let id = DecafPoint(ExtendedPoint::identity()); let id = DecafPoint::identity();
assert_eq!(id.compress(), CompressedDecaf([0u8; 32])); assert_eq!(id.compress(), CompressedDecaf::identity());
} }
#[test] #[test]