@@ -74,25 +74,67 @@ void secp256k1_context_destroy(
74
74
secp256k1_context_t * ctx
75
75
) SECP256K1_ARG_NONNULL (1 );
76
76
77
+ /** Data type to hold a parsed public key.
78
+ This data type should be considered opaque to the user, and only created
79
+ through API functions.
80
+ */
81
+ typedef struct {
82
+ unsigned char data [64 ];
83
+ } secp256k1_pubkey_t ;
84
+
85
+ /** Parse a variable-length public key into the pubkey object.
86
+ * Returns: 1 if the public key was fully valid.
87
+ * 0 if the public key could not be parsed or is invalid.
88
+ * In: ctx: a secp256k1 context object.
89
+ * input: pointer to a serialized public key
90
+ * inputlen: length of the array pointed to by input
91
+ * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a
92
+ * parsed version of input. If not, its value is undefined.
93
+ * This function supports parsing compressed (33 bytes, header byte 0x02 or
94
+ * 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header
95
+ * byte 0x06 or 0x07) format public keys.
96
+ */
97
+ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse (
98
+ const secp256k1_context_t * ctx ,
99
+ secp256k1_pubkey_t * pubkey ,
100
+ const unsigned char * input ,
101
+ int inputlen
102
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
103
+
104
+ /** Serialize a pubkey object into a serialized byte sequence.
105
+ * Returns: 1 always.
106
+ * In: ctx: a secp256k1 context object.
107
+ * pubkey: a pointer to a secp256k1_pubkey_t containing an initialized
108
+ * public key.
109
+ * compressed: whether to serialize in compressed format.
110
+ * Out: output: a pointer to a 65-byte (if compressed==0) or 33-byte (if
111
+ * compressed==1) byte array to place the serialized key in.
112
+ * outputlen: a pointer to an integer which will contain the serialized
113
+ * size.
114
+ */
115
+ int secp256k1_ec_pubkey_serialize (
116
+ const secp256k1_context_t * ctx ,
117
+ unsigned char * output ,
118
+ int * outputlen ,
119
+ const secp256k1_pubkey_t * pubkey ,
120
+ int compressed
121
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
122
+
77
123
/** Verify an ECDSA signature.
78
124
* Returns: 1: correct signature
79
- * 0: incorrect signature
80
- * -1: invalid public key
81
- * -2: invalid signature
125
+ * 0: incorrect or unparseable signature
82
126
* In: ctx: a secp256k1 context object, initialized for verification.
83
127
* msg32: the 32-byte message hash being verified (cannot be NULL)
84
128
* sig: the signature being verified (cannot be NULL)
85
129
* siglen: the length of the signature
86
130
* pubkey: the public key to verify with (cannot be NULL)
87
- * pubkeylen: the length of pubkey
88
131
*/
89
132
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify (
90
133
const secp256k1_context_t * ctx ,
91
134
const unsigned char * msg32 ,
92
135
const unsigned char * sig ,
93
136
int siglen ,
94
- const unsigned char * pubkey ,
95
- int pubkeylen
137
+ const secp256k1_pubkey_t * pubkey
96
138
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (5 );
97
139
98
140
/** A pointer to a function to deterministically generate a nonce.
@@ -124,7 +166,6 @@ extern const secp256k1_nonce_function_t secp256k1_nonce_function_rfc6979;
124
166
/** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */
125
167
extern const secp256k1_nonce_function_t secp256k1_nonce_function_default ;
126
168
127
-
128
169
/** Create an ECDSA signature.
129
170
* Returns: 1: signature created
130
171
* 0: the nonce generation function failed, the private key was invalid, or there is not
@@ -202,20 +243,16 @@ int secp256k1_ecdsa_sign_compact(
202
243
* In: ctx: pointer to a context object, initialized for verification (cannot be NULL)
203
244
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
204
245
* sig64: signature as 64 byte array (cannot be NULL)
205
- * compressed: whether to recover a compressed or uncompressed pubkey
206
246
* recid: the recovery id (0-3, as returned by ecdsa_sign_compact)
207
- * Out: pubkey: pointer to a 33 or 65 byte array to put the pubkey (cannot be NULL)
208
- * pubkeylen: pointer to an int that will contain the pubkey length (cannot be NULL)
247
+ * Out: pubkey: pointer to the recoved public key (cannot be NULL)
209
248
*/
210
249
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover_compact (
211
250
const secp256k1_context_t * ctx ,
212
251
const unsigned char * msg32 ,
213
252
const unsigned char * sig64 ,
214
- unsigned char * pubkey ,
215
- int * pubkeylen ,
216
- int compressed ,
253
+ secp256k1_pubkey_t * pubkey ,
217
254
int recid
218
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL ( 5 ) ;
255
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
219
256
220
257
/** Verify an ECDSA secret key.
221
258
* Returns: 1: secret key is valid
@@ -228,24 +265,11 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(
228
265
const unsigned char * seckey
229
266
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 );
230
267
231
- /** Just validate a public key.
232
- * Returns: 1: public key is valid
233
- * 0: public key is invalid
234
- * In: ctx: pointer to a context object (cannot be NULL)
235
- * pubkey: pointer to a 33-byte or 65-byte public key (cannot be NULL).
236
- * pubkeylen: length of pubkey
237
- */
238
- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_verify (
239
- const secp256k1_context_t * ctx ,
240
- const unsigned char * pubkey ,
241
- int pubkeylen
242
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 );
243
-
244
268
/** Compute the public key for a secret key.
245
269
* In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
246
270
* compressed: whether the computed public key should be compressed
247
271
* seckey: pointer to a 32-byte private key (cannot be NULL)
248
- * Out: pubkey: pointer to a 33-byte (if compressed) or 65-byte (if uncompressed )
272
+ * Out: pubkey: pointer to the created public key (cannot be NULL )
249
273
* area to store the public key (cannot be NULL)
250
274
* pubkeylen: pointer to int that will be updated to contains the pubkey's
251
275
* length (cannot be NULL)
@@ -254,45 +278,9 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_verify(
254
278
*/
255
279
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create (
256
280
const secp256k1_context_t * ctx ,
257
- unsigned char * pubkey ,
258
- int * pubkeylen ,
259
- const unsigned char * seckey ,
260
- int compressed
261
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
262
-
263
- /** Compress a public key.
264
- * In: ctx: pointer to a context object (cannot be NULL)
265
- * pubkeyin: pointer to a 33-byte or 65-byte public key (cannot be NULL)
266
- * Out: pubkeyout: pointer to a 33-byte array to put the compressed public key (cannot be NULL)
267
- * May alias pubkeyin.
268
- * pubkeylen: pointer to the size of the public key pointed to by pubkeyin (cannot be NULL)
269
- * It will be updated to reflect the size of the public key in pubkeyout.
270
- * Returns: 0: pubkeyin was invalid
271
- * 1: pubkeyin was valid, and pubkeyout is its compressed version
272
- */
273
- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_compress (
274
- const secp256k1_context_t * ctx ,
275
- const unsigned char * pubkeyin ,
276
- unsigned char * pubkeyout ,
277
- int * pubkeylen
278
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
279
-
280
- /** Decompress a public key.
281
- * In: ctx: pointer to a context object (cannot be NULL)
282
- * pubkeyin: pointer to a 33-byte or 65-byte public key (cannot be NULL)
283
- * Out: pubkeyout: pointer to a 65-byte array to put the decompressed public key (cannot be NULL)
284
- * May alias pubkeyin.
285
- * pubkeylen: pointer to the size of the public key pointed to by pubkeyin (cannot be NULL)
286
- * It will be updated to reflect the size of the public key in pubkeyout.
287
- * Returns: 0: pubkeyin was invalid
288
- * 1: pubkeyin was valid, and pubkeyout is its decompressed version
289
- */
290
- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_decompress (
291
- const secp256k1_context_t * ctx ,
292
- const unsigned char * pubkeyin ,
293
- unsigned char * pubkeyout ,
294
- int * pubkeylen
295
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
281
+ secp256k1_pubkey_t * pubkey ,
282
+ const unsigned char * seckey
283
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
296
284
297
285
/** Export a private key in DER format.
298
286
* In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
@@ -325,10 +313,9 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
325
313
*/
326
314
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add (
327
315
const secp256k1_context_t * ctx ,
328
- unsigned char * pubkey ,
329
- int pubkeylen ,
316
+ secp256k1_pubkey_t * pubkey ,
330
317
const unsigned char * tweak
331
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
318
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
332
319
333
320
/** Tweak a private key by multiplying it with tweak. */
334
321
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul (
@@ -342,10 +329,9 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
342
329
*/
343
330
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul (
344
331
const secp256k1_context_t * ctx ,
345
- unsigned char * pubkey ,
346
- int pubkeylen ,
332
+ secp256k1_pubkey_t * pubkey ,
347
333
const unsigned char * tweak
348
- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
334
+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
349
335
350
336
/** Updates the context randomization.
351
337
* Returns: 1: randomization successfully updated
0 commit comments