INNER CODE UNIT · Rust
x
IronCoreLabs/recrypt-rs · src/internal/mod.rs:398
let x = if (k & 1) == 1 { t + extra } else { extra };
sum_n_loop(t + t, k >> 1, x)
}
}
/// This is not constant time, it reveals the n, but if the t has a constant time square and multiply, doesn't reveal the t.
fn pow_for_square<T: One + Mul<T, Output = T> + Copy + Square>(t: T, exp: u32) -> T {
if exp == 0 {
T::one()
} else {
let mut mut_exp = exp;
let mut y = T::one();
let mut x = t;
while mut_exp > 1 {
if mut_exp & 1 == 1 {
y = x * y;
}
x = x.square();