Skip to content

Commit

Permalink
elliptic-curve: move BatchNormalize trait under point (#1404)
Browse files Browse the repository at this point in the history
Since it's functionality related to elliptic curve points, put it under
the corresponding module.
  • Loading branch information
tarcieri authored Nov 15, 2023
1 parent 4a66334 commit ce2dc02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 0 additions & 11 deletions elliptic-curve/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,3 @@ pub trait PrimeCurveArithmetic:
/// Prime order elliptic curve group.
type CurveGroup: group::prime::PrimeCurve<Affine = <Self as CurveArithmetic>::AffinePoint>;
}

/// Normalize point(s) in projective representation by converting them to their affine ones.
pub trait BatchNormalize<Points: ?Sized>: group::Curve {
/// The output of the batch normalization; a container of affine points.
type Output: AsRef<[Self::AffineRepr]>;

/// Perform a batched conversion to affine representation on a sequence of projective points
/// at an amortized cost that should be practically as efficient as a single conversion.
/// Internally, implementors should rely upon `InvertBatch`.
fn batch_normalize(points: &Points) -> <Self as BatchNormalize<Points>>::Output;
}
4 changes: 2 additions & 2 deletions elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ pub use zeroize;
#[cfg(feature = "arithmetic")]
pub use {
crate::{
arithmetic::{BatchNormalize, CurveArithmetic, PrimeCurveArithmetic},
point::{AffinePoint, ProjectivePoint},
arithmetic::{CurveArithmetic, PrimeCurveArithmetic},
point::{AffinePoint, BatchNormalize, ProjectivePoint},
public_key::PublicKey,
scalar::{NonZeroScalar, Scalar},
},
Expand Down
12 changes: 12 additions & 0 deletions elliptic-curve/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ pub trait AffineCoordinates {
fn y_is_odd(&self) -> Choice;
}

/// Normalize point(s) in projective representation by converting them to their affine ones.
#[cfg(feature = "arithmetic")]
pub trait BatchNormalize<Points: ?Sized>: group::Curve {
/// The output of the batch normalization; a container of affine points.
type Output: AsRef<[Self::AffineRepr]>;

/// Perform a batched conversion to affine representation on a sequence of projective points
/// at an amortized cost that should be practically as efficient as a single conversion.
/// Internally, implementors should rely upon `InvertBatch`.
fn batch_normalize(points: &Points) -> <Self as BatchNormalize<Points>>::Output;
}

/// Double a point (i.e. add it to itself)
pub trait Double {
/// Double this point.
Expand Down

0 comments on commit ce2dc02

Please sign in to comment.