pub struct Scalar(_);arithmetic only.Expand description
Scalars are elements in the finite field modulo n.
Implementations
sourceimpl Scalar
impl Scalar
sourcepub fn from_be_bytes(repr: FieldBytes) -> CtOption<Self>
pub fn from_be_bytes(repr: FieldBytes) -> CtOption<Self>
Create a Scalar from a canonical big-endian representation.
sourcepub fn from_le_bytes(repr: FieldBytes) -> CtOption<Self>
pub fn from_le_bytes(repr: FieldBytes) -> CtOption<Self>
Create a Scalar from a canonical little-endian representation.
sourcepub fn from_le_slice(slice: &[u8]) -> Result<Self>
pub fn from_le_slice(slice: &[u8]) -> Result<Self>
Decode Scalar from a little endian byte slice.
sourcepub fn to_be_bytes(self) -> FieldBytes
pub fn to_be_bytes(self) -> FieldBytes
Returns the big-endian encoding of this Scalar.
sourcepub fn to_le_bytes(self) -> FieldBytes
pub fn to_le_bytes(self) -> FieldBytes
Returns the little-endian encoding of this Scalar.
sourcepub const fn to_canonical(self) -> U384
pub const fn to_canonical(self) -> U384
Trait Implementations
sourceimpl AddAssign<&'_ Scalar> for Scalar
impl AddAssign<&'_ Scalar> for Scalar
sourcefn add_assign(&mut self, other: &Scalar)
fn add_assign(&mut self, other: &Scalar)
Performs the += operation. Read more
sourceimpl AddAssign<Scalar> for Scalar
impl AddAssign<Scalar> for Scalar
sourcefn add_assign(&mut self, other: Scalar)
fn add_assign(&mut self, other: Scalar)
Performs the += operation. Read more
sourceimpl ConditionallySelectable for Scalar
impl ConditionallySelectable for Scalar
sourceimpl ConstantTimeEq for Scalar
impl ConstantTimeEq for Scalar
sourceimpl ConstantTimeGreater for Scalar
impl ConstantTimeGreater for Scalar
sourceimpl ConstantTimeLess for Scalar
impl ConstantTimeLess for Scalar
sourceimpl Field for Scalar
impl Field for Scalar
sourcefn random(rng: impl RngCore) -> Self
fn random(rng: impl RngCore) -> Self
Returns an element chosen uniformly at random using a user-provided RNG.
sourcefn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Computes the multiplicative inverse of this element, failing if the element is zero. Read more
sourcefn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
Returns the square root of the field element, if it is quadratic residue. Read more
fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
Returns true iff this element is zero. Read more
fn cube(&self) -> Self
fn cube(&self) -> Self
Cubes this element.
sourceimpl From<&'_ Scalar> for ScalarCore<NistP384>
impl From<&'_ Scalar> for ScalarCore<NistP384>
sourcefn from(scalar: &Scalar) -> ScalarCore<NistP384>
fn from(scalar: &Scalar) -> ScalarCore<NistP384>
Converts to this type from the input type.
sourceimpl From<&'_ Scalar> for FieldBytes
impl From<&'_ Scalar> for FieldBytes
sourceimpl From<&'_ ScalarCore<NistP384>> for Scalar
impl From<&'_ ScalarCore<NistP384>> for Scalar
sourcefn from(w: &ScalarCore<NistP384>) -> Scalar
fn from(w: &ScalarCore<NistP384>) -> Scalar
Converts to this type from the input type.
sourceimpl From<Scalar> for ScalarCore<NistP384>
impl From<Scalar> for ScalarCore<NistP384>
sourcefn from(scalar: Scalar) -> ScalarCore<NistP384>
fn from(scalar: Scalar) -> ScalarCore<NistP384>
Converts to this type from the input type.
sourceimpl From<Scalar> for FieldBytes
impl From<Scalar> for FieldBytes
sourceimpl From<ScalarCore<NistP384>> for Scalar
impl From<ScalarCore<NistP384>> for Scalar
sourcefn from(w: ScalarCore<NistP384>) -> Self
fn from(w: ScalarCore<NistP384>) -> Self
Converts to this type from the input type.
sourceimpl Mul<&'_ Scalar> for AffinePoint
impl Mul<&'_ Scalar> for AffinePoint
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the * operator.
sourcefn mul(self, scalar: &Scalar) -> ProjectivePoint
fn mul(self, scalar: &Scalar) -> ProjectivePoint
Performs the * operation. Read more
sourceimpl Mul<&'_ Scalar> for &ProjectivePoint
impl Mul<&'_ Scalar> for &ProjectivePoint
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the * operator.
sourcefn mul(self, other: &Scalar) -> ProjectivePoint
fn mul(self, other: &Scalar) -> ProjectivePoint
Performs the * operation. Read more
sourceimpl Mul<&'_ Scalar> for ProjectivePoint
impl Mul<&'_ Scalar> for ProjectivePoint
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the * operator.
sourcefn mul(self, other: &Scalar) -> ProjectivePoint
fn mul(self, other: &Scalar) -> ProjectivePoint
Performs the * operation. Read more
sourceimpl Mul<Scalar> for AffinePoint
impl Mul<Scalar> for AffinePoint
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the * operator.
sourcefn mul(self, scalar: Scalar) -> ProjectivePoint
fn mul(self, scalar: Scalar) -> ProjectivePoint
Performs the * operation. Read more
sourceimpl Mul<Scalar> for ProjectivePoint
impl Mul<Scalar> for ProjectivePoint
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the * operator.
sourcefn mul(self, other: Scalar) -> ProjectivePoint
fn mul(self, other: Scalar) -> ProjectivePoint
Performs the * operation. Read more
sourceimpl MulAssign<&'_ Scalar> for ProjectivePoint
impl MulAssign<&'_ Scalar> for ProjectivePoint
sourcefn mul_assign(&mut self, rhs: &Scalar)
fn mul_assign(&mut self, rhs: &Scalar)
Performs the *= operation. Read more
sourceimpl MulAssign<&'_ Scalar> for Scalar
impl MulAssign<&'_ Scalar> for Scalar
sourcefn mul_assign(&mut self, other: &Scalar)
fn mul_assign(&mut self, other: &Scalar)
Performs the *= operation. Read more
sourceimpl MulAssign<Scalar> for ProjectivePoint
impl MulAssign<Scalar> for ProjectivePoint
sourcefn mul_assign(&mut self, rhs: Scalar)
fn mul_assign(&mut self, rhs: Scalar)
Performs the *= operation. Read more
sourceimpl MulAssign<Scalar> for Scalar
impl MulAssign<Scalar> for Scalar
sourcefn mul_assign(&mut self, other: Scalar)
fn mul_assign(&mut self, other: Scalar)
Performs the *= operation. Read more
sourceimpl PrimeField for Scalar
impl PrimeField for Scalar
type Repr = GenericArray<u8, <<NistP384 as Curve>::UInt as ArrayEncoding>::ByteSize>
type Repr = GenericArray<u8, <<NistP384 as Curve>::UInt as ArrayEncoding>::ByteSize>
The prime field can be converted back and forth into this binary representation. Read more
sourceconst CAPACITY: u32 = 383u32
const CAPACITY: u32 = 383u32
How many bits of information can be reliably stored in the field element. Read more
sourceconst S: u32 = 1u32
const S: u32 = 1u32
An integer s satisfying the equation 2^s * t = modulus - 1 with t odd. Read more
sourcefn from_repr(bytes: FieldBytes) -> CtOption<Self>
fn from_repr(bytes: FieldBytes) -> CtOption<Self>
Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus). Read more
sourcefn to_repr(&self) -> FieldBytes
fn to_repr(&self) -> FieldBytes
Converts an element of the prime field into the standard byte representation for this field. Read more
sourcefn multiplicative_generator() -> Self
fn multiplicative_generator() -> Self
Returns a fixed multiplicative generator of modulus - 1 order. This element must
also be a quadratic nonresidue. Read more
sourcefn root_of_unity() -> Self
fn root_of_unity() -> Self
Returns the 2^s root of unity. Read more
fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Interpret a string of numbers as a (congruent) prime field element. Does not accept unnecessary leading zeroes or a blank string. Read more
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus). Read more
sourceimpl Reduce<UInt<{_: usize}>> for Scalar
impl Reduce<UInt<{_: usize}>> for Scalar
sourcefn from_uint_reduced(w: U384) -> Self
fn from_uint_reduced(w: U384) -> Self
Perform a modular reduction, returning a field element.
sourcefn from_be_bytes_reduced(
bytes: GenericArray<u8, <UInt as ArrayEncoding>::ByteSize>
) -> Self
fn from_be_bytes_reduced(
bytes: GenericArray<u8, <UInt as ArrayEncoding>::ByteSize>
) -> Self
Interpret the given byte array as a big endian integer and perform a modular reduction. Read more
sourcefn from_le_bytes_reduced(
bytes: GenericArray<u8, <UInt as ArrayEncoding>::ByteSize>
) -> Self
fn from_le_bytes_reduced(
bytes: GenericArray<u8, <UInt as ArrayEncoding>::ByteSize>
) -> Self
Interpret the given byte array as a little endian integer and perform a modular reduction. Read more
sourcefn from_be_digest_reduced<D>(digest: D) -> Self where
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
fn from_be_digest_reduced<D>(digest: D) -> Self where
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
Interpret a digest as a big endian integer and perform a modular reduction. Read more
sourcefn from_le_digest_reduced<D>(digest: D) -> Self where
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
fn from_le_digest_reduced<D>(digest: D) -> Self where
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
Interpret a digest as a little endian integer and perform a modular reduction. Read more
sourceimpl SignPrimitive<NistP384> for Scalar
Available on crate feature ecdsa-core only.
impl SignPrimitive<NistP384> for Scalar
ecdsa-core only.sourcefn try_sign_prehashed<K>(
&self,
k: K,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
K: Borrow<Self> + Invert<Output = CtOption<Self>>,
fn try_sign_prehashed<K>(
&self,
k: K,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
K: Borrow<Self> + Invert<Output = CtOption<Self>>,
Try to sign the prehashed message. Read more
sourcefn try_sign_prehashed_rfc6979<D>(
&self,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
fn try_sign_prehashed_rfc6979<D>(
&self,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
sourcefn try_sign_digest_rfc6979<D>(
&self,
msg_digest: D,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
fn try_sign_digest_rfc6979<D>(
&self,
msg_digest: D,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
sourceimpl SubAssign<&'_ Scalar> for Scalar
impl SubAssign<&'_ Scalar> for Scalar
sourcefn sub_assign(&mut self, other: &Scalar)
fn sub_assign(&mut self, other: &Scalar)
Performs the -= operation. Read more
sourceimpl SubAssign<Scalar> for Scalar
impl SubAssign<Scalar> for Scalar
sourcefn sub_assign(&mut self, other: Scalar)
fn sub_assign(&mut self, other: Scalar)
Performs the -= operation. Read more
impl Copy for Scalar
impl DefaultIsZeroes for Scalar
impl Eq for Scalar
Auto Trait Implementations
impl RefUnwindSafe for Scalar
impl Send for Scalar
impl Sync for Scalar
impl Unpin for Scalar
impl UnwindSafe for Scalar
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more