From faf49459b7ba571c79c1d80ee6fcd43a91290438 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 7 Dec 2010 21:54:50 +0000 Subject: Avoid a conditional in point multiplication --- src/math/numbertheory/point_gfp.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/math/numbertheory') diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 04fde03df..5e42e37a5 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -306,17 +306,14 @@ PointGFp operator*(const BigInt& scalar, const PointGFp& point) const size_t window_size = 4; - std::vector Ps((1 << window_size) - 1); - Ps[0] = point; + std::vector Ps(1 << window_size); + Ps[0] = PointGFp(curve); + Ps[1] = point; - for(size_t i = 1; i != Ps.size(); ++i) + for(size_t i = 2; i != Ps.size(); ++i) { Ps[i] = Ps[i-1]; - - if(i % 1 == 1) - Ps[i].mult2(ws); - else - Ps[i].add(Ps[0], ws); + Ps[i].add(point, ws); } PointGFp H(curve); // create as zero @@ -330,8 +327,7 @@ PointGFp operator*(const BigInt& scalar, const PointGFp& point) const u32bit nibble = scalar.get_substring(bits_left - window_size, window_size); - if(nibble) - H.add(Ps[nibble-1], ws); + H.add(Ps[nibble], ws); bits_left -= window_size; } @@ -340,7 +336,7 @@ PointGFp operator*(const BigInt& scalar, const PointGFp& point) { H.mult2(ws); if(scalar.get_bit(bits_left-1)) - H.add(Ps[0], ws); + H.add(point, ws); --bits_left; } -- cgit v1.2.3