@@ -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.
@@ -384,6 +394,133 @@ SECP256K1_API int secp256k1_frost_nonce_gen(
384
394
const unsigned char * extra_input32
385
395
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
386
396
397
+ /** Takes the public nonces of all signers and computes a session that is
398
+ * required for signing and verification of partial signatures. The participant
399
+ * IDs can be sorted before combining, but the corresponding pubnonces must be
400
+ * resorted as well. All signers must use the same sorting of pubnonces,
401
+ * otherwise signing will fail.
402
+ *
403
+ * Returns: 0 if the arguments are invalid or if some signer sent invalid
404
+ * pubnonces, 1 otherwise
405
+ * Args: ctx: pointer to a context object
406
+ * Out: session: pointer to a struct to store the session
407
+ * In: pubnonces: array of pointers to public nonces sent by the signers
408
+ * n_pubnonces: number of elements in the pubnonces array. Must be
409
+ * greater than 0.
410
+ * msg32: the 32-byte message to sign
411
+ * myd_id33: the 33-byte ID of the participant who will use the
412
+ * session for signing
413
+ * ids33: array of the 33-byte participant IDs of the signers
414
+ * keygen_cache: pointer to frost_keygen_cache struct
415
+ * adaptor: optional pointer to an adaptor point encoded as a
416
+ * public key if this signing session is part of an
417
+ * adaptor signature protocol (can be NULL)
418
+ */
419
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_nonce_process (
420
+ const secp256k1_context * ctx ,
421
+ secp256k1_frost_session * session ,
422
+ const secp256k1_frost_pubnonce * const * pubnonces ,
423
+ size_t n_pubnonces ,
424
+ const unsigned char * msg32 ,
425
+ const unsigned char * my_id33 ,
426
+ const unsigned char * const * ids33 ,
427
+ const secp256k1_frost_keygen_cache * keygen_cache ,
428
+ const secp256k1_pubkey * adaptor
429
+ ) 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 );
430
+
431
+ /** Extracts the nonce_parity bit from a session
432
+ *
433
+ * This is used for adaptor signatures.
434
+ *
435
+ * Returns: 0 if the arguments are invalid, 1 otherwise
436
+ * Args: ctx: pointer to a context object
437
+ * Out: nonce_parity: pointer to an integer that indicates the parity
438
+ * of the aggregate public nonce. Used for adaptor
439
+ * signatures.
440
+ * In: session: pointer to the session that was created with
441
+ * frost_nonce_process
442
+ */
443
+ SECP256K1_API int secp256k1_frost_nonce_parity (
444
+ const secp256k1_context * ctx ,
445
+ int * nonce_parity ,
446
+ const secp256k1_frost_session * session
447
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
448
+
449
+ /** Verifies that the adaptor can be extracted by combining the adaptor
450
+ * pre-signature and the completed signature.
451
+ *
452
+ * Returns: 0 if the arguments are invalid or the adaptor signature does not
453
+ * verify, 1 otherwise
454
+ * Args: ctx: pointer to a context object
455
+ * In: pre_sig64: 64-byte pre-signature
456
+ * msg32: the 32-byte message being verified
457
+ * pubkey: pointer to an x-only public key to verify with
458
+ * adaptor: pointer to the adaptor point being verified
459
+ * nonce_parity: the output of `frost_nonce_parity` called with the
460
+ * session used for producing the pre-signature
461
+ */
462
+ SECP256K1_API int secp256k1_frost_verify_adaptor (
463
+ const secp256k1_context * ctx ,
464
+ const unsigned char * pre_sig64 ,
465
+ const unsigned char * msg32 ,
466
+ const secp256k1_xonly_pubkey * pubkey ,
467
+ const secp256k1_pubkey * adaptor ,
468
+ int nonce_parity
469
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
470
+
471
+ /** Creates a signature from a pre-signature and an adaptor.
472
+ *
473
+ * If the sec_adaptor32 argument is incorrect, the output signature will be
474
+ * invalid. This function does not verify the signature.
475
+ *
476
+ * Returns: 0 if the arguments are invalid, or pre_sig64 or sec_adaptor32 contain
477
+ * invalid (overflowing) values. 1 otherwise (which does NOT mean the
478
+ * signature or the adaptor are valid!)
479
+ * Args: ctx: pointer to a context object
480
+ * Out: sig64: 64-byte signature. This pointer may point to the same
481
+ * memory area as `pre_sig`.
482
+ * In: pre_sig64: 64-byte pre-signature
483
+ * sec_adaptor32: 32-byte secret adaptor to add to the pre-signature
484
+ * nonce_parity: the output of `frost_nonce_parity` called with the
485
+ * session used for producing the pre-signature
486
+ */
487
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_adapt (
488
+ const secp256k1_context * ctx ,
489
+ unsigned char * sig64 ,
490
+ const unsigned char * pre_sig64 ,
491
+ const unsigned char * sec_adaptor32 ,
492
+ int nonce_parity
493
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
494
+
495
+ /** Extracts a secret adaptor from a FROST pre-signature and corresponding
496
+ * signature
497
+ *
498
+ * This function will not fail unless given grossly invalid data; if it is
499
+ * merely given signatures that do not verify, the returned value will be
500
+ * nonsense. It is therefore important that all data be verified at earlier
501
+ * steps of any protocol that uses this function. In particular, this includes
502
+ * verifying all partial signatures that were aggregated into pre_sig64.
503
+ *
504
+ * Returns: 0 if the arguments are NULL, or sig64 or pre_sig64 contain
505
+ * grossly invalid (overflowing) values. 1 otherwise (which does NOT
506
+ * mean the signatures or the adaptor are valid!)
507
+ * Args: ctx: pointer to a context object
508
+ * Out:sec_adaptor32: 32-byte secret adaptor
509
+ * In: sig64: complete, valid 64-byte signature
510
+ * pre_sig64: the pre-signature corresponding to sig64, i.e., the
511
+ * aggregate of partial signatures without the secret
512
+ * adaptor
513
+ * nonce_parity: the output of `frost_nonce_parity` called with the
514
+ * session used for producing sig64
515
+ */
516
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_extract_adaptor (
517
+ const secp256k1_context * ctx ,
518
+ unsigned char * sec_adaptor32 ,
519
+ const unsigned char * sig64 ,
520
+ const unsigned char * pre_sig64 ,
521
+ int nonce_parity
522
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
523
+
387
524
#ifdef __cplusplus
388
525
}
389
526
#endif
0 commit comments