pub struct ScalarPrimitive<C: Curve> { /* private fields */ }
Expand description
Generic scalar type with primitive functionality.
This type provides a baseline level of scalar arithmetic functionality which is always available for all curves, regardless of if they implement any arithmetic traits.
§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> ScalarPrimitive<C>where
C: Curve,
impl<C> ScalarPrimitive<C>where
C: Curve,
Sourcepub fn random(rng: &mut impl CryptoRngCore) -> Self
pub fn random(rng: &mut impl CryptoRngCore) -> Self
Generate a random ScalarPrimitive
.
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 ScalarPrimitive
from a serialized field element
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Decode ScalarPrimitive
from a big endian byte slice.
Sourcepub fn is_zero(&self) -> Choice
pub fn is_zero(&self) -> Choice
Is this ScalarPrimitive
value equal to zero?
Sourcepub fn is_even(&self) -> Choice
pub fn is_even(&self) -> Choice
Is this ScalarPrimitive
value even?
Sourcepub fn is_odd(&self) -> Choice
pub fn is_odd(&self) -> Choice
Is this ScalarPrimitive
value odd?
Sourcepub fn to_bytes(&self) -> FieldBytes<C>
pub fn to_bytes(&self) -> FieldBytes<C>
Encode ScalarPrimitive
as a serialized field element.
Trait Implementations§
Source§impl<C> Add<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
impl<C> Add<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> Add for ScalarPrimitive<C>where
C: Curve,
impl<C> Add for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> AddAssign<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
impl<C> AddAssign<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
+=
operation. Read moreSource§impl<C> AddAssign for ScalarPrimitive<C>where
C: Curve,
impl<C> AddAssign for ScalarPrimitive<C>where
C: Curve,
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moreSource§impl<C: Clone + Curve> Clone for ScalarPrimitive<C>
impl<C: Clone + Curve> Clone for ScalarPrimitive<C>
Source§fn clone(&self) -> ScalarPrimitive<C>
fn clone(&self) -> ScalarPrimitive<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<C> ConditionallySelectable for ScalarPrimitive<C>where
C: Curve,
impl<C> ConditionallySelectable for ScalarPrimitive<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)
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moreSource§impl<C> ConstantTimeEq for ScalarPrimitive<C>where
C: Curve,
impl<C> ConstantTimeEq for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> ConstantTimeGreater for ScalarPrimitive<C>where
C: Curve,
impl<C> ConstantTimeGreater for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> ConstantTimeLess for ScalarPrimitive<C>where
C: Curve,
impl<C> ConstantTimeLess for ScalarPrimitive<C>where
C: Curve,
Source§impl<C: Default + Curve> Default for ScalarPrimitive<C>
impl<C: Default + Curve> Default for ScalarPrimitive<C>
Source§fn default() -> ScalarPrimitive<C>
fn default() -> ScalarPrimitive<C>
Source§impl<C> Display for ScalarPrimitive<C>where
C: Curve,
impl<C> Display for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> From<&NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
impl<C> From<&NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
Source§fn from(scalar: &NonZeroScalar<C>) -> ScalarPrimitive<C>
fn from(scalar: &NonZeroScalar<C>) -> ScalarPrimitive<C>
Source§impl<C> From<NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
impl<C> From<NonZeroScalar<C>> for ScalarPrimitive<C>where
C: CurveArithmetic,
Source§fn from(scalar: NonZeroScalar<C>) -> ScalarPrimitive<C>
fn from(scalar: NonZeroScalar<C>) -> ScalarPrimitive<C>
Source§impl<C> FromStr for ScalarPrimitive<C>where
C: Curve,
impl<C> FromStr for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> FromUintUnchecked for ScalarPrimitive<C>where
C: Curve,
impl<C> FromUintUnchecked for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> IsHigh for ScalarPrimitive<C>where
C: Curve,
impl<C> IsHigh for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> LowerHex for ScalarPrimitive<C>where
C: Curve,
impl<C> LowerHex for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> Neg for &ScalarPrimitive<C>where
C: Curve,
impl<C> Neg for &ScalarPrimitive<C>where
C: Curve,
Source§type Output = ScalarPrimitive<C>
type Output = ScalarPrimitive<C>
-
operator.Source§fn neg(self) -> ScalarPrimitive<C>
fn neg(self) -> ScalarPrimitive<C>
-
operation. Read moreSource§impl<C> Neg for ScalarPrimitive<C>where
C: Curve,
impl<C> Neg for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> Ord for ScalarPrimitive<C>where
C: Curve,
impl<C> Ord for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> PartialEq for ScalarPrimitive<C>where
C: Curve,
impl<C> PartialEq for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> PartialOrd for ScalarPrimitive<C>where
C: Curve,
impl<C> PartialOrd for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> ShrAssign<usize> for ScalarPrimitive<C>where
C: Curve,
impl<C> ShrAssign<usize> for ScalarPrimitive<C>where
C: Curve,
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moreSource§impl<C> Sub<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
impl<C> Sub<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> Sub for ScalarPrimitive<C>where
C: Curve,
impl<C> Sub for ScalarPrimitive<C>where
C: Curve,
Source§impl<C> SubAssign<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
impl<C> SubAssign<&ScalarPrimitive<C>> for ScalarPrimitive<C>where
C: Curve,
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
-=
operation. Read moreSource§impl<C> SubAssign for ScalarPrimitive<C>where
C: Curve,
impl<C> SubAssign for ScalarPrimitive<C>where
C: Curve,
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read moreSource§impl<C> UpperHex for ScalarPrimitive<C>where
C: Curve,
impl<C> UpperHex for ScalarPrimitive<C>where
C: Curve,
impl<C: Copy + Curve> Copy for ScalarPrimitive<C>
impl<C: Curve> DefaultIsZeroes for ScalarPrimitive<C>
impl<C: Curve> Eq for ScalarPrimitive<C>
Auto Trait Implementations§
impl<C> Freeze for ScalarPrimitive<C>
impl<C> RefUnwindSafe for ScalarPrimitive<C>
impl<C> Send for ScalarPrimitive<C>
impl<C> Sync for ScalarPrimitive<C>
impl<C> Unpin for ScalarPrimitive<C>
impl<C> UnwindSafe for ScalarPrimitive<C>
Blanket Implementations§
Source§impl<A, T> AsBits<T> for A
impl<A, T> AsBits<T> for A
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> ConditionallyNegatable for T
impl<T> ConditionallyNegatable for T
Source§fn conditional_negate(&mut self, choice: Choice)
fn conditional_negate(&mut self, choice: Choice)
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.