p256/arithmetic/
util.rs

1//! Helper functions.
2// TODO(tarcieri): replace these with `crypto-bigint`
3
4/// Computes `a + b + carry`, returning the result along with the new carry. 64-bit version.
5#[inline(always)]
6pub const fn adc(a: u64, b: u64, carry: u64) -> (u64, u64) {
7    let ret = (a as u128) + (b as u128) + (carry as u128);
8    (ret as u64, (ret >> 64) as u64)
9}
10
11/// Computes `a - (b + borrow)`, returning the result along with the new borrow. 64-bit version.
12#[inline(always)]
13pub const fn sbb(a: u64, b: u64, borrow: u64) -> (u64, u64) {
14    let ret = (a as u128).wrapping_sub((b as u128) + ((borrow >> 63) as u128));
15    (ret as u64, (ret >> 64) as u64)
16}
17
18/// Computes `a + (b * c) + carry`, returning the result along with the new carry.
19#[inline(always)]
20pub const fn mac(a: u64, b: u64, c: u64, carry: u64) -> (u64, u64) {
21    let ret = (a as u128) + ((b as u128) * (c as u128)) + (carry as u128);
22    (ret as u64, (ret >> 64) as u64)
23}