[][src]Struct k256::Scalar

pub struct Scalar(_);
This is supported on crate feature arithmetic only.

An element in the finite field modulo curve order.

Implementations

impl Scalar[src]

pub const fn zero() -> Self[src]

Returns the zero scalar.

pub const fn one() -> Scalar[src]

Returns the multiplicative identity.

pub fn is_zero(&self) -> Choice[src]

Checks if the scalar is zero.

pub fn truncate_to_u32(&self) -> u32[src]

Returns the value of the scalar truncated to a 32-bit unsigned integer.

pub fn from_bytes_reduced(bytes: &FieldBytes) -> Self[src]

Parses the given byte array as a scalar.

Subtracts the modulus when the byte array is larger than the modulus.

pub fn to_bytes(&self) -> FieldBytes[src]

Returns the SEC1 encoding of this scalar.

pub fn is_high(&self) -> Choice[src]

Is this scalar greater than or equal to n / 2?

pub fn negate(&self) -> Self[src]

Negates the scalar.

pub fn add(&self, rhs: &Scalar) -> Scalar[src]

Modulo adds two scalars

pub fn sub(&self, rhs: &Scalar) -> Scalar[src]

Modulo subtracts one scalar from the other.

pub fn mul(&self, rhs: &Scalar) -> Scalar[src]

Modulo multiplies two scalars.

pub fn square(&self) -> Self[src]

Modulo squares the scalar.

pub fn rshift(&self, shift: usize) -> Scalar[src]

Right shifts the scalar. Note: not constant-time in shift.

pub fn invert(&self) -> CtOption<Self>[src]

Inverts the scalar.

pub fn generate_biased(rng: impl CryptoRng + RngCore) -> Self[src]

Returns a (nearly) uniformly-random scalar, generated in constant time.

pub fn generate_vartime(rng: impl RngCore) -> Self[src]

Returns a uniformly-random scalar, generated using rejection sampling.

pub fn conditional_add_bit(&self, bit: usize, flag: Choice) -> Self[src]

If flag evaluates to true, adds (1 << bit) to self.

pub fn mul_shift_var(&self, b: &Scalar, shift: usize) -> Self[src]

Multiplies self by b (without modulo reduction) divide the result by 2^shift (rounding to the nearest integer). Variable time in shift.

Trait Implementations

impl<'_, '_> Add<&'_ Scalar> for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

impl<'_> Add<&'_ Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

impl Add<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

impl<'_> Add<Scalar> for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the + operator.

impl<'_> AddAssign<&'_ Scalar> for Scalar[src]

impl AddAssign<Scalar> for Scalar[src]

impl Clone for Scalar[src]

impl ConditionallySelectable for Scalar[src]

impl ConstantTimeEq for Scalar[src]

impl Copy for Scalar[src]

impl Debug for Scalar[src]

impl Default for Scalar[src]

impl Eq for Scalar[src]

impl Field for Scalar[src]

impl<'_> From<&'_ Scalar> for ScalarBits[src]

impl<'_> From<&'_ Scalar> for FieldBytes[src]

impl From<Scalar> for FieldBytes[src]

impl From<u32> for Scalar[src]

impl From<u64> for Scalar[src]

impl FromDigest<Secp256k1> for Scalar[src]

fn from_digest<D>(digest: D) -> Self where
    D: Digest<OutputSize = U32>, 
[src]

Convert the output of a digest algorithm into a Scalar reduced modulo n.

impl<'_, '_> Mul<&'_ Scalar> for &'_ ProjectivePoint[src]

type Output = ProjectivePoint

The resulting type after applying the * operator.

impl<'_> Mul<&'_ Scalar> for ProjectivePoint[src]

type Output = ProjectivePoint

The resulting type after applying the * operator.

impl<'_, '_> Mul<&'_ Scalar> for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the * operator.

impl<'_> Mul<&'_ Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the * operator.

impl Mul<Scalar> for ProjectivePoint[src]

type Output = ProjectivePoint

The resulting type after applying the * operator.

impl Mul<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the * operator.

impl<'_> MulAssign<&'_ Scalar> for ProjectivePoint[src]

impl<'_> MulAssign<&'_ Scalar> for Scalar[src]

impl MulAssign<Scalar> for ProjectivePoint[src]

impl MulAssign<Scalar> for Scalar[src]

impl Neg for Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

impl<'_> Neg for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

impl NormalizeLow for Scalar[src]

impl PartialEq<Scalar> for Scalar[src]

impl PrimeField for Scalar[src]

type Repr = FieldBytes

The prime field can be converted back and forth into this binary representation. Read more

type ReprBits = [u64; 4]

The backing store for a bit representation of a prime field element.

fn from_repr(bytes: FieldBytes) -> Option<Self>[src]

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).

impl RecoverableSignPrimitive<Secp256k1> for Scalar[src]

impl Shr<usize> for Scalar[src]

type Output = Self

The resulting type after applying the >> operator.

impl<'_> Shr<usize> for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the >> operator.

impl<'_, '_> Sub<&'_ Scalar> for &'_ Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

impl<'_> Sub<&'_ Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

impl Sub<Scalar> for Scalar[src]

type Output = Scalar

The resulting type after applying the - operator.

impl<'_> SubAssign<&'_ Scalar> for Scalar[src]

impl SubAssign<Scalar> for Scalar[src]

impl Zeroize for Scalar[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ConditionallyNegatable for T where
    T: ConditionallySelectable,
    &'a T: for<'a> Neg,
    <&'a T as Neg>::Output == T, 
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T where
    T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>, 

impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for T where
    T: for<'r> GroupOps<&'r Rhs, Output>, 

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<F> Invert for F where
    F: Field, 
[src]

type Output = F

Field element type

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T where
    T: Mul<Rhs, Output = Output> + MulAssign<Rhs>, 

impl<T, Rhs, Output> ScalarMulOwned<Rhs, Output> for T where
    T: for<'r> ScalarMul<&'r Rhs, Output>, 

impl<C, T> SignPrimitive<C> for T where
    C: Curve + ProjectiveArithmetic,
    T: RecoverableSignPrimitive<C>,
    GenericArray<u8, <C as Curve>::FieldSize>: From<<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    GenericArray<u8, <C as Curve>::FieldSize>: for<'r> From<&'r <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar>,
    <<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar: PrimeField,
    <<C as Curve>::FieldSize as Add<<C as Curve>::FieldSize>>::Output: ArrayLength<u8>,
    <<<C as ProjectiveArithmetic>::ProjectivePoint as Group>::Scalar as PrimeField>::Repr == GenericArray<u8, <C as Curve>::FieldSize>, 
[src]

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<Z> Zeroize for Z where
    Z: DefaultIsZeroes
[src]