diff --git a/src/modules/batch/main_impl.h b/src/modules/batch/main_impl.h index d24ddc9d46..caac0eba5c 100644 --- a/src/modules/batch/main_impl.h +++ b/src/modules/batch/main_impl.h @@ -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: diff --git a/src/modules/extrakeys/batch_add_impl.h b/src/modules/extrakeys/batch_add_impl.h index 66eb7e5b08..ad894e8366 100644 --- a/src/modules/extrakeys/batch_add_impl.h +++ b/src/modules/extrakeys/batch_add_impl.h @@ -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 */ diff --git a/src/modules/schnorrsig/batch_add_impl.h b/src/modules/schnorrsig/batch_add_impl.h index ae1519f01d..5dc9e5b8b7 100644 --- a/src/modules/schnorrsig/batch_add_impl.h +++ b/src/modules/schnorrsig/batch_add_impl.h @@ -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);