diff --git a/primeorder/src/lib.rs b/primeorder/src/lib.rs index 75f25d20..34d501bb 100644 --- a/primeorder/src/lib.rs +++ b/primeorder/src/lib.rs @@ -23,6 +23,8 @@ mod projective; pub use crate::{affine::AffinePoint, projective::ProjectivePoint}; pub use elliptic_curve::{self, array, point::Double, Field, FieldBytes, PrimeCurve, PrimeField}; +use elliptic_curve::ops::Invert; +use elliptic_curve::subtle::CtOption; use elliptic_curve::CurveArithmetic; /// Parameters for elliptic curves of prime order which can be described by the @@ -34,8 +36,8 @@ pub trait PrimeCurveParams: + CurveArithmetic> { /// Base field element type. - // TODO(tarcieri): add `Invert` bound - type FieldElement: PrimeField>; + type FieldElement: PrimeField> + + Invert>; /// [Point arithmetic](point_arithmetic) implementation, might be optimized for this specific curve type PointArithmetic: point_arithmetic::PointArithmetic; diff --git a/primeorder/src/projective.rs b/primeorder/src/projective.rs index 5b310935..729ffe66 100644 --- a/primeorder/src/projective.rs +++ b/primeorder/src/projective.rs @@ -17,7 +17,7 @@ use elliptic_curve::{ prime::{PrimeCurve, PrimeGroup}, Group, GroupEncoding, }, - ops::{BatchInvert, Invert, LinearCombination, MulByGenerator}, + ops::{BatchInvert, LinearCombination, MulByGenerator}, point::Double, rand_core::RngCore, sec1::{ @@ -334,21 +334,19 @@ where ProjectivePoint::to_affine(self) } - // TODO(tarcieri): re-enable when we can add `Invert` bounds on `FieldElement` - // #[cfg(feature = "alloc")] - // #[inline] - // fn batch_normalize(projective: &[Self], affine: &mut [Self::AffineRepr]) { - // assert_eq!(projective.len(), affine.len()); - // let mut zs = vec![C::FieldElement::ONE; projective.len()]; - // batch_normalize_generic(projective, zs.as_mut_slice(), affine); - // } + #[cfg(feature = "alloc")] + #[inline] + fn batch_normalize(projective: &[Self], affine: &mut [Self::AffineRepr]) { + assert_eq!(projective.len(), affine.len()); + let mut zs = vec![C::FieldElement::ONE; projective.len()]; + batch_normalize_generic(projective, zs.as_mut_slice(), affine); + } } impl BatchNormalize<[ProjectivePoint; N]> for ProjectivePoint where Self: Double, C: PrimeCurveParams, - C::FieldElement: Invert>, { type Output = [Self::AffineRepr; N]; @@ -366,7 +364,6 @@ impl BatchNormalize<[ProjectivePoint]> for ProjectivePoint where Self: Double, C: PrimeCurveParams, - C::FieldElement: Invert>, { type Output = Vec;