pub struct Scalar(pub(super) MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>);Expand description
Element in the NIST P-521 scalar field modulo n.
§Trait impls
Much of the important functionality is provided by traits from the [ff] crate:
- [
Field] represents elements of finite fields and provides:- [
Field::random] generate a random field element double,square, andinvertoperations- Bounds for
Add,Sub,Mul, andNeg(and*Assignequivalents) - Bounds for
ConditionallySelectablefrom thesubtlecrate
- [
PrimeFieldrepresents elements of prime fields and provides:from_repr/to_reprfor converting field elements from/to big integers.MULTIPLICATIVE_GENERATORandROOT_OF_UNITYconstants.
Please see the documentation for the relevant traits for more information.
Tuple Fields§
§0: MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>Implementations§
Source§impl Scalar
impl Scalar
Sourcepub fn from_bytes(
repr: &MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>,
) -> CtOption<Self>
pub fn from_bytes( repr: &MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>, ) -> CtOption<Self>
Create a Scalar from a canonical byte representation using the field’s configured byte order.
Sourcepub fn from_slice(slice: &[u8]) -> Option<Self>
pub fn from_slice(slice: &[u8]) -> Option<Self>
Decode Scalar from a byte slice using the field’s configured byte order.
Sourcepub const fn from_hex_vartime(hex: &str) -> Self
pub const fn from_hex_vartime(hex: &str) -> Self
Sourcepub fn to_bytes(self) -> MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
pub fn to_bytes(self) -> MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
Returns the big-endian encoding of this Scalar.
Sourcepub const fn pow_vartime<const RHS_LIMBS: usize>(
&self,
exp: &Uint<RHS_LIMBS>,
) -> Self
pub const fn pow_vartime<const RHS_LIMBS: usize>( &self, exp: &Uint<RHS_LIMBS>, ) -> Self
Returns self^exp, where exp is a little-endian integer exponent.
This operation is variable time with respect to the exponent exp.
If the exponent is fixed, this operation is constant time.
Sourcepub const fn sqn_vartime(&self, n: usize) -> Self
pub const fn sqn_vartime(&self, n: usize) -> Self
Returns self^(2^n) mod p.
This operation is variable time with respect to the exponent n.
If the exponent is fixed, this operation is constant time.
Source§impl Scalar
impl Scalar
Sourcepub(crate) const fn from_uint_unchecked(w: Uint) -> Self
pub(crate) const fn from_uint_unchecked(w: Uint) -> Self
Sourcepub const fn to_canonical(self) -> Uint
pub const fn to_canonical(self) -> Uint
Sourcepub fn invert_vartime(&self) -> CtOption<Self>
pub fn invert_vartime(&self) -> CtOption<Self>
Compute
Scalar
inversion: 1 / self in variable-time.
Sourcepub const fn const_invert(&self) -> Self
pub const fn const_invert(&self) -> Self
Compute field inversion as a const fn. Panics if self is zero.
This is mainly intended for inverting constants at compile time.
Trait Implementations§
Source§impl AddAssign<&Scalar> for Scalar
impl AddAssign<&Scalar> for Scalar
Source§fn add_assign(&mut self, other: &Scalar)
fn add_assign(&mut self, other: &Scalar)
+= operation. Read moreSource§impl AddAssign for Scalar
impl AddAssign for Scalar
Source§fn add_assign(&mut self, other: Scalar)
fn add_assign(&mut self, other: Scalar)
+= operation. Read moreSource§impl ConditionallySelectable for Scalar
impl ConditionallySelectable for Scalar
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 ConstMontyParams<{ <$params>::LIMBS }> for Scalar
impl ConstMontyParams<{ <$params>::LIMBS }> for Scalar
Source§impl ConstantTimeEq for Scalar
impl ConstantTimeEq for Scalar
Source§impl ConstantTimeGreater for Scalar
impl ConstantTimeGreater for Scalar
Source§impl ConstantTimeLess for Scalar
impl ConstantTimeLess for Scalar
Source§impl Field for Scalar
impl Field for Scalar
Source§fn try_random<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error>
fn try_random<R: TryRng + ?Sized>(rng: &mut R) -> Result<Self, R::Error>
Source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Source§fn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
Source§fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)
fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)
Source§fn random<R>(rng: &mut R) -> Self
fn random<R>(rng: &mut R) -> Self
Source§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
Source§impl From<&NonZeroScalar<NistP521>> for Scalar
impl From<&NonZeroScalar<NistP521>> for Scalar
Source§fn from(scalar: &NonZeroScalar<NistP521>) -> Self
fn from(scalar: &NonZeroScalar<NistP521>) -> Self
Source§impl From<&Scalar> for MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
impl From<&Scalar> for MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
Source§impl From<MontyFieldElement<ScalarParams, { <$params>::LIMBS }>> for Scalar
impl From<MontyFieldElement<ScalarParams, { <$params>::LIMBS }>> for Scalar
Source§fn from(fe: MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>) -> Scalar
fn from(fe: MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>) -> Scalar
Source§impl From<NonZeroScalar<NistP521>> for Scalar
impl From<NonZeroScalar<NistP521>> for Scalar
Source§fn from(scalar: NonZeroScalar<NistP521>) -> Self
fn from(scalar: NonZeroScalar<NistP521>) -> Self
Source§impl From<Scalar> for MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
impl From<Scalar> for MontyFieldBytes<ScalarParams, { ScalarParams::LIMBS }>
Source§impl From<Scalar> for MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>
impl From<Scalar> for MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>
Source§fn from(fe: Scalar) -> MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>
fn from(fe: Scalar) -> MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>
Source§impl From<ScalarValue<NistP521>> for Scalar
impl From<ScalarValue<NistP521>> for Scalar
Source§fn from(w: ScalarValue<NistP521>) -> Self
fn from(w: ScalarValue<NistP521>) -> Self
Source§impl FromUintUnchecked for Scalar
impl FromUintUnchecked for Scalar
Source§impl Generate for Scalar
impl Generate for Scalar
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>
TryCryptoRng. Read moreSource§fn generate_from_rng<R>(rng: &mut R) -> Self
fn generate_from_rng<R>(rng: &mut R) -> Self
CryptoRng.Source§impl Mul<&<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
impl Mul<&<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<&<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
impl Mul<&<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<&<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
impl Mul<&<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: &ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: &ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<&<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
impl Mul<&<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: &ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: &ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
impl Mul<<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
impl Mul<<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
impl Mul<<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl Mul<<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
impl Mul<<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
Source§type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
type Output = <NistP521 as CurveArithmetic>::ProjectivePoint
* operator.Source§fn mul(self, rhs: ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul(self, rhs: ProjectivePoint<NistP521>) -> ProjectivePoint<NistP521>
* operation. Read moreSource§impl MulAssign<&Scalar> for Scalar
impl MulAssign<&Scalar> for Scalar
Source§fn mul_assign(&mut self, other: &Scalar)
fn mul_assign(&mut self, other: &Scalar)
*= operation. Read moreSource§impl MulAssign for Scalar
impl MulAssign for Scalar
Source§fn mul_assign(&mut self, other: Scalar)
fn mul_assign(&mut self, other: Scalar)
*= operation. Read moreSource§impl MulVartime<&<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
impl MulVartime<&<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
Source§fn mul_vartime(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul_vartime(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<&<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
impl MulVartime<&<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
Source§fn mul_vartime(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul_vartime(self, rhs: &AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<&<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
impl MulVartime<&<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
Source§fn mul_vartime(
self,
rhs: &ProjectivePoint<NistP521>,
) -> ProjectivePoint<NistP521>
fn mul_vartime( self, rhs: &ProjectivePoint<NistP521>, ) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<&<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
impl MulVartime<&<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
Source§fn mul_vartime(
self,
rhs: &ProjectivePoint<NistP521>,
) -> ProjectivePoint<NistP521>
fn mul_vartime( self, rhs: &ProjectivePoint<NistP521>, ) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
impl MulVartime<<NistP521 as CurveArithmetic>::AffinePoint> for &Scalar
Source§fn mul_vartime(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul_vartime(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
impl MulVartime<<NistP521 as CurveArithmetic>::AffinePoint> for Scalar
Source§fn mul_vartime(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
fn mul_vartime(self, rhs: AffinePoint<NistP521>) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
impl MulVartime<<NistP521 as CurveArithmetic>::ProjectivePoint> for &Scalar
Source§fn mul_vartime(
self,
rhs: ProjectivePoint<NistP521>,
) -> ProjectivePoint<NistP521>
fn mul_vartime( self, rhs: ProjectivePoint<NistP521>, ) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl MulVartime<<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
impl MulVartime<<NistP521 as CurveArithmetic>::ProjectivePoint> for Scalar
Source§fn mul_vartime(
self,
rhs: ProjectivePoint<NistP521>,
) -> ProjectivePoint<NistP521>
fn mul_vartime( self, rhs: ProjectivePoint<NistP521>, ) -> ProjectivePoint<NistP521>
self by rhs in variable-time.Source§impl Ord for Scalar
impl Ord for Scalar
Source§impl PartialOrd for Scalar
impl PartialOrd for Scalar
Source§impl PrimeField for Scalar
impl PrimeField for Scalar
Source§const MODULUS: &'static str
const MODULUS: &'static str
Source§const NUM_BITS: u32 = ::primefield::MontyFieldElement<ScalarParams,
{ ScalarParams::LIMBS }>::NUM_BITS
const NUM_BITS: u32 = ::primefield::MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>::NUM_BITS
Source§const CAPACITY: u32 = ::primefield::MontyFieldElement<ScalarParams,
{ ScalarParams::LIMBS }>::CAPACITY
const CAPACITY: u32 = ::primefield::MontyFieldElement<ScalarParams, { ScalarParams::LIMBS }>::CAPACITY
Source§const MULTIPLICATIVE_GENERATOR: Self
const MULTIPLICATIVE_GENERATOR: Self
modulus - 1 order. This element must also be
a quadratic nonresidue. Read moreSource§const ROOT_OF_UNITY: Self
const ROOT_OF_UNITY: Self
2^s root of unity. Read moreSource§const ROOT_OF_UNITY_INV: Self
const ROOT_OF_UNITY_INV: Self
Self::ROOT_OF_UNITY.Source§type Repr = Array<u8, <ScalarParams as MontyFieldParams<{ <$params>::LIMBS }>>::ByteSize>
type Repr = Array<u8, <ScalarParams as MontyFieldParams<{ <$params>::LIMBS }>>::ByteSize>
Source§fn from_repr(bytes: Self::Repr) -> CtOption<Self>
fn from_repr(bytes: Self::Repr) -> CtOption<Self>
Source§fn to_repr(&self) -> Self::Repr
fn to_repr(&self) -> Self::Repr
Source§fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
Source§impl PrimeFieldExt for Scalar
impl PrimeFieldExt for Scalar
Source§const REPR_ENDIANNESS: ByteOrder
const REPR_ENDIANNESS: ByteOrder
ff::PrimeField::Repr.Source§fn to_be_repr(&self) -> Self::Repr
fn to_be_repr(&self) -> Self::Repr
self using a big endian representation.Source§fn to_le_repr(&self) -> Self::Repr
fn to_le_repr(&self) -> Self::Repr
self using a little endian representation.Source§impl Reduce<Array<u8, <NistP521 as Curve>::FieldBytesSize>> for Scalar
impl Reduce<Array<u8, <NistP521 as Curve>::FieldBytesSize>> for Scalar
Source§fn reduce(bytes: &FieldBytes) -> Self
fn reduce(bytes: &FieldBytes) -> Self
self modulo Modulus.Source§impl SubAssign<&Scalar> for Scalar
impl SubAssign<&Scalar> for Scalar
Source§fn sub_assign(&mut self, other: &Scalar)
fn sub_assign(&mut self, other: &Scalar)
-= operation. Read moreSource§impl SubAssign for Scalar
impl SubAssign for Scalar
Source§fn sub_assign(&mut self, other: Scalar)
fn sub_assign(&mut self, other: Scalar)
-= operation. Read moreSource§impl TryFrom<Scalar> for NonZeroScalar<NistP521>
The constant-time alternative is available at
elliptic_curve::NonZeroScalar<NistP521>::new().
impl TryFrom<Scalar> for NonZeroScalar<NistP521>
The constant-time alternative is available at
elliptic_curve::NonZeroScalar<NistP521>::new().