Skip to content

Commit e8ba116

Browse files
committed
batch_add: use enum instead of a string for batch_add_type
1 parent e8c650c commit e8ba116

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/modules/batch/main_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
#include "src/hash.h"
1212
#include "src/scratch.h"
1313

14+
/* Assume two batch objects batch1 and batch2. If we call
15+
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
16+
* In this case same randomizer will be created if the bytes added to
17+
* batch1->sha and batch2->sha are same. Including this tag during
18+
* randomizer generation prevents such mishaps. */
19+
enum batch_add_type {schnorrsig = 1, tweak_check = 2};
20+
1421
/** Opaque data structure that holds information required for the batch verification.
1522
*
1623
* Members:

src/modules/extrakeys/batch_add_impl.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
static void secp256k1_batch_xonlypub_tweak_randomizer_gen(unsigned char *randomizer32, secp256k1_sha256 *sha256, const unsigned char *tweaked_pubkey32, const unsigned char *tweaked_pk_parity, const unsigned char *internal_pk33, const unsigned char *tweak32) {
1313
secp256k1_sha256 sha256_cpy;
14-
/* Assume two batch objects batch1 and batch2. If we call
15-
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
16-
* In this case same randomizer will be created if the bytes added to
17-
* batch1->sha and batch2->sha are same. This tag prevents such cases. */
18-
unsigned char batch_add_type[1] = "2";
14+
unsigned char batch_add_type = (unsigned char) tweak_check;
1915

20-
secp256k1_sha256_write(sha256, batch_add_type, sizeof(batch_add_type));
16+
secp256k1_sha256_write(sha256, &batch_add_type, sizeof(batch_add_type));
2117
/* add tweaked pubkey check data to sha object */
2218
secp256k1_sha256_write(sha256, tweaked_pubkey32, 32);
2319
secp256k1_sha256_write(sha256, tweaked_pk_parity, 1);

src/modules/schnorrsig/batch_add_impl.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111

1212
static void secp256k1_batch_schnorrsig_randomizer_gen(unsigned char *randomizer32, secp256k1_sha256 *sha256, const unsigned char *sig64, const unsigned char *msg, size_t msglen, const unsigned char *compressed_pk33) {
1313
secp256k1_sha256 sha256_cpy;
14-
unsigned char batch_add_type[1] = "1";
15-
/* Assume two batch objects batch1 and batch2. If we call
16-
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
17-
* In this case same randomizer will be created if the bytes added to
18-
* batch1->sha and batch2->sha are same. This tag prevents such cases. */
19-
secp256k1_sha256_write(sha256, batch_add_type, sizeof(batch_add_type));
14+
unsigned char batch_add_type = (unsigned char) schnorrsig;
15+
16+
secp256k1_sha256_write(sha256, &batch_add_type, sizeof(batch_add_type));
2017
/* add schnorrsig data to sha256 object */
2118
secp256k1_sha256_write(sha256, sig64, 64);
2219
secp256k1_sha256_write(sha256, msg, msglen);

0 commit comments

Comments
 (0)