Skip to content

Commit

Permalink
batch_add: use enum instead of a string for batch_add_type
Browse files Browse the repository at this point in the history
  • Loading branch information
siv2r committed Jul 12, 2022
1 parent e8c650c commit 41ad09e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/modules/batch/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
#include "src/hash.h"
#include "src/scratch.h"

/* Assume two batch objects batch1 and batch2. If we call
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
* In this case same randomizer will be created if the bytes added to
* batch1->sha and batch2->sha are same. Including this tag during
* randomizer generation prevents such mishaps. */
enum batch_add_type {schnorrsig = 1, tweak_check = 2};

/** Opaque data structure that holds information required for the batch verification.
*
* Members:
Expand Down
6 changes: 1 addition & 5 deletions src/modules/extrakeys/batch_add_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

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) {
secp256k1_sha256 sha256_cpy;
/* Assume two batch objects batch1 and batch2. If we call
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
* In this case same randomizer will be created if the bytes added to
* batch1->sha and batch2->sha are same. This tag prevents such cases. */
unsigned char batch_add_type[1] = "2";
unsigned char batch_add_type[1] = tweak_check;

secp256k1_sha256_write(sha256, batch_add_type, sizeof(batch_add_type));
/* add tweaked pubkey check data to sha object */
Expand Down
7 changes: 2 additions & 5 deletions src/modules/schnorrsig/batch_add_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

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) {
secp256k1_sha256 sha256_cpy;
unsigned char batch_add_type[1] = "1";
/* Assume two batch objects batch1 and batch2. If we call
* batch_add_tweaks on batch1 and batch_add_schnorrsig on batch2.
* In this case same randomizer will be created if the bytes added to
* batch1->sha and batch2->sha are same. This tag prevents such cases. */
unsigned char batch_add_type[1] = schnorrsig;

secp256k1_sha256_write(sha256, batch_add_type, sizeof(batch_add_type));
/* add schnorrsig data to sha256 object */
secp256k1_sha256_write(sha256, sig64, 64);
Expand Down

0 comments on commit 41ad09e

Please sign in to comment.