48
48
*
49
49
* Numbers reference steps of `Algorithm SPA-resistant Width-w NAF with Odd Scalar` on pp. 335
50
50
*/
51
- static int secp256k1_wnaf_const (int * wnaf , secp256k1_scalar s , int w , int size ) {
51
+ static int secp256k1_wnaf_const (int * wnaf , const secp256k1_scalar * scalar , int w , int size ) {
52
52
int global_sign ;
53
53
int skew = 0 ;
54
54
int word = 0 ;
@@ -59,7 +59,7 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
59
59
60
60
int flip ;
61
61
int bit ;
62
- secp256k1_scalar neg_s ;
62
+ secp256k1_scalar s ;
63
63
int not_neg_one ;
64
64
/* Note that we cannot handle even numbers by negating them to be odd, as is
65
65
* done in other implementations, since if our scalars were specified to have
@@ -75,12 +75,13 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w, int size)
75
75
* {1, 2} we want to add to the scalar when ensuring that it's odd. Further
76
76
* complicating things, -1 interacts badly with `secp256k1_scalar_cadd_bit` and
77
77
* we need to special-case it in this logic. */
78
- flip = secp256k1_scalar_is_high (& s );
78
+ flip = secp256k1_scalar_is_high (scalar );
79
79
/* We add 1 to even numbers, 2 to odd ones, noting that negation flips parity */
80
- bit = flip ^ !secp256k1_scalar_is_even (& s );
80
+ bit = flip ^ !secp256k1_scalar_is_even (scalar );
81
81
/* We check for negative one, since adding 2 to it will cause an overflow */
82
- secp256k1_scalar_negate (& neg_s , & s );
83
- not_neg_one = !secp256k1_scalar_is_one (& neg_s );
82
+ secp256k1_scalar_negate (& s , scalar );
83
+ not_neg_one = !secp256k1_scalar_is_one (& s );
84
+ s = * scalar ;
84
85
secp256k1_scalar_cadd_bit (& s , bit , not_neg_one );
85
86
/* If we had negative one, flip == 1, s.d[0] == 0, bit == 1, so caller expects
86
87
* that we added two to it and flipped it. In fact for -1 these operations are
@@ -132,21 +133,20 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
132
133
int wnaf_1 [1 + WNAF_SIZE (WINDOW_A - 1 )];
133
134
134
135
int i ;
135
- secp256k1_scalar sc = * scalar ;
136
136
137
137
/* build wnaf representation for q. */
138
138
int rsize = size ;
139
139
#ifdef USE_ENDOMORPHISM
140
140
if (size > 128 ) {
141
141
rsize = 128 ;
142
142
/* split q into q_1 and q_lam (where q = q_1 + q_lam*lambda, and q_1 and q_lam are ~128 bit) */
143
- secp256k1_scalar_split_lambda (& q_1 , & q_lam , & sc );
144
- skew_1 = secp256k1_wnaf_const (wnaf_1 , q_1 , WINDOW_A - 1 , 128 );
145
- skew_lam = secp256k1_wnaf_const (wnaf_lam , q_lam , WINDOW_A - 1 , 128 );
143
+ secp256k1_scalar_split_lambda (& q_1 , & q_lam , scalar );
144
+ skew_1 = secp256k1_wnaf_const (wnaf_1 , & q_1 , WINDOW_A - 1 , 128 );
145
+ skew_lam = secp256k1_wnaf_const (wnaf_lam , & q_lam , WINDOW_A - 1 , 128 );
146
146
} else
147
147
#endif
148
148
{
149
- skew_1 = secp256k1_wnaf_const (wnaf_1 , sc , WINDOW_A - 1 , size );
149
+ skew_1 = secp256k1_wnaf_const (wnaf_1 , scalar , WINDOW_A - 1 , size );
150
150
#ifdef USE_ENDOMORPHISM
151
151
skew_lam = 0 ;
152
152
#endif
0 commit comments