@@ -17,7 +17,7 @@ extern "C" {
17
17
* (https://crysp.uwaterloo.ca/software/frost/).
18
18
*
19
19
* The module also supports BIP-341 ("Taproot") and BIP-32 ("ordinary") public
20
- * key tweaking.
20
+ * key tweaking, and adaptor signatures .
21
21
*
22
22
* Following the convention used in the MuSig module, the API uses the singular
23
23
* term "nonce" to refer to the two "nonces" used by the FROST scheme.
@@ -78,6 +78,16 @@ typedef struct {
78
78
unsigned char data [132 ];
79
79
} secp256k1_frost_pubnonce ;
80
80
81
+ /** Opaque data structure that holds a FROST session.
82
+ *
83
+ * This structure is not required to be kept secret for the signing protocol
84
+ * to be secure. Guaranteed to be 133 bytes in size. It can be safely
85
+ * copied/moved. No serialization and parsing functions.
86
+ */
87
+ typedef struct {
88
+ unsigned char data [133 ];
89
+ } secp256k1_frost_session ;
90
+
81
91
/** Parse a signer's public nonce.
82
92
*
83
93
* Returns: 1 when the nonce could be parsed, 0 otherwise.
@@ -421,6 +431,135 @@ SECP256K1_API int secp256k1_frost_nonce_gen(
421
431
const unsigned char * extra_input32
422
432
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
423
433
434
+ /** Takes the public nonces of all signers and computes a session that is
435
+ * required for signing and verification of partial signatures. The participant
436
+ * IDs can be sorted before combining, but the corresponding pubnonces must be
437
+ * resorted as well. All signers must use the same sorting of pubnonces,
438
+ * otherwise signing will fail.
439
+ *
440
+ * Returns: 0 if the arguments are invalid or if some signer sent invalid
441
+ * pubnonces, 1 otherwise
442
+ * Args: ctx: pointer to a context object
443
+ * Out: session: pointer to a struct to store the session
444
+ * In: pubnonces: array of pointers to public nonces sent by the signers
445
+ * n_pubnonces: number of elements in the pubnonces array. Must be
446
+ * greater than 0.
447
+ * msg32: the 32-byte message to sign
448
+ * agg_pk: the FROST-aggregated public key
449
+ * myd_id33: the 33-byte ID of the participant who will use the
450
+ * session for signing
451
+ * ids33: array of the 33-byte participant IDs of the signers
452
+ * tweak_cache: pointer to frost_tweak_cache struct (can be NULL)
453
+ * adaptor: optional pointer to an adaptor point encoded as a
454
+ * public key if this signing session is part of an
455
+ * adaptor signature protocol (can be NULL)
456
+ */
457
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_nonce_process (
458
+ const secp256k1_context * ctx ,
459
+ secp256k1_frost_session * session ,
460
+ const secp256k1_frost_pubnonce * const * pubnonces ,
461
+ size_t n_pubnonces ,
462
+ const unsigned char * msg32 ,
463
+ const secp256k1_xonly_pubkey * agg_pk ,
464
+ const unsigned char * my_id33 ,
465
+ const unsigned char * const * ids33 ,
466
+ const secp256k1_frost_tweak_cache * tweak_cache ,
467
+ const secp256k1_pubkey * adaptor
468
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 ) SECP256K1_ARG_NONNULL (6 ) SECP256K1_ARG_NONNULL (7 ) SECP256K1_ARG_NONNULL (8 );
469
+
470
+ /** Extracts the nonce_parity bit from a session
471
+ *
472
+ * This is used for adaptor signatures.
473
+ *
474
+ * Returns: 0 if the arguments are invalid, 1 otherwise
475
+ * Args: ctx: pointer to a context object
476
+ * Out: nonce_parity: pointer to an integer that indicates the parity
477
+ * of the aggregate public nonce. Used for adaptor
478
+ * signatures.
479
+ * In: session: pointer to the session that was created with
480
+ * frost_nonce_process
481
+ */
482
+ SECP256K1_API int secp256k1_frost_nonce_parity (
483
+ const secp256k1_context * ctx ,
484
+ int * nonce_parity ,
485
+ const secp256k1_frost_session * session
486
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
487
+
488
+ /** Verifies that the adaptor can be extracted by combining the adaptor
489
+ * pre-signature and the completed signature.
490
+ *
491
+ * Returns: 0 if the arguments are invalid or the adaptor signature does not
492
+ * verify, 1 otherwise
493
+ * Args: ctx: pointer to a context object
494
+ * In: pre_sig64: 64-byte pre-signature
495
+ * msg32: the 32-byte message being verified
496
+ * pubkey: pointer to an x-only public key to verify with
497
+ * adaptor: pointer to the adaptor point being verified
498
+ * nonce_parity: the output of `frost_nonce_parity` called with the
499
+ * session used for producing the pre-signature
500
+ */
501
+ SECP256K1_API int secp256k1_frost_verify_adaptor (
502
+ const secp256k1_context * ctx ,
503
+ const unsigned char * pre_sig64 ,
504
+ const unsigned char * msg32 ,
505
+ const secp256k1_xonly_pubkey * pubkey ,
506
+ const secp256k1_pubkey * adaptor ,
507
+ int nonce_parity
508
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
509
+
510
+ /** Creates a signature from a pre-signature and an adaptor.
511
+ *
512
+ * If the sec_adaptor32 argument is incorrect, the output signature will be
513
+ * invalid. This function does not verify the signature.
514
+ *
515
+ * Returns: 0 if the arguments are invalid, or pre_sig64 or sec_adaptor32 contain
516
+ * invalid (overflowing) values. 1 otherwise (which does NOT mean the
517
+ * signature or the adaptor are valid!)
518
+ * Args: ctx: pointer to a context object
519
+ * Out: sig64: 64-byte signature. This pointer may point to the same
520
+ * memory area as `pre_sig`.
521
+ * In: pre_sig64: 64-byte pre-signature
522
+ * sec_adaptor32: 32-byte secret adaptor to add to the pre-signature
523
+ * nonce_parity: the output of `frost_nonce_parity` called with the
524
+ * session used for producing the pre-signature
525
+ */
526
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_adapt (
527
+ const secp256k1_context * ctx ,
528
+ unsigned char * sig64 ,
529
+ const unsigned char * pre_sig64 ,
530
+ const unsigned char * sec_adaptor32 ,
531
+ int nonce_parity
532
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
533
+
534
+ /** Extracts a secret adaptor from a FROST pre-signature and corresponding
535
+ * signature
536
+ *
537
+ * This function will not fail unless given grossly invalid data; if it is
538
+ * merely given signatures that do not verify, the returned value will be
539
+ * nonsense. It is therefore important that all data be verified at earlier
540
+ * steps of any protocol that uses this function. In particular, this includes
541
+ * verifying all partial signatures that were aggregated into pre_sig64.
542
+ *
543
+ * Returns: 0 if the arguments are NULL, or sig64 or pre_sig64 contain
544
+ * grossly invalid (overflowing) values. 1 otherwise (which does NOT
545
+ * mean the signatures or the adaptor are valid!)
546
+ * Args: ctx: pointer to a context object
547
+ * Out:sec_adaptor32: 32-byte secret adaptor
548
+ * In: sig64: complete, valid 64-byte signature
549
+ * pre_sig64: the pre-signature corresponding to sig64, i.e., the
550
+ * aggregate of partial signatures without the secret
551
+ * adaptor
552
+ * nonce_parity: the output of `frost_nonce_parity` called with the
553
+ * session used for producing sig64
554
+ */
555
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_extract_adaptor (
556
+ const secp256k1_context * ctx ,
557
+ unsigned char * sec_adaptor32 ,
558
+ const unsigned char * sig64 ,
559
+ const unsigned char * pre_sig64 ,
560
+ int nonce_parity
561
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
562
+
424
563
#ifdef __cplusplus
425
564
}
426
565
#endif
0 commit comments