@@ -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_algo [13 ] = "BIP0340/nonce" ;
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 * 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 ) {
51
51
secp256k1_sha256 sha ;
52
52
unsigned char masked_key [32 ];
53
53
int i ;
@@ -82,7 +82,7 @@ static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *ms
82
82
secp256k1_sha256_write (& sha , key32 , 32 );
83
83
}
84
84
secp256k1_sha256_write (& sha , xonly_pk32 , 32 );
85
- secp256k1_sha256_write (& sha , msg32 , 32 );
85
+ secp256k1_sha256_write (& sha , msg , msglen );
86
86
secp256k1_sha256_finalize (& sha , nonce32 );
87
87
return 1 ;
88
88
}
@@ -104,28 +104,27 @@ static void secp256k1_schnorrsig_sha256_tagged(secp256k1_sha256 *sha) {
104
104
sha -> bytes = 64 ;
105
105
}
106
106
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 )
108
108
{
109
109
unsigned char buf [32 ];
110
110
secp256k1_sha256 sha ;
111
111
112
- /* tagged hash(r.x, pk.x, msg32 ) */
112
+ /* tagged hash(r.x, pk.x, msg ) */
113
113
secp256k1_schnorrsig_sha256_tagged (& sha );
114
114
secp256k1_sha256_write (& sha , r32 , 32 );
115
115
secp256k1_sha256_write (& sha , pubkey32 , 32 );
116
- secp256k1_sha256_write (& sha , msg32 , 32 );
116
+ secp256k1_sha256_write (& sha , msg , msglen );
117
117
secp256k1_sha256_finalize (& sha , buf );
118
118
/* Set scalar e to the challenge hash modulo the curve order as per
119
119
* BIP340. */
120
120
secp256k1_scalar_set_b32 (e , buf , NULL );
121
121
}
122
122
123
-
124
123
int 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 );
126
125
}
127
126
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 ) {
129
128
secp256k1_scalar sk ;
130
129
secp256k1_scalar e ;
131
130
secp256k1_scalar k ;
@@ -140,7 +139,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
140
139
VERIFY_CHECK (ctx != NULL );
141
140
ARG_CHECK (secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx ));
142
141
ARG_CHECK (sig64 != NULL );
143
- ARG_CHECK (msg32 != NULL );
142
+ ARG_CHECK (msg != NULL || msglen == 0 );
144
143
ARG_CHECK (keypair != NULL );
145
144
146
145
if (noncefp == NULL ) {
@@ -157,7 +156,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
157
156
158
157
secp256k1_scalar_get_b32 (seckey , & sk );
159
158
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 );
161
160
secp256k1_scalar_set_b32 (& k , buf , NULL );
162
161
ret &= !secp256k1_scalar_is_zero (& k );
163
162
secp256k1_scalar_cmov (& k , & secp256k1_scalar_one , !ret );
@@ -175,7 +174,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
175
174
secp256k1_fe_normalize_var (& r .x );
176
175
secp256k1_fe_get_b32 (& sig64 [0 ], & r .x );
177
176
178
- secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg32 , pk_buf );
177
+ secp256k1_schnorrsig_challenge (& e , & sig64 [0 ], msg , msglen , pk_buf );
179
178
secp256k1_scalar_mul (& e , & e , & sk );
180
179
secp256k1_scalar_add (& e , & e , & k );
181
180
secp256k1_scalar_get_b32 (& sig64 [32 ], & e );
@@ -188,7 +187,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
188
187
return ret ;
189
188
}
190
189
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 ) {
192
191
secp256k1_scalar s ;
193
192
secp256k1_scalar e ;
194
193
secp256k1_gej rj ;
@@ -202,7 +201,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
202
201
VERIFY_CHECK (ctx != NULL );
203
202
ARG_CHECK (secp256k1_ecmult_context_is_built (& ctx -> ecmult_ctx ));
204
203
ARG_CHECK (sig64 != NULL );
205
- ARG_CHECK (msg32 != NULL );
204
+ ARG_CHECK (msg != NULL || msglen == 0 );
206
205
ARG_CHECK (pubkey != NULL );
207
206
208
207
if (!secp256k1_fe_set_b32 (& rx , & sig64 [0 ])) {
@@ -220,7 +219,7 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
220
219
221
220
/* Compute e. */
222
221
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 );
224
223
225
224
/* Compute rj = s*G + (-e)*pkj */
226
225
secp256k1_scalar_negate (& e , & e );
0 commit comments