Struct crypto_bigint::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§

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 = 32usize

Available on 32-bit only.

Size of the inner integer in bits.

source

pub const BYTES: usize = 4usize

Available on 32-bit only.

Size of the inner integer in bytes.

Trait Implementations§

source§

impl BitAnd for Limb

§

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

§

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

§

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 = 32usize

Size of this integer in bits.
source§

const BYTES: usize = 4usize

Size of this integer in bytes.
source§

impl CheckedAdd for Limb

§

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

§

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

§

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<'de> Deserialize<'de> for Limb

Available on crate feature serde only.
source§

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

Deserialize this value from the given Serde deserializer. 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

§

type Repr = [u8; 4]

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 Word

source§

fn from(limb: Limb) -> Word

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<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<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.
source§

impl Not for Limb

§

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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

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

impl PartialEq for Limb

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Random for Limb

Available on crate feature rand_core only.
source§

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

Generate a cryptographically secure random value.
source§

impl RandomMod for Limb

Available on crate feature rand_core only.
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 Serialize for Limb

Available on crate feature serde only.
source§

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

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

impl Shl<usize> for Limb

§

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

§

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

§

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

§

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

Available on crate feature zeroize only.
source§

impl Eq for Limb

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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 Zwhere 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.
source§

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