@@ -341,6 +341,194 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(
341
341
const unsigned char * seed32
342
342
) SECP256K1_ARG_NONNULL (1 );
343
343
344
+ /** Create a signature using a custom EC-Schnorr-SHA256 construction. It
345
+ * produces non-malleable 64-byte signatures which support public key recovery
346
+ * batch validation, and multiparty signing.
347
+ * Returns: 1: signature created
348
+ * 0: the nonce generation function failed, or the private key was
349
+ * invalid.
350
+ * In: ctx: pointer to a context object, initialized for signing
351
+ * (cannot be NULL)
352
+ * msg32: the 32-byte message hash being signed (cannot be NULL)
353
+ * seckey: pointer to a 32-byte secret key (cannot be NULL)
354
+ * noncefp:pointer to a nonce generation function. If NULL,
355
+ * secp256k1_nonce_function_default is used
356
+ * ndata: pointer to arbitrary data used by the nonce generation
357
+ * function (can be NULL)
358
+ * Out: sig64: pointer to a 64-byte array where the signature will be
359
+ * placed (cannot be NULL)
360
+ */
361
+ int secp256k1_schnorr_sign (
362
+ const secp256k1_context_t * ctx ,
363
+ const unsigned char * msg32 ,
364
+ unsigned char * sig64 ,
365
+ const unsigned char * seckey ,
366
+ secp256k1_nonce_function_t noncefp ,
367
+ const void * ndata
368
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
369
+
370
+ /** Verify a signature created by secp256k1_schnorr_sign.
371
+ * Returns: 1: public key and signature correct
372
+ * 0: incorrect signature
373
+ * -1: invalid public key
374
+ * In: ctx: a secp256k1 context object, initialized for verification.
375
+ * msg32: the 32-byte message hash being verified (cannot be NULL)
376
+ * sig64: the 64-byte signature being verified (cannot be NULL)
377
+ * pubkey: the public key to verify with (cannot be NULL)
378
+ * pubkeylen: the length of pubkey
379
+ */
380
+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify (
381
+ const secp256k1_context_t * ctx ,
382
+ const unsigned char * msg32 ,
383
+ const unsigned char * sig64 ,
384
+ const unsigned char * pubkey ,
385
+ int pubkeylen
386
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
387
+
388
+ /** Recover an EC public key from a Schnorr signature created using
389
+ * secp256k1_schnorr_sign.
390
+ * Returns: 1: public key successfully recovered (which guarantees a correct
391
+ * signature).
392
+ * 0: otherwise.
393
+ * In: ctx: pointer to a context object, initialized for
394
+ * verification (cannot be NULL)
395
+ * msg32: the 32-byte message hash assumed to be signed (cannot
396
+ * be NULL)
397
+ * sig64: signature as 64 byte array (cannot be NULL)
398
+ * compressed: whether to recover a compressed or uncompressed pubkey
399
+ * Out: pubkey: pointer to a 33 or 65 byte array to put the pubkey
400
+ * (cannot be NULL)
401
+ * pubkeylen: pointer to an int that will contain the pubkey length
402
+ * (cannot be NULL)
403
+ */
404
+ int secp256k1_schnorr_recover (
405
+ const secp256k1_context_t * ctx ,
406
+ const unsigned char * msg32 ,
407
+ const unsigned char * sig64 ,
408
+ unsigned char * pubkey ,
409
+ int * pubkeylen ,
410
+ int compressed
411
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
412
+
413
+ /** Generate a nonce pair deterministically for use with
414
+ * secp256k1_schnorr_partial_sign.
415
+ * Returns: 1: valid nonce pair was generated.
416
+ * 0: otherwise (nonce generation function failed)
417
+ * In: ctx: pointer to a context object, initialized for signing
418
+ * (cannot be NULL)
419
+ * msg32: the 32-byte message hash assumed to be signed (cannot
420
+ * be NULL)
421
+ * sec32: the 32-byte private key (cannot be NULL)
422
+ * noncefp: pointer to a nonce generation function. If NULL,
423
+ * secp256k1_nonce_function_default is used
424
+ * noncedata: pointer to arbitrary data used by the nonce generation
425
+ * function (can be NULL)
426
+ * Out: pubnonce33: public side of the nonce (represented as a 33-byte
427
+ * compressed public key) (cannot be NULL)
428
+ * privnonce32:private side of the nonce (32 byte) (cannot be NULL)
429
+ *
430
+ * Do not use the output as a private/public key pair for signing/validation.
431
+ */
432
+ int secp256k1_schnorr_generate_nonce_pair (
433
+ const secp256k1_context_t * ctx ,
434
+ const unsigned char * msg32 ,
435
+ const unsigned char * sec32 ,
436
+ secp256k1_nonce_function_t noncefp ,
437
+ const void * noncedata ,
438
+ unsigned char * pubnonce33 ,
439
+ unsigned char * privnonce32
440
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (6 ) SECP256K1_ARG_NONNULL (7 );
441
+
442
+ /** Add a number of public keys together.
443
+ * Returns: 1: the sum of the public keys is valid.
444
+ * 0: the sum of the public keys is not valid.
445
+ * -1: one or more of the inputs were invalid.
446
+ * In: ctx: pointer to a context object
447
+ * out: pointer to 33-byte array for placing the resulting
448
+ * public key (in compressed format) (cannot be NULL)
449
+ * n: the number of public keys to add together (must be at least 1)
450
+ * ins: pointer to array of pointers to public keys in
451
+ * compressed format (cannot be NULL)
452
+ * Use secp256k1_ec_pubkey_compress and secp256k1_ec_pubkey_decompress if the
453
+ * uncompressed format is needed.
454
+ */
455
+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine (
456
+ const secp256k1_context_t * ctx ,
457
+ unsigned char * out ,
458
+ int n ,
459
+ const unsigned char * * ins
460
+ ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
461
+
462
+ /** Produce a partial Schnorr signature, which can be combined using
463
+ * secp256k1_schnorr_partial_combine, to end up with a full signature that is
464
+ * verifiable using secp256k1_schnorr_verify.
465
+ * Returns: 1: signature created succesfully.
466
+ * 0: no valid signature exists with this combination of keys, nonces
467
+ * and message (chance around 1 in 2^128)
468
+ * -1: invalid private key, nonce, or public nonces.
469
+ * In: ctx: pointer to context object, initialized for signing (cannot
470
+ * be NULL)
471
+ * msg32: pointer to 32-byte message to sign
472
+ * sec32: pointer to 32-byte private key
473
+ * secnonce32: pointer to 32-byte array containing our nonce
474
+ * pubnonce33: pointer to 33-byte array containing the sum of the other's
475
+ * nonces (see secp256k1_ec_pubkey_combine)
476
+ * Out: sig64: pointer to 64-byte array to put partial signature in
477
+ *
478
+ * The intended procedure for creating a multiparty signature is:
479
+ * - Each signer S[i] with private key x[i] and public key Q[i] runs
480
+ * secp256k1_schnorr_generate_nonce_pair to produce a pair (k[i],R[i]) of
481
+ * private/public nonces.
482
+ * - All signers communicate their public nonces to each other (revealing your
483
+ * private nonce can lead to discovery of your private key, so it should be
484
+ * considered secret).
485
+ * - All signers combine all the public nonces they received (excluding their
486
+ * own) using secp256k1_ec_pubkey_combine to obtain an
487
+ * Rall[i] = sum(R[0..i-1,i+1..n]).
488
+ * - All signers produce a partial signature using
489
+ * secp256k1_schnorr_partial_sign, passing in their own private key x[i],
490
+ * their own private nonce k[i], and the sum of the others' public nonces
491
+ * Rall[i].
492
+ * - All signers communicate their partial signatures to each other.
493
+ * - Someone combines all partial signatures using
494
+ * secp256k1_schnorr_partial_combine, to obtain a full signature.
495
+ * - The resulting signature is validatable using secp256k1_schnorr_verify, with
496
+ * public key equal to the result of secp256k1_ec_pubkey_combine of the
497
+ * signers' public keys (sum(Q[0..n])).
498
+ *
499
+ * Note that secp256k1_schnorr_partial_combine and secp256k1_ec_pubkey_combine
500
+ * function take their arguments in any order, and it is possible to
501
+ * pre-combine several inputs already with one call, and add more inputs later
502
+ * by calling the function again.
503
+ */
504
+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign (
505
+ const secp256k1_context_t * ctx ,
506
+ const unsigned char * msg32 ,
507
+ unsigned char * sig64 ,
508
+ const unsigned char * sec32 ,
509
+ const unsigned char * secnonce32 ,
510
+ const unsigned char * pubnonce33
511
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 ) SECP256K1_ARG_NONNULL (6 );
512
+
513
+ /** Combine multiple Schnorr partial signatures.
514
+ * Returns: 1: the passed signatures were succesfully combined.
515
+ * 0: some signatures cancel eachother out (chance of 1 in 2^128 per
516
+ * signature)
517
+ * -1: some inputs were invalid, or the signatures were not created
518
+ * using the same set of nonces
519
+ * In: ctx: pointer to a context object
520
+ * sig64: pointer to a 64-byte array to place the combined signature
521
+ * (cannot be NULL)
522
+ * n: the number of signatures to combine (at least 1)
523
+ * Out: sig64sin: pointer to an array of n pointers to 64-byte input
524
+ * signatures
525
+ */
526
+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_combine (
527
+ const secp256k1_context_t * ctx ,
528
+ unsigned char * sig64 ,
529
+ int n ,
530
+ const unsigned char * * sig64sin
531
+ ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
344
532
345
533
# ifdef __cplusplus
346
534
}
0 commit comments