Skip to main content

UintRef

Struct UintRef 

Source
#[repr(transparent)]
pub struct UintRef { pub(crate) limbs: [Limb], }
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.

Fields§

§limbs: [Limb]

Inner limb array. Stored from least significant to most significant.

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(crate) const fn is_zero_vartime(&self) -> bool

Determine in variable time whether the self is zero.

Source

pub(crate) const fn cmp(lhs: &Self, rhs: &Self) -> Ordering

Returns the Ordering between lhs and rhs.

Source

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

Returns the Ordering between self and rhs in variable time.

Source

pub(crate) const fn lt(lhs: &Self, rhs: &Self) -> Choice

Returns the truthy value if self < rhs and the falsy value otherwise.

Source§

impl UintRef

Source

pub(crate) const fn div_rem(&mut self, rhs: &mut Self)

Computes self / rhs, returning the quotient in self and the remainder in rhs.

§Panics

If the divisor is zero.

Source

pub(crate) const fn div_rem_vartime(&mut self, rhs: &mut Self)

Computes self / rhs, returning the quotient in self and the remainder in rhs.

This function operates in variable-time with respect to rhs. For a fixed divisor, it operates in constant-time

§Panics

If the divisor is zero.

Source

pub(crate) const fn rem_wide( x_lower_upper: (&mut Self, &mut Self), rhs: &mut Self, )

Computes x_lower_upper % rhs, returning the remainder in rhs.

The x_lower_upper tuple represents a wide integer. The size of x_lower_upper.1 must be at least as large as rhs. x_lower_upper is left in an indeterminate state.

§Panics

If the divisor is zero.

Source

pub(crate) const fn rem_wide_vartime( x_lower_upper: (&mut Self, &mut Self), rhs: &mut Self, )

Computes x_lower_upper % rhs, returning the remainder in rhs.

This function operates in variable-time with respect to rhs. For a fixed divisor, it operates in constant-time.

The x_lower_upper tuple represents a wide integer. The size of x_lower_upper.1 must be at least as large as rhs. x_lower_upper is left in an indeterminate state.

§Panics

If the divisor is zero.

Source

pub(crate) const fn div_rem_shifted( &mut self, x_hi: Limb, y: &mut Self, ywords: u32, )

Perform in-place division (self / y) for a pre-shifted dividend and divisor.

The dividend and divisor must be left-shifted such that the high bit of the divisor is set, and x_hi holds the top bits of the dividend.

The quotient is returned in self and the remainder in y, but these values require additional correction. This is left to the caller for performance reasons.

Source

pub(crate) const fn div_rem_large_shifted( &mut self, x_hi: Limb, y: &Self, ywords: u32, reciprocal: Reciprocal, vartime: Choice, ) -> Limb

Computes self / y for a “large” divisor (>1 limbs), returning the quotient and the remainder in self.

While the divisor may only be a single limb, additional corrections to the result are required in this case.

The dividend and divisor must be left-shifted such that the high bit of the divisor is set, and x_hi holds the top bits of the dividend.

Source

pub(crate) const fn div_rem_large_vartime(&mut self, rhs: &mut Self)

Perform in-place variable-time division for a “large” divisor (>1 limbs). The quotient is returned in self and the remainder in rhs.

Source

const fn rem_wide_shifted( x: (&mut Self, &mut Self), x_hi: Limb, y: &mut Self, ywords: u32, )

Perform in-place division (x / y) for a pre-shifted dividend and divisor, tracking only the remainder.

The dividend and divisor must be left-shifted such that the high bit of the divisor is set, and x_hi holds the top bits of the dividend.

The shifted remainder is returned in y, and must be unshifted by the caller. x is left in an indeterminate state.

Source

const fn rem_wide_large_shifted( x: (&Self, &mut Self), x_hi: Limb, y: &Self, ywords: u32, reciprocal: Reciprocal, vartime: Choice, ) -> Limb

Computes x % y for a “large” divisor (>1 limbs), returning the remainder in x.1.

While the divisor may only be a single limb, additional corrections to the result are required in this case.

The dividend and divisor must be left-shifted such that the high bit of the divisor is set, and x_hi holds the top bits of the dividend.

Source

pub(crate) const fn div_rem_limb(&mut self, rhs: NonZero<Limb>) -> Limb

Divides self by the divisor encoded in the reciprocal, setting self to the quotient and returning the remainder.

Source

pub(crate) const fn div_rem_limb_with_reciprocal( &mut self, reciprocal: &Reciprocal, ) -> Limb

Divides self by the divisor encoded in the reciprocal, setting self to the quotient and returning the remainder.

Source

pub(crate) const fn div_rem_limb_with_reciprocal_shifted( &mut self, hi: Limb, reciprocal: &Reciprocal, ) -> Limb

Divides self by the divisor encoded in the reciprocal, setting self to the quotient and returning the remainder.

Source

pub(crate) const fn rem_limb(&self, rhs: NonZero<Limb>) -> Limb

Divides self by the divisor encoded in the reciprocal, returning the remainder.

Source

pub(crate) const fn rem_limb_with_reciprocal( &self, reciprocal: &Reciprocal, carry: Limb, ) -> Limb

Divides self by the divisor encoded in the reciprocal, and returns the remainder.

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

pub(crate) const fn check_mul_overflow( &self, rhs: &UintRef, carry: Choice, ) -> Choice

Determine whether overflow occurs during wrapped multiplication.

We determine this by comparing limbs in self[i=0..n] and rhs[j=0..m]. Any combination where the sum of indexes i + j >= n, having self[i] != 0 and rhs[j] != 0 would cause an overflow. For efficiency, we OR all limbs in rhs that would apply to each limb in self in turn.

Source

pub(crate) const fn check_square_overflow(&self, carry: Choice) -> Choice

Determine whether overflow occurs during wrapped squaring.

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(crate) const fn bounded_shl_by_limbs_assign( &mut self, shift: u32, shift_upper_bound: u32, )

Left-shifts by shift * Limb::BITS 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(crate) const fn conditional_shl_assign_by_limbs_vartime( &mut self, shift: u32, c: Choice, )

Conditionally left-shifts by shift limbs 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(crate) const fn unbounded_shl_assign_by_limbs_vartime(&mut self, shift: u32)

Left-shifts by shift limbs 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(crate) const fn unbounded_shl_vartime(&self, shift: u32, out: &mut Self)

Copies self << shift into out in a panic-free manner, producing zero if the shift exceeds the precision.

out is assumed to be initialized with zeros.

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 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(crate) const fn shl1_assign_with_carry(&mut self, carry: Limb) -> 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(crate) const fn conditional_shl_assign_limb_nonzero( &mut self, shift: NonZeroU32, carry: Limb, choice: Choice, ) -> Limb

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

§Panics
  • if shift >= Limb::BITS.
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

pub(crate) const fn shl_assign_limb_with_carry( &mut self, shift: u32, carry: Limb, ) -> Limb

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

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

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

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

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.

§Panics

If the shift size is equal to or larger than the width of the integer.

Source

pub(crate) const fn shl_assign_limb_with_carry_vartime( &mut self, shift: u32, carry: Limb, ) -> Limb

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

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.

§Panics

If the shift size is equal to or larger than the width of the integer.

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(crate) const fn bounded_shr_by_limbs_assign( &mut self, shift: u32, shift_upper_bound: u32, )

Right-shifts by shift * Limb::BITS 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(crate) const fn conditional_shr_assign_by_limbs_vartime( &mut self, shift: u32, c: Choice, )

Conditionally right-shifts by shift limbs 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(crate) const fn unbounded_shr_assign_by_limbs(&mut self, shift: u32)

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

Source

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

Right-shifts by shift limbs 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(crate) const fn unbounded_shr_vartime(&self, shift: u32, out: &mut Self)

Copies self >> shift into out in a panic-free manner, producing zero if the shift exceeds the precision.

out is assumed to be initialized with zeros.

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 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(crate) const fn shr1_assign_with_carry(&mut self, carry: Limb) -> 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(crate) const fn conditional_shr_assign_limb_nonzero( &mut self, shift: NonZeroU32, carry: Limb, choice: Choice, ) -> Limb

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

§Panics
  • if shift >= Limb::BITS.
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

pub(crate) const fn shr_assign_limb_with_carry( &mut self, shift: u32, carry: Limb, ) -> Limb

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

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

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

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

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.

§Panics

If the shift size is equal to or larger than the width of the integer.

Source

pub(crate) const fn shr_assign_limb_with_carry_vartime( &mut self, shift: u32, carry: Limb, ) -> Limb

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

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.

§Panics

If the shift size is equal to or larger than the width of the integer.

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

pub(crate) fn conditional_borrowing_sub_assign( &mut self, rhs: &Self, choice: Choice, ) -> Choice

Perform in-place wrapping subtraction, returning the truthy value as the second element of the tuple if an underflow has occurred.

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(crate) const fn as_nz_unchecked(&self) -> &NonZero<Self>

Cast to NonZero without first checking that the contained value is non-zero.

Use with care! This method bypasses NonZero invariant checks.

§Warning: Panics

We don’t explicitly flag this function as unsafe because it doesn’t have a memory safety impact, however functions called with NonZero arguments assume this value is non-zero and may panic if given a zero value.

Source

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

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

Source

pub(crate) const fn as_odd_unchecked(&self) -> &Odd<Self>

Cast to Odd without first checking that the contained value is actually odd.

Use with care! This method bypasses Odd invariant checks.

§Panics

We don’t explicitly flag this function as unsafe because it doesn’t have a memory safety impact, however functions called with Odd arguments assume this value is actually odd and may panic if given an even value.

Source

pub(crate) const fn lowest_u64(&self) -> u64

Get the least significant 64-bits.

Source

pub(crate) fn fold_limbs<F>( &mut self, lhs: &Self, rhs: &Self, carry: Limb, f: F, ) -> Limb
where F: Fn(Limb, Limb, Limb) -> (Limb, Limb),

Perform a carry chain-like operation over the limbs of lhs and rhs inputs, virtually padding each with Limb::ZERO as needed to match the width of self and assigning the result to self.

Source

pub(crate) fn fold_limbs_assign<F>( &mut self, rhs: &UintRef, carry: Limb, f: F, ) -> Limb
where F: Fn(Limb, Limb, Limb) -> (Limb, Limb),

Perform a carry chain-like operation over the limbs of the inputs, virtually padding rhs with Limb::ZERO as needed to match the width of self and assigning the result to self.

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

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

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

Source§

fn borrow(&self) -> &UintRef

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<UintRef> for BoxedUint

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

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