A very slightly faster modexp.
This commit is contained in:
@@ -165,23 +165,25 @@ impl UCN {
|
|||||||
|
|
||||||
pub fn fastmodexp(&self, e: &UCN, mu: &BarrettUCN) -> UCN {
|
pub fn fastmodexp(&self, e: &UCN, mu: &BarrettUCN) -> UCN {
|
||||||
let mut b = self.reduce(&mu);
|
let mut b = self.reduce(&mu);
|
||||||
let mut eprime = e.clone();
|
|
||||||
let mut result = UCN::from(1 as u8);
|
let mut result = UCN::from(1 as u8);
|
||||||
|
|
||||||
loop {
|
for digit in e.contents.iter() {
|
||||||
if eprime.is_zero() {
|
let mut work = *digit;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if eprime.is_odd() {
|
for _ in 0..64 {
|
||||||
|
if (work & 0x1) == 1 {
|
||||||
result = (result * &b).reduce(&mu);
|
result = (result * &b).reduce(&mu);
|
||||||
}
|
}
|
||||||
|
|
||||||
b = (&b * &b).reduce(&mu);
|
b = (&b * &b).reduce(&mu);
|
||||||
eprime >>= 1;
|
|
||||||
|
work >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_bytes(&self, len: usize) -> Vec<u8> {
|
pub fn to_bytes(&self, len: usize) -> Vec<u8> {
|
||||||
let mylen = self.contents.len() * 8;
|
let mylen = self.contents.len() * 8;
|
||||||
let mut res = Vec::with_capacity(mylen);
|
let mut res = Vec::with_capacity(mylen);
|
||||||
|
|||||||
Reference in New Issue
Block a user