diff options
author | Артём Павлов [Artyom Pavlov] <newpavlov@gmail.com> | 2017-08-13 04:08:23 +0300 |
---|---|---|
committer | Артём Павлов [Artyom Pavlov] <newpavlov@gmail.com> | 2017-08-13 04:08:23 +0300 |
commit | 7919c89b5eecdfef77bd859b4fd33ea04b155cc9 (patch) | |
tree | 36c72d420612d8efa4e36ec1347be2fdf04894b9 /src/tools.rs | |
download | PAKEs-7919c89b5eecdfef77bd859b4fd33ea04b155cc9.tar.xz |
First commit
Diffstat (limited to 'src/tools.rs')
-rw-r--r-- | src/tools.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/tools.rs b/src/tools.rs new file mode 100644 index 0000000..8cb6910 --- /dev/null +++ b/src/tools.rs @@ -0,0 +1,19 @@ +use num::BigUint; + +pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint { + let zero = BigUint::new(vec![0]); + let one = BigUint::new(vec![1]); + let two = BigUint::new(vec![2]); + let mut exp = exp.clone(); + let mut result = one.clone(); + let mut base = base % modulus; + + while exp > zero { + if &exp % &two == one { + result = (result * &base) % modulus; + } + exp = exp >> 1; + base = (&base * &base) % modulus; + } + result +} |