Skip to content

Commit

Permalink
Remove separate point validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Apr 23, 2024
1 parent 0009b20 commit aac2ae1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- Remove `Copy` trait for `SecretKey` [#5]
- Remove separate checks for point validity in favor of the singular `pk.is_valid`

## [0.2.0] - 2024-02-28

Expand Down
23 changes: 4 additions & 19 deletions src/keys/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,6 @@ impl PublicKey {
Self(G2Affine::from_slice_unchecked(bytes))
}

/// Returns true if the inner point is free of an $h$-torsion component, and
/// so it exists within the $q$-order subgroup $\mathbb{G}_2$. This
/// should always return true unless an "unchecked" API was used.
pub fn is_torsion_free(&self) -> bool {
self.0.is_torsion_free().into()
}

/// Returns true if the inner point is on the curve. This should always
/// return true unless an "unchecked" API was used.
pub fn is_on_curve(&self) -> bool {
self.0.is_on_curve().into()
}

/// Returns true if the inner point is the identity (the point at infinity).
pub fn is_identity(&self) -> bool {
self.0.is_identity().into()
}

/// Returns true if the inner point is valid according to certain criteria.
///
/// A [`PublicKey`] is considered valid if its inner point meets the
Expand All @@ -124,6 +106,9 @@ impl PublicKey {
/// 2. It is on the curve.
/// 3. It is not the identity.
pub fn is_valid(&self) -> bool {
self.is_torsion_free() && self.is_on_curve() && !self.is_identity()
let is_identity: bool = self.0.is_identity().into();
self.0.is_torsion_free().into()
&& self.0.is_on_curve().into()
&& !is_identity
}
}

0 comments on commit aac2ae1

Please sign in to comment.