Struct NonZeroScalar
pub struct NonZeroScalar<C>where
C: CurveArithmetic,{ /* private fields */ }Expand description
Non-zero scalar type.
This type ensures that its value is not zero, ala core::num::NonZero*.
To do this, the generic S type must impl both Default and
ConstantTimeEq, with the requirement that S::default() returns 0.
In the context of ECC, it’s useful for ensuring that scalar multiplication cannot result in the point at infinity.
Implementations§
§impl<C> NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> NonZeroScalar<C>where
C: CurveArithmetic,
pub fn random(rng: &mut impl CryptoRngCore) -> NonZeroScalar<C>
pub fn random(rng: &mut impl CryptoRngCore) -> NonZeroScalar<C>
Generate a random NonZeroScalar.
pub fn new(scalar: <C as CurveArithmetic>::Scalar) -> CtOption<NonZeroScalar<C>>
pub fn new(scalar: <C as CurveArithmetic>::Scalar) -> CtOption<NonZeroScalar<C>>
Create a NonZeroScalar from a scalar.
pub fn from_repr(
repr: GenericArray<u8, <C as Curve>::FieldBytesSize>,
) -> CtOption<NonZeroScalar<C>>
pub fn from_repr( repr: GenericArray<u8, <C as Curve>::FieldBytesSize>, ) -> CtOption<NonZeroScalar<C>>
Decode a NonZeroScalar from a big endian-serialized field element.
pub fn from_uint(uint: <C as Curve>::Uint) -> CtOption<NonZeroScalar<C>>
pub fn from_uint(uint: <C as Curve>::Uint) -> CtOption<NonZeroScalar<C>>
Create a NonZeroScalar from a C::Uint.
Trait Implementations§
§impl<C> AsRef<<C as CurveArithmetic>::Scalar> for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> AsRef<<C as CurveArithmetic>::Scalar> for NonZeroScalar<C>where
C: CurveArithmetic,
§fn as_ref(&self) -> &<C as CurveArithmetic>::Scalar
fn as_ref(&self) -> &<C as CurveArithmetic>::Scalar
Converts this type into a shared reference of the (usually inferred) input type.
§impl<C> Clone for NonZeroScalar<C>where
C: Clone + CurveArithmetic,
impl<C> Clone for NonZeroScalar<C>where
C: Clone + CurveArithmetic,
§fn clone(&self) -> NonZeroScalar<C>
fn clone(&self) -> NonZeroScalar<C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl<C> ConditionallySelectable for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> ConditionallySelectable for NonZeroScalar<C>where
C: CurveArithmetic,
§fn conditional_select(
a: &NonZeroScalar<C>,
b: &NonZeroScalar<C>,
choice: Choice,
) -> NonZeroScalar<C>
fn conditional_select( a: &NonZeroScalar<C>, b: &NonZeroScalar<C>, choice: Choice, ) -> NonZeroScalar<C>
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
Conditionally swap
self and other if choice == 1; otherwise,
reassign both unto themselves. Read more§impl<C> ConstantTimeEq for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> ConstantTimeEq for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> Deref for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> Deref for NonZeroScalar<C>where
C: CurveArithmetic,
§type Target = <C as CurveArithmetic>::Scalar
type Target = <C as CurveArithmetic>::Scalar
The resulting type after dereferencing.
§fn deref(&self) -> &<C as CurveArithmetic>::Scalar
fn deref(&self) -> &<C as CurveArithmetic>::Scalar
Dereferences the value.
§impl<C> Display for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> Display for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> From<&NonZeroScalar<C>> for GenericArray<u8, <C as Curve>::FieldBytesSize>where
C: CurveArithmetic,
impl<C> From<&NonZeroScalar<C>> for GenericArray<u8, <C as Curve>::FieldBytesSize>where
C: CurveArithmetic,
§fn from(
scalar: &NonZeroScalar<C>,
) -> GenericArray<u8, <C as Curve>::FieldBytesSize>
fn from( scalar: &NonZeroScalar<C>, ) -> GenericArray<u8, <C as Curve>::FieldBytesSize>
Converts to this type from the input type.
§impl<C> From<&NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
impl<C> From<&NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
§fn from(scalar: &NonZeroScalar<C>) -> ScalarPrimitive<C>
fn from(scalar: &NonZeroScalar<C>) -> ScalarPrimitive<C>
Converts to this type from the input type.
§impl<C> From<&NonZeroScalar<C>> for SecretKey<C>where
C: CurveArithmetic,
Available on crate feature arithmetic only.
impl<C> From<&NonZeroScalar<C>> for SecretKey<C>where
C: CurveArithmetic,
Available on crate feature
arithmetic only.§fn from(scalar: &NonZeroScalar<C>) -> SecretKey<C>
fn from(scalar: &NonZeroScalar<C>) -> SecretKey<C>
Converts to this type from the input type.
§impl<C> From<&SecretKey<C>> for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> From<&SecretKey<C>> for NonZeroScalar<C>where
C: CurveArithmetic,
§fn from(sk: &SecretKey<C>) -> NonZeroScalar<C>
fn from(sk: &SecretKey<C>) -> NonZeroScalar<C>
Converts to this type from the input type.
§impl<C> From<NonZeroScalar<C>> for GenericArray<u8, <C as Curve>::FieldBytesSize>where
C: CurveArithmetic,
impl<C> From<NonZeroScalar<C>> for GenericArray<u8, <C as Curve>::FieldBytesSize>where
C: CurveArithmetic,
§fn from(
scalar: NonZeroScalar<C>,
) -> GenericArray<u8, <C as Curve>::FieldBytesSize>
fn from( scalar: NonZeroScalar<C>, ) -> GenericArray<u8, <C as Curve>::FieldBytesSize>
Converts to this type from the input type.
§impl<C> From<NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
impl<C> From<NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
§fn from(scalar: NonZeroScalar<C>) -> ScalarPrimitive<C>
fn from(scalar: NonZeroScalar<C>) -> ScalarPrimitive<C>
Converts to this type from the input type.
§impl<C> From<NonZeroScalar<C>> for SecretKey<C>where
C: CurveArithmetic,
Available on crate feature arithmetic only.
impl<C> From<NonZeroScalar<C>> for SecretKey<C>where
C: CurveArithmetic,
Available on crate feature
arithmetic only.§fn from(scalar: NonZeroScalar<C>) -> SecretKey<C>
fn from(scalar: NonZeroScalar<C>) -> SecretKey<C>
Converts to this type from the input type.
§impl<C> From<NonZeroScalar<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>> + SignPrimitive<C>,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> From<NonZeroScalar<C>> for SigningKey<C>where
C: PrimeCurve + CurveArithmetic,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>> + SignPrimitive<C>,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
§fn from(secret_scalar: NonZeroScalar<C>) -> SigningKey<C>
fn from(secret_scalar: NonZeroScalar<C>) -> SigningKey<C>
Converts to this type from the input type.
§impl<C> From<SecretKey<C>> for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> From<SecretKey<C>> for NonZeroScalar<C>where
C: CurveArithmetic,
§fn from(sk: SecretKey<C>) -> NonZeroScalar<C>
fn from(sk: SecretKey<C>) -> NonZeroScalar<C>
Converts to this type from the input type.
§impl<C> FromStr for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> FromStr for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> Invert for NonZeroScalar<C>where
C: CurveArithmetic,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>>,
impl<C> Invert for NonZeroScalar<C>where
C: CurveArithmetic,
<C as CurveArithmetic>::Scalar: Invert<Output = CtOption<<C as CurveArithmetic>::Scalar>>,
§type Output = NonZeroScalar<C>
type Output = NonZeroScalar<C>
Field element type
§fn invert(&self) -> NonZeroScalar<C>
fn invert(&self) -> NonZeroScalar<C>
Invert a field element.
§fn invert_vartime(&self) -> <NonZeroScalar<C> as Invert>::Output
fn invert_vartime(&self) -> <NonZeroScalar<C> as Invert>::Output
Invert a field element in variable time. Read more
§impl<C> IsHigh for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> IsHigh for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> LowerHex for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> LowerHex for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C, P> Mul<&NonZeroScalar<C>> for &NonIdentity<P>
impl<C, P> Mul<&NonZeroScalar<C>> for &NonIdentity<P>
§type Output = NonIdentity<P>
type Output = NonIdentity<P>
The resulting type after applying the
* operator.§fn mul(
self,
rhs: &NonZeroScalar<C>,
) -> <&NonIdentity<P> as Mul<&NonZeroScalar<C>>>::Output
fn mul( self, rhs: &NonZeroScalar<C>, ) -> <&NonIdentity<P> as Mul<&NonZeroScalar<C>>>::Output
Performs the
* operation. Read more§impl<C> Mul<&NonZeroScalar<C>> for NonZeroScalar<C>where
C: PrimeCurve + CurveArithmetic,
impl<C> Mul<&NonZeroScalar<C>> for NonZeroScalar<C>where
C: PrimeCurve + CurveArithmetic,
§type Output = NonZeroScalar<C>
type Output = NonZeroScalar<C>
The resulting type after applying the
* operator.§fn mul(self, other: &NonZeroScalar<C>) -> NonZeroScalar<C>
fn mul(self, other: &NonZeroScalar<C>) -> NonZeroScalar<C>
Performs the
* operation. Read more§impl<C, P> Mul<NonZeroScalar<C>> for NonIdentity<P>
impl<C, P> Mul<NonZeroScalar<C>> for NonIdentity<P>
§type Output = NonIdentity<P>
type Output = NonIdentity<P>
The resulting type after applying the
* operator.§fn mul(
self,
rhs: NonZeroScalar<C>,
) -> <NonIdentity<P> as Mul<NonZeroScalar<C>>>::Output
fn mul( self, rhs: NonZeroScalar<C>, ) -> <NonIdentity<P> as Mul<NonZeroScalar<C>>>::Output
Performs the
* operation. Read more§impl<C> Mul for NonZeroScalar<C>where
C: PrimeCurve + CurveArithmetic,
impl<C> Mul for NonZeroScalar<C>where
C: PrimeCurve + CurveArithmetic,
§type Output = NonZeroScalar<C>
type Output = NonZeroScalar<C>
The resulting type after applying the
* operator.§fn mul(self, other: NonZeroScalar<C>) -> NonZeroScalar<C>
fn mul(self, other: NonZeroScalar<C>) -> NonZeroScalar<C>
Performs the
* operation. Read more§impl<C> Neg for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> Neg for NonZeroScalar<C>where
C: CurveArithmetic,
§type Output = NonZeroScalar<C>
type Output = NonZeroScalar<C>
The resulting type after applying the
- operator.§fn neg(self) -> NonZeroScalar<C>
fn neg(self) -> NonZeroScalar<C>
Performs the unary
- operation. Read more§impl<C, I> Reduce<I> for NonZeroScalar<C>where
C: CurveArithmetic,
I: Integer + ArrayEncoding,
<C as CurveArithmetic>::Scalar: Reduce<I> + ReduceNonZero<I>,
Note: this is a non-zero reduction, as it’s impl’d for NonZeroScalar.
impl<C, I> Reduce<I> for NonZeroScalar<C>where
C: CurveArithmetic,
I: Integer + ArrayEncoding,
<C as CurveArithmetic>::Scalar: Reduce<I> + ReduceNonZero<I>,
Note: this is a non-zero reduction, as it’s impl’d for NonZeroScalar.
§type Bytes = <<C as CurveArithmetic>::Scalar as Reduce<I>>::Bytes
type Bytes = <<C as CurveArithmetic>::Scalar as Reduce<I>>::Bytes
Bytes used as input to
Reduce::reduce_bytes.§fn reduce(n: I) -> NonZeroScalar<C>
fn reduce(n: I) -> NonZeroScalar<C>
Perform a modular reduction, returning a field element.
§fn reduce_bytes(
bytes: &<NonZeroScalar<C> as Reduce<I>>::Bytes,
) -> NonZeroScalar<C>
fn reduce_bytes( bytes: &<NonZeroScalar<C> as Reduce<I>>::Bytes, ) -> NonZeroScalar<C>
Interpret the given bytes as an integer and perform a modular reduction.
§impl<C, I> ReduceNonZero<I> for NonZeroScalar<C>where
NonZeroScalar<C>: Reduce<I>,
C: CurveArithmetic,
I: Integer + ArrayEncoding,
<C as CurveArithmetic>::Scalar: Reduce<I, Bytes = <NonZeroScalar<C> as Reduce<I>>::Bytes> + ReduceNonZero<I>,
Note: forwards to the Reduce impl.
impl<C, I> ReduceNonZero<I> for NonZeroScalar<C>where
NonZeroScalar<C>: Reduce<I>,
C: CurveArithmetic,
I: Integer + ArrayEncoding,
<C as CurveArithmetic>::Scalar: Reduce<I, Bytes = <NonZeroScalar<C> as Reduce<I>>::Bytes> + ReduceNonZero<I>,
Note: forwards to the Reduce impl.
§fn reduce_nonzero(n: I) -> NonZeroScalar<C>
fn reduce_nonzero(n: I) -> NonZeroScalar<C>
Perform a modular reduction, returning a field element.
§fn reduce_nonzero_bytes(
bytes: &<NonZeroScalar<C> as Reduce<I>>::Bytes,
) -> NonZeroScalar<C>
fn reduce_nonzero_bytes( bytes: &<NonZeroScalar<C> as Reduce<I>>::Bytes, ) -> NonZeroScalar<C>
Interpret the given bytes as an integer and perform a modular reduction
to a non-zero output.
§impl<C> TryFrom<&[u8]> for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> TryFrom<&[u8]> for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> UpperHex for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> UpperHex for NonZeroScalar<C>where
C: CurveArithmetic,
§impl<C> Zeroize for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> Zeroize for NonZeroScalar<C>where
C: CurveArithmetic,
impl<C> Copy for NonZeroScalar<C>where
C: CurveArithmetic,
Auto Trait Implementations§
impl<C> Freeze for NonZeroScalar<C>
impl<C> RefUnwindSafe for NonZeroScalar<C>
impl<C> Send for NonZeroScalar<C>
impl<C> Sync for NonZeroScalar<C>
impl<C> Unpin for NonZeroScalar<C>
impl<C> UnwindSafe for NonZeroScalar<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more