For performance, don't double/square until we've seen a bit.

This commit is contained in:
Sean Bowe 2017-07-09 21:11:29 -06:00
parent f2b1b0632d
commit b965c58ac1
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
2 changed files with 15 additions and 2 deletions

View File

@ -475,9 +475,15 @@ macro_rules! curve_impl {
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S) {
let mut res = Self::zero();
let mut found_one = false;
for i in BitIterator::new(other.into())
{
res.double();
if found_one {
res.double();
} else {
found_one = i;
}
if i {
res.add_assign(self);

View File

@ -219,8 +219,15 @@ pub trait Field: Sized +
{
let mut res = Self::one();
let mut found_one = false;
for i in BitIterator::new(exp) {
res.square();
if found_one {
res.square();
} else {
found_one = i;
}
if i {
res.mul_assign(self);
}