Skip to content

Commit d373a72

Browse files
Merge #1316: Do not invoke fe_is_zero on failed set_b32_limit
6433175 Do not invoke fe_is_zero on failed set_b32_limit (Pieter Wuille) Pull request description: Noticed in the CI output of #1313 (https://cirrus-ci.com/task/5117786435878912) The code violates the field element contract that states that a field element that comes out of a failed `secp256k1_fe_set_b32_limit` call cannot be used before overwriting it. This is not an issue in practice, as such failure can only occur with negligible probability, but the experimental compiler in that CI setting is technically correct in detecting this possibility. Fix it by setting it to 1 based on a `secp256k1_fe_normalizes_to_zero` test rather than a `secp256k1_fe_is_zero` one (which does not require normalization). ACKs for top commit: stratospher: ACK 6433175 real-or-random: utACK 6433175 Tree-SHA512: 49da4535181c4607c1f4d23d1fd7cd65e7751c7cfa68643f1da77f3ec7961754fc8553bb415137fd61d86c805fe69f5adf97c05b9dc4d3bf357ae7c6409cc51a
2 parents 5f7903c + 6433175 commit d373a72

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/ecmult_gen_impl.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
8787
secp256k1_fe s;
8888
unsigned char nonce32[32];
8989
secp256k1_rfc6979_hmac_sha256 rng;
90-
int overflow;
9190
unsigned char keydata[64];
9291
if (seed32 == NULL) {
9392
/* When seed is NULL, reset the initial point and blinding value. */
@@ -106,11 +105,9 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
106105
memcpy(keydata + 32, seed32, 32);
107106
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, 64);
108107
memset(keydata, 0, sizeof(keydata));
109-
/* Accept unobservably small non-uniformity. */
110108
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
111-
overflow = !secp256k1_fe_set_b32_limit(&s, nonce32);
112-
overflow |= secp256k1_fe_is_zero(&s);
113-
secp256k1_fe_cmov(&s, &secp256k1_fe_one, overflow);
109+
secp256k1_fe_set_b32_mod(&s, nonce32);
110+
secp256k1_fe_cmov(&s, &secp256k1_fe_one, secp256k1_fe_normalizes_to_zero(&s));
114111
/* Randomize the projection to defend against multiplier sidechannels.
115112
Do this before our own call to secp256k1_ecmult_gen below. */
116113
secp256k1_gej_rescale(&ctx->initial, &s);

0 commit comments

Comments
 (0)