mirror of
https://github.com/saymrwulf/betrusted-curve25519-dalek-source.git
synced 2026-09-05 20:30:54 +00:00
Add impl of Identity for DecafPoint and CompressedDecaf
This commit is contained in:
parent
f06afbc493
commit
ea5efcdc29
1 changed files with 16 additions and 3 deletions
19
src/decaf.rs
19
src/decaf.rs
|
|
@ -30,6 +30,7 @@ use core::ops::{Add, Sub, Neg};
|
|||
use curve::ExtendedPoint;
|
||||
use curve::BasepointMult;
|
||||
use curve::ScalarMult;
|
||||
use curve::Identity;
|
||||
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.
|
||||
///
|
||||
/// 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
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
@ -262,7 +275,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_decaf_decompress_id() {
|
||||
let compressed_id = CompressedDecaf([0u8; 32]);
|
||||
let compressed_id = CompressedDecaf::identity();
|
||||
let id = compressed_id.decompress().unwrap();
|
||||
// This should compress (as ed25519) to the following:
|
||||
let mut bytes = [0u8; 32]; bytes[0] = 1;
|
||||
|
|
@ -271,8 +284,8 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_decaf_compress_id() {
|
||||
let id = DecafPoint(ExtendedPoint::identity());
|
||||
assert_eq!(id.compress(), CompressedDecaf([0u8; 32]));
|
||||
let id = DecafPoint::identity();
|
||||
assert_eq!(id.compress(), CompressedDecaf::identity());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue