tiny_ec::curve

Struct Scalar

Source
pub struct Scalar(pub [u32; 8]);
Expand description

A 256-bit scalar value.

Tuple Fields§

§0: [u32; 8]

Implementations§

Source§

impl Scalar

Source

pub fn clear(&mut self)

Clear a scalar to prevent the leak of sensitive data.

Source

pub fn set_int(&mut self, v: u32)

Set a scalar to an unsigned integer.

Source

pub fn from_int(v: u32) -> Scalar

Create a scalar from an unsigned integer.

Source

pub fn bits(&self, offset: usize, count: usize) -> u32

Access bits from a scalar. All requested bits must belong to the same 32-bit limb.

Source

pub fn bits_var(&self, offset: usize, count: usize) -> u32

Access bits from a scalar. Not constant time.

Source

pub fn cadd_bit(&mut self, bit: usize, flag: bool)

Conditionally add a power of two to a scalar. The result is not allowed to overflow.

Source

pub fn set_b32(&mut self, b32: &[u8; 32]) -> Choice

Set a scalar from a big endian byte array, return whether it overflowed.

Source

pub fn b32(&self) -> [u8; 32]

Convert a scalar to a byte array.

Source

pub fn fill_b32(&self, bin: &mut [u8; 32])

Convert a scalar to a byte array.

Source

pub fn is_zero(&self) -> bool

Check whether a scalar equals zero.

Source

pub fn is_one(&self) -> bool

Check whether a scalar equals one.

Source

pub fn is_high(&self) -> bool

Check whether a scalar is higher than the group order divided by 2.

Source

pub fn cond_neg_assign(&mut self, flag: Choice)

Conditionally negate a number, in constant time.

Source§

impl Scalar

Source

pub fn mul_in_place(&mut self, a: &Scalar, b: &Scalar)

Source

pub fn shr_int(&mut self, n: usize) -> u32

Shift a scalar right by some amount strictly between 0 and 16, returning the low bits that were shifted off.

Source

pub fn sqr_in_place(&mut self, a: &Scalar)

Source

pub fn sqr(&self) -> Scalar

Source

pub fn inv_in_place(&mut self, x: &Scalar)

Source

pub fn inv(&self) -> Scalar

Source

pub fn inv_var(&self) -> Scalar

Source

pub fn is_even(&self) -> bool

Trait Implementations§

Source§

impl<'a, 'b> Add<&'a Scalar> for &'b Scalar

Source§

type Output = Scalar

The resulting type after applying the + operator.
Source§

fn add(self, other: &'a Scalar) -> Scalar

Performs the + operation. Read more
Source§

impl Add for Scalar

Source§

type Output = Scalar

The resulting type after applying the + operator.
Source§

fn add(self, other: Scalar) -> Scalar

Performs the + operation. Read more
Source§

impl<'a> AddAssign<&'a Scalar> for Scalar

Source§

fn add_assign(&mut self, other: &'a Scalar)

Performs the += operation. Read more
Source§

impl AddAssign for Scalar

Source§

fn add_assign(&mut self, other: Scalar)

Performs the += operation. Read more
Source§

impl Clone for Scalar

Source§

fn clone(&self) -> Scalar

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scalar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Scalar

Source§

fn default() -> Scalar

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Scalar

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Scalar, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&[u8]> for Scalar

Source§

fn from(bytes: &[u8]) -> Scalar

Converts to this type from the input type.
Source§

impl From<&[u8; 32]> for Scalar

Source§

fn from(bytes: &[u8; 32]) -> Scalar

Converts to this type from the input type.
Source§

impl Into<Scalar> for SecretKey

Source§

fn into(self) -> Scalar

Converts this type into the (usually inferred) input type.
Source§

impl LowerHex for Scalar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, 'b> Mul<&'a Scalar> for &'b Scalar

Source§

type Output = Scalar

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'a Scalar) -> Scalar

Performs the * operation. Read more
Source§

impl Mul for Scalar

Source§

type Output = Scalar

The resulting type after applying the * operator.
Source§

fn mul(self, other: Scalar) -> Scalar

Performs the * operation. Read more
Source§

impl<'a> MulAssign<&'a Scalar> for Scalar

Source§

fn mul_assign(&mut self, other: &'a Scalar)

Performs the *= operation. Read more
Source§

impl MulAssign for Scalar

Source§

fn mul_assign(&mut self, other: Scalar)

Performs the *= operation. Read more
Source§

impl<'a> Neg for &'a Scalar

Source§

type Output = Scalar

The resulting type after applying the - operator.
Source§

fn neg(self) -> Scalar

Performs the unary - operation. Read more
Source§

impl Neg for Scalar

Source§

type Output = Scalar

The resulting type after applying the - operator.
Source§

fn neg(self) -> Scalar

Performs the unary - operation. Read more
Source§

impl Ord for Scalar

Source§

fn cmp(&self, other: &Scalar) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Scalar

Source§

fn eq(&self, other: &Scalar) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Scalar

Source§

fn partial_cmp(&self, other: &Scalar) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Scalar

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Scalar> for SecretKey

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(scalar: Scalar) -> Result<Self, Error>

Performs the conversion.
Source§

impl Copy for Scalar

Source§

impl Eq for Scalar

Source§

impl StructuralPartialEq for Scalar

Auto Trait Implementations§

§

impl Freeze for Scalar

§

impl RefUnwindSafe for Scalar

§

impl Send for Scalar

§

impl Sync for Scalar

§

impl Unpin for Scalar

§

impl UnwindSafe for Scalar

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,