pub struct Scalar(_);
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
p384::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.
serde
support
When the serde
feature of this crate is enabled, the Serialize
and
Deserialize
traits are impl’d 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 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_be_slice(slice: &[u8]) -> Result<Self>
pub fn from_be_slice(slice: &[u8]) -> Result<Self>
Decode Scalar
from a big endian byte slice.
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§
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<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 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
source§fn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
source§fn sqrt(&self) -> CtOption<Self>
fn sqrt(&self) -> CtOption<Self>
§fn is_zero_vartime(&self) -> bool
fn is_zero_vartime(&self) -> bool
§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<ScalarCore<NistP384>> for Scalar
impl From<ScalarCore<NistP384>> for Scalar
source§fn from(w: ScalarCore<NistP384>) -> Self
fn from(w: ScalarCore<NistP384>) -> Self
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)
*=
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 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>
source§const CAPACITY: u32 = 383u32
const CAPACITY: u32 = 383u32
source§fn from_repr(bytes: FieldBytes) -> CtOption<Self>
fn from_repr(bytes: FieldBytes) -> CtOption<Self>
source§fn to_repr(&self) -> FieldBytes
fn to_repr(&self) -> FieldBytes
source§fn multiplicative_generator() -> Self
fn multiplicative_generator() -> Self
modulus - 1
order. This element must
also be a quadratic nonresidue. Read moresource§fn root_of_unity() -> Self
fn root_of_unity() -> Self
2^s
root of unity. Read more§fn from_str_vartime(s: &str) -> Option<Self>
fn from_str_vartime(s: &str) -> Option<Self>
§fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
fn from_repr_vartime(repr: Self::Repr) -> Option<Self>
source§impl Reduce<UInt<_>> for Scalar
impl Reduce<UInt<_>> for Scalar
source§fn from_uint_reduced(w: U384) -> Self
fn from_uint_reduced(w: U384) -> Self
source§fn 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
source§fn 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
source§fn from_be_digest_reduced<D>(digest: D) -> Selfwhere
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
fn from_be_digest_reduced<D>(digest: D) -> Selfwhere
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
digest
only.source§fn from_le_digest_reduced<D>(digest: D) -> Selfwhere
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
fn from_le_digest_reduced<D>(digest: D) -> Selfwhere
D: FixedOutput<OutputSize = <UInt as ArrayEncoding>::ByteSize>,
digest
only.source§impl SignPrimitive<NistP384> for Scalar
Available on crate features ecdsa-core
and ecdsa
only.
impl SignPrimitive<NistP384> for Scalar
ecdsa-core
and ecdsa
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)
-=
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)
-=
operation. Read more