@@ -310,14 +310,45 @@ static void secp256k1_nonce_function_musig_helper(secp256k1_sha256 *sha, unsigne
310
310
}
311
311
}
312
312
313
+ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying
314
+ * SHA256 to SHA256("MuSig/aux")||SHA256("MuSig/aux"). */
315
+ static void secp256k1_nonce_function_musig_sha256_tagged_aux (secp256k1_sha256 * sha ) {
316
+ secp256k1_sha256_initialize (sha );
317
+ sha -> s [0 ] = 0xa19e884bul ;
318
+ sha -> s [1 ] = 0xf463fe7eul ;
319
+ sha -> s [2 ] = 0x2f18f9a2ul ;
320
+ sha -> s [3 ] = 0xbeb0f9fful ;
321
+ sha -> s [4 ] = 0x0f37e8b0ul ;
322
+ sha -> s [5 ] = 0x06ebd26ful ;
323
+ sha -> s [6 ] = 0xe3b243d2ul ;
324
+ sha -> s [7 ] = 0x522fb150ul ;
325
+ sha -> bytes = 64 ;
326
+
327
+ }
328
+
329
+ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying
330
+ * SHA256 to SHA256("MuSig/nonce")||SHA256("MuSig/nonce"). */
331
+ static void secp256k1_nonce_function_musig_sha256_tagged (secp256k1_sha256 * sha ) {
332
+ secp256k1_sha256_initialize (sha );
333
+ sha -> s [0 ] = 0x07101b64ul ;
334
+ sha -> s [1 ] = 0x18003414ul ;
335
+ sha -> s [2 ] = 0x0391bc43ul ;
336
+ sha -> s [3 ] = 0x0e6258eeul ;
337
+ sha -> s [4 ] = 0x29d26b72ul ;
338
+ sha -> s [5 ] = 0x8343937eul ;
339
+ sha -> s [6 ] = 0xb7a0a4fbul ;
340
+ sha -> s [7 ] = 0xff568a30ul ;
341
+ sha -> bytes = 64 ;
342
+ }
343
+
313
344
static void secp256k1_nonce_function_musig (secp256k1_scalar * k , const unsigned char * session_id , const unsigned char * msg32 , const unsigned char * seckey32 , const unsigned char * pk33 , const unsigned char * agg_pk32 , const unsigned char * extra_input32 ) {
314
345
secp256k1_sha256 sha ;
315
346
unsigned char rand [32 ];
316
347
unsigned char i ;
317
348
unsigned char msg_present ;
318
349
319
350
if (seckey32 != NULL ) {
320
- secp256k1_sha256_initialize_tagged (& sha , ( unsigned char * ) "MuSig/aux" , sizeof ( "MuSig/aux" ) - 1 );
351
+ secp256k1_nonce_function_musig_sha256_tagged_aux (& sha );
321
352
secp256k1_sha256_write (& sha , session_id , 32 );
322
353
secp256k1_sha256_finalize (& sha , rand );
323
354
for (i = 0 ; i < 32 ; i ++ ) {
@@ -328,7 +359,7 @@ static void secp256k1_nonce_function_musig(secp256k1_scalar *k, const unsigned c
328
359
}
329
360
330
361
/* Subtract one from `sizeof` to avoid hashing the implicit null byte */
331
- secp256k1_sha256_initialize_tagged (& sha , ( unsigned char * ) "MuSig/nonce" , sizeof ( "MuSig/nonce" ) - 1 );
362
+ secp256k1_nonce_function_musig_sha256_tagged (& sha );
332
363
secp256k1_sha256_write (& sha , rand , sizeof (rand ));
333
364
secp256k1_nonce_function_musig_helper (& sha , 1 , pk33 , 33 );
334
365
secp256k1_nonce_function_musig_helper (& sha , 1 , agg_pk32 , 32 );
@@ -465,13 +496,28 @@ int secp256k1_musig_nonce_agg(const secp256k1_context* ctx, secp256k1_musig_aggn
465
496
return 1 ;
466
497
}
467
498
499
+ /* Initializes SHA256 with fixed midstate. This midstate was computed by applying
500
+ * SHA256 to SHA256("MuSig/noncecoef")||SHA256("MuSig/noncecoef"). */
501
+ static void secp256k1_musig_compute_noncehash_sha256_tagged (secp256k1_sha256 * sha ) {
502
+ secp256k1_sha256_initialize (sha );
503
+ sha -> s [0 ] = 0x2c7d5a45ul ;
504
+ sha -> s [1 ] = 0x06bf7e53ul ;
505
+ sha -> s [2 ] = 0x89be68a6ul ;
506
+ sha -> s [3 ] = 0x971254c0ul ;
507
+ sha -> s [4 ] = 0x60ac12d2ul ;
508
+ sha -> s [5 ] = 0x72846dcdul ;
509
+ sha -> s [6 ] = 0x6c81212ful ;
510
+ sha -> s [7 ] = 0xde7a2500ul ;
511
+ sha -> bytes = 64 ;
512
+ }
513
+
468
514
/* tagged_hash(aggnonce[0], aggnonce[1], agg_pk, msg) */
469
515
static int secp256k1_musig_compute_noncehash (unsigned char * noncehash , secp256k1_ge * aggnonce , const unsigned char * agg_pk32 , const unsigned char * msg ) {
470
516
unsigned char buf [33 ];
471
517
secp256k1_sha256 sha ;
472
518
int i ;
473
519
474
- secp256k1_sha256_initialize_tagged (& sha , ( unsigned char * ) "MuSig/noncecoef" , sizeof ( "MuSig/noncecoef" ) - 1 );
520
+ secp256k1_musig_compute_noncehash_sha256_tagged (& sha );
475
521
for (i = 0 ; i < 2 ; i ++ ) {
476
522
secp256k1_musig_ge_serialize_ext (buf , & aggnonce [i ]);
477
523
secp256k1_sha256_write (& sha , buf , sizeof (buf ));
0 commit comments