From ea7e2e3a9e3122e9f2c0082f94641ed16f869d28 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 26 Aug 2020 12:47:35 -0700 Subject: [PATCH] elliptic-curve: conditionally impl Invert for NonZeroScalar ...if the underlying scalar type it wraps also impls `Invert` --- elliptic-curve/src/scalar.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/elliptic-curve/src/scalar.rs b/elliptic-curve/src/scalar.rs index 957d7bd74..78946fe02 100644 --- a/elliptic-curve/src/scalar.rs +++ b/elliptic-curve/src/scalar.rs @@ -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")] @@ -84,6 +84,19 @@ where } } +impl Invert for NonZeroScalar +where + C: Curve + Arithmetic, + C::Scalar: Invert, +{ + type Output = ::Output; + + /// Perform a scalar inversion + fn invert(&self) -> CtOption { + self.scalar.invert() + } +} + #[cfg(feature = "rand")] impl Generate for NonZeroScalar where