@@ -47,7 +47,7 @@ static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 *
47
47
* by using the correct tagged hash function. */
48
48
static const unsigned char bip340_algo16 [16 ] = "BIP0340/nonce\0\0\0" ;
49
49
50
- static int nonce_function_bip340 (unsigned char * nonce32 , const unsigned char * msg32 , const unsigned char * key32 , const unsigned char * xonly_pk32 , const unsigned char * algo16 , void * data ) {
50
+ static int nonce_function_bip340 (unsigned char * nonce32 , const unsigned char * msg , size_t msg_len , const unsigned char * key32 , const unsigned char * xonly_pk32 , const unsigned char * algo16 , void * data ) {
51
51
secp256k1_sha256 sha ;
52
52
unsigned char masked_key [32 ];
53
53
int i ;
@@ -86,7 +86,7 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms
86
86
secp256k1_sha256_write (& sha , key32 , 32 );
87
87
}
88
88
secp256k1_sha256_write (& sha , xonly_pk32 , 32 );
89
- secp256k1_sha256_write (& sha , msg32 , 32 );
89
+ secp256k1_sha256_write (& sha , msg , msg_len );
90
90
secp256k1_sha256_finalize (& sha , nonce32 );
91
91
return 1 ;
92
92
}
@@ -108,28 +108,28 @@ static void secp256k1_schnorrsig_sha256_tagged(secp256k1_sha256 *sha) {
108
108
sha -> bytes = 64 ;
109
109
}
110
110
111
- static void secp256k1_schnorrsig_challenge (secp256k1_scalar * e , const unsigned char * r32 , const unsigned char * msg32 , const unsigned char * pubkey32 )
111
+ static void secp256k1_schnorrsig_challenge (secp256k1_scalar * e , const unsigned char * r32 , const unsigned char * msg , size_t msg_len , const unsigned char * pubkey32 )
112
112
{
113
113
unsigned char buf [32 ];
114
114
secp256k1_sha256 sha ;
115
115
116
- /* tagged hash(r.x, pk.x, msg32 ) */
116
+ /* tagged hash(r.x, pk.x, msg ) */
117
117
secp256k1_schnorrsig_sha256_tagged (& sha );
118
118
secp256k1_sha256_write (& sha , r32 , 32 );
119
119
secp256k1_sha256_write (& sha , pubkey32 , 32 );
120
- secp256k1_sha256_write (& sha , msg32 , 32 );
120
+ secp256k1_sha256_write (& sha , msg , msg_len );
121
121
secp256k1_sha256_finalize (& sha , buf );
122
122
/* Set scalar e to the challenge hash modulo the curve order as per
123
123
* BIP340. */
124
124
secp256k1_scalar_set_b32 (e , buf , NULL );
125
125
}
126
126
127
127
128
- int secp256k1_schnorrsig_sign (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg32 , const secp256k1_keypair * keypair , unsigned char * aux_rand32 ) {
129
- return secp256k1_schnorrsig_sign_custom (ctx , sig64 , msg32 , keypair , NULL , aux_rand32 );
128
+ int secp256k1_schnorrsig_sign (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg , size_t msg_len , const secp256k1_keypair * keypair , unsigned char * aux_rand32 ) {
129
+ return secp256k1_schnorrsig_sign_custom (ctx , sig64 , msg , msg_len , keypair , NULL , aux_rand32 );
130
130
}
131
131
132
- int secp256k1_schnorrsig_sign_custom (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg32 , const secp256k1_keypair * keypair , secp256k1_nonce_function_hardened noncefp , void * ndata ) {
132
+ int secp256k1_schnorrsig_sign_custom (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg , size_t msg_len , const secp256k1_keypair * keypair , secp256k1_nonce_function_hardened noncefp , void * ndata ) {
133
133
secp256k1_scalar sk ;
134
134
secp256k1_scalar e ;
135
135
secp256k1_scalar k ;
@@ -144,7 +144,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
144
144
VERIFY_CHECK (ctx != NULL );
145
145
ARG_CHECK (secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx ));
146
146
ARG_CHECK (sig64 != NULL );
147
- ARG_CHECK (msg32 != NULL );
147
+ ARG_CHECK (msg != NULL );
148
148
ARG_CHECK (keypair != NULL );
149
149
150
150
if (noncefp == NULL ) {
@@ -161,7 +161,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
161
161
162
162
secp256k1_scalar_get_b32 (seckey , & sk );
163
163
secp256k1_fe_get_b32 (pk_buf , & pk .x );
164
- ret &= !!noncefp (buf , msg32 , seckey , pk_buf , bip340_algo16 , ndata );
164
+ ret &= !!noncefp (buf , msg , msg_len , seckey , pk_buf , bip340_algo16 , ndata );
165
165
secp256k1_scalar_set_b32 (& k , buf , NULL );
166
166
ret &= !secp256k1_scalar_is_zero (& k );
167
167
secp256k1_scalar_cmov (& k , & secp256k1_scalar_one , !ret );
@@ -179,7 +179,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
179
179
secp256k1_fe_normalize_var (& r .x );
180
180
secp256k1_fe_get_b32 (& sig64 [0 ], & r .x );
181
181
182
- secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg32 , pk_buf );
182
+ secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg , msg_len , pk_buf );
183
183
secp256k1_scalar_mul (& e , & e , & sk );
184
184
secp256k1_scalar_add (& e , & e , & k );
185
185
secp256k1_scalar_get_b32 (& sig64 [32 ], & e );
@@ -192,7 +192,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
192
192
return ret ;
193
193
}
194
194
195
- int secp256k1_schnorrsig_verify (const secp256k1_context * ctx , const unsigned char * sig64 , const unsigned char * msg32 , const secp256k1_xonly_pubkey * pubkey ) {
195
+ int secp256k1_schnorrsig_verify (const secp256k1_context * ctx , const unsigned char * sig64 , const unsigned char * msg , size_t msg_len , const secp256k1_xonly_pubkey * pubkey ) {
196
196
secp256k1_scalar s ;
197
197
secp256k1_scalar e ;
198
198
secp256k1_gej rj ;
@@ -206,7 +206,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
206
206
VERIFY_CHECK (ctx != NULL );
207
207
ARG_CHECK (secp256k1_ecmult_context_is_built (& ctx -> ecmult_ctx ));
208
208
ARG_CHECK (sig64 != NULL );
209
- ARG_CHECK (msg32 != NULL );
209
+ ARG_CHECK (msg != NULL );
210
210
ARG_CHECK (pubkey != NULL );
211
211
212
212
if (!secp256k1_fe_set_b32 (& rx , & sig64 [0 ])) {
@@ -224,7 +224,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
224
224
225
225
/* Compute e. */
226
226
secp256k1_fe_get_b32 (buf , & pk .x );
227
- secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg32 , buf );
227
+ secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg , msg_len , buf );
228
228
229
229
/* Compute rj = s*G + (-e)*pkj */
230
230
secp256k1_scalar_negate (& e , & e );
0 commit comments