@@ -1143,7 +1143,7 @@ void musig_test_vectors_noncegen(void) {
1143
1143
}
1144
1144
}
1145
1145
1146
- void musig_test_vectors_sign_helper (secp256k1_musig_keyagg_cache * keyagg_cache , int * fin_nonce_parity , unsigned char * sig , const unsigned char * secnonce_bytes , const unsigned char * agg_pubnonce_ser , const unsigned char * sk , const unsigned char * msg , const unsigned char * tweak , const secp256k1_pubkey * adaptor , const unsigned char * * pk_ser , int signer_pos ) {
1146
+ void musig_test_vectors_sign_helper (secp256k1_musig_keyagg_cache * keyagg_cache , int * fin_nonce_parity , unsigned char * sig , const unsigned char * secnonce_bytes , const unsigned char * agg_pubnonce_ser , const unsigned char * sk , const unsigned char * msg , const unsigned char * tweak , int xonly_tweak , const secp256k1_pubkey * adaptor , const unsigned char * * pk_ser , int signer_pos ) {
1147
1147
secp256k1_keypair signer_keypair ;
1148
1148
secp256k1_musig_secnonce secnonce ;
1149
1149
secp256k1_xonly_pubkey pk [3 ];
@@ -1164,7 +1164,11 @@ void musig_test_vectors_sign_helper(secp256k1_musig_keyagg_cache *keyagg_cache,
1164
1164
}
1165
1165
CHECK (secp256k1_musig_pubkey_agg (ctx , NULL , & agg_pk , keyagg_cache , pk_ptr , 3 ) == 1 );
1166
1166
if (tweak != NULL ) {
1167
- CHECK (secp256k1_musig_pubkey_xonly_tweak_add (ctx , NULL , keyagg_cache , tweak ) == 1 );
1167
+ if (xonly_tweak ) {
1168
+ CHECK (secp256k1_musig_pubkey_xonly_tweak_add (ctx , NULL , keyagg_cache , tweak ) == 1 );
1169
+ } else {
1170
+ CHECK (secp256k1_musig_pubkey_ec_tweak_add (ctx , NULL , keyagg_cache , tweak ) == 1 );
1171
+ }
1168
1172
}
1169
1173
memcpy (& secnonce .data [0 ], secp256k1_musig_secnonce_magic , 4 );
1170
1174
memcpy (& secnonce .data [4 ], secnonce_bytes , sizeof (secnonce .data ) - 4 );
@@ -1243,7 +1247,7 @@ void musig_test_vectors_sign(void) {
1243
1247
0x20 , 0xA1 , 0x81 , 0x85 , 0x5F , 0xD8 , 0xBD , 0xB7 ,
1244
1248
0xF1 , 0x27 , 0xBB , 0x12 , 0x40 , 0x3B , 0x4D , 0x3B ,
1245
1249
};
1246
- musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , NULL , pk , 0 );
1250
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , 0 , NULL , pk , 0 );
1247
1251
/* TODO: remove when test vectors are not expected to change anymore */
1248
1252
/* int k, l; */
1249
1253
/* printf("const unsigned char sig_expected[32] = {\n"); */
@@ -1272,7 +1276,7 @@ void musig_test_vectors_sign(void) {
1272
1276
0x81 , 0x38 , 0xDA , 0xEC , 0x5C , 0xB2 , 0x0A , 0x35 ,
1273
1277
0x7C , 0xEC , 0xA7 , 0xC8 , 0x42 , 0x42 , 0x95 , 0xEA ,
1274
1278
};
1275
- musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , NULL , pk , 1 );
1279
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , 0 , NULL , pk , 1 );
1276
1280
/* Check that the description of the test vector is correct */
1277
1281
CHECK (musig_test_pk_parity (& keyagg_cache ) == 0 );
1278
1282
CHECK (musig_test_is_second_pk (& keyagg_cache , sk ));
@@ -1288,15 +1292,15 @@ void musig_test_vectors_sign(void) {
1288
1292
0xE6 , 0xA7 , 0xF7 , 0xFB , 0xE1 , 0x5C , 0xDC , 0xAF ,
1289
1293
0xA4 , 0xA3 , 0xD1 , 0xBC , 0xAA , 0xBC , 0x75 , 0x17 ,
1290
1294
};
1291
- musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , NULL , pk , 2 );
1295
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , 0 , NULL , pk , 2 );
1292
1296
/* Check that the description of the test vector is correct */
1293
1297
CHECK (musig_test_pk_parity (& keyagg_cache ) == 1 );
1294
1298
CHECK (fin_nonce_parity == 0 );
1295
1299
CHECK (!musig_test_is_second_pk (& keyagg_cache , sk ));
1296
1300
CHECK (memcmp (sig , sig_expected , 32 ) == 0 );
1297
1301
}
1298
1302
{
1299
- /* This is a test that includes a public key tweak. */
1303
+ /* This is a test that includes an xonly public key tweak. */
1300
1304
const unsigned char sig_expected [32 ] = {
1301
1305
0x5E , 0x24 , 0xC7 , 0x49 , 0x6B , 0x56 , 0x5D , 0xEB ,
1302
1306
0xC3 , 0xB9 , 0x63 , 0x9E , 0x6F , 0x13 , 0x04 , 0xA2 ,
@@ -1309,13 +1313,34 @@ void musig_test_vectors_sign(void) {
1309
1313
0x96 , 0x12 , 0xA6 , 0x82 , 0xA2 , 0x5E , 0xBE , 0x79 ,
1310
1314
0x80 , 0x2B , 0x26 , 0x3C , 0xDF , 0xCD , 0x83 , 0xBB ,
1311
1315
};
1312
- musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , tweak , NULL , pk , 2 );
1316
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , tweak , 1 , NULL , pk , 2 );
1313
1317
1314
1318
CHECK (musig_test_pk_parity (& keyagg_cache ) == 1 );
1315
1319
CHECK (!musig_test_is_second_pk (& keyagg_cache , sk ));
1316
1320
CHECK (fin_nonce_parity == 1 );
1317
1321
CHECK (memcmp (sig , sig_expected , 32 ) == 0 );
1318
1322
}
1323
+ {
1324
+ /* This is a test that includes an ordinary public key tweak. */
1325
+ const unsigned char sig_expected [32 ] = {
1326
+ 0x78 , 0x40 , 0x8D , 0xDC , 0xAB , 0x48 , 0x13 , 0xD1 ,
1327
+ 0x39 , 0x4C , 0x97 , 0xD4 , 0x93 , 0xEF , 0x10 , 0x84 ,
1328
+ 0x19 , 0x5C , 0x1D , 0x4B , 0x52 , 0xE6 , 0x3E , 0xCD ,
1329
+ 0x7B , 0xC5 , 0x99 , 0x16 , 0x44 , 0xE4 , 0x4D , 0xDD ,
1330
+ };
1331
+ const unsigned char tweak [32 ] = {
1332
+ 0xE8 , 0xF7 , 0x91 , 0xFF , 0x92 , 0x25 , 0xA2 , 0xAF ,
1333
+ 0x01 , 0x02 , 0xAF , 0xFF , 0x4A , 0x9A , 0x72 , 0x3D ,
1334
+ 0x96 , 0x12 , 0xA6 , 0x82 , 0xA2 , 0x5E , 0xBE , 0x79 ,
1335
+ 0x80 , 0x2B , 0x26 , 0x3C , 0xDF , 0xCD , 0x83 , 0xBB ,
1336
+ };
1337
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , tweak , 0 , NULL , pk , 2 );
1338
+
1339
+ CHECK (musig_test_pk_parity (& keyagg_cache ) == 1 );
1340
+ CHECK (!musig_test_is_second_pk (& keyagg_cache , sk ));
1341
+ CHECK (fin_nonce_parity == 0 );
1342
+ CHECK (memcmp (sig , sig_expected , 32 ) == 0 );
1343
+ }
1319
1344
{
1320
1345
/* This is a test that includes an adaptor. */
1321
1346
const unsigned char sig_expected [32 ] = {
@@ -1332,7 +1357,7 @@ void musig_test_vectors_sign(void) {
1332
1357
};
1333
1358
secp256k1_pubkey pub_adaptor ;
1334
1359
CHECK (secp256k1_ec_pubkey_create (ctx , & pub_adaptor , sec_adaptor ) == 1 );
1335
- musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , & pub_adaptor , pk , 2 );
1360
+ musig_test_vectors_sign_helper (& keyagg_cache , & fin_nonce_parity , sig , secnonce , agg_pubnonce , sk , msg , NULL , 0 , & pub_adaptor , pk , 2 );
1336
1361
1337
1362
CHECK (musig_test_pk_parity (& keyagg_cache ) == 1 );
1338
1363
CHECK (!musig_test_is_second_pk (& keyagg_cache , sk ));
0 commit comments