@@ -47,7 +47,7 @@ static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 *
4747 * by using the correct tagged hash function. */
4848static const unsigned char bip340_algo [13 ] = "BIP0340/nonce" ;
4949
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 * algo , size_t algolen , void * data ) {
50+ static int nonce_function_bip340 (unsigned char * nonce32 , const unsigned char * msg , size_t msglen , const unsigned char * key32 , const unsigned char * xonly_pk32 , const unsigned char * algo , size_t algolen , void * data ) {
5151 secp256k1_sha256 sha ;
5252 unsigned char masked_key [32 ];
5353 int i ;
@@ -82,7 +82,7 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms
8282 secp256k1_sha256_write (& sha , key32 , 32 );
8383 }
8484 secp256k1_sha256_write (& sha , xonly_pk32 , 32 );
85- secp256k1_sha256_write (& sha , msg32 , 32 );
85+ secp256k1_sha256_write (& sha , msg , msglen );
8686 secp256k1_sha256_finalize (& sha , nonce32 );
8787 return 1 ;
8888}
@@ -104,28 +104,27 @@ static void secp256k1_schnorrsig_sha256_tagged(secp256k1_sha256 *sha) {
104104 sha -> bytes = 64 ;
105105}
106106
107- static void secp256k1_schnorrsig_challenge (secp256k1_scalar * e , const unsigned char * r32 , const unsigned char * msg32 , const unsigned char * pubkey32 )
107+ static void secp256k1_schnorrsig_challenge (secp256k1_scalar * e , const unsigned char * r32 , const unsigned char * msg , size_t msglen , const unsigned char * pubkey32 )
108108{
109109 unsigned char buf [32 ];
110110 secp256k1_sha256 sha ;
111111
112- /* tagged hash(r.x, pk.x, msg32 ) */
112+ /* tagged hash(r.x, pk.x, msg ) */
113113 secp256k1_schnorrsig_sha256_tagged (& sha );
114114 secp256k1_sha256_write (& sha , r32 , 32 );
115115 secp256k1_sha256_write (& sha , pubkey32 , 32 );
116- secp256k1_sha256_write (& sha , msg32 , 32 );
116+ secp256k1_sha256_write (& sha , msg , msglen );
117117 secp256k1_sha256_finalize (& sha , buf );
118118 /* Set scalar e to the challenge hash modulo the curve order as per
119119 * BIP340. */
120120 secp256k1_scalar_set_b32 (e , buf , NULL );
121121}
122122
123-
124123int secp256k1_schnorrsig_sign (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg32 , const secp256k1_keypair * keypair , unsigned char * aux_rand32 ) {
125- return secp256k1_schnorrsig_sign_custom (ctx , sig64 , msg32 , keypair , NULL , aux_rand32 );
124+ return secp256k1_schnorrsig_sign_custom (ctx , sig64 , msg32 , 32 , keypair , NULL , aux_rand32 );
126125}
127126
128- 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 ) {
127+ int secp256k1_schnorrsig_sign_custom (const secp256k1_context * ctx , unsigned char * sig64 , const unsigned char * msg , size_t msglen , const secp256k1_keypair * keypair , secp256k1_nonce_function_hardened noncefp , void * ndata ) {
129128 secp256k1_scalar sk ;
130129 secp256k1_scalar e ;
131130 secp256k1_scalar k ;
@@ -140,7 +139,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
140139 VERIFY_CHECK (ctx != NULL );
141140 ARG_CHECK (secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx ));
142141 ARG_CHECK (sig64 != NULL );
143- ARG_CHECK (msg32 != NULL );
142+ ARG_CHECK (msg != NULL || msglen == 0 );
144143 ARG_CHECK (keypair != NULL );
145144
146145 if (noncefp == NULL ) {
@@ -157,7 +156,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
157156
158157 secp256k1_scalar_get_b32 (seckey , & sk );
159158 secp256k1_fe_get_b32 (pk_buf , & pk .x );
160- ret &= !!noncefp (buf , msg32 , seckey , pk_buf , bip340_algo , sizeof (bip340_algo ), ndata );
159+ ret &= !!noncefp (buf , msg , msglen , seckey , pk_buf , bip340_algo , sizeof (bip340_algo ), ndata );
161160 secp256k1_scalar_set_b32 (& k , buf , NULL );
162161 ret &= !secp256k1_scalar_is_zero (& k );
163162 secp256k1_scalar_cmov (& k , & secp256k1_scalar_one , !ret );
@@ -175,7 +174,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
175174 secp256k1_fe_normalize_var (& r .x );
176175 secp256k1_fe_get_b32 (& sig64 [0 ], & r .x );
177176
178- secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg32 , pk_buf );
177+ secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg , msglen , pk_buf );
179178 secp256k1_scalar_mul (& e , & e , & sk );
180179 secp256k1_scalar_add (& e , & e , & k );
181180 secp256k1_scalar_get_b32 (& sig64 [32 ], & e );
@@ -188,7 +187,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
188187 return ret ;
189188}
190189
191- int secp256k1_schnorrsig_verify (const secp256k1_context * ctx , const unsigned char * sig64 , const unsigned char * msg32 , const secp256k1_xonly_pubkey * pubkey ) {
190+ int secp256k1_schnorrsig_verify (const secp256k1_context * ctx , const unsigned char * sig64 , const unsigned char * msg , size_t msglen , const secp256k1_xonly_pubkey * pubkey ) {
192191 secp256k1_scalar s ;
193192 secp256k1_scalar e ;
194193 secp256k1_gej rj ;
@@ -202,7 +201,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
202201 VERIFY_CHECK (ctx != NULL );
203202 ARG_CHECK (secp256k1_ecmult_context_is_built (& ctx -> ecmult_ctx ));
204203 ARG_CHECK (sig64 != NULL );
205- ARG_CHECK (msg32 != NULL );
204+ ARG_CHECK (msg != NULL || msglen == 0 );
206205 ARG_CHECK (pubkey != NULL );
207206
208207 if (!secp256k1_fe_set_b32 (& rx , & sig64 [0 ])) {
@@ -220,7 +219,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
220219
221220 /* Compute e. */
222221 secp256k1_fe_get_b32 (buf , & pk .x );
223- secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg32 , buf );
222+ secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg , msglen , buf );
224223
225224 /* Compute rj = s*G + (-e)*pkj */
226225 secp256k1_scalar_negate (& e , & e );
0 commit comments