Skip to content

Commit

Permalink
elliptic-curve: conditionally impl Invert for NonZeroScalar
Browse files Browse the repository at this point in the history
...if the underlying scalar type it wraps also impls `Invert`
  • Loading branch information
tarcieri committed Aug 26, 2020
1 parent 05d2eae commit ea7e2e3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion elliptic-curve/src/scalar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Scalar types

use crate::{Arithmetic, Curve, ElementBytes, FromBytes};
use crate::{ops::Invert, Arithmetic, Curve, ElementBytes, FromBytes};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "rand")]
Expand Down Expand Up @@ -84,6 +84,19 @@ where
}
}

impl<C> Invert for NonZeroScalar<C>
where
C: Curve + Arithmetic,
C::Scalar: Invert,
{
type Output = <C::Scalar as Invert>::Output;

/// Perform a scalar inversion
fn invert(&self) -> CtOption<Self::Output> {
self.scalar.invert()
}
}

#[cfg(feature = "rand")]
impl<C> Generate for NonZeroScalar<C>
where
Expand Down

0 comments on commit ea7e2e3

Please sign in to comment.