Skip to content

Commit 22ae23d

Browse files
authored
Implement Mul<NonIdentity> for NonZeroScalar (#1855)
This implements `Mul<NonIdentity> for NonZeroScalar`. Analogous to #1854.
1 parent 91d6acd commit 22ae23d

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

elliptic-curve/src/point/non_identity.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,32 @@ where
175175
}
176176
}
177177

178-
impl<C, P> Mul<&NonZeroScalar<C>> for &NonIdentity<P>
178+
impl<C, P> Mul<NonZeroScalar<C>> for &NonIdentity<P>
179179
where
180180
C: CurveArithmetic,
181181
P: Copy + Mul<Scalar<C>, Output = P>,
182182
{
183183
type Output = NonIdentity<P>;
184184

185-
fn mul(self, rhs: &NonZeroScalar<C>) -> Self::Output {
185+
fn mul(self, rhs: NonZeroScalar<C>) -> Self::Output {
186186
NonIdentity {
187187
point: self.point * *rhs.as_ref(),
188188
}
189189
}
190190
}
191191

192+
impl<C, P> Mul<&NonZeroScalar<C>> for &NonIdentity<P>
193+
where
194+
C: CurveArithmetic,
195+
P: Copy + Mul<Scalar<C>, Output = P>,
196+
{
197+
type Output = NonIdentity<P>;
198+
199+
fn mul(self, rhs: &NonZeroScalar<C>) -> Self::Output {
200+
self * *rhs
201+
}
202+
}
203+
192204
#[cfg(feature = "serde")]
193205
impl<P> Serialize for NonIdentity<P>
194206
where

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::{
44
CurveArithmetic, Error, FieldBytes, PrimeCurve, Scalar, ScalarPrimitive, SecretKey,
55
ops::{Invert, Reduce, ReduceNonZero},
6+
point::NonIdentity,
67
scalar::IsHigh,
78
};
89
use base16ct::HexDisplay;
@@ -258,6 +259,54 @@ where
258259
}
259260
}
260261

262+
impl<C, P> Mul<NonIdentity<P>> for NonZeroScalar<C>
263+
where
264+
C: CurveArithmetic,
265+
NonIdentity<P>: Mul<NonZeroScalar<C>, Output = NonIdentity<P>>,
266+
{
267+
type Output = NonIdentity<P>;
268+
269+
fn mul(self, rhs: NonIdentity<P>) -> Self::Output {
270+
rhs * self
271+
}
272+
}
273+
274+
impl<C, P> Mul<&NonIdentity<P>> for NonZeroScalar<C>
275+
where
276+
C: CurveArithmetic,
277+
for<'a> &'a NonIdentity<P>: Mul<NonZeroScalar<C>, Output = NonIdentity<P>>,
278+
{
279+
type Output = NonIdentity<P>;
280+
281+
fn mul(self, rhs: &NonIdentity<P>) -> Self::Output {
282+
rhs * self
283+
}
284+
}
285+
286+
impl<C, P> Mul<NonIdentity<P>> for &NonZeroScalar<C>
287+
where
288+
C: CurveArithmetic,
289+
for<'a> NonIdentity<P>: Mul<&'a NonZeroScalar<C>, Output = NonIdentity<P>>,
290+
{
291+
type Output = NonIdentity<P>;
292+
293+
fn mul(self, rhs: NonIdentity<P>) -> Self::Output {
294+
rhs * self
295+
}
296+
}
297+
298+
impl<C, P> Mul<&NonIdentity<P>> for &NonZeroScalar<C>
299+
where
300+
C: CurveArithmetic,
301+
for<'a> &'a NonIdentity<P>: Mul<&'a NonZeroScalar<C>, Output = NonIdentity<P>>,
302+
{
303+
type Output = NonIdentity<P>;
304+
305+
fn mul(self, rhs: &NonIdentity<P>) -> Self::Output {
306+
rhs * self
307+
}
308+
}
309+
261310
impl<C> PartialEq for NonZeroScalar<C>
262311
where
263312
C: CurveArithmetic,

0 commit comments

Comments
 (0)