Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mul<ScalarField> for Affine #449

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Mul<ScalarField> for Affine
  • Loading branch information
Pratyush committed Aug 4, 2022
commit 459f02421452c2bc0c9bc89d50de6d324a3e8b06
2 changes: 2 additions & 0 deletions ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ pub trait AffineCurve:
+ Neg<Output = Self>
+ Zeroize
+ core::iter::Sum<Self>
+ Mul<Self::ScalarField, Output = Self::Projective>
+ for<'a> Mul<&'a Self::ScalarField, Output = Self::Projective>
+ for<'a> core::iter::Sum<&'a Self>
+ From<<Self as AffineCurve>::Projective>
{
Expand Down
9 changes: 9 additions & 0 deletions ec/src/models/short_weierstrass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ impl<'a, P: SWCurveConfig> core::iter::Sum<&'a Self> for Affine<P> {
}
}

impl<'a, P: SWCurveConfig, T: Borrow<P::ScalarField>> Mul<T> for Affine<P> {
type Output = Projective<P>;

#[inline]
fn mul(self, other: T) -> Self::Output {
self.mul_bigint(other.borrow().into_bigint())
}
}

/// Jacobian coordinates for a point on an elliptic curve in short Weierstrass
/// form, over the base field `P::BaseField`. This struct implements arithmetic
/// via the Jacobian formulae
Expand Down
9 changes: 9 additions & 0 deletions ec/src/models/twisted_edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ impl<P: TECurveConfig> Distribution<Affine<P>> for Standard {
}
}

impl<'a, P: TECurveConfig, T: Borrow<P::ScalarField>> Mul<T> for Affine<P> {
type Output = Projective<P>;

#[inline]
fn mul(self, other: T) -> Self::Output {
self.mul_bigint(other.borrow().into_bigint())
}
}

//////////////////////////////////////////////////////////////////////////////

/// `Projective` implements Extended Twisted Edwards Coordinates
Expand Down