]> git.lizzy.rs Git - PAKEs.git/blob - srp/src/tools.rs
srp: fix some low-hanging clippy warnings
[PAKEs.git] / srp / src / tools.rs
1 use num::BigUint;
2
3 pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
4     let zero = BigUint::new(vec![0]);
5     let one = BigUint::new(vec![1]);
6     let two = BigUint::new(vec![2]);
7     let mut exp = exp.clone();
8     let mut result = one.clone();
9     let mut base = base % modulus;
10
11     while exp > zero {
12         if &exp % &two == one {
13             result = (result * &base) % modulus;
14         }
15         exp >>= 1;
16         base = (&base * &base) % modulus;
17     }
18     result
19 }