Skip to content

Commit 4cc0b1b

Browse files
ecmult_gen: Skip RNG when creating blinding if no seed is available
Running the RNG is pointless if no seed is available because the key will be fixed. The computation just wastes time. Previously, users could avoid this computation at least by asking for a context without signing capabilities. But since 3b0c218 we always build an ecmult_gen context, ignoring the context flags. Moreover, users could never avoid this pointless computation when asking for the creation of a signing context.
1 parent af65d30 commit 4cc0b1b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/ecmult_gen_impl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
8888
unsigned char nonce32[32];
8989
secp256k1_rfc6979_hmac_sha256 rng;
9090
int overflow;
91-
unsigned char keydata[64] = {0};
91+
unsigned char keydata[64];
9292
if (seed32 == NULL) {
9393
/* When seed is NULL, reset the initial point and blinding value. */
9494
secp256k1_gej_set_ge(&ctx->initial, &secp256k1_ge_const_g);
9595
secp256k1_gej_neg(&ctx->initial, &ctx->initial);
9696
secp256k1_scalar_set_int(&ctx->blind, 1);
97+
return;
9798
}
9899
/* The prior blinding value (if not reset) is chained forward by including it in the hash. */
99100
secp256k1_scalar_get_b32(nonce32, &ctx->blind);
@@ -102,10 +103,9 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
102103
* asking the caller for blinding values directly and expecting them to retry on failure.
103104
*/
104105
memcpy(keydata, nonce32, 32);
105-
if (seed32 != NULL) {
106-
memcpy(keydata + 32, seed32, 32);
107-
}
108-
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, seed32 ? 64 : 32);
106+
VERIFY_CHECK(seed32 != NULL);
107+
memcpy(keydata + 32, seed32, 32);
108+
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, 64);
109109
memset(keydata, 0, sizeof(keydata));
110110
/* Accept unobservably small non-uniformity. */
111111
secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);

0 commit comments

Comments
 (0)