diff --git a/k256/src/arithmetic/projective.rs b/k256/src/arithmetic/projective.rs index 0bccd1f4..dd7ec132 100644 --- a/k256/src/arithmetic/projective.rs +++ b/k256/src/arithmetic/projective.rs @@ -272,8 +272,8 @@ impl BatchNormalize<[ProjectivePoint]> for ProjectivePoint { type Output = Vec; fn batch_normalize(points: &[Self]) -> Vec { - let mut zs: Vec<_> = vec![FieldElement::ONE; points.len()]; - let mut affine_points: Vec<_> = vec![AffinePoint::IDENTITY; points.len()]; + let mut zs = vec![FieldElement::ONE; points.len()]; + let mut affine_points = vec![AffinePoint::IDENTITY; points.len()]; batch_normalize_generic(points, zs.as_mut_slice(), &mut affine_points); affine_points } @@ -449,11 +449,15 @@ impl Curve for ProjectivePoint { } #[cfg(feature = "alloc")] - fn batch_normalize(p: &[Self], q: &mut [Self::AffineRepr]) { - assert_eq!(p.len(), q.len()); + fn batch_normalize(projective: &[Self], affine: &mut [Self::AffineRepr]) { + assert_eq!(projective.len(), affine.len()); - let affine_points: Vec<_> = >::batch_normalize(p); - q.copy_from_slice(&affine_points); + for point in affine.iter_mut() { + *point = AffinePoint::IDENTITY; + } + + let mut zs = vec![FieldElement::ONE; projective.len()]; + batch_normalize_generic(projective, zs.as_mut_slice(), affine); } } diff --git a/primeorder/src/projective.rs b/primeorder/src/projective.rs index baf4d261..7b7556bc 100644 --- a/primeorder/src/projective.rs +++ b/primeorder/src/projective.rs @@ -331,11 +331,15 @@ where } #[cfg(feature = "alloc")] - fn batch_normalize(p: &[Self], q: &mut [Self::AffineRepr]) { - assert_eq!(p.len(), q.len()); + fn batch_normalize(projective: &[Self], affine: &mut [Self::AffineRepr]) { + assert_eq!(projective.len(), affine.len()); - let affine_points: Vec<_> = ::batch_normalize_vec(p); - q.copy_from_slice(affine_points) + for point in affine.iter_mut() { + *point = AffinePoint::IDENTITY; + } + + let mut zs = vec![FieldElement::ONE; projective.len()]; + batch_normalize_generic(projective, zs.as_mut_slice(), affine); } } @@ -363,8 +367,8 @@ where type Output = Vec; fn batch_normalize(points: &[Self; N]) -> Vec { - let mut zs: Vec<_> = vec![C::FieldElement::ONE; points.len()]; - let mut affine_points: Vec<_> = vec![AffinePoint::IDENTITY; points.len()]; + let mut zs = vec![C::FieldElement::ONE; points.len()]; + let mut affine_points = vec![AffinePoint::IDENTITY; points.len()]; batch_normalize_generic(points, zs.as_mut_slice(), &mut affine_points); affine_points } @@ -375,7 +379,7 @@ fn batch_normalize_generic(points: &P, zs: &mut Z, out: &mut O) where C: PrimeCurveParams, C::FieldElement: BatchInvert, - ProjectivePoint: Double, + C::ProjectivePoint: Double, P: AsRef<[ProjectivePoint]> + ?Sized, Z: AsMut<[C::FieldElement]> + ?Sized, O: AsMut<[AffinePoint]> + ?Sized,