@@ -195,6 +195,8 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
195
195
if (EXPECT (first , 0 )) {
196
196
/* If this is the first table lookup, we can skip addition. */
197
197
secp256k1_gej_set_ge (r , & add );
198
+ /* Give the entry a random Z coordinate to blind intermediary results. */
199
+ secp256k1_gej_rescale (r , & ctx -> proj_blind );
198
200
first = 0 ;
199
201
} else {
200
202
secp256k1_gej_add_ge (r , r , & add );
@@ -222,6 +224,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
222
224
secp256k1_scalar b ;
223
225
secp256k1_scalar diff ;
224
226
secp256k1_gej gb ;
227
+ secp256k1_fe f ;
225
228
unsigned char nonce32 [32 ];
226
229
secp256k1_rfc6979_hmac_sha256 rng ;
227
230
unsigned char keydata [64 ] = {0 };
@@ -233,6 +236,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
233
236
/* When seed is NULL, reset the final point and blinding value. */
234
237
secp256k1_ge_neg (& ctx -> final_point_add , & secp256k1_ge_const_g );
235
238
secp256k1_scalar_add (& ctx -> scalar_offset , & secp256k1_scalar_one , & diff );
239
+ ctx -> proj_blind = secp256k1_fe_one ;
236
240
}
237
241
/* The prior blinding value (if not reset) is chained forward by including it in the hash. */
238
242
secp256k1_scalar_get_b32 (nonce32 , & ctx -> scalar_offset );
@@ -247,7 +251,11 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
247
251
secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , seed32 ? 64 : 32 );
248
252
memset (keydata , 0 , sizeof (keydata ));
249
253
250
- /* TODO: reintroduce projective blinding. */
254
+ /* Compute projective blinding factor (cannot be 0). */
255
+ secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
256
+ secp256k1_fe_set_b32 (& f , nonce32 );
257
+ secp256k1_fe_cmov (& f , & secp256k1_fe_one , secp256k1_fe_is_zero (& f ));
258
+ ctx -> proj_blind = f ;
251
259
252
260
/* For a random blinding value b, set scalar_offset=diff-n, final_point_add=bG */
253
261
secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
0 commit comments