Add implementations of is_prime_order() for AffinePoint and ExtendedPoint.

This commit is contained in:
Sean Bowe 2019-03-26 21:31:34 -06:00
parent 390aa23db2
commit 35d32faa63
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
1 changed files with 17 additions and 0 deletions

View File

@ -303,6 +303,15 @@ impl AffinePoint {
ExtendedPoint::from(*self).is_torsion_free()
}
/// Determines if this point is prime order, or in other words that
/// the smallest scalar multiplied by this point that produces the
/// identity is `r`. This is equivalent to checking that the point
/// is both torsion free and not the identity.
pub fn is_prime_order(&self) -> Choice {
let extended = ExtendedPoint::from(*self);
extended.is_torsion_free() & (!extended.is_identity())
}
/// Converts this element into its byte representation.
pub fn into_bytes(&self) -> [u8; 32] {
let mut tmp = self.v.into_bytes();
@ -426,6 +435,14 @@ impl ExtendedPoint {
self.multiply(&FR_MODULUS_BYTES).is_identity()
}
/// Determines if this point is prime order, or in other words that
/// the smallest scalar multiplied by this point that produces the
/// identity is `r`. This is equivalent to checking that the point
/// is both torsion free and not the identity.
pub fn is_prime_order(&self) -> Choice {
self.is_torsion_free() & (!self.is_identity())
}
/// Multiplies this element by the cofactor `8`.
pub fn mul_by_cofactor(&self) -> ExtendedPoint {
self.double().double().double()