diff --git a/src/curve.rs b/src/curve.rs index b9c3848..1d60559 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -655,6 +655,25 @@ impl ExtendedPoint { r = s.double(); return r.to_extended(); } + + /// Determine if this point is of small order. + /// + /// The order of the group of points on the curve Ɛ is |Ɛ| = 8q. Thus, to + /// check if a point P is of small order, we multiply by 8 and then test + /// if the result is equal to the identity. + /// + /// # Return + /// + /// True if it is of small order; false otherwise. + pub fn is_small_order(&self) -> bool { + let p8: ExtendedPoint = self.mult_by_pow_2(3); + + if p8.is_identity() { + return true; + } else { + return false; + } + } } /// Given a point `A` and scalars `a` and `b`, compute the point @@ -1045,6 +1064,15 @@ mod test { assert_eq!(p1.xy2d, p2.xy2d); } + #[test] + fn test_is_small_order() { + let p1: ExtendedPoint = ExtendedPoint::identity(); + let p2: ExtendedPoint = BASE_CMPRSSD.decompress().unwrap(); + + assert!(p1.is_small_order() == true); + assert!(p2.is_small_order() == false); + } + #[bench] fn bench_basepoint_mult(b: &mut Bencher) { b.iter(|| ExtendedPoint::basepoint_mult(&A_SCALAR));