Skip to content

Commit

Permalink
Remove unnecessary sign variable from wnaf_const
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasnick committed Apr 29, 2020
1 parent 6bb0b77 commit 37dba32
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ecmult_const_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,22 @@ static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w
/* 4 */
u_last = secp256k1_scalar_shr_int(&s, w);
do {
int sign;
int even;

/* 4.1 4.4 */
u = secp256k1_scalar_shr_int(&s, w);
/* 4.2 */
even = ((u & 1) == 0);
sign = 2 * (u_last > 0) - 1;
u += sign * even;
u_last -= sign * even * (1 << w);
/* In contrast to the original algorithm, u_last is always > 0 and
* therefore we do not need to check its sign. In particular, it's easy
* to see that u_last is never < 0 because u is never < 0. Moreover,
* u_last is never = 0 because u is never even after a loop
* iteration. The same holds analogously for the initial value of
* u_last (in the first loop iteration). */
VERIFY_CHECK(u_last > 0);
VERIFY_CHECK((u_last & 1) == 1);
u += even;
u_last -= even * (1 << w);

/* 4.3, adapted for global sign change */
wnaf[word++] = u_last * global_sign;
Expand Down

0 comments on commit 37dba32

Please sign in to comment.