bigint::monty: simplify modpow zero test

This commit is contained in:
Josh Stone 2017-10-22 15:38:50 -07:00
parent 96c4a26624
commit b380880ed3
1 changed files with 2 additions and 3 deletions

View File

@ -1,5 +1,5 @@
use integer::Integer; use integer::Integer;
use traits::{Zero, One}; use traits::Zero;
use biguint::BigUint; use biguint::BigUint;
@ -116,8 +116,7 @@ pub fn monty_modpow(a: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint{
// Binary exponentiation // Binary exponentiation
let mut ans = &r % mr.p; let mut ans = &r % mr.p;
let mut e = exp.clone(); let mut e = exp.clone();
let zero = Zero::zero(); while !e.is_zero() {
while e > zero {
if e.is_odd() { if e.is_odd() {
ans = monty_mult(ans, &apri, &mr); ans = monty_mult(ans, &apri, &mr);
} }