@@ -220,9 +220,24 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
220220 return last_set_bit + 1 ;
221221}
222222
223+ /* Same as secp256k1_ecmult_wnaf, but stores to int8_t array. Requires w <= 8. */
224+ static int secp256k1_ecmult_wnaf_small (int8_t * wnaf , int len , const secp256k1_scalar * a , int w ) {
225+ int wnaf_tmp [256 ];
226+ int ret , i ;
227+
228+ VERIFY_CHECK (2 <= w && w <= 8 );
229+ ret = secp256k1_ecmult_wnaf (wnaf_tmp , len , a , w );
230+
231+ for (i = 0 ; i < len ; i ++ ) {
232+ wnaf [i ] = (int8_t )wnaf_tmp [i ];
233+ }
234+
235+ return ret ;
236+ }
237+
223238struct secp256k1_strauss_point_state {
224- int wnaf_na_1 [129 ];
225- int wnaf_na_lam [129 ];
239+ int8_t wnaf_na_1 [129 ];
240+ int8_t wnaf_na_lam [129 ];
226241 int bits_na_1 ;
227242 int bits_na_lam ;
228243};
@@ -259,8 +274,8 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
259274 secp256k1_scalar_split_lambda (& na_1 , & na_lam , & na [np ]);
260275
261276 /* build wnaf representation for na_1 and na_lam. */
262- state -> ps [no ].bits_na_1 = secp256k1_ecmult_wnaf (state -> ps [no ].wnaf_na_1 , 129 , & na_1 , WINDOW_A );
263- state -> ps [no ].bits_na_lam = secp256k1_ecmult_wnaf (state -> ps [no ].wnaf_na_lam , 129 , & na_lam , WINDOW_A );
277+ state -> ps [no ].bits_na_1 = secp256k1_ecmult_wnaf_small (state -> ps [no ].wnaf_na_1 , 129 , & na_1 , WINDOW_A );
278+ state -> ps [no ].bits_na_lam = secp256k1_ecmult_wnaf_small (state -> ps [no ].wnaf_na_lam , 129 , & na_lam , WINDOW_A );
264279 VERIFY_CHECK (state -> ps [no ].bits_na_1 <= 129 );
265280 VERIFY_CHECK (state -> ps [no ].bits_na_lam <= 129 );
266281 if (state -> ps [no ].bits_na_1 > bits ) {
0 commit comments