INNER CODE UNIT · Rust

sum_n_loop

IronCoreLabs/recrypt-rs · src/internal/mod.rs:394

fn sum_n_loop<T: Add<Output = T> + Copy>(t: T, k: u32, extra: T) -> T {
    if k == 1 {
        t + extra
    } else {
        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 {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…