pub struct ScalarValue<C: Curve> { /* private fields */ }Expand description
Integer values within the range of a given Curve’s scalar modulus.
This type provides a baseline level of scalar arithmetic functionality which is always available for all curves.
§serde support
When the optional serde feature of this create is enabled, Serialize
and Deserialize impls are provided for this type.
The serialization is a fixed-width big endian encoding. When used with textual formats, the binary data is encoded as hexadecimal.
Implementations§
Source§impl<C> ScalarValue<C>where
C: Curve,
impl<C> ScalarValue<C>where
C: Curve,
Sourcepub fn new(uint: C::Uint) -> CtOption<Self>
pub fn new(uint: C::Uint) -> CtOption<Self>
Create a new scalar from Curve::Uint.
Sourcepub fn from_bytes(bytes: &FieldBytes<C>) -> CtOption<Self>
pub fn from_bytes(bytes: &FieldBytes<C>) -> CtOption<Self>
Decode ScalarValue from a serialized field element
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Decode ScalarValue from a big endian byte slice.
§Errors
- if
sliceis not sized appropriately forSelf::MODULUS. - if the decoded scalar field element overflows
Self::MODULUS.
Sourcepub fn is_zero(&self) -> Choice
pub fn is_zero(&self) -> Choice
Is this ScalarValue value equal to zero?
Sourcepub fn is_even(&self) -> Choice
pub fn is_even(&self) -> Choice
Is this ScalarValue value even?
Sourcepub fn is_odd(&self) -> Choice
pub fn is_odd(&self) -> Choice
Is this ScalarValue value odd?
Sourcepub fn to_bytes(&self) -> FieldBytes<C>
pub fn to_bytes(&self) -> FieldBytes<C>
Encode ScalarValue as a serialized field element.
Trait Implementations§
Source§impl<C> Add for ScalarValue<C>where
C: Curve,
impl<C> Add for ScalarValue<C>where
C: Curve,
Source§impl<C> Add<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> Add<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
Source§impl<C> AddAssign for ScalarValue<C>where
C: Curve,
impl<C> AddAssign for ScalarValue<C>where
C: Curve,
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl<C> AddAssign<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> AddAssign<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
Performs the
+= operation. Read moreSource§impl<C: Clone + Curve> Clone for ScalarValue<C>
impl<C: Clone + Curve> Clone for ScalarValue<C>
Source§fn clone(&self) -> ScalarValue<C>
fn clone(&self) -> ScalarValue<C>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C> ConditionallySelectable for ScalarValue<C>where
C: Curve,
impl<C> ConditionallySelectable for ScalarValue<C>where
C: Curve,
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
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 moreSource§impl<C> ConstantTimeEq for ScalarValue<C>where
C: Curve,
impl<C> ConstantTimeEq for ScalarValue<C>where
C: Curve,
Source§impl<C> ConstantTimeGreater for ScalarValue<C>where
C: Curve,
impl<C> ConstantTimeGreater for ScalarValue<C>where
C: Curve,
Source§impl<C> ConstantTimeLess for ScalarValue<C>where
C: Curve,
impl<C> ConstantTimeLess for ScalarValue<C>where
C: Curve,
impl<C: Copy + Curve> Copy for ScalarValue<C>
Source§impl<C> CtEq for ScalarValue<C>where
C: Curve,
impl<C> CtEq for ScalarValue<C>where
C: Curve,
Source§impl<C> CtGt for ScalarValue<C>where
C: Curve,
impl<C> CtGt for ScalarValue<C>where
C: Curve,
Source§impl<C> CtLt for ScalarValue<C>where
C: Curve,
impl<C> CtLt for ScalarValue<C>where
C: Curve,
Source§impl<C> CtSelect for ScalarValue<C>where
C: Curve,
impl<C> CtSelect for ScalarValue<C>where
C: Curve,
Source§impl<C: Default + Curve> Default for ScalarValue<C>
impl<C: Default + Curve> Default for ScalarValue<C>
Source§fn default() -> ScalarValue<C>
fn default() -> ScalarValue<C>
Returns the “default value” for a type. Read more
impl<C: Curve> DefaultIsZeroes for ScalarValue<C>
Source§impl<'de, C> Deserialize<'de> for ScalarValue<C>where
C: Curve,
Available on crate feature serde only.
impl<'de, C> Deserialize<'de> for ScalarValue<C>where
C: Curve,
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<C> Display for ScalarValue<C>where
C: Curve,
impl<C> Display for ScalarValue<C>where
C: Curve,
impl<C: Curve> Eq for ScalarValue<C>
Source§impl<C> From<&NonZeroScalar<C>> for ScalarValue<C>where
C: CurveArithmetic,
impl<C> From<&NonZeroScalar<C>> for ScalarValue<C>where
C: CurveArithmetic,
Source§fn from(scalar: &NonZeroScalar<C>) -> ScalarValue<C>
fn from(scalar: &NonZeroScalar<C>) -> ScalarValue<C>
Converts to this type from the input type.
Source§impl<C> From<NonZeroScalar<C>> for ScalarValue<C>where
C: CurveArithmetic,
impl<C> From<NonZeroScalar<C>> for ScalarValue<C>where
C: CurveArithmetic,
Source§fn from(scalar: NonZeroScalar<C>) -> ScalarValue<C>
fn from(scalar: NonZeroScalar<C>) -> ScalarValue<C>
Converts to this type from the input type.
Source§impl<C> FromStr for ScalarValue<C>where
C: Curve,
impl<C> FromStr for ScalarValue<C>where
C: Curve,
Source§impl<C> FromUintUnchecked for ScalarValue<C>where
C: Curve,
impl<C> FromUintUnchecked for ScalarValue<C>where
C: Curve,
Source§impl<C> Generate for ScalarValue<C>where
C: Curve,
impl<C> Generate for ScalarValue<C>where
C: Curve,
Source§fn try_generate_from_rng<R: TryCryptoRng + ?Sized>(
rng: &mut R,
) -> Result<Self, R::Error>
fn try_generate_from_rng<R: TryCryptoRng + ?Sized>( rng: &mut R, ) -> Result<Self, R::Error>
Generate random key using the provided
TryCryptoRng. Read moreSource§fn generate_from_rng<R>(rng: &mut R) -> Self
fn generate_from_rng<R>(rng: &mut R) -> Self
Generate random key using the provided
CryptoRng.Source§fn try_generate() -> Result<Self, Error>
fn try_generate() -> Result<Self, Error>
Randomly generate a value of this type using the system’s ambient cryptographically secure
random number generator. Read more
Source§impl<C> IsHigh for ScalarValue<C>where
C: Curve,
impl<C> IsHigh for ScalarValue<C>where
C: Curve,
Source§impl<C> LowerHex for ScalarValue<C>where
C: Curve,
impl<C> LowerHex for ScalarValue<C>where
C: Curve,
Source§impl<C> Neg for ScalarValue<C>where
C: Curve,
impl<C> Neg for ScalarValue<C>where
C: Curve,
Source§impl<C> Neg for &ScalarValue<C>where
C: Curve,
impl<C> Neg for &ScalarValue<C>where
C: Curve,
Source§type Output = ScalarValue<C>
type Output = ScalarValue<C>
The resulting type after applying the
- operator.Source§fn neg(self) -> ScalarValue<C>
fn neg(self) -> ScalarValue<C>
Performs the unary
- operation. Read moreSource§impl<C> Ord for ScalarValue<C>where
C: Curve,
impl<C> Ord for ScalarValue<C>where
C: Curve,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<C> PartialEq for ScalarValue<C>where
C: Curve,
impl<C> PartialEq for ScalarValue<C>where
C: Curve,
Source§impl<C> PartialOrd for ScalarValue<C>where
C: Curve,
impl<C> PartialOrd for ScalarValue<C>where
C: Curve,
Source§impl<C> Serialize for ScalarValue<C>where
C: Curve,
Available on crate feature serde only.
impl<C> Serialize for ScalarValue<C>where
C: Curve,
Available on crate feature
serde only.Source§impl<C> ShrAssign<usize> for ScalarValue<C>where
C: Curve,
impl<C> ShrAssign<usize> for ScalarValue<C>where
C: Curve,
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
Performs the
>>= operation. Read moreSource§impl<C> Sub for ScalarValue<C>where
C: Curve,
impl<C> Sub for ScalarValue<C>where
C: Curve,
Source§impl<C> Sub<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> Sub<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
Source§impl<C> SubAssign for ScalarValue<C>where
C: Curve,
impl<C> SubAssign for ScalarValue<C>where
C: Curve,
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-= operation. Read moreSource§impl<C> SubAssign<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> SubAssign<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl<C> Freeze for ScalarValue<C>
impl<C> RefUnwindSafe for ScalarValue<C>
impl<C> Send for ScalarValue<C>
impl<C> Sync for ScalarValue<C>
impl<C> Unpin for ScalarValue<C>
impl<C> UnsafeUnpin for ScalarValue<C>
impl<C> UnwindSafe for ScalarValue<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