Skip to content

Commit

Permalink
Add Mul<ScalarField> for Affine
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush committed Aug 4, 2022
1 parent dd5b9d6 commit ddc708d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit ddc708d

Please sign in to comment.