Add a coset4 function for debugging

This commit is contained in:
Henry & Isis 2017-02-20 03:38:31 -08:00 committed by Henry de Valence
parent 375d326e75
commit f06afbc493

View file

@ -154,6 +154,15 @@ impl DecafPoint {
s.negate(); s.negate();
CompressedDecaf(s.abs_decaf().to_bytes()) CompressedDecaf(s.abs_decaf().to_bytes())
} }
/// Return the coset self + E[4], for debugging.
fn coset4(&self) -> [ExtendedPoint; 4] {
[ self.0
, &self.0 + &constants::EIGHT_TORSION[2]
, &self.0 + &constants::EIGHT_TORSION[4]
, &self.0 + &constants::EIGHT_TORSION[6]
]
}
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -228,7 +237,9 @@ impl Debug for CompressedDecaf {
impl Debug for DecafPoint { impl Debug for DecafPoint {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "DecafPoint: {:?}", &self.0) let coset = self.coset4();
write!(f, "DecafPoint: coset \n{:?}\n{:?}\n{:?}\n{:?}",
coset[0], coset[1], coset[2], coset[3])
} }
} }
@ -277,9 +288,9 @@ mod test {
#[test] #[test]
fn test_decaf_four_torsion_basepoint() { fn test_decaf_four_torsion_basepoint() {
let bp = DecafPoint::basepoint(); let bp = DecafPoint::basepoint();
for i in (0..8).filter(|x| x % 2 == 0) { let bp_coset = bp.coset4();
let Q = &bp + &DecafPoint(constants::EIGHT_TORSION[i]); for i in 0..4 {
assert_eq!(Q, bp); assert_eq!(bp, DecafPoint(bp_coset[i]));
} }
} }
@ -288,9 +299,9 @@ mod test {
let mut rng = OsRng::new().unwrap(); let mut rng = OsRng::new().unwrap();
let s = Scalar::random(&mut rng); let s = Scalar::random(&mut rng);
let P = DecafPoint::basepoint_mult(&s); let P = DecafPoint::basepoint_mult(&s);
for i in (0..8).filter(|x| x % 2 == 0) { let P_coset = P.coset4();
let Q = &P + &DecafPoint(constants::EIGHT_TORSION[i]); for i in 0..4 {
assert_eq!(Q, P); assert_eq!(P, DecafPoint(P_coset[i]));
} }
} }
} }