Skip to content

Commit 8193edd

Browse files
committed
f batch verification n_sigs limit and ecmult_callback scalar copy
1 parent 40f8f7a commit 8193edd

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

include/secp256k1_schnorrsig.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(
101101
* msg32: array of messages, or NULL if there are no signatures
102102
* pk: array of public keys, or NULL if there are no signatures
103103
* n_sigs: number of signatures in above arrays. Must be smaller than
104-
* 2^31 and smaller than 2^(sizeof(size_t)*8-1) i.e. half the
105-
* maximum size_t value. Must be 0 if above arrays are NULL.
104+
* 2^31 and smaller than half the maximum size_t value. Must be 0
105+
* if above arrays are NULL.
106106
*/
107107
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify_batch(
108108
const secp256k1_context* ctx,

src/modules/schnorrsig/main_impl.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ static int secp256k1_schnorrsig_verify_batch_ecmult_callback(secp256k1_scalar *s
191191
/* R */
192192
if (idx % 2 == 0) {
193193
secp256k1_fe rx;
194-
secp256k1_scalar_clear(sc);
195-
secp256k1_scalar_add(sc, sc, &ecmult_context->randomizer_cache[(idx / 2) % 2]);
194+
*sc = ecmult_context->randomizer_cache[(idx / 2) % 2];
196195
if (!secp256k1_fe_set_b32(&rx, &ecmult_context->sig[idx / 2]->data[0])) {
197196
return 0;
198197
}
@@ -308,9 +307,9 @@ int secp256k1_schnorrsig_verify_batch(const secp256k1_context *ctx, secp256k1_sc
308307
ARG_CHECK(scratch != NULL);
309308
/* Check that n_sigs is less than half of the maximum size_t value. This is necessary because
310309
* the number of points given to ecmult_multi is 2*n_sigs. */
311-
ARG_CHECK(n_sigs < (size_t)1 << (sizeof(size_t)*8-1));
312-
/* Check that n_sigs is less 2^31 to ensure the same behavior of this function on 32-bit and
313-
* 64-bit platforms. */
310+
ARG_CHECK(n_sigs <= (size_t)-1 / 2);
311+
/* Check that n_sigs is less than 2^31 to ensure the same behavior of this function on 32-bit
312+
* and 64-bit platforms. */
314313
ARG_CHECK(n_sigs < (size_t)(1 << 31));
315314

316315
secp256k1_sha256_initialize(&sha);

0 commit comments

Comments
 (0)