Skip to content

Commit 19951ca

Browse files
ecmult_gen: Improve comments about projective blinding
Whenever I read this code, I first think that rescaling ctx->initial is a dead store because we overwrite it later with gb. But that's wrong. The rescaling blinds the computation of gb and affects its result.
1 parent ad59761 commit 19951ca

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/ecmult_gen_impl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
111111
overflow = !secp256k1_fe_set_b32(&s, nonce32);
112112
overflow |= secp256k1_fe_is_zero(&s);
113113
secp256k1_fe_cmov(&s, &secp256k1_fe_one, overflow);
114-
/* Randomize the projection to defend against multiplier sidechannels. */
114+
/* Randomize the projection to defend against multiplier sidechannels.
115+
Do this before our own call to secp256k1_ecmult_gen below. */
115116
secp256k1_gej_rescale(&ctx->initial, &s);
116117
secp256k1_fe_clear(&s);
117118
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
@@ -120,6 +121,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
120121
secp256k1_scalar_cmov(&b, &secp256k1_scalar_one, secp256k1_scalar_is_zero(&b));
121122
secp256k1_rfc6979_hmac_sha256_finalize(&rng);
122123
memset(nonce32, 0, 32);
124+
/* The random projection in ctx->initial ensures that gb will have a random projection. */
123125
secp256k1_ecmult_gen(ctx, &gb, &b);
124126
secp256k1_scalar_negate(&b, &b);
125127
ctx->blind = b;

0 commit comments

Comments
 (0)