crypto_bigint

Struct Limb

Source
#[repr(transparent)]
pub struct Limb(pub Word);
Expand description

Big integers are represented as an array of smaller CPU word-size integers called “limbs”.

Tuple Fields§

§0: Word

Implementations§

Source§

impl Limb

Source

pub const fn adc(self, rhs: Limb, carry: Limb) -> (Limb, Limb)

Computes self + rhs + carry, returning the result along with the new carry.

Source

pub const fn saturating_add(&self, rhs: Self) -> Self

Perform saturating addition.

Source

pub const fn wrapping_add(&self, rhs: Self) -> Self

Perform wrapping addition, discarding overflow.

Source§

impl Limb

Source

pub const fn bitand(self, rhs: Self) -> Self

Calculates a & b.

Source§

impl Limb

Source

pub const fn not(self) -> Self

Calculates !a.

Source§

impl Limb

Source

pub const fn bitor(self, rhs: Self) -> Self

Calculates a | b.

Source§

impl Limb

Source

pub const fn bitxor(self, rhs: Self) -> Self

Calculates a ^ b.

Source§

impl Limb

Source

pub const fn bits(self) -> usize

Calculate the number of bits needed to represent this number.

Source

pub const fn leading_zeros(self) -> usize

Calculate the number of leading zeros in the binary representation of this number.

Source

pub const fn trailing_zeros(self) -> usize

Calculate the number of trailing zeros in the binary representation of this number.

Source

pub const fn trailing_ones(self) -> usize

Calculate the number of trailing ones the binary representation of this number.

Source§

impl Limb

Source

pub fn is_odd(&self) -> Choice

Is this limb an odd number?

Source

pub fn cmp_vartime(&self, other: &Self) -> Ordering

Perform a comparison of the inner value in variable-time.

Note that the PartialOrd and Ord impls wrap constant-time comparisons using the subtle crate.

Source

pub const fn eq_vartime(&self, other: &Self) -> bool

Performs an equality check in variable-time.

Source§

impl Limb

Source

pub const fn from_u8(n: u8) -> Self

Create a Limb from a u8 integer (const-friendly)

Source

pub const fn from_u16(n: u16) -> Self

Create a Limb from a u16 integer (const-friendly)

Source

pub const fn from_u32(n: u32) -> Self

Create a Limb from a u32 integer (const-friendly)

Source

pub const fn from_u64(n: u64) -> Self

Create a Limb from a u64 integer (const-friendly)

Source§

impl Limb

Source

pub const fn mac(self, b: Limb, c: Limb, carry: Limb) -> (Limb, Limb)

Computes self + (b * c) + carry, returning the result along with the new carry.

Source

pub const fn saturating_mul(&self, rhs: Self) -> Self

Perform saturating multiplication.

Source

pub const fn wrapping_mul(&self, rhs: Self) -> Self

Perform wrapping multiplication, discarding overflow.

Source§

impl Limb

Source

pub const fn wrapping_neg(self) -> Self

Perform wrapping negation.

Source§

impl Limb

Source

pub const fn shl(self, rhs: Self) -> Self

Computes self << rhs. Panics if rhs overflows Limb::BITS.

Source§

impl Limb

Source

pub const fn shr(self, rhs: Self) -> Self

Computes self >> rhs. Panics if rhs overflows Limb::BITS.

Source§

impl Limb

Source

pub const fn sbb(self, rhs: Limb, borrow: Limb) -> (Limb, Limb)

Computes self - (rhs + borrow), returning the result along with the new borrow.

Source

pub const fn saturating_sub(&self, rhs: Self) -> Self

Perform saturating subtraction.

Source

pub const fn wrapping_sub(&self, rhs: Self) -> Self

Perform wrapping subtraction, discarding underflow and wrapping around the boundary of the type.

Source§

impl Limb

Source

pub const ZERO: Self = _

The value 0.

Source

pub const ONE: Self = _

The value 1.

Source

pub const MAX: Self = _

Maximum value this Limb can express.

Source

pub const BITS: usize = 64usize

Size of the inner integer in bits.

Source

pub const BYTES: usize = 8usize

Size of the inner integer in bytes.

Trait Implementations§

Source§

impl BitAnd for Limb

Source§

type Output = Limb

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitOr for Limb

Source§

type Output = Limb

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitXor for Limb

Source§

type Output = Limb

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Bounded for Limb

Source§

const BITS: usize = 64usize

Size of this integer in bits.
Source§

const BYTES: usize = 8usize

Size of this integer in bytes.
Source§

impl CheckedAdd for Limb

Source§

type Output = Limb

Output type.
Source§

fn checked_add(&self, rhs: Self) -> CtOption<Self>

Perform checked subtraction, returning a CtOption which is_some only if the operation did not overflow.
Source§

impl CheckedMul for Limb

Source§

type Output = Limb

Output type.
Source§

fn checked_mul(&self, rhs: Self) -> CtOption<Self>

Perform checked multiplication, returning a CtOption which is_some only if the operation did not overflow.
Source§

impl CheckedSub for Limb

Source§

type Output = Limb

Output type.
Source§

fn checked_sub(&self, rhs: Self) -> CtOption<Self>

Perform checked subtraction, returning a CtOption which is_some only if the operation did not underflow.
Source§

impl Clone for Limb

Source§

fn clone(&self) -> Limb

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 ConditionallySelectable for Limb

Source§

fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice. Read more
Source§

fn conditional_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice. Read more
Source§

fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Source§

impl ConstantTimeEq for Limb

Source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
Source§

impl ConstantTimeGreater for Limb

Source§

fn ct_gt(&self, other: &Self) -> Choice

Determine whether self > other. Read more
Source§

impl ConstantTimeLess for Limb

Source§

fn ct_lt(&self, other: &Self) -> Choice

Determine whether self < other. Read more
Source§

impl Debug for Limb

Source§

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

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

impl Default for Limb

Source§

fn default() -> Limb

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

impl Display for Limb

Source§

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

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

impl Encoding for Limb

Source§

type Repr = [u8; 8]

Byte array representation.
Source§

fn from_be_bytes(bytes: Self::Repr) -> Self

Decode from big endian bytes.
Source§

fn from_le_bytes(bytes: Self::Repr) -> Self

Decode from little endian bytes.
Source§

fn to_be_bytes(&self) -> Self::Repr

Encode to big endian bytes.
Source§

fn to_le_bytes(&self) -> Self::Repr

Encode to little endian bytes.
Source§

impl<const LIMBS: usize> From<Limb> for Uint<LIMBS>

Source§

fn from(limb: Limb) -> Self

Converts to this type from the input type.
Source§

impl From<Limb> for WideWord

Source§

fn from(limb: Limb) -> WideWord

Converts to this type from the input type.
Source§

impl From<Limb> for Word

Source§

fn from(limb: Limb) -> Word

Converts to this type from the input type.
Source§

impl From<u16> for Limb

Source§

fn from(n: u16) -> Limb

Converts to this type from the input type.
Source§

impl From<u32> for Limb

Source§

fn from(n: u32) -> Limb

Converts to this type from the input type.
Source§

impl From<u64> for Limb

Source§

fn from(n: u64) -> Limb

Converts to this type from the input type.
Source§

impl From<u8> for Limb

Source§

fn from(n: u8) -> Limb

Converts to this type from the input type.
Source§

impl Hash for Limb

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for Limb

Source§

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

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

impl Not for Limb

Source§

type Output = Limb

The resulting type after applying the ! operator.
Source§

fn not(self) -> <Self as Not>::Output

Performs the unary ! operation. Read more
Source§

impl Ord for Limb

Source§

fn cmp(&self, other: &Self) -> 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 Limb

Source§

fn eq(&self, other: &Self) -> 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 Limb

Source§

fn partial_cmp(&self, other: &Self) -> 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 Random for Limb

Source§

fn random(rng: &mut impl CryptoRngCore) -> Self

Generate a cryptographically secure random value.
Source§

impl RandomMod for Limb

Source§

fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self

Generate a cryptographically secure random number which is less than a given modulus. Read more
Source§

impl Shl<usize> for Limb

Source§

type Output = Limb

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self::Output

Performs the << operation. Read more
Source§

impl Shl for Limb

Source§

type Output = Limb

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: Self) -> Self::Output

Performs the << operation. Read more
Source§

impl ShlAssign<usize> for Limb

Source§

fn shl_assign(&mut self, other: usize)

Performs the <<= operation. Read more
Source§

impl ShlAssign for Limb

Source§

fn shl_assign(&mut self, other: Self)

Performs the <<= operation. Read more
Source§

impl Shr<usize> for Limb

Source§

type Output = Limb

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self::Output

Performs the >> operation. Read more
Source§

impl Shr for Limb

Source§

type Output = Limb

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: Self) -> Self::Output

Performs the >> operation. Read more
Source§

impl ShrAssign<usize> for Limb

Source§

fn shr_assign(&mut self, other: usize)

Performs the >>= operation. Read more
Source§

impl ShrAssign for Limb

Source§

fn shr_assign(&mut self, other: Self)

Performs the >>= operation. Read more
Source§

impl UpperHex for Limb

Source§

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

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

impl Zero for Limb

Source§

const ZERO: Self = Self::ZERO

The value 0.
Source§

fn is_zero(&self) -> Choice

Determine if this value is equal to zero. Read more
Source§

impl Copy for Limb

Source§

impl DefaultIsZeroes for Limb

Source§

impl Eq for Limb

Auto Trait Implementations§

§

impl Freeze for Limb

§

impl RefUnwindSafe for Limb

§

impl Send for Limb

§

impl Sync for Limb

§

impl Unpin for Limb

§

impl UnwindSafe for Limb

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

🔬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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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<Z> Zeroize for Z
where Z: DefaultIsZeroes,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.