pub struct UintRef { /* private fields */ }Expand description
Implementations§
Source§impl UintRef
impl UintRef
Sourcepub const fn add_assign_limb(&mut self, rhs: Limb) -> Limb
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.
Sourcepub const fn carrying_add_assign(&mut self, rhs: &Self, carry: Limb) -> Limb
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.
Sourcepub const fn carrying_add_assign_slice(
&mut self,
rhs: &[Limb],
carry: Limb,
) -> Limb
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.
Sourcepub const fn conditional_add_assign(
&mut self,
rhs: &Self,
carry: Limb,
choice: Choice,
) -> Limb
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§impl UintRef
impl UintRef
Sourcepub const fn bits_precision(&self) -> u32
pub const fn bits_precision(&self) -> u32
Get the precision of this number in bits.
Sourcepub const fn bit(&self, index: u32) -> Choice
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.
Sourcepub const fn bit_vartime(&self, index: u32) -> bool
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.
Sourcepub const fn bits(&self) -> u32
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.
Sourcepub const fn bits_vartime(&self) -> u32
pub const fn bits_vartime(&self) -> u32
Calculate the number of bits needed to represent this number in variable-time with respect
to self.
Sourcepub const fn set_bit(&mut self, index: u32, bit_value: Choice)
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.
Sourcepub const fn set_bit_vartime(&mut self, index: u32, bit_value: bool)
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.
Sourcepub const fn leading_zeros(&self) -> u32
pub const fn leading_zeros(&self) -> u32
Calculate the number of leading zeros in the binary representation of this number.
Sourcepub const fn trailing_zeros(&self) -> u32
pub const fn trailing_zeros(&self) -> u32
Calculate the number of trailing zeros in the binary representation of this number.
Sourcepub const fn trailing_zeros_vartime(&self) -> u32
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.
Sourcepub const fn trailing_ones(&self) -> u32
pub const fn trailing_ones(&self) -> u32
Calculate the number of trailing ones in the binary representation of this number.
Sourcepub const fn trailing_ones_vartime(&self) -> u32
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.
Sourcepub const fn restrict_bits(&mut self, len: u32)
pub const fn restrict_bits(&mut self, len: u32)
Clear all bits at or above a given bit position.
Source§impl UintRef
impl UintRef
Sourcepub const fn is_odd(&self) -> Choice
pub const fn is_odd(&self) -> Choice
Returns the truthy value if self is odd or the falsy value otherwise.
Sourcepub const fn is_nonzero(&self) -> Choice
pub const fn is_nonzero(&self) -> Choice
Returns Choice::TRUE if self != 0 or Choice::FALSE otherwise.
Sourcepub const fn cmp_vartime(&self, rhs: &Self) -> Ordering
pub const fn cmp_vartime(&self, rhs: &Self) -> Ordering
Returns the Ordering between self and rhs in variable time.
Source§impl UintRef
impl UintRef
Sourcepub fn overflowing_mul(&self, rhs: &UintRef, out: &mut UintRef) -> Choice
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.
Sourcepub fn overflowing_square(&self, out: &mut UintRef) -> Choice
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.
Sourcepub fn wrapping_mul(&self, rhs: &UintRef, out: &mut UintRef) -> Limb
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.
Sourcepub fn wrapping_square(&self, out: &mut UintRef) -> Limb
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
impl UintRef
Sourcepub const fn shl_assign(&mut self, shift: u32)
pub const fn shl_assign(&mut self, shift: u32)
Sourcepub const fn overflowing_shl_assign(&mut self, shift: u32) -> Choice
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.
Sourcepub const fn unbounded_shl_assign(&mut self, shift: u32)
pub const fn unbounded_shl_assign(&mut self, shift: u32)
Left-shifts by shift bits, producing zero if the shift exceeds the precision.
Sourcepub const fn bounded_shl_assign(&mut self, shift: u32, shift_upper_bound: u32)
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.
Sourcepub const fn unbounded_shl_assign_vartime(&mut self, shift: u32)
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.
Sourcepub const fn wrapping_shl_assign(&mut self, shift: u32)
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.
Sourcepub const fn wrapping_shl_assign_vartime(&mut self, shift: u32)
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.
Sourcepub const fn shl1_assign(&mut self) -> Limb
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.
Sourcepub const fn shl_assign_limb(&mut self, shift: u32) -> Limb
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
impl UintRef
Sourcepub const fn shr_assign(&mut self, shift: u32)
pub const fn shr_assign(&mut self, shift: u32)
Sourcepub const fn overflowing_shr_assign(&mut self, shift: u32) -> Choice
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.
Sourcepub const fn unbounded_shr_assign(&mut self, shift: u32)
pub const fn unbounded_shr_assign(&mut self, shift: u32)
Right-shifts by shift bits, producing zero if the shift exceeds the precision.
Sourcepub const fn bounded_shr_assign(&mut self, shift: u32, shift_upper_bound: u32)
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.
Sourcepub const fn unbounded_shr_assign_vartime(&mut self, shift: u32)
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.
Sourcepub const fn wrapping_shr_assign(&mut self, shift: u32)
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.
Sourcepub const fn wrapping_shr_assign_vartime(&mut self, shift: u32)
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.
Sourcepub const fn shr1_assign(&mut self) -> Limb
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.
Sourcepub const fn shr_assign_limb(&mut self, shift: u32) -> Limb
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
impl UintRef
Sourcepub const fn conditional_copy_from(&mut self, rhs: &UintRef, copy: Choice)
pub const fn conditional_copy_from(&mut self, rhs: &UintRef, copy: Choice)
Sourcepub const fn copy_from_slice(&mut self, limbs: &[Limb])
pub const fn copy_from_slice(&mut self, limbs: &[Limb])
Sourcepub const fn conditional_copy_from_slice(
&mut self,
limbs: &[Limb],
copy: Choice,
)
pub const fn conditional_copy_from_slice( &mut self, limbs: &[Limb], copy: Choice, )
Sourcepub const fn split_at(&self, mid: usize) -> (&Self, &Self)
pub const fn split_at(&self, mid: usize) -> (&Self, &Self)
Split the limb slice at a fixed position, producing head and tail slices.
Sourcepub const fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
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.
Sourcepub const fn leading(&self, len: usize) -> &Self
pub const fn leading(&self, len: usize) -> &Self
Access a limb slice up to a number of elements len.
Sourcepub const fn leading_mut(&mut self, len: usize) -> &mut Self
pub const fn leading_mut(&mut self, len: usize) -> &mut Self
Access a mutable limb slice up to a number of elements len.
Sourcepub const fn trailing(&self, start: usize) -> &Self
pub const fn trailing(&self, start: usize) -> &Self
Access a limb slice starting from the index start.
Sourcepub const fn trailing_mut(&mut self, start: usize) -> &mut Self
pub const fn trailing_mut(&mut self, start: usize) -> &mut Self
Access a mutable limb slice starting from the index start.
Source§impl UintRef
impl UintRef
Sourcepub const fn borrowing_sub_assign(&mut self, rhs: &Self, borrow: Limb) -> Limb
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§impl UintRef
impl UintRef
Sourcepub const fn new_flattened_mut<const N: usize>(
slice: &mut [[Limb; N]],
) -> &mut Self
pub const fn new_flattened_mut<const N: usize>( slice: &mut [[Limb; N]], ) -> &mut Self
Sourcepub const fn as_mut_limbs(&mut self) -> &mut [Limb]
pub const fn as_mut_limbs(&mut self) -> &mut [Limb]
Mutably borrow the inner &mut [Limb] slice.
Sourcepub const fn as_mut_words(&mut self) -> &mut [Word]
pub const fn as_mut_words(&mut self) -> &mut [Word]
Borrow the inner limbs as a mutable slice of Words.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &Limb>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &Limb>
Get an iterator over the inner limbs.
Sourcepub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Limb>
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Limb>
Get a mutable iterator over the inner limbs.
Sourcepub const fn conditional_set_zero(&mut self, choice: Choice)
pub const fn conditional_set_zero(&mut self, choice: Choice)
Conditionally assign all of the limbs to zero.
Sourcepub const fn conditional_set_max(&mut self, choice: Choice)
pub const fn conditional_set_max(&mut self, choice: Choice)
Conditionally assign all of the limbs to the maximum.
Sourcepub const fn to_uint_resize<const LIMBS: usize>(&self) -> Uint<LIMBS>
pub const fn to_uint_resize<const LIMBS: usize>(&self) -> Uint<LIMBS>
Extract up to LIMBS limbs into a new Uint.
Sourcepub const fn as_nz_vartime(&self) -> Option<&NonZero<Self>>
pub const fn as_nz_vartime(&self) -> Option<&NonZero<Self>>
Trait Implementations§
Source§impl BitOps for UintRef
impl BitOps for UintRef
Source§fn bits_precision(&self) -> u32
fn bits_precision(&self) -> u32
Source§fn bytes_precision(&self) -> usize
fn bytes_precision(&self) -> usize
Source§fn leading_zeros(&self) -> u32
fn leading_zeros(&self) -> u32
Source§fn bit(&self, index: u32) -> Choice
fn bit(&self, index: u32) -> Choice
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)
fn set_bit(&mut self, index: u32, bit_value: Choice)
index to 0 or 1 depending on the value of bit_value.Source§fn trailing_zeros(&self) -> u32
fn trailing_zeros(&self) -> u32
Source§fn trailing_ones(&self) -> u32
fn trailing_ones(&self) -> u32
Source§fn bit_vartime(&self, index: u32) -> bool
fn bit_vartime(&self, index: u32) -> bool
Source§fn bits_vartime(&self) -> u32
fn bits_vartime(&self) -> u32
self.Source§fn set_bit_vartime(&mut self, index: u32, bit_value: bool)
fn set_bit_vartime(&mut self, index: u32, bit_value: bool)
index to 0 or 1 depending on the value of bit_value,
variable time in self.Source§fn trailing_zeros_vartime(&self) -> u32
fn trailing_zeros_vartime(&self) -> u32
self.Source§fn trailing_ones_vartime(&self) -> u32
fn trailing_ones_vartime(&self) -> u32
self.Source§fn leading_zeros_vartime(&self) -> u32
fn leading_zeros_vartime(&self) -> u32
Source§impl BorrowMut<UintRef> for BoxedUint
Available on crate feature alloc only.
impl BorrowMut<UintRef> for BoxedUint
alloc only.Source§fn borrow_mut(&mut self) -> &mut UintRef
fn borrow_mut(&mut self) -> &mut UintRef
Source§impl ToOwned for UintRef
Available on crate feature alloc only.
impl ToOwned for UintRef
alloc only.Source§impl ToUnsigned for UintRef
Available on crate feature alloc only.
impl ToUnsigned for UintRef
alloc only.