Skip to main content

Module primitives

Module primitives 

Source
Expand description

Integer primitives for cryptographic arithmetic.

FunctionsΒ§

borrowing_sub πŸ”’
Computes lhs - rhs - borrow, using word-sized borrow masks.
carrying_add πŸ”’
Computes lhs + rhs + carry, returning the result along with the new carry (0, 1, or 2).
carrying_mul_add πŸ”’
Computes (lhs * rhs) + addend + carry, returning the result along with the new carry.
leading_zeros πŸ”’
Count leading zero bits, returning Word::BITS if value is zero.
leading_zeros_u32 πŸ”’
Count leading zero bits, using native instructions where supported.
leading_zeros_u32_soft πŸ”’
Fixed-stage binary search for the highest set bit, including the zero case.
overflowing_add πŸ”’
Computes lhs + rhs, returning the result along with the carry (0 or 1).
trailing_zeros πŸ”’
Count trailing zero bits, returning Word::BITS if value is zero.
trailing_zeros_u32 πŸ”’
Count trailing zero bits, using native instructions where supported.
u32_bits πŸ”’
Compute the number of bits needed to represent n.
u32_max πŸ”’
const fn equivalent of u32::max(a, b).
u32_min πŸ”’
const equivalent of u32::min(a, b).
u32_rem πŸ”’
Remainder calculation, constant time for a given divisor d. Based on β€œFaster Remainder by Direct Computation: Applications to Compilers and Software Libraries” by Daniel Lemire, Owen Kaser, and Nathan Kurz., Fig. 1.
u64_invert_odd πŸ”’
Returns the multiplicative inverse of the argument modulo 2^64. The implementation is based on Hurchalla’s method for computing the multiplicative inverse modulo a power of two, and is essentially an optimized Newton iteration.
usize_lt πŸ”’
Return a Choice representing whether a < b.
widening_mul πŸ”’
Computes lhs * rhs, returning the low and the high words of the result.