@@ -120,22 +120,94 @@ int secp256k1_ec_pubkey_serialize(
120120 int compressed
121121) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
122122
123+ /** Data type to hold a parsed ECDSA signature, optionally supporting pubkey
124+ * recovery */
125+ typedef struct {
126+ unsigned char data [65 ];
127+ } secp256k1_ecdsa_signature_t ;
128+
129+ /** Parse a DER ECDSA signature.
130+ * Returns: 1 when the signature could be parsed, 0 otherwise.
131+ * In: ctx: a secp256k1 context object
132+ * input: a pointer to the signature to be parsed
133+ * inputlen: the length of the array pointed to be input
134+ * Out: sig: a pointer to a signature object
135+ *
136+ * Note that this function also supports some violations of DER.
137+ *
138+ * The resulting signature object will not support pubkey recovery.
139+ */
140+ int secp256k1_ecdsa_signature_parse_der (
141+ const secp256k1_context_t * ctx ,
142+ secp256k1_ecdsa_signature_t * sig ,
143+ const unsigned char * input ,
144+ int inputlen
145+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
146+
147+ /** Parse a compact ECDSA signature (64 bytes + recovery id).
148+ * Returns: 1 when the signature could be parsed, 0 otherwise
149+ * In: ctx: a secp256k1 context object
150+ * input64: a pointer to a 64-byte compact signature
151+ * recid: the recovery id (0, 1, 2 or 3, or -1 for unknown)
152+ * Out: sig: a pointer to a signature object
153+ *
154+ * If recid is not -1, the resulting signature object will support pubkey
155+ * recovery.
156+ */
157+ int secp256k1_ecdsa_signature_parse_compact (
158+ const secp256k1_context_t * ctx ,
159+ secp256k1_ecdsa_signature_t * sig ,
160+ const unsigned char * input64 ,
161+ int recid
162+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
163+
164+ /** Serialize an ECDSA signature in DER format.
165+ * Returns: 1 if enough space was available to serialize, 0 otherwise
166+ * In: ctx: a secp256k1 context object
167+ * sig: a pointer to an initialized signature object
168+ * Out: output: a pointer to an array to store the DER serialization
169+ * In/Out: outputlen: a pointer to a length integer. Initially, this integer
170+ * should be set to the length of output. After the call
171+ * it will be set to the length of the serialization (even
172+ * if 0 was returned).
173+ */
174+ int secp256k1_ecdsa_signature_serialize_der (
175+ const secp256k1_context_t * ctx ,
176+ unsigned char * output ,
177+ int * outputlen ,
178+ const secp256k1_ecdsa_signature_t * sig
179+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
180+
181+ /** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
182+ * Returns: 1
183+ * In: ctx: a secp256k1 context object
184+ * sig: a pointer to an initialized signature object (cannot be NULL)
185+ * Out: output64: a pointer to a 64-byte array of the compact signature (cannot be NULL)
186+ * recid: a pointer to an integer to hold the recovery id (can be NULL).
187+ *
188+ * If recid is not NULL, the signature must support pubkey recovery.
189+ */
190+ int secp256k1_ecdsa_signature_serialize_compact (
191+ const secp256k1_context_t * ctx ,
192+ unsigned char * output64 ,
193+ int * recid ,
194+ const secp256k1_ecdsa_signature_t * sig
195+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
196+
123197/** Verify an ECDSA signature.
124198 * Returns: 1: correct signature
125199 * 0: incorrect or unparseable signature
126200 * In: ctx: a secp256k1 context object, initialized for verification.
127201 * msg32: the 32-byte message hash being verified (cannot be NULL)
128202 * sig: the signature being verified (cannot be NULL)
129- * siglen: the length of the signature
130203 * pubkey: the public key to verify with (cannot be NULL)
131204 */
132205SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify (
133206 const secp256k1_context_t * ctx ,
134207 const unsigned char * msg32 ,
135- const unsigned char * sig ,
136- int siglen ,
208+ const secp256k1_ecdsa_signature_t * sig ,
137209 const secp256k1_pubkey_t * pubkey
138- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 );
210+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
139211
140212/** A pointer to a function to deterministically generate a nonce.
141213 * Returns: 1 if a nonce was successfully generated. 0 will cause signing to fail.
@@ -168,16 +240,15 @@ extern const secp256k1_nonce_function_t secp256k1_nonce_function_default;
168240
169241/** Create an ECDSA signature.
170242 * Returns: 1: signature created
171- * 0: the nonce generation function failed, the private key was invalid, or there is not
172- * enough space in the signature (as indicated by siglen).
243+ * 0: the nonce generation function failed, or the private key was invalid.
173244 * In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
174245 * msg32: the 32-byte message hash being signed (cannot be NULL)
175246 * seckey: pointer to a 32-byte secret key (cannot be NULL)
176247 * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
177248 * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
178249 * Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
179- * In/Out: siglen: pointer to an int with the length of sig, which will be updated
180- * to contain the actual signature length (<=72) .
250+ *
251+ * The resulting signature will support pubkey recovery .
181252 *
182253 * The sig always has an s value in the lower half of the range (From 0x1
183254 * to 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
@@ -208,50 +279,25 @@ extern const secp256k1_nonce_function_t secp256k1_nonce_function_default;
208279int secp256k1_ecdsa_sign (
209280 const secp256k1_context_t * ctx ,
210281 const unsigned char * msg32 ,
211- unsigned char * sig ,
212- int * siglen ,
282+ secp256k1_ecdsa_signature_t * sig ,
213283 const unsigned char * seckey ,
214284 secp256k1_nonce_function_t noncefp ,
215285 const void * ndata
216- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
217-
218- /** Create a compact ECDSA signature (64 byte + recovery id).
219- * Returns: 1: signature created
220- * 0: the nonce generation function failed, or the secret key was invalid.
221- * In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
222- * msg32: the 32-byte message hash being signed (cannot be NULL)
223- * seckey: pointer to a 32-byte secret key (cannot be NULL)
224- * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
225- * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
226- * Out: sig: pointer to a 64-byte array where the signature will be placed (cannot be NULL)
227- * In case 0 is returned, the returned signature length will be zero.
228- * recid: pointer to an int, which will be updated to contain the recovery id (can be NULL)
229- */
230- int secp256k1_ecdsa_sign_compact (
231- const secp256k1_context_t * ctx ,
232- const unsigned char * msg32 ,
233- unsigned char * sig64 ,
234- const unsigned char * seckey ,
235- secp256k1_nonce_function_t noncefp ,
236- const void * ndata ,
237- int * recid
238286) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
239287
240- /** Recover an ECDSA public key from a compact signature.
288+ /** Recover an ECDSA public key from a signature.
241289 * Returns: 1: public key successfully recovered (which guarantees a correct signature).
242290 * 0: otherwise.
243291 * In: ctx: pointer to a context object, initialized for verification (cannot be NULL)
244292 * msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
245- * sig64: signature as 64 byte array (cannot be NULL)
246- * recid: the recovery id (0-3, as returned by ecdsa_sign_compact)
293+ * sig64: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
247294 * Out: pubkey: pointer to the recoved public key (cannot be NULL)
248295 */
249- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover_compact (
296+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover (
250297 const secp256k1_context_t * ctx ,
251298 const unsigned char * msg32 ,
252- const unsigned char * sig64 ,
253- secp256k1_pubkey_t * pubkey ,
254- int recid
299+ const secp256k1_ecdsa_signature_t * sig ,
300+ secp256k1_pubkey_t * pubkey
255301) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
256302
257303/** Verify an ECDSA secret key.
@@ -267,12 +313,8 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
267313
268314/** Compute the public key for a secret key.
269315 * In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
270- * compressed: whether the computed public key should be compressed
271316 * seckey: pointer to a 32-byte private key (cannot be NULL)
272317 * Out: pubkey: pointer to the created public key (cannot be NULL)
273- * area to store the public key (cannot be NULL)
274- * pubkeylen: pointer to int that will be updated to contains the pubkey's
275- * length (cannot be NULL)
276318 * Returns: 1: secret was valid, public key stores
277319 * 0: secret was invalid, try again
278320 */
0 commit comments