diff options
author | lloyd <[email protected]> | 2010-03-15 20:18:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-15 20:18:00 +0000 |
commit | c0c1ab2cbc36aca001c43c208b337420fa4ebc57 (patch) | |
tree | b982bf7947ff8810790c440150ae7c59bb6dcb42 /src | |
parent | 053c78fa79ec9eaef13262314c702b4a1024234d (diff) |
Rewrite point mult to make larger windows easier
Diffstat (limited to 'src')
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index a74b301ba..c5a4abf91 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -221,17 +221,20 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) if(scalar.is_negative()) P.negate(); - u32bit scalar_bits = scalar.bits(); + const u32bit scalar_bits = scalar.bits(); PointGFp P2 = P * 2; PointGFp P3 = P2 + P; - for(u32bit i = 0; i < scalar_bits - 1; i += 2) + u32bit window_size = 2; + u32bit bits_left = scalar_bits; + + while(bits_left >= window_size) { - u32bit nibble = scalar.get_substring(scalar_bits - i - 2, 2); + u32bit nibble = scalar.get_substring(bits_left - window_size, window_size); - H.mult2(ws); - H.mult2(ws); + for(u32bit i = 0; i != window_size; ++i) + H.mult2(ws); if(nibble == 3) H.add(P3, ws); @@ -239,13 +242,17 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) H.add(P2, ws); else if(nibble == 1) H.add(P, ws); + + bits_left -= window_size; } - if(scalar_bits % 2) + while(bits_left) { H.mult2(ws); - if(scalar.get_bit(0)) + if(scalar.get_bit(bits_left-1)) H.add(P, ws); + + --bits_left; } *this = H; |