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::BITSifvalueis 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::BITSifvalueis 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 fnequivalent ofu32::max(a, b).- u32_min π
constequivalent ofu32::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
Choicerepresenting whethera < b. - widening_
mul π - Computes
lhs * rhs, returning the low and the high words of the result.