@@ -60,6 +60,10 @@ typedef int (*secp256k1_nonce_function_hardened)(
60
60
*/
61
61
SECP256K1_API extern const secp256k1_nonce_function_hardened secp256k1_nonce_function_bip340 ;
62
62
63
+ /** Opaque data structure that holds additional arguments for schnorrsig signing.
64
+ */
65
+ typedef struct secp256k1_schnorrsig_config_struct secp256k1_schnorrsig_config ;
66
+
63
67
/** Create a Schnorr signature.
64
68
*
65
69
* Does _not_ strictly follow BIP-340 because it does not verify the resulting
@@ -86,28 +90,68 @@ SECP256K1_API int secp256k1_schnorrsig_sign(
86
90
unsigned char * aux_rand32
87
91
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 );
88
92
93
+ /** Create a schnorrsig config (in dynamically allocated memory).
94
+ *
95
+ * This function uses malloc to allocate memory. It is guaranteed that malloc is
96
+ * called at most once for every call of this function.
97
+ *
98
+ * The allocated memory must be freed with secp256k1_schnorrsig_config_destroy.
99
+ *
100
+ * Returns: a newly created schnorrsig config
101
+ * Args: ctx: an existing context object (cannot be NULL)
102
+ */
103
+ SECP256K1_API secp256k1_schnorrsig_config * secp256k1_schnorrsig_config_create (
104
+ const secp256k1_context * ctx
105
+ ) SECP256K1_ARG_NONNULL (1 );
106
+
107
+ /** Destroy a schnorrsig config (created in dynamically allocated memory).
108
+ *
109
+ * The config pointer may not be used afterwards.
110
+ * Args: ctx: a secp256k1 context object
111
+ * In: config: the config to destroy
112
+ */
113
+ SECP256K1_API void secp256k1_schnorrsig_config_destroy (
114
+ const secp256k1_context * ctx ,
115
+ secp256k1_schnorrsig_config * config
116
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 );
117
+
118
+ /** Set nonce function pointer and nonce data of a config object
119
+ *
120
+ * Returns: 1 if the arguments are valid. 0 otherwise
121
+ * Args: ctx: a secp256k1 context object
122
+ * In: config: the config to set the noncefp and ndata for
123
+ * noncefp: the nonce function pointer to set
124
+ * ndata: the nonce data to set
125
+ */
126
+ SECP256K1_API int secp256k1_schnorrsig_config_set_nonce (
127
+ const secp256k1_context * ctx ,
128
+ secp256k1_schnorrsig_config * config ,
129
+ secp256k1_nonce_function_hardened noncefp ,
130
+ void * ndata
131
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 );
132
+
89
133
/** Create a Schnorr signature with a more flexible API.
90
134
*
91
- * Same arguments as secp256k1_schnorrsig_sign except that it misses aux_rand32
92
- * and instead allows allows providing a different nonce derivation function
93
- * with its own data argument .
135
+ * Same arguments as secp256k1_schnorrsig_sign except that it accepts a pointer
136
+ * to a config object that allows customizing signing by passing additional
137
+ * arguments .
94
138
*
95
139
* In: noncefp: pointer to a nonce generation function. If NULL,
96
140
* secp256k1_nonce_function_bip340 is used
97
141
* ndata: pointer to arbitrary data used by the nonce generation function
98
142
* (can be NULL). If it is non-NULL and
99
143
* secp256k1_nonce_function_bip340 is used, then ndata must be a
100
144
* pointer to 32-byte auxiliary randomness as per BIP-340.
145
+ * config: pointer to a config object.
101
146
*/
102
147
SECP256K1_API int secp256k1_schnorrsig_sign_custom (
103
148
const secp256k1_context * ctx ,
104
149
unsigned char * sig64 ,
105
150
const unsigned char * msg ,
106
151
size_t msg_len ,
107
152
const secp256k1_keypair * keypair ,
108
- secp256k1_nonce_function_hardened noncefp ,
109
- void * ndata
110
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 );
153
+ secp256k1_schnorrsig_config * config
154
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 ) SECP256K1_ARG_NONNULL (6 );
111
155
112
156
113
157
/** Verify a Schnorr signature.
0 commit comments