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
k256::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
Returns the SEC1 encoding of this scalar.
Right shifts the scalar.
Note: not constant-time with respect to the shift
parameter.
Returns a (nearly) uniformly-random scalar, generated in constant time.
Returns a uniformly-random scalar, generated using rejection sampling.
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Tonelli-Shank’s algorithm for q mod 16 = 1 https://eprint.iacr.org/2012/685.pdf (page 12, algorithm 5)
Returns an element chosen uniformly at random using a user-provided RNG.
Computes the multiplicative inverse of this element, failing if the element is zero. 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.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ProjectivePoint
type Output = ProjectivePoint
The resulting type after applying the *
operator.
Performs the *
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Attempts to parse the given byte array as an SEC1-encoded scalar.
Returns None if the byte array does not contain a big-endian integer in the range [0, p).
type Repr = FieldBytes
type Repr = FieldBytes
The prime field can be converted back and forth into this binary representation. Read more
How many bits of information can be reliably stored in the field element. Read more
Converts an element of the prime field into the standard byte representation for this field. Read more
Returns a fixed multiplicative generator of modulus - 1
order. This element must
also be a quadratic nonresidue. Read more
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
Perform a modular reduction, returning a field element.
Perform a modular reduction, returning a field element.
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for Scalar
impl UnwindSafe for Scalar
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: for<'a> Neg,
<&'a T as Neg>::Output == T,
impl<T> ConditionallyNegatable for T where
T: ConditionallySelectable,
&'a T: for<'a> Neg,
<&'a T as Neg>::Output == T,
Negate self
if choice == Choice(1)
; otherwise, leave it
unchanged. Read more