pub struct Scalar(_);
Available on crate feature
arithmetic
only.Expand description
Scalars are elements in the finite field modulo n
.
Trait impls
Much of the important functionality of scalars is provided by traits from
the ff
crate, which is re-exported as
p224::elliptic_curve::ff
:
Field
- represents elements of finite fields and provides:Field::random
- generate a random scalardouble
,square
, andinvert
operations- Bounds for
Add
,Sub
,Mul
, andNeg
(as well as*Assign
equivalents) - Bounds for
ConditionallySelectable
from thesubtle
crate
PrimeField
- represents elements of prime fields and provides:from_repr
/to_repr
for converting field elements from/to big integers.multiplicative_generator
androot_of_unity
constants.
PrimeFieldBits
- operations over field elements represented as bits (requiresbits
feature)
Please see the documentation for the relevant traits for more information.
Warning: sqrt
unimplemented!
Scalar::sqrt
has not been implemented and will panic if invoked!
See RustCrypto/elliptic-curves#847 for more info.
Implementations§
source§impl Scalar
impl Scalar
sourcepub fn from_bytes(repr: &FieldBytes) -> CtOption<Self>
pub fn from_bytes(repr: &FieldBytes) -> CtOption<Self>
Create a Scalar
from a canonical big-endian representation.
sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Decode Scalar
from a big endian byte slice.
sourcepub fn to_bytes(self) -> FieldBytes
pub fn to_bytes(self) -> FieldBytes
Returns the big-endian encoding of this Scalar
.
sourcepub const fn to_canonical(self) -> Uint
pub const fn to_canonical(self) -> Uint
sourcepub const fn pow_vartime(&self, exp: &[u64]) -> Self
pub const fn pow_vartime(&self, exp: &[u64]) -> Self
Returns self^exp
, where exp
is a little-endian integer exponent.
This operation is variable time with respect to the exponent.
If the exponent is fixed, this operation is effectively constant 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)
Performs the
+=
operation. Read moresource§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)
Performs the
+=
operation. Read moresource§impl ConditionallySelectable for Scalar
impl ConditionallySelectable 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 random(rng: impl RngCore) -> Self
fn random(rng: impl RngCore) -> Self
Returns an element chosen uniformly at random using a user-provided RNG.
source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Computes the multiplicative inverse of this element,
failing if the element is zero.
source§fn 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 pow_vartime<S>(&self, exp: S) -> Selfwhere
S: AsRef<[u64]>,
fn pow_vartime<S>(&self, exp: S) -> Selfwhere S: AsRef<[u64]>,
source§impl From<&Scalar> for FieldBytes
impl From<&Scalar> for FieldBytes
source§impl From<Scalar> for FieldBytes
impl From<Scalar> for FieldBytes
source§impl From<ScalarPrimitive<NistP224>> for Scalar
impl From<ScalarPrimitive<NistP224>> for Scalar
source§fn from(w: ScalarPrimitive<NistP224>) -> Self
fn from(w: ScalarPrimitive<NistP224>) -> Self
Converts to this type from the input type.
source§impl FromUintUnchecked for Scalar
impl FromUintUnchecked for Scalar
source§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)
Performs the
*=
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)
Performs the
*=
operation. Read moresource§impl Ord for Scalar
impl Ord for Scalar
source§impl PartialOrd<Scalar> for Scalar
impl PartialOrd<Scalar> for Scalar
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl PrimeField for Scalar
impl PrimeField for Scalar
§type Repr = GenericArray<u8, <NistP224 as Curve>::FieldBytesSize>
type Repr = GenericArray<u8, <NistP224 as Curve>::FieldBytesSize>
The prime field can be converted back and forth into this binary
representation.
source§const MODULUS: &'static str = ORDER_HEX
const MODULUS: &'static str = ORDER_HEX
Modulus of the field written as a string for debugging purposes. Read more
source§const CAPACITY: u32 = 223u32
const CAPACITY: u32 = 223u32
How many bits of information can be reliably stored in the field element. Read more
source§const MULTIPLICATIVE_GENERATOR: Self = _
const MULTIPLICATIVE_GENERATOR: Self = _
A fixed multiplicative generator of
modulus - 1
order. This element must also be
a quadratic nonresidue. Read moresource§const ROOT_OF_UNITY: Self = _
const ROOT_OF_UNITY: Self = _
The
2^s
root of unity. Read moresource§const ROOT_OF_UNITY_INV: Self = _
const ROOT_OF_UNITY_INV: Self = _
Inverse of [
Self::ROOT_OF_UNITY
].source§fn 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
source§fn 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
§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
source§impl Reduce<Uint<crypto_bigint::::uint::U224::{constant#0}>> for Scalar
impl Reduce<Uint<crypto_bigint::::uint::U224::{constant#0}>> for Scalar
§type Bytes = GenericArray<u8, <NistP224 as Curve>::FieldBytesSize>
type Bytes = GenericArray<u8, <NistP224 as Curve>::FieldBytesSize>
Bytes used as input to
Reduce::reduce_bytes
.source§fn reduce_bytes(bytes: &FieldBytes) -> Self
fn reduce_bytes(bytes: &FieldBytes) -> Self
Interpret the given bytes as an integer and perform a modular reduction.
source§impl ShrAssign<usize> for Scalar
impl ShrAssign<usize> for Scalar
source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
Performs the
>>=
operation. Read moresource§impl SignPrimitive<NistP224> for Scalar
Available on crate features ecdsa-core
and ecdsa
only.
impl SignPrimitive<NistP224> for Scalar
Available on crate features
ecdsa-core
and ecdsa
only.source§fn try_sign_prehashed<K>(
&self,
k: K,
z: &GenericArray<u8, <C as Curve>::FieldBytesSize>
) -> Result<(Signature<C>, Option<RecoveryId>), Error>where
K: AsRef<Self> + Invert<Output = CtOption<Self>>,
fn try_sign_prehashed<K>( &self, k: K, z: &GenericArray<u8, <C as Curve>::FieldBytesSize> ) -> Result<(Signature<C>, Option<RecoveryId>), Error>where K: AsRef<Self> + Invert<Output = CtOption<Self>>,
Try to sign the prehashed message. Read more
source§fn try_sign_prehashed_rfc6979<D>(
&self,
z: &GenericArray<u8, <C as Curve>::FieldBytesSize>,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error>where
Self: From<ScalarPrimitive<C>> + Invert<Output = CtOption<Self>>,
D: Digest<OutputSize = <C as Curve>::FieldBytesSize> + BlockSizeUser + FixedOutput + FixedOutputReset,
fn try_sign_prehashed_rfc6979<D>( &self, z: &GenericArray<u8, <C as Curve>::FieldBytesSize>, ad: &[u8] ) -> Result<(Signature<C>, Option<RecoveryId>), Error>where Self: From<ScalarPrimitive<C>> + Invert<Output = CtOption<Self>>, D: Digest<OutputSize = <C as Curve>::FieldBytesSize> + BlockSizeUser + FixedOutput + FixedOutputReset,
Available on crate feature
rfc6979
only.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)
Performs the
-=
operation. Read moresource§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)
Performs the
-=
operation. Read more