Skip to content

Commit

Permalink
Fixed compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ycscaly committed Nov 14, 2023
1 parent eac363b commit 9e9beb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions k256/src/arithmetic/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use elliptic_curve::{
sec1::{FromEncodedPoint, ToEncodedPoint},
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption},
zeroize::DefaultIsZeroes,
Error, Normalize, Result,
BatchNormalize, Error, Result,
};

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -256,10 +256,12 @@ impl From<AffinePoint> for ProjectivePoint {
}
}

impl<const N: usize> Normalize<&[ProjectivePoint; N]> for ProjectivePoint {
impl<const N: usize> BatchNormalize<&[ProjectivePoint; N]> for ProjectivePoint {
type Output = [Self::AffineRepr; N];

fn batch_normalize(points: &[Self; N]) -> <Self as Normalize<&[ProjectivePoint; N]>>::Output {
fn batch_normalize(
points: &[Self; N],
) -> <Self as BatchNormalize<&[ProjectivePoint; N]>>::Output {
let mut zs = [FieldElement::ONE; N];

for i in 0..N {
Expand Down Expand Up @@ -288,10 +290,10 @@ impl<const N: usize> Normalize<&[ProjectivePoint; N]> for ProjectivePoint {
}

#[cfg(feature = "alloc")]
impl Normalize<&[ProjectivePoint]> for ProjectivePoint {
impl BatchNormalize<&[ProjectivePoint]> for ProjectivePoint {
type Output = Vec<Self::AffineRepr>;

fn batch_normalize(points: &[Self]) -> <Self as Normalize<&[ProjectivePoint]>>::Output {
fn batch_normalize(points: &[Self]) -> <Self as BatchNormalize<&[ProjectivePoint]>>::Output {
let mut zs: Vec<_> = vec![FieldElement::ONE; points.len()];

for i in 0..points.len() {
Expand Down Expand Up @@ -462,7 +464,7 @@ impl Curve for ProjectivePoint {
fn batch_normalize(p: &[Self], q: &mut [Self::AffineRepr]) {
assert_eq!(p.len(), q.len());

let affine_points: Vec<_> = <Self as Normalize<_>>::batch_normalize(p);
let affine_points: Vec<_> = <Self as BatchNormalize<_>>::batch_normalize(p);
q.copy_from_slice(&affine_points);
}
}
Expand Down Expand Up @@ -689,7 +691,7 @@ mod tests {
use elliptic_curve::group::{ff::PrimeField, prime::PrimeCurveAffine};
use elliptic_curve::ops::MulByGenerator;
use elliptic_curve::Field;
use elliptic_curve::{group, Normalize};
use elliptic_curve::{group, BatchNormalize};
use rand_core::OsRng;

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -722,7 +724,7 @@ mod tests {
let mut res = [AffinePoint::IDENTITY; 2];
let expected = [g.to_affine(), h.to_affine()];
assert_eq!(
<ProjectivePoint as Normalize<_>>::batch_normalize(&[g, h]),
<ProjectivePoint as BatchNormalize<_>>::batch_normalize(&[g, h]),
expected
);

Expand All @@ -731,7 +733,10 @@ mod tests {

let expected = [g.to_affine(), AffinePoint::IDENTITY];
assert_eq!(
<ProjectivePoint as Normalize<_>>::batch_normalize(&[g, ProjectivePoint::IDENTITY]),
<ProjectivePoint as BatchNormalize<_>>::batch_normalize(&[
g,
ProjectivePoint::IDENTITY
]),
expected
);

Expand All @@ -753,15 +758,15 @@ mod tests {
let expected = vec![g.to_affine(), h.to_affine()];
let scalars = vec![g, h];
let mut res: Vec<_> =
<ProjectivePoint as Normalize<_>>::batch_normalize(scalars.as_slice());
<ProjectivePoint as BatchNormalize<_>>::batch_normalize(scalars.as_slice());
assert_eq!(res, expected);

<ProjectivePoint as group::Curve>::batch_normalize(&[g, h], res.as_mut());
assert_eq!(res.to_vec(), expected);

let expected = vec![g.to_affine(), AffinePoint::IDENTITY];
let scalars = vec![g, ProjectivePoint::IDENTITY];
res = <ProjectivePoint as Normalize<_>>::batch_normalize(scalars.as_slice());
res = <ProjectivePoint as BatchNormalize<_>>::batch_normalize(scalars.as_slice());

assert_eq!(res, expected);

Expand Down
12 changes: 6 additions & 6 deletions primeorder/src/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use elliptic_curve::{
},
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption},
zeroize::DefaultIsZeroes,
Error, FieldBytes, FieldBytesSize, Normalize, PublicKey, Result, Scalar,
BatchNormalize, Error, FieldBytes, FieldBytesSize, PublicKey, Result, Scalar,
};

/// Point on a Weierstrass curve in projective coordinates.
Expand Down Expand Up @@ -335,12 +335,12 @@ where
fn batch_normalize(p: &[Self], q: &mut [Self::AffineRepr]) {
assert_eq!(p.len(), q.len());

let affine_points: Vec<_> = <Self as Normalize>::batch_normalize_vec(p);
let affine_points: Vec<_> = <Self as BatchNormalize>::batch_normalize_vec(p);
q.copy_from_slice(affine_points)
}
}

impl<const N: usize, C> Normalize<&[ProjectivePoint<C>; N]> for ProjectivePoint<C>
impl<const N: usize, C> BatchNormalize<&[ProjectivePoint<C>; N]> for ProjectivePoint<C>
where
Self: Double,
C: PrimeCurveParams,
Expand All @@ -349,7 +349,7 @@ where

fn batch_normalize(
points: &[Self; N],
) -> <Self as Normalize<&[ProjectivePoint<C>; N]>>::Output {
) -> <Self as BatchNormalize<&[ProjectivePoint<C>; N]>>::Output {
let mut zs = [C::FieldElement::ONE; N];

for i in 0..N {
Expand Down Expand Up @@ -378,7 +378,7 @@ where
}

#[cfg(feature = "alloc")]
impl<C> Normalize<&[ProjectivePoint<C>]> for ProjectivePoint<C>
impl<C> BatchNormalize<&[ProjectivePoint<C>]> for ProjectivePoint<C>
where
Self: Double,
C: PrimeCurveParams,
Expand All @@ -387,7 +387,7 @@ where

fn batch_normalize(
points: &[Self; N],
) -> <Self as Normalize<&[ProjectivePoint<C>; N]>>::Output {
) -> <Self as BatchNormalize<&[ProjectivePoint<C>; N]>>::Output {
let mut zs: Vec<_> = vec![C::FieldElement::ONE; points.len()];

for i in 0..points.len() {
Expand Down

0 comments on commit 9e9beb5

Please sign in to comment.