@@ -175,6 +175,8 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
175
175
if (EXPECT (first , 0 )) {
176
176
/* If this is the first table lookup, we can skip addition. */
177
177
secp256k1_gej_set_ge (r , & add );
178
+ /* Give the entry a random Z coordinate to blind intermediary results. */
179
+ secp256k1_gej_rescale (r , & ctx -> proj_blind );
178
180
first = 0 ;
179
181
} else {
180
182
secp256k1_gej_add_ge (r , r , & add );
@@ -203,6 +205,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
203
205
secp256k1_scalar base_offset , negone ;
204
206
unsigned i ;
205
207
secp256k1_gej gb ;
208
+ secp256k1_fe f ;
206
209
unsigned char nonce32 [32 ];
207
210
secp256k1_rfc6979_hmac_sha256 rng ;
208
211
unsigned char keydata [64 ] = {0 };
@@ -220,6 +223,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
220
223
secp256k1_ge_neg (& ctx -> final_point_add , & secp256k1_ge_const_g );
221
224
ctx -> scalar_offset = secp256k1_scalar_one ;
222
225
secp256k1_scalar_add (& ctx -> scalar_offset , & ctx -> scalar_offset , & base_offset );
226
+ ctx -> proj_blind = secp256k1_fe_one ;
223
227
}
224
228
/* The prior blinding value (if not reset) is chained forward by including it in the hash. */
225
229
secp256k1_scalar_get_b32 (nonce32 , & ctx -> scalar_offset );
@@ -234,7 +238,11 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
234
238
secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , seed32 ? 64 : 32 );
235
239
memset (keydata , 0 , sizeof (keydata ));
236
240
237
- /* TODO: reintroduce projective blinding. */
241
+ /* Compute projective blinding factor (cannot be 0). */
242
+ secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
243
+ secp256k1_fe_set_b32 (& f , nonce32 );
244
+ secp256k1_fe_cmov (& f , & secp256k1_fe_one , secp256k1_fe_is_zero (& f ));
245
+ ctx -> proj_blind = f ;
238
246
239
247
/* For a random blinding value b, set scalar_offset=base_offset-n, final_point_add=bG */
240
248
secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
0 commit comments