55#include "src/hash.h"
66#include "src/modules/batch/main_impl.h"
77
8+ /* The number of objects allocated on the scratch space by
9+ * secp256k1_batch_add_schnorrsig*/
10+ #define BATCH_TWEAK_CHECK_SCRATCH_OBJS 2
11+
812static 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 ) {
913 secp256k1_sha256 sha256_cpy ;
1014
@@ -61,7 +65,7 @@ static int secp256k1_batch_xonlypub_tweak_randomizer_set(const secp256k1_context
6165 *
6266 * This function's algorithm is based on secp256k1_xonly_pubkey_tweak_add_check.
6367 */
64- int secp256k1_batch_add_xonlypub_tweak_check (const secp256k1_context * ctx , secp256k1_batch * batch , const unsigned char * tweaked_pubkey32 , int tweaked_pk_parity , const secp256k1_xonly_pubkey * internal_pubkey ,const unsigned char * tweak32 ) {
68+ int secp256k1_batch_add_xonlypub_tweak_check (const secp256k1_context * ctx , secp256k1_batch * batch , const unsigned char * tweaked_pubkey32 , int tweaked_pk_parity , const secp256k1_xonly_pubkey * internal_pubkey , const unsigned char * tweak32 , int * batch_len_reset ) {
6569 secp256k1_scalar tweak ;
6670 secp256k1_scalar ai ;
6771 secp256k1_scalar tmp ;
@@ -90,9 +94,12 @@ int secp256k1_batch_add_xonlypub_tweak_check(const secp256k1_context* ctx, secp2
9094 return 0 ;
9195 }
9296
97+ if (batch_len_reset ) {
98+ * batch_len_reset = 0 ;
99+ }
100+
93101 /* run verify if batch object's scratch is full */
94- /* todo: create a function to do this?? */
95- if (batch -> capacity - batch -> len < 2 ) {
102+ if (batch -> capacity - batch -> len < BATCH_TWEAK_CHECK_SCRATCH_OBJS ) {
96103 printf ("\nbatch_add_xonlypub_tweak: Batch object is full...\n" );
97104 printf ("batch_add_xonlypub_tweak: Verifying the batch object...\n" );
98105 if (!secp256k1_batch_verify (ctx , batch )) {
@@ -101,6 +108,9 @@ int secp256k1_batch_add_xonlypub_tweak_check(const secp256k1_context* ctx, secp2
101108 }
102109 printf ("batch_add_xonlypub_tweak: Clearing the batch object for future use...\n" );
103110 secp256k1_batch_scratch_clear (batch );
111+ if (batch_len_reset ) {
112+ * batch_len_reset = 1 ;
113+ }
104114 }
105115
106116 i = batch -> len ;
0 commit comments