Skip to main content

Module primitives

Module primitives 

Source
Expand description

Constant-time integer primitives for cryptographic arithmetic.

Core integer methods can lower to branches or table lookups on targets without the corresponding instructions. These helpers provide alternatives if value is zero-bit counting and carry propagation.

Like Choice, they use optimization barriers where needed. Their generated code should still be checked for the target and compiler in use.

Native zero counts are used when supported and advertised by the target configuration.

Macrosยง

bitborrow ๐Ÿ”’
Outgoing borrow bit for a wrapping x - y - borrow_in result.
bitle ๐Ÿ”’
Bitwise less-than-or equal: returns 1 if x <= y, and otherwise returns 0.
bitlt ๐Ÿ”’
Bitwise less-than: returns 1 if x < y, and otherwise returns 0.
bitnz ๐Ÿ”’
Bitwise non-zero: returns 1 if x != 0, and otherwise returns 0.
borrowing_sub_primitives ๐Ÿ”’
comparison_primitives ๐Ÿ”’

Functionsยง

borrowing_sub_inner_u32 ๐Ÿ”’
borrowing_sub_inner_u64 ๐Ÿ”’
borrowing_sub_mask_u32
Subtract rhs and an incoming borrow from lhs, using word-sized borrow masks.
borrowing_sub_mask_u64
Subtract rhs and an incoming borrow from lhs, using word-sized borrow masks.
borrowing_sub_u32
Subtract rhs and an incoming borrow from lhs.
borrowing_sub_u64
Subtract rhs and an incoming borrow from lhs.
le_u32 ๐Ÿ”’
le_u64 ๐Ÿ”’
leading_zeros_u32
Count leading zero bits, returning 32 if value is zero.
leading_zeros_u64
Count leading zero bits, returning 64 if value is zero.
lt_u32 ๐Ÿ”’
lt_u64 ๐Ÿ”’
nz_u32 ๐Ÿ”’
nz_u64 ๐Ÿ”’
overflowing_add_u64
Add two integers, returning the wrapping sum and Choice::TRUE on overflow.
overflowing_add_u128
Add two integers, returning the wrapping sum and Choice::TRUE on overflow.
trailing_zeros_u32
Count trailing zero bits, returning 32 if value is zero.
trailing_zeros_u64
Count trailing zero bits, returning 64 if value is zero.