Struct crypto_bigint::Limb

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

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

The Limb type uses a 32-bit or 64-bit saturated representation, depending on the target. All bits of an inner Word are used to represent larger big integer types.

Tuple Fields§

§0: Word

Implementations§

source§

impl Limb

source

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

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

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

Calculate the number of bits needed to represent this number.

source

pub const fn leading_zeros(self) -> u32

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

source

pub const fn trailing_zeros(self) -> u32

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

source

pub const fn trailing_ones(self) -> u32

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

Available on 64-bit only.

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, shift: u32) -> Self

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

source§

impl Limb

source

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

Computes self >> shift. Panics if shift 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: u32 = 64u32

Available on 64-bit only.

Size of the inner integer in bits.

source

pub const BYTES: usize = 8usize

Available on 64-bit only.

Size of the inner integer in bytes.

source

pub const fn to_nz(self) -> ConstCtOption<NonZero<Self>>

Convert to a NonZero<Limb>.

Returns some if the original value is non-zero, and false otherwise.

Trait Implementations§

source§

impl Add for Limb

§

type Output = Limb

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
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 BitAndAssign<&Limb> for Limb

source§

fn bitand_assign(&mut self, rhs: &Limb)

Performs the &= operation. Read more
source§

impl BitAndAssign for Limb

source§

fn bitand_assign(&mut self, rhs: Self)

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 BitOrAssign<&Limb> for Limb

source§

fn bitor_assign(&mut self, other: &Self)

Performs the |= operation. Read more
source§

impl BitOrAssign for Limb

source§

fn bitor_assign(&mut self, other: Self)

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

source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
source§

impl Bounded for Limb

source§

const BITS: u32 = 64u32

Size of this integer in bits.
source§

const BYTES: usize = 8usize

Size of this integer in bytes.
source§

impl CheckedAdd for Limb

source§

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

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

impl CheckedMul for Limb

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§

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

source§

const ZERO: Self = Self::ZERO

The value 0.
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 Constants for Limb

source§

const ONE: Self = Self::ONE

The value 1.
source§

const MAX: Self = Self::MAX

Maximum value this integer can express.
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; 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 From<Limb> for BoxedUint

Available on crate feature alloc only.
source§

fn from(limb: Limb) -> Self

Converts to this type from the input type.
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

Available on 64-bit only.
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.
source§

impl Mul<&Limb> for &Limb

§

type Output = Limb

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Limb) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Limb> for Limb

§

type Output = Limb

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Limb) -> Self

Performs the * operation. Read more
source§

impl Mul<Limb> for &Limb

§

type Output = Limb

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Limb) -> Self::Output

Performs the * operation. Read more
source§

impl Mul for Limb

§

type Output = Limb

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Limb) -> Self

Performs the * operation. Read more
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 One for Limb

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
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 + 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<i32> for &Limb

§

type Output = Limb

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

fn shl(self, shift: i32) -> Limb

Performs the << operation. Read more
source§

impl Shl<i32> for Limb

§

type Output = Limb

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

fn shl(self, shift: i32) -> Limb

Performs the << operation. Read more
source§

impl Shl<u32> for &Limb

§

type Output = Limb

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

fn shl(self, shift: u32) -> Limb

Performs the << operation. Read more
source§

impl Shl<u32> for Limb

§

type Output = Limb

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

fn shl(self, shift: u32) -> Limb

Performs the << operation. Read more
source§

impl Shl<usize> for &Limb

§

type Output = Limb

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

fn shl(self, shift: usize) -> Limb

Performs the << operation. Read more
source§

impl Shl<usize> for Limb

§

type Output = Limb

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

fn shl(self, shift: usize) -> Limb

Performs the << operation. Read more
source§

impl ShlAssign<i32> for Limb

source§

fn shl_assign(&mut self, shift: i32)

Performs the <<= operation. Read more
source§

impl ShlAssign<u32> for Limb

source§

fn shl_assign(&mut self, shift: u32)

Performs the <<= operation. Read more
source§

impl ShlAssign<usize> for Limb

source§

fn shl_assign(&mut self, shift: usize)

Performs the <<= operation. Read more
source§

impl Shr<i32> for &Limb

§

type Output = Limb

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

fn shr(self, shift: i32) -> Limb

Performs the >> operation. Read more
source§

impl Shr<i32> for Limb

§

type Output = Limb

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

fn shr(self, shift: i32) -> Limb

Performs the >> operation. Read more
source§

impl Shr<u32> for &Limb

§

type Output = Limb

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

fn shr(self, shift: u32) -> Limb

Performs the >> operation. Read more
source§

impl Shr<u32> for Limb

§

type Output = Limb

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

fn shr(self, shift: u32) -> Limb

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, shift: usize) -> Limb

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, shift: usize) -> Limb

Performs the >> operation. Read more
source§

impl ShrAssign<i32> for Limb

source§

fn shr_assign(&mut self, shift: i32)

Performs the >>= operation. Read more
source§

impl ShrAssign<u32> for Limb

source§

fn shr_assign(&mut self, shift: u32)

Performs the >>= operation. Read more
source§

impl ShrAssign<usize> for Limb

source§

fn shr_assign(&mut self, shift: usize)

Performs the >>= operation. Read more
source§

impl Sub<&Limb> for Limb

§

type Output = Limb

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Self) -> Self

Performs the - operation. Read more
source§

impl Sub for Limb

§

type Output = Limb

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> 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 WrappingAdd for Limb

source§

fn wrapping_add(&self, v: &Self) -> Self

Wrapping (modular) addition. Computes self + other, wrapping around at the boundary of the type.
source§

impl WrappingMul for Limb

source§

fn wrapping_mul(&self, v: &Self) -> Self

Wrapping (modular) multiplication. Computes self * other, wrapping around at the boundary of the type.
source§

impl WrappingNeg for Limb

source§

fn wrapping_neg(&self) -> Self

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. Read more
source§

impl WrappingShl for Limb

source§

fn wrapping_shl(&self, shift: u32) -> Limb

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high order bits of rhs that would cause the shift to exceed the bitwidth of the type. Read more
source§

impl WrappingShr for Limb

source§

fn wrapping_shr(&self, shift: u32) -> Limb

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high order bits of rhs that would cause the shift to exceed the bitwidth of the type. Read more
source§

impl WrappingSub for Limb

source§

fn wrapping_sub(&self, v: &Self) -> Self

Wrapping (modular) subtraction. Computes self - other, wrapping around at the boundary of the type.
source§

impl Zero for Limb

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
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 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> ConstantTimeSelect for T

source§

fn ct_select(a: &T, b: &T, choice: Choice) -> T

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

fn ct_assign(&mut self, other: &T, choice: Choice)

Conditionally assign other to self, according to choice.
source§

fn ct_swap(a: &mut T, b: &mut T, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves.
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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 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>,

§

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

§

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> Zero for T
where T: ConstZero,

source§

fn zero() -> T

The value 0.
source§

fn is_zero(&self) -> Choice

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

fn set_zero(&mut self)

Set self to its additive identity, i.e. Self::zero.
source§

fn zero_like(other: &Self) -> Self
where Self: Clone,

Return the value 0 with the same precision as other.
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.
source§

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