mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Add method for determining if an ExtendedPoint is of small order.
This commit is contained in:
parent
7b57be69fd
commit
03589dff43
1 changed files with 28 additions and 0 deletions
28
src/curve.rs
28
src/curve.rs
|
|
@ -655,6 +655,25 @@ impl ExtendedPoint {
|
||||||
r = s.double();
|
r = s.double();
|
||||||
return r.to_extended();
|
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
|
/// Given a point `A` and scalars `a` and `b`, compute the point
|
||||||
|
|
@ -1045,6 +1064,15 @@ mod test {
|
||||||
assert_eq!(p1.xy2d, p2.xy2d);
|
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]
|
#[bench]
|
||||||
fn bench_basepoint_mult(b: &mut Bencher) {
|
fn bench_basepoint_mult(b: &mut Bencher) {
|
||||||
b.iter(|| ExtendedPoint::basepoint_mult(&A_SCALAR));
|
b.iter(|| ExtendedPoint::basepoint_mult(&A_SCALAR));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue