Skip to main content

UintRef

Struct UintRef 

Source
pub struct UintRef { /* private fields */ }
Expand description

Unsigned integer reference type.

This type contains a limb slice which can be borrowed from either a Uint or BoxedUint and thus provides an abstraction for writing shared implementations.

Implementations§

Source§

impl UintRef

Source

pub const fn add_assign_limb(&mut self, rhs: Limb) -> Limb

Perform an in-place carrying add of a limb, returning the carried limb value.

Source

pub const fn carrying_add_assign(&mut self, rhs: &Self, carry: Limb) -> Limb

Perform an in-place carrying add of another UintRef, returning the carried limb value.

Source

pub const fn carrying_add_assign_slice( &mut self, rhs: &[Limb], carry: Limb, ) -> Limb

Perform an in-place carrying add of another limb slice, returning the carried limb value.

§Panics

If self and rhs have different lengths.

Source

pub const fn conditional_add_assign( &mut self, rhs: &Self, carry: Limb, choice: Choice, ) -> Limb

Perform an in-place carrying add of another limb slice, returning the carried limb value.

Source

pub const fn conditional_add_assign_slice( &mut self, rhs: &[Limb], carry: Limb, choice: Choice, ) -> Limb

Perform an in-place carrying add of another limb slice, returning the carried limb value.

§Panics

If self and rhs have different lengths.

Source§

impl UintRef

Source

pub const fn bits_precision(&self) -> u32

Get the precision of this number in bits.

Source

pub const fn bit(&self, index: u32) -> Choice

Get the value of the bit at position index, as a truthy or falsy Choice. Returns the falsy value for indices out of range.

Source

pub const fn bit_vartime(&self, index: u32) -> bool

Returns true if the bit at position index is set, false for an unset bit or for indices out of range.

§Remarks

This operation is variable time with respect to index only.

Source

pub const fn bits(&self) -> u32

Calculate the number of bits needed to represent this number, i.e. the index of the highest set bit.

Use UintRef::bits_precision to get the total capacity of this integer.

Source

pub const fn bits_vartime(&self) -> u32

Calculate the number of bits needed to represent this number in variable-time with respect to self.

Source

pub const fn set_bit(&mut self, index: u32, bit_value: Choice)

Sets the bit at index to 0 or 1 depending on the value of bit_value.

Source

pub const fn set_bit_vartime(&mut self, index: u32, bit_value: bool)

Sets the bit at index to 0 or 1 depending on the value of bit_value, in variable-time with respect to index.

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_zeros_vartime(&self) -> u32

Calculate the number of trailing zeros in the binary representation of this number, in variable-time with respect to self.

Source

pub const fn trailing_ones(&self) -> u32

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

Source

pub const fn trailing_ones_vartime(&self) -> u32

Calculate the number of trailing ones in the binary representation of this number, in variable-time with respect to self.

Source

pub const fn restrict_bits(&mut self, len: u32)

Clear all bits at or above a given bit position.

Source§

impl UintRef

Source

pub const fn is_odd(&self) -> Choice

Returns the truthy value if self is odd or the falsy value otherwise.

Source

pub const fn is_nonzero(&self) -> Choice

Returns Choice::TRUE if self != 0 or Choice::FALSE otherwise.

Source

pub const fn is_zero(&self) -> Choice

Are all of limbs equal to 0?

Source

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

Returns the Ordering between self and rhs in variable time.

Source§

impl UintRef

Source

pub fn overflowing_mul(&self, rhs: &UintRef, out: &mut UintRef) -> Choice

Compute the wrapping product of self and rhs, placing the result into out and returning a Choice indicating whether overflow occurred.

Source

pub fn overflowing_square(&self, out: &mut UintRef) -> Choice

Compute the wrapping squaring of self, placing the result into out and returning a Choice indicating whether overflow occurred.

Source

pub fn wrapping_mul(&self, rhs: &UintRef, out: &mut UintRef) -> Limb

Compute the wrapping product of self and rhs, placing the result into out and returning a carry Limb.

Source

pub fn wrapping_square(&self, out: &mut UintRef) -> Limb

Compute the wrapping squaring of self, placing the result into out and returning a carry Limb.

Source§

impl UintRef

Source

pub const fn shl_assign(&mut self, shift: u32)

Left-shifts by shift bits.

§Panics
  • if the shift exceeds the type’s width.
Source

pub const fn overflowing_shl_assign(&mut self, shift: u32) -> Choice

Left-shifts by shift bits in constant-time.

Returns truthy Choice and leaves self unmodified if shift >= self.bits_precision(), otherwise returns a falsy Choice and shifts self in place.

Source

pub const fn unbounded_shl_assign(&mut self, shift: u32)

Left-shifts by shift bits, producing zero if the shift exceeds the precision.

Source

pub const fn bounded_shl_assign(&mut self, shift: u32, shift_upper_bound: u32)

Left-shifts by shift bits where shift < shift_upper_bound.

The runtime is determined by shift_upper_bound which may be larger or smaller than self.bits_precision().

§Panics
  • if the shift exceeds the upper bound.
Source

pub const fn unbounded_shl_assign_vartime(&mut self, shift: u32)

Left-shifts by shift bits in a panic-free manner, producing zero if the shift exceeds the precision.

NOTE: this operation is variable time with respect to shift ONLY.

When used with a fixed shift, this function is constant-time with respect to self.

Source

pub const fn wrapping_shl_assign(&mut self, shift: u32)

Left-shifts by shift bits in a panic-free manner, reducing shift modulo the type’s width.

Source

pub const fn wrapping_shl_assign_vartime(&mut self, shift: u32)

Left-shifts by shift bits in a panic-free manner, reducing shift modulo the type’s width.

NOTE: this operation is variable time with respect to shift ONLY.

When used with a fixed shift, this function is constant-time with respect to self.

Source

pub const fn shl1_assign(&mut self) -> Limb

Left-shifts by a single bit in constant-time, returning Limb::ONE if the least significant bit was set, and Limb::ZERO otherwise.

Source

pub const fn shl_assign_limb(&mut self, shift: u32) -> Limb

Left-shifts by shift bits where 0 < shift < Limb::BITS, returning the carry.

§Panics
  • if shift >= Limb::BITS.
Source§

impl UintRef

Source

pub const fn shr_assign(&mut self, shift: u32)

Right-shifts by shift bits.

§Panics
  • if the shift exceeds the type’s width.
Source

pub const fn overflowing_shr_assign(&mut self, shift: u32) -> Choice

Right-shifts by shift bits in constant-time.

Returns truthy Choice and leaves self unmodified if shift >= self.bits_precision(), otherwise returns a falsy Choice and shifts self in place.

Source

pub const fn unbounded_shr_assign(&mut self, shift: u32)

Right-shifts by shift bits, producing zero if the shift exceeds the precision.

Source

pub const fn bounded_shr_assign(&mut self, shift: u32, shift_upper_bound: u32)

Right-shifts by shift bits where shift < shift_upper_bound, producing zero if the shift exceeds the precision.

The runtime is determined by shift_upper_bound which may be smaller than self.bits_precision().

§Panics
  • if the shift exceeds the upper bound.
Source

pub const fn unbounded_shr_assign_vartime(&mut self, shift: u32)

Right-shifts by shift bits in a panic-free manner, producing zero if the shift exceeds the precision.

NOTE: this operation is variable time with respect to shift ONLY.

When used with a fixed shift, this function is constant-time with respect to self.

Source

pub const fn wrapping_shr_assign(&mut self, shift: u32)

Right-shifts by shift bits in a panic-free manner, reducing shift modulo the type’s width.

Source

pub const fn wrapping_shr_assign_vartime(&mut self, shift: u32)

Right-shifts by shift bits in a panic-free manner, reducing shift modulo the type’s width.

NOTE: this operation is variable time with respect to shift ONLY.

When used with a fixed shift, this function is constant-time with respect to self.

Source

pub const fn shr1_assign(&mut self) -> Limb

Right-shifts by a single bit in constant-time, returning Limb::ONE << Limb::HI_BIT if the least significant bit was set, and Limb::ZERO otherwise.

Source

pub const fn shr_assign_limb(&mut self, shift: u32) -> Limb

Right-shifts by shift bits where 0 < shift < Limb::BITS, returning the carry.

§Panics
  • if shift >= Limb::BITS.
Source§

impl UintRef

Source

pub const fn copy_from(&mut self, rhs: &UintRef)

Copy the contents from a UintRef.

§Panics

If self.nlimbs() != rhs.nlimbs()

Source

pub const fn conditional_copy_from(&mut self, rhs: &UintRef, copy: Choice)

Conditionally copy the contents from a UintRef.

§Panics

If self.nlimbs() != rhs.nlimbs()

Source

pub const fn copy_from_slice(&mut self, limbs: &[Limb])

Copy the contents from a limb slice.

§Panics

If self.nlimbs() != limbs.len()

Source

pub const fn conditional_copy_from_slice( &mut self, limbs: &[Limb], copy: Choice, )

Conditionally copy the contents from a limb slice.

§Panics

If self.nlimbs() != rhs.nlimbs()

Source

pub const fn fill(&mut self, limb: Limb)

Fill the limb slice with a repeated limb value.

Source

pub const fn split_at(&self, mid: usize) -> (&Self, &Self)

Split the limb slice at a fixed position, producing head and tail slices.

Source

pub const fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)

Split the mutable limb slice at index mid, producing head and tail slices.

Source

pub const fn leading(&self, len: usize) -> &Self

Access a limb slice up to a number of elements len.

Source

pub const fn leading_mut(&mut self, len: usize) -> &mut Self

Access a mutable limb slice up to a number of elements len.

Source

pub const fn trailing(&self, start: usize) -> &Self

Access a limb slice starting from the index start.

Source

pub const fn trailing_mut(&mut self, start: usize) -> &mut Self

Access a mutable limb slice starting from the index start.

Source

pub const fn is_empty(&self) -> bool

Determine if the slice has zero limbs.

Source§

impl UintRef

Source

pub const fn borrowing_sub_assign(&mut self, rhs: &Self, borrow: Limb) -> Limb

Perform an in-place borrowing subtraction of another UintRef, returning the carried limb value.

Source

pub const fn borrowing_sub_assign_slice( &mut self, rhs: &[Limb], borrow: Limb, ) -> Limb

Perform an in-place borrowing subtraction of another limb slice, returning the borrowed limb value.

§Panics

If self and rhs have different lengths.

Source§

impl UintRef

Source

pub const fn new(limbs: &[Limb]) -> &Self

Create a UintRef reference type from a Limb slice.

Source

pub const fn new_mut(limbs: &mut [Limb]) -> &mut Self

Create a mutable UintRef reference type from a Limb slice.

Source

pub const fn new_flattened_mut<const N: usize>( slice: &mut [[Limb; N]], ) -> &mut Self

Create a new mutable UintRef reference type from a slice of Limb arrays.

Source

pub const fn as_limbs(&self) -> &[Limb]

Borrow the inner &[Limb] slice.

Source

pub const fn as_mut_limbs(&mut self) -> &mut [Limb]

Mutably borrow the inner &mut [Limb] slice.

Source

pub const fn as_words(&self) -> &[Word]

Borrow the inner limbs as a slice of Words.

Source

pub const fn as_mut_words(&mut self) -> &mut [Word]

Borrow the inner limbs as a mutable slice of Words.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &Limb>

Get an iterator over the inner limbs.

Source

pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Limb>

Get a mutable iterator over the inner limbs.

Source

pub const fn nlimbs(&self) -> usize

Access the number of limbs.

Source

pub const fn conditional_set_zero(&mut self, choice: Choice)

Conditionally assign all of the limbs to zero.

Source

pub const fn conditional_set_max(&mut self, choice: Choice)

Conditionally assign all of the limbs to the maximum.

Source

pub const fn to_uint_resize<const LIMBS: usize>(&self) -> Uint<LIMBS>

Extract up to LIMBS limbs into a new Uint.

Source

pub const fn as_nz_vartime(&self) -> Option<&NonZero<Self>>

Construct a NonZero reference, returning None in the event self is 0.

Source

pub const fn as_odd_vartime(&self) -> Option<&Odd<Self>>

Construct a Odd reference, returning None in the event self is even.

Trait Implementations§

Source§

impl AsMut<[Limb]> for UintRef

Source§

fn as_mut(&mut self) -> &mut [Limb]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<UintRef> for BoxedUint

Available on crate feature alloc only.
Source§

fn as_mut(&mut self) -> &mut UintRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<UintRef> for Limb

Source§

fn as_mut(&mut self) -> &mut UintRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const LIMBS: usize> AsMut<UintRef> for Uint<LIMBS>

Source§

fn as_mut(&mut self) -> &mut UintRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<UintRef> for UintRef

Source§

fn as_mut(&mut self) -> &mut Self

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: AsMut<UintRef>> AsMut<UintRef> for Wrapping<T>

Source§

fn as_mut(&mut self) -> &mut UintRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[Limb]> for UintRef

Source§

fn as_ref(&self) -> &[Limb]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UintRef> for BoxedUint

Available on crate feature alloc only.
Source§

fn as_ref(&self) -> &UintRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UintRef> for Limb

Source§

fn as_ref(&self) -> &UintRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const LIMBS: usize> AsRef<UintRef> for Uint<LIMBS>

Source§

fn as_ref(&self) -> &UintRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<UintRef> for UintRef

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: AsRef<UintRef>> AsRef<UintRef> for Wrapping<T>

Source§

fn as_ref(&self) -> &UintRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Binary for UintRef

Source§

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

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

impl BitOps for UintRef

Source§

fn bits_precision(&self) -> u32

Precision of this integer in bits.
Source§

fn bytes_precision(&self) -> usize

Precision of this integer in bytes.
Source§

fn leading_zeros(&self) -> u32

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

fn bit(&self, index: u32) -> Choice

Get the value of the bit at position index, as a truthy or falsy Choice. Returns the falsy value for indices out of range.
Source§

fn set_bit(&mut self, index: u32, bit_value: Choice)

Sets the bit at index to 0 or 1 depending on the value of bit_value.
Source§

fn trailing_zeros(&self) -> u32

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

fn trailing_ones(&self) -> u32

Calculate the number of trailing ones in the binary representation of this number.
Source§

fn bit_vartime(&self, index: u32) -> bool

Returns true if the bit at position index is set, false otherwise. Read more
Source§

fn bits_vartime(&self) -> u32

Calculate the number of bits required to represent a given number in variable-time with respect to self.
Source§

fn set_bit_vartime(&mut self, index: u32, bit_value: bool)

Sets the bit at index to 0 or 1 depending on the value of bit_value, variable time in self.
Source§

fn trailing_zeros_vartime(&self) -> u32

Calculate the number of trailing zeros in the binary representation of this number in variable-time with respect to self.
Source§

fn trailing_ones_vartime(&self) -> u32

Calculate the number of trailing ones in the binary representation of this number, variable time in self.
Source§

fn log2_bits(&self) -> u32

floor(log2(self.bits_precision())).
Source§

fn bits(&self) -> u32

Calculate the number of bits required to represent a given number.
Source§

fn leading_zeros_vartime(&self) -> u32

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

impl Borrow<UintRef> for BoxedUint

Available on crate feature alloc only.
Source§

fn borrow(&self) -> &UintRef

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<UintRef> for BoxedUint

Available on crate feature alloc only.
Source§

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

Mutably borrows from an owned value. Read more
Source§

impl CtAssign for UintRef

Source§

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

Conditionally assign src to self if choice is Choice::TRUE.
Source§

impl<Rhs: AsRef<UintRef> + ?Sized> CtEq<Rhs> for UintRef

Source§

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

Determine if self is equal to other in constant-time.
Source§

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

Determine if self is NOT equal to other in constant-time.
Source§

impl CtLt for UintRef

Source§

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

Compute whether self < other in constant time.
Source§

impl Debug for UintRef

Source§

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

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

impl Display for UintRef

Source§

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

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

impl From<&UintRef> for BoxedUint

Available on crate feature alloc only.
Source§

fn from(uint_ref: &UintRef) -> BoxedUint

Converts to this type from the input type.
Source§

impl Index<usize> for UintRef

Source§

type Output = Limb

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Limb

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for UintRef

Source§

fn index_mut(&mut self, index: usize) -> &mut Limb

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl LowerHex for UintRef

Source§

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

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

impl PartialEq for UintRef

Source§

fn eq(&self, other: &UintRef) -> 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 ToOwned for UintRef

Available on crate feature alloc only.
Source§

type Owned = BoxedUint

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> BoxedUint

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl ToUnsigned for UintRef

Available on crate feature alloc only.
Source§

type Unsigned = BoxedUint

The corresponding owned Unsigned type.
Source§

fn to_unsigned(&self) -> Self::Unsigned

Convert from a reference into an owned instance.
Source§

fn to_unsigned_zero(&self) -> Self::Unsigned

Convert from a reference into an owned instance representing zero.
Source§

impl UpperHex for UintRef

Source§

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

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

impl Eq for UintRef

Source§

impl StructuralPartialEq for UintRef

Auto Trait Implementations§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more