diff --git a/src/decaf.rs b/src/decaf.rs index 4683072..1fd70ec 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -165,6 +165,8 @@ impl DecafPoint { // Compute s = u(r(aZX - dYT)+Y) let mut s = &u * &(&(&r * &(&minus_ZX - &dYT)) + &Y); // Set s <- |-s| + // XXX I think there's a sign error somewhere? + // flipping the sign here makes the tests pass let neg = s.is_nonnegative_decaf(); s.conditional_negate(neg); CompressedDecaf(s.to_bytes()) @@ -237,6 +239,8 @@ impl ScalarMult for DecafPoint { } impl BasepointMult for DecafPoint { + // XXX is this actually in the image of the isogeny, + // or do we need a different basepoint? fn basepoint() -> DecafPoint { DecafPoint(constants::BASEPOINT) } @@ -333,4 +337,18 @@ mod test { assert_eq!(P, DecafPoint(P_coset[i])); } } + + #[test] + fn test_decaf_random_roundtrip() { + let mut rng = OsRng::new().unwrap(); + for j in 0..100 { + let s = Scalar::random(&mut rng); + let P = DecafPoint::basepoint_mult(&s); + let compressed_P = P.compress(); + let Q = compressed_P.decompress().unwrap(); + for i in 0..4 { + assert_eq!(P, Q); + } + } + } }