INNER CODE UNIT · Rust
pow_for_square
IronCoreLabs/recrypt-rs · src/internal/mod.rs:404
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();
mut_exp >>= 1;
}
y * x
}
}