5
5
#include "src/hash.h"
6
6
#include "src/modules/batch/main_impl.h"
7
7
8
- static int secp256k1_batch_xonlypub_tweak_check_randomizer ( const secp256k1_context * ctx , secp256k1_batch * batch , secp256k1_scalar * r , const unsigned char * tweaked_pubkey32 , int tweaked_pk_parity , const secp256k1_xonly_pubkey * internal_pubkey , const unsigned char * tweak32 ) {
8
+ static void secp256k1_batch_add_xonlypub_tweak_check_randomizer_gen ( unsigned char * randomizer32 , secp256k1_sha256 * sha256 , const unsigned char * tweaked_pubkey32 , int tweaked_pk_parity , const unsigned char * internal_pk33 , const unsigned char * tweak32 ) {
9
9
secp256k1_sha256 sha256_cpy ;
10
- unsigned char randomizer [32 ];
11
10
unsigned char parity = (unsigned char ) tweaked_pk_parity ;
11
+
12
+ /* add tweaked pubkey check data to sha object */
13
+ secp256k1_sha256_write (sha256 , tweaked_pubkey32 , 32 );
14
+ secp256k1_sha256_write (sha256 , & parity , sizeof (parity ));
15
+ secp256k1_sha256_write (sha256 , tweak32 , 32 );
16
+ secp256k1_sha256_write (sha256 , internal_pk33 , 33 );
17
+
18
+ /* generate randomizer */
19
+ sha256_cpy = * sha256 ;
20
+ secp256k1_sha256_finalize (& sha256_cpy , randomizer32 );
21
+ }
22
+
23
+ static int secp256k1_batch_add_xonlypub_tweak_check_randomizer_set (const secp256k1_context * ctx , secp256k1_batch * batch , secp256k1_scalar * r , const unsigned char * tweaked_pubkey32 , int tweaked_pk_parity , const secp256k1_xonly_pubkey * internal_pubkey ,const unsigned char * tweak32 ) {
24
+ unsigned char randomizer [32 ];
12
25
unsigned char internal_buf [33 ];
13
26
size_t internal_buflen = sizeof (internal_buf );
14
27
int overflow ;
@@ -21,15 +34,7 @@ static int secp256k1_batch_xonlypub_tweak_check_randomizer(const secp256k1_conte
21
34
return 0 ;
22
35
}
23
36
24
- /* add tweaked pubkey check data to sha object */
25
- secp256k1_sha256_write (& batch -> sha256 , tweaked_pubkey32 , 32 );
26
- secp256k1_sha256_write (& batch -> sha256 , & parity , sizeof (parity ));
27
- secp256k1_sha256_write (& batch -> sha256 , tweak32 , 32 );
28
- secp256k1_sha256_write (& batch -> sha256 , internal_buf , internal_buflen );
29
-
30
- /* generate randomizer */
31
- sha256_cpy = batch -> sha256 ;
32
- secp256k1_sha256_finalize (& sha256_cpy , randomizer );
37
+ secp256k1_batch_add_xonlypub_tweak_check_randomizer_gen (randomizer , & batch -> sha256 , tweaked_pubkey32 , tweaked_pk_parity , internal_buf , tweak32 );
33
38
secp256k1_scalar_set_b32 (r , randomizer , & overflow );
34
39
VERIFY_CHECK (overflow == 0 );
35
40
@@ -112,9 +117,7 @@ int secp256k1_batch_add_xonlypub_tweak_check(const secp256k1_context* ctx, secp2
112
117
secp256k1_gej_set_ge (& batch -> points [i + 1 ], & pk );
113
118
114
119
/* Compute ai */
115
- if (!secp256k1_batch_xonlypub_tweak_check_randomizer (ctx , batch , & ai , tweaked_pubkey32 , tweaked_pk_parity , internal_pubkey , tweak32 )) {
116
- return 0 ;
117
- }
120
+ secp256k1_batch_add_xonlypub_tweak_check_randomizer_set (ctx , batch , & ai , tweaked_pubkey32 , tweaked_pk_parity , internal_pubkey , tweak32 );
118
121
119
122
/* append scalars -ai, ai respectively to scratch space */
120
123
secp256k1_scalar_negate (& tmp , & ai );
0 commit comments