Skip to content

Commit

Permalink
elliptic-curve: impl Neg for NonZeroScalar<C> (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Nov 17, 2021
1 parent dc78782 commit f484ed6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion elliptic-curve/src/scalar/non_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
rand_core::{CryptoRng, RngCore},
Curve, Error, FieldBytes, IsHigh, Result, Scalar, ScalarArithmetic, ScalarCore, SecretKey,
};
use core::ops::Deref;
use core::ops::{Deref, Neg};
use ff::{Field, PrimeField};
use generic_array::GenericArray;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
Expand Down Expand Up @@ -175,6 +175,19 @@ where
}
}

impl<C> Neg for NonZeroScalar<C>
where
C: Curve + ScalarArithmetic,
{
type Output = NonZeroScalar<C>;

fn neg(self) -> NonZeroScalar<C> {
let scalar = -self.scalar;
debug_assert!(!bool::from(scalar.is_zero()));
NonZeroScalar { scalar }
}
}

impl<C> TryFrom<&[u8]> for NonZeroScalar<C>
where
C: Curve + ScalarArithmetic,
Expand Down

0 comments on commit f484ed6

Please sign in to comment.