]>
Commit | Line | Data |
---|---|---|
35b73a1f | 1 | /* |
48e5119a | 2 | * Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. |
aa8f3d76 | 3 | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
6cc5e19d | 4 | * |
48f4ad77 | 5 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
6 | * this file except in compliance with the License. You can obtain a copy |
7 | * in the file LICENSE in the source distribution or at | |
8 | * https://www.openssl.org/source/license.html | |
6cc5e19d | 9 | */ |
21dcbebc | 10 | |
6cc5e19d | 11 | #ifndef HEADER_EC_H |
0f113f3e | 12 | # define HEADER_EC_H |
6cc5e19d | 13 | |
0f113f3e | 14 | # include <openssl/opensslconf.h> |
87c9c659 | 15 | |
3c27208f | 16 | # ifndef OPENSSL_NO_EC |
0f113f3e MC |
17 | # include <openssl/asn1.h> |
18 | # include <openssl/symhacks.h> | |
fcd2d5a6 | 19 | # if !OPENSSL_API_1_1_0 |
0f113f3e MC |
20 | # include <openssl/bn.h> |
21 | # endif | |
52df25cf | 22 | # include <openssl/ecerr.h> |
0f113f3e | 23 | # ifdef __cplusplus |
65e81670 | 24 | extern "C" { |
7f24b1c3 | 25 | # endif |
6cc5e19d | 26 | |
0f113f3e MC |
27 | # ifndef OPENSSL_ECC_MAX_FIELD_BITS |
28 | # define OPENSSL_ECC_MAX_FIELD_BITS 661 | |
29 | # endif | |
5e3225cc | 30 | |
ba12070f NL |
31 | /** Enum for the point conversion form as defined in X9.62 (ECDSA) |
32 | * for the encoding of a elliptic curve point (x,y) */ | |
3a12ce01 | 33 | typedef enum { |
0f113f3e | 34 | /** the point is encoded as z||x, where the octet z specifies |
ba12070f | 35 | * which solution of the quadratic equation y is */ |
0f113f3e | 36 | POINT_CONVERSION_COMPRESSED = 2, |
91d2728b | 37 | /** the point is encoded as z||x||y, where z is the octet 0x04 */ |
0f113f3e MC |
38 | POINT_CONVERSION_UNCOMPRESSED = 4, |
39 | /** the point is encoded as z||x||y, where the octet z specifies | |
40 | * which solution of the quadratic equation y is */ | |
41 | POINT_CONVERSION_HYBRID = 6 | |
3a12ce01 BM |
42 | } point_conversion_form_t; |
43 | ||
3a12ce01 | 44 | typedef struct ec_method_st EC_METHOD; |
60b350a3 | 45 | typedef struct ec_group_st EC_GROUP; |
3a12ce01 | 46 | typedef struct ec_point_st EC_POINT; |
60b350a3 RS |
47 | typedef struct ecpk_parameters_st ECPKPARAMETERS; |
48 | typedef struct ec_parameters_st ECPARAMETERS; | |
3a12ce01 | 49 | |
ba12070f | 50 | /********************************************************************/ |
0f113f3e | 51 | /* EC_METHODs for curves over GF(p) */ |
ba12070f NL |
52 | /********************************************************************/ |
53 | ||
54 | /** Returns the basic GFp ec methods which provides the basis for the | |
0f113f3e | 55 | * optimized methods. |
ba12070f | 56 | * \return EC_METHOD object |
3a12ce01 | 57 | */ |
3a12ce01 | 58 | const EC_METHOD *EC_GFp_simple_method(void); |
ba12070f NL |
59 | |
60 | /** Returns GFp methods using montgomery multiplication. | |
61 | * \return EC_METHOD object | |
62 | */ | |
3a12ce01 | 63 | const EC_METHOD *EC_GFp_mont_method(void); |
ba12070f NL |
64 | |
65 | /** Returns GFp methods using optimized methods for NIST recommended curves | |
66 | * \return EC_METHOD object | |
67 | */ | |
5c6bf031 | 68 | const EC_METHOD *EC_GFp_nist_method(void); |
3a12ce01 | 69 | |
0f113f3e | 70 | # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 |
04daec86 BM |
71 | /** Returns 64-bit optimized methods for nistp224 |
72 | * \return EC_METHOD object | |
73 | */ | |
74 | const EC_METHOD *EC_GFp_nistp224_method(void); | |
3e00b4c9 BM |
75 | |
76 | /** Returns 64-bit optimized methods for nistp256 | |
77 | * \return EC_METHOD object | |
78 | */ | |
79 | const EC_METHOD *EC_GFp_nistp256_method(void); | |
80 | ||
81 | /** Returns 64-bit optimized methods for nistp521 | |
82 | * \return EC_METHOD object | |
83 | */ | |
84 | const EC_METHOD *EC_GFp_nistp521_method(void); | |
0f113f3e | 85 | # endif |
ba12070f | 86 | |
0f113f3e MC |
87 | # ifndef OPENSSL_NO_EC2M |
88 | /********************************************************************/ | |
ba12070f NL |
89 | /* EC_METHOD for curves over GF(2^m) */ |
90 | /********************************************************************/ | |
91 | ||
0f113f3e | 92 | /** Returns the basic GF2m ec method |
ba12070f | 93 | * \return EC_METHOD object |
7793f30e BM |
94 | */ |
95 | const EC_METHOD *EC_GF2m_simple_method(void); | |
96 | ||
0f113f3e | 97 | # endif |
3a12ce01 | 98 | |
ba12070f NL |
99 | /********************************************************************/ |
100 | /* EC_GROUP functions */ | |
101 | /********************************************************************/ | |
102 | ||
a9612d6c MC |
103 | /** |
104 | * Creates a new EC_GROUP object | |
105 | * \param libctx The associated library context or NULL for the default | |
106 | * library context | |
107 | * \param meth EC_METHOD to use | |
108 | * \return newly created EC_GROUP object or NULL in case of an error. | |
109 | */ | |
110 | EC_GROUP *EC_GROUP_new_ex(OPENSSL_CTX *libctx, const EC_METHOD *meth); | |
111 | ||
112 | /** | |
113 | * Creates a new EC_GROUP object. Same as EC_GROUP_new_ex with NULL for the | |
114 | * library context. | |
115 | * \param libctx The associated library context or NULL for the default | |
116 | * library context | |
117 | * \param meth EC_METHOD to use | |
ba12070f NL |
118 | * \return newly created EC_GROUP object or NULL in case of an error. |
119 | */ | |
120 | EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); | |
121 | ||
122 | /** Frees a EC_GROUP object | |
123 | * \param group EC_GROUP object to be freed. | |
124 | */ | |
125 | void EC_GROUP_free(EC_GROUP *group); | |
126 | ||
127 | /** Clears and frees a EC_GROUP object | |
128 | * \param group EC_GROUP object to be cleared and freed. | |
129 | */ | |
130 | void EC_GROUP_clear_free(EC_GROUP *group); | |
131 | ||
132 | /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD. | |
133 | * \param dst destination EC_GROUP object | |
134 | * \param src source EC_GROUP object | |
135 | * \return 1 on success and 0 if an error occurred. | |
136 | */ | |
137 | int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); | |
138 | ||
9fdcc21f | 139 | /** Creates a new EC_GROUP object and copies the content |
ba12070f NL |
140 | * form src to the newly created EC_KEY object |
141 | * \param src source EC_GROUP object | |
142 | * \return newly created EC_GROUP object or NULL in case of an error. | |
143 | */ | |
144 | EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); | |
145 | ||
146 | /** Returns the EC_METHOD of the EC_GROUP object. | |
0f113f3e | 147 | * \param group EC_GROUP object |
ba12070f NL |
148 | * \return EC_METHOD used in this EC_GROUP object. |
149 | */ | |
150 | const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); | |
151 | ||
152 | /** Returns the field type of the EC_METHOD. | |
153 | * \param meth EC_METHOD object | |
154 | * \return NID of the underlying field type OID. | |
155 | */ | |
156 | int EC_METHOD_get_field_type(const EC_METHOD *meth); | |
157 | ||
68756b12 | 158 | /** Sets the generator and its order/cofactor of a EC_GROUP object. |
0f113f3e | 159 | * \param group EC_GROUP object |
ba12070f NL |
160 | * \param generator EC_POINT object with the generator. |
161 | * \param order the order of the group generated by the generator. | |
162 | * \param cofactor the index of the sub-group generated by the generator | |
163 | * in the group of all points on the elliptic curve. | |
478b50cf | 164 | * \return 1 on success and 0 if an error occurred |
ba12070f | 165 | */ |
0f113f3e MC |
166 | int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, |
167 | const BIGNUM *order, const BIGNUM *cofactor); | |
ba12070f NL |
168 | |
169 | /** Returns the generator of a EC_GROUP object. | |
170 | * \param group EC_GROUP object | |
171 | * \return the currently used generator (possibly NULL). | |
172 | */ | |
173 | const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); | |
174 | ||
f54be179 AP |
175 | /** Returns the montgomery data for order(Generator) |
176 | * \param group EC_GROUP object | |
14f46560 | 177 | * \return the currently used montgomery data (possibly NULL). |
f54be179 AP |
178 | */ |
179 | BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group); | |
180 | ||
ba12070f NL |
181 | /** Gets the order of a EC_GROUP |
182 | * \param group EC_GROUP object | |
183 | * \param order BIGNUM to which the order is copied | |
a773b52a | 184 | * \param ctx unused |
478b50cf | 185 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
186 | */ |
187 | int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); | |
48fe4d62 | 188 | |
be2e334f DSH |
189 | /** Gets the order of an EC_GROUP |
190 | * \param group EC_GROUP object | |
191 | * \return the group order | |
192 | */ | |
be2e334f DSH |
193 | const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); |
194 | ||
8483a003 | 195 | /** Gets the number of bits of the order of an EC_GROUP |
be2e334f DSH |
196 | * \param group EC_GROUP object |
197 | * \return number of bits of group order. | |
198 | */ | |
be2e334f DSH |
199 | int EC_GROUP_order_bits(const EC_GROUP *group); |
200 | ||
ba12070f NL |
201 | /** Gets the cofactor of a EC_GROUP |
202 | * \param group EC_GROUP object | |
203 | * \param cofactor BIGNUM to which the cofactor is copied | |
a773b52a | 204 | * \param ctx unused |
478b50cf | 205 | * \return 1 on success and 0 if an error occurred |
ba12070f | 206 | */ |
0f113f3e MC |
207 | int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, |
208 | BN_CTX *ctx); | |
b6db386f | 209 | |
be2e334f DSH |
210 | /** Gets the cofactor of an EC_GROUP |
211 | * \param group EC_GROUP object | |
212 | * \return the group cofactor | |
213 | */ | |
be2e334f DSH |
214 | const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); |
215 | ||
ba12070f NL |
216 | /** Sets the name of a EC_GROUP object |
217 | * \param group EC_GROUP object | |
218 | * \param nid NID of the curve name OID | |
219 | */ | |
220 | void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); | |
b6db386f | 221 | |
ba12070f NL |
222 | /** Returns the curve name of a EC_GROUP object |
223 | * \param group EC_GROUP object | |
224 | * \return NID of the curve name OID or 0 if not set. | |
225 | */ | |
226 | int EC_GROUP_get_curve_name(const EC_GROUP *group); | |
945e15a2 | 227 | |
fa1f0306 DA |
228 | /** Gets the field of an EC_GROUP |
229 | * \param group EC_GROUP object | |
230 | * \return the group field | |
231 | */ | |
232 | const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group); | |
233 | ||
ba12070f NL |
234 | void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); |
235 | int EC_GROUP_get_asn1_flag(const EC_GROUP *group); | |
5f3d6f70 | 236 | |
0f113f3e MC |
237 | void EC_GROUP_set_point_conversion_form(EC_GROUP *group, |
238 | point_conversion_form_t form); | |
5f3d6f70 BM |
239 | point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); |
240 | ||
9945b460 | 241 | unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); |
5f3d6f70 BM |
242 | size_t EC_GROUP_get_seed_len(const EC_GROUP *); |
243 | size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); | |
48fe4d62 | 244 | |
8e3cced7 MC |
245 | /** Sets the parameters of a ec curve defined by y^2 = x^3 + a*x + b (for GFp) |
246 | * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) | |
ba12070f | 247 | * \param group EC_GROUP object |
8e3cced7 MC |
248 | * \param p BIGNUM with the prime number (GFp) or the polynomial |
249 | * defining the underlying field (GF2m) | |
250 | * \param a BIGNUM with parameter a of the equation | |
251 | * \param b BIGNUM with parameter b of the equation | |
252 | * \param ctx BN_CTX object (optional) | |
253 | * \return 1 on success and 0 if an error occurred | |
254 | */ | |
255 | int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | |
256 | const BIGNUM *b, BN_CTX *ctx); | |
257 | ||
258 | /** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp) | |
259 | * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) | |
260 | * \param group EC_GROUP object | |
261 | * \param p BIGNUM with the prime number (GFp) or the polynomial | |
262 | * defining the underlying field (GF2m) | |
263 | * \param a BIGNUM for parameter a of the equation | |
264 | * \param b BIGNUM for parameter b of the equation | |
265 | * \param ctx BN_CTX object (optional) | |
266 | * \return 1 on success and 0 if an error occurred | |
267 | */ | |
268 | int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, | |
269 | BN_CTX *ctx); | |
270 | ||
271 | /** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve | |
272 | * \param group EC_GROUP object | |
273 | * \param p BIGNUM with the prime number (GFp) or the polynomial | |
274 | * defining the underlying field (GF2m) | |
ba12070f NL |
275 | * \param a BIGNUM with parameter a of the equation |
276 | * \param b BIGNUM with parameter b of the equation | |
277 | * \param ctx BN_CTX object (optional) | |
478b50cf | 278 | * \return 1 on success and 0 if an error occurred |
ba12070f | 279 | */ |
672f943a RL |
280 | DEPRECATEDIN_3(int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, |
281 | const BIGNUM *a, const BIGNUM *b, | |
282 | BN_CTX *ctx)) | |
ba12070f | 283 | |
8e3cced7 | 284 | /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve |
ba12070f | 285 | * \param group EC_GROUP object |
8e3cced7 MC |
286 | * \param p BIGNUM with the prime number (GFp) or the polynomial |
287 | * defining the underlying field (GF2m) | |
ba12070f NL |
288 | * \param a BIGNUM for parameter a of the equation |
289 | * \param b BIGNUM for parameter b of the equation | |
290 | * \param ctx BN_CTX object (optional) | |
478b50cf | 291 | * \return 1 on success and 0 if an error occurred |
ba12070f | 292 | */ |
672f943a RL |
293 | DEPRECATEDIN_3(int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, |
294 | BIGNUM *a, BIGNUM *b, | |
295 | BN_CTX *ctx)) | |
ba12070f | 296 | |
0f113f3e | 297 | # ifndef OPENSSL_NO_EC2M |
8e3cced7 | 298 | /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve |
ba12070f | 299 | * \param group EC_GROUP object |
8e3cced7 MC |
300 | * \param p BIGNUM with the prime number (GFp) or the polynomial |
301 | * defining the underlying field (GF2m) | |
ba12070f NL |
302 | * \param a BIGNUM with parameter a of the equation |
303 | * \param b BIGNUM with parameter b of the equation | |
304 | * \param ctx BN_CTX object (optional) | |
478b50cf | 305 | * \return 1 on success and 0 if an error occurred |
ba12070f | 306 | */ |
672f943a RL |
307 | DEPRECATEDIN_3(int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, |
308 | const BIGNUM *a, const BIGNUM *b, | |
309 | BN_CTX *ctx)) | |
ba12070f | 310 | |
8e3cced7 | 311 | /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve |
ba12070f | 312 | * \param group EC_GROUP object |
8e3cced7 MC |
313 | * \param p BIGNUM with the prime number (GFp) or the polynomial |
314 | * defining the underlying field (GF2m) | |
ba12070f NL |
315 | * \param a BIGNUM for parameter a of the equation |
316 | * \param b BIGNUM for parameter b of the equation | |
317 | * \param ctx BN_CTX object (optional) | |
478b50cf | 318 | * \return 1 on success and 0 if an error occurred |
ba12070f | 319 | */ |
672f943a RL |
320 | DEPRECATEDIN_3(int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, |
321 | BIGNUM *a, BIGNUM *b, | |
322 | BN_CTX *ctx)) | |
0f113f3e MC |
323 | # endif |
324 | /** Returns the number of bits needed to represent a field element | |
ba12070f NL |
325 | * \param group EC_GROUP object |
326 | * \return number of bits needed to represent a field element | |
327 | */ | |
328 | int EC_GROUP_get_degree(const EC_GROUP *group); | |
3a12ce01 | 329 | |
ba12070f NL |
330 | /** Checks whether the parameter in the EC_GROUP define a valid ec group |
331 | * \param group EC_GROUP object | |
332 | * \param ctx BN_CTX object (optional) | |
333 | * \return 1 if group is a valid ec group and 0 otherwise | |
334 | */ | |
af28dd6c | 335 | int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); |
945e15a2 | 336 | |
ba12070f NL |
337 | /** Checks whether the discriminant of the elliptic curve is zero or not |
338 | * \param group EC_GROUP object | |
339 | * \param ctx BN_CTX object (optional) | |
340 | * \return 1 if the discriminant is not zero and 0 otherwise | |
341 | */ | |
342 | int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); | |
343 | ||
344 | /** Compares two EC_GROUP objects | |
345 | * \param a first EC_GROUP object | |
346 | * \param b second EC_GROUP object | |
347 | * \param ctx BN_CTX object (optional) | |
14f46560 | 348 | * \return 0 if the groups are equal, 1 if not, or -1 on error |
ba12070f NL |
349 | */ |
350 | int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); | |
ada0e717 | 351 | |
0f113f3e MC |
352 | /* |
353 | * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after | |
354 | * choosing an appropriate EC_METHOD | |
355 | */ | |
945e15a2 | 356 | |
ba12070f NL |
357 | /** Creates a new EC_GROUP object with the specified parameters defined |
358 | * over GFp (defined by the equation y^2 = x^3 + a*x + b) | |
359 | * \param p BIGNUM with the prime number | |
360 | * \param a BIGNUM with the parameter a of the equation | |
361 | * \param b BIGNUM with the parameter b of the equation | |
362 | * \param ctx BN_CTX object (optional) | |
363 | * \return newly created EC_GROUP object with the specified parameters | |
364 | */ | |
0f113f3e MC |
365 | EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, |
366 | const BIGNUM *b, BN_CTX *ctx); | |
367 | # ifndef OPENSSL_NO_EC2M | |
ba12070f NL |
368 | /** Creates a new EC_GROUP object with the specified parameters defined |
369 | * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b) | |
370 | * \param p BIGNUM with the polynomial defining the underlying field | |
371 | * \param a BIGNUM with the parameter a of the equation | |
372 | * \param b BIGNUM with the parameter b of the equation | |
373 | * \param ctx BN_CTX object (optional) | |
374 | * \return newly created EC_GROUP object with the specified parameters | |
375 | */ | |
0f113f3e MC |
376 | EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, |
377 | const BIGNUM *b, BN_CTX *ctx); | |
378 | # endif | |
60b350a3 | 379 | |
a9612d6c MC |
380 | /** |
381 | * Creates a EC_GROUP object with a curve specified by a NID | |
382 | * \param libctx The associated library context or NULL for the default | |
383 | * context | |
384 | * \param nid NID of the OID of the curve name | |
385 | * \return newly created EC_GROUP object with specified curve or NULL | |
386 | * if an error occurred | |
387 | */ | |
388 | EC_GROUP *EC_GROUP_new_by_curve_name_ex(OPENSSL_CTX *libctx, int nid); | |
389 | ||
390 | /** | |
391 | * Creates a EC_GROUP object with a curve specified by a NID. Same as | |
392 | * EC_GROUP_new_by_curve_name_ex but the libctx is always NULL. | |
393 | * \param nid NID of the OID of the curve name | |
ba12070f NL |
394 | * \return newly created EC_GROUP object with specified curve or NULL |
395 | * if an error occurred | |
396 | */ | |
8b15c740 | 397 | EC_GROUP *EC_GROUP_new_by_curve_name(int nid); |
ba12070f | 398 | |
60b350a3 RS |
399 | /** Creates a new EC_GROUP object from an ECPARAMETERS object |
400 | * \param params pointer to the ECPARAMETERS object | |
401 | * \return newly created EC_GROUP object with specified curve or NULL | |
402 | * if an error occurred | |
403 | */ | |
404 | EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); | |
405 | ||
436ad81f | 406 | /** Creates an ECPARAMETERS object for the given EC_GROUP object. |
60b350a3 RS |
407 | * \param group pointer to the EC_GROUP object |
408 | * \param params pointer to an existing ECPARAMETERS object or NULL | |
409 | * \return pointer to the new ECPARAMETERS object or NULL | |
410 | * if an error occurred. | |
411 | */ | |
412 | ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, | |
413 | ECPARAMETERS *params); | |
414 | ||
415 | /** Creates a new EC_GROUP object from an ECPKPARAMETERS object | |
416 | * \param params pointer to an existing ECPKPARAMETERS object, or NULL | |
417 | * \return newly created EC_GROUP object with specified curve, or NULL | |
418 | * if an error occurred | |
419 | */ | |
420 | EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); | |
421 | ||
436ad81f | 422 | /** Creates an ECPKPARAMETERS object for the given EC_GROUP object. |
60b350a3 RS |
423 | * \param group pointer to the EC_GROUP object |
424 | * \param params pointer to an existing ECPKPARAMETERS object or NULL | |
425 | * \return pointer to the new ECPKPARAMETERS object or NULL | |
426 | * if an error occurred. | |
427 | */ | |
428 | ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, | |
429 | ECPKPARAMETERS *params); | |
430 | ||
ba12070f NL |
431 | /********************************************************************/ |
432 | /* handling of internal curves */ | |
433 | /********************************************************************/ | |
434 | ||
0f113f3e MC |
435 | typedef struct { |
436 | int nid; | |
437 | const char *comment; | |
438 | } EC_builtin_curve; | |
ba12070f | 439 | |
0f113f3e MC |
440 | /* |
441 | * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all | |
8483a003 | 442 | * available curves or zero if a error occurred. In case r is not zero, |
0f113f3e MC |
443 | * nitems EC_builtin_curve structures are filled with the data of the first |
444 | * nitems internal groups | |
445 | */ | |
65b1d31d | 446 | size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); |
7eb18f12 | 447 | |
64095ce9 DSH |
448 | const char *EC_curve_nid2nist(int nid); |
449 | int EC_curve_nist2nid(const char *name); | |
a9612d6c MC |
450 | int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only, |
451 | BN_CTX *ctx); | |
7e31164a | 452 | |
ba12070f NL |
453 | /********************************************************************/ |
454 | /* EC_POINT functions */ | |
455 | /********************************************************************/ | |
456 | ||
457 | /** Creates a new EC_POINT object for the specified EC_GROUP | |
458 | * \param group EC_GROUP the underlying EC_GROUP object | |
459 | * \return newly created EC_POINT object or NULL if an error occurred | |
460 | */ | |
461 | EC_POINT *EC_POINT_new(const EC_GROUP *group); | |
462 | ||
463 | /** Frees a EC_POINT object | |
464 | * \param point EC_POINT object to be freed | |
465 | */ | |
466 | void EC_POINT_free(EC_POINT *point); | |
467 | ||
468 | /** Clears and frees a EC_POINT object | |
469 | * \param point EC_POINT object to be cleared and freed | |
470 | */ | |
471 | void EC_POINT_clear_free(EC_POINT *point); | |
472 | ||
473 | /** Copies EC_POINT object | |
474 | * \param dst destination EC_POINT object | |
475 | * \param src source EC_POINT object | |
478b50cf | 476 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
477 | */ |
478 | int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); | |
945e15a2 | 479 | |
ba12070f NL |
480 | /** Creates a new EC_POINT object and copies the content of the supplied |
481 | * EC_POINT | |
482 | * \param src source EC_POINT object | |
483 | * \param group underlying the EC_GROUP object | |
0f113f3e | 484 | * \return newly created EC_POINT object or NULL if an error occurred |
ba12070f NL |
485 | */ |
486 | EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); | |
0f113f3e MC |
487 | |
488 | /** Returns the EC_METHOD used in EC_POINT object | |
ba12070f NL |
489 | * \param point EC_POINT object |
490 | * \return the EC_METHOD used | |
491 | */ | |
492 | const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); | |
493 | ||
494 | /** Sets a point to infinity (neutral element) | |
495 | * \param group underlying EC_GROUP object | |
496 | * \param point EC_POINT to set to infinity | |
478b50cf | 497 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
498 | */ |
499 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); | |
500 | ||
501 | /** Sets the jacobian projective coordinates of a EC_POINT over GFp | |
502 | * \param group underlying EC_GROUP object | |
503 | * \param p EC_POINT object | |
504 | * \param x BIGNUM with the x-coordinate | |
505 | * \param y BIGNUM with the y-coordinate | |
506 | * \param z BIGNUM with the z-coordinate | |
507 | * \param ctx BN_CTX object (optional) | |
478b50cf | 508 | * \return 1 on success and 0 if an error occurred |
ba12070f | 509 | */ |
0f113f3e MC |
510 | int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, |
511 | EC_POINT *p, const BIGNUM *x, | |
512 | const BIGNUM *y, const BIGNUM *z, | |
513 | BN_CTX *ctx); | |
ba12070f NL |
514 | |
515 | /** Gets the jacobian projective coordinates of a EC_POINT over GFp | |
516 | * \param group underlying EC_GROUP object | |
517 | * \param p EC_POINT object | |
518 | * \param x BIGNUM for the x-coordinate | |
519 | * \param y BIGNUM for the y-coordinate | |
520 | * \param z BIGNUM for the z-coordinate | |
521 | * \param ctx BN_CTX object (optional) | |
478b50cf | 522 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
523 | */ |
524 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, | |
0f113f3e MC |
525 | const EC_POINT *p, BIGNUM *x, |
526 | BIGNUM *y, BIGNUM *z, | |
527 | BN_CTX *ctx); | |
ba12070f | 528 | |
8e3cced7 MC |
529 | /** Sets the affine coordinates of an EC_POINT |
530 | * \param group underlying EC_GROUP object | |
531 | * \param p EC_POINT object | |
532 | * \param x BIGNUM with the x-coordinate | |
533 | * \param y BIGNUM with the y-coordinate | |
534 | * \param ctx BN_CTX object (optional) | |
535 | * \return 1 on success and 0 if an error occurred | |
536 | */ | |
537 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, | |
538 | const BIGNUM *x, const BIGNUM *y, | |
539 | BN_CTX *ctx); | |
540 | ||
541 | /** Gets the affine coordinates of an EC_POINT. | |
542 | * \param group underlying EC_GROUP object | |
543 | * \param p EC_POINT object | |
544 | * \param x BIGNUM for the x-coordinate | |
545 | * \param y BIGNUM for the y-coordinate | |
546 | * \param ctx BN_CTX object (optional) | |
547 | * \return 1 on success and 0 if an error occurred | |
548 | */ | |
549 | int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, | |
550 | BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | |
551 | ||
552 | /** Sets the affine coordinates of an EC_POINT. A synonym of | |
553 | * EC_POINT_set_affine_coordinates | |
ba12070f NL |
554 | * \param group underlying EC_GROUP object |
555 | * \param p EC_POINT object | |
556 | * \param x BIGNUM with the x-coordinate | |
557 | * \param y BIGNUM with the y-coordinate | |
558 | * \param ctx BN_CTX object (optional) | |
478b50cf | 559 | * \return 1 on success and 0 if an error occurred |
ba12070f | 560 | */ |
672f943a RL |
561 | DEPRECATEDIN_3(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, |
562 | EC_POINT *p, | |
563 | const BIGNUM *x, | |
564 | const BIGNUM *y, | |
565 | BN_CTX *ctx)) | |
ba12070f | 566 | |
8e3cced7 MC |
567 | /** Gets the affine coordinates of an EC_POINT. A synonym of |
568 | * EC_POINT_get_affine_coordinates | |
ba12070f NL |
569 | * \param group underlying EC_GROUP object |
570 | * \param p EC_POINT object | |
571 | * \param x BIGNUM for the x-coordinate | |
572 | * \param y BIGNUM for the y-coordinate | |
573 | * \param ctx BN_CTX object (optional) | |
478b50cf | 574 | * \return 1 on success and 0 if an error occurred |
ba12070f | 575 | */ |
672f943a RL |
576 | DEPRECATEDIN_3(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, |
577 | const EC_POINT *p, | |
578 | BIGNUM *x, | |
579 | BIGNUM *y, | |
580 | BN_CTX *ctx)) | |
ba12070f | 581 | |
8e3cced7 MC |
582 | /** Sets the x9.62 compressed coordinates of a EC_POINT |
583 | * \param group underlying EC_GROUP object | |
584 | * \param p EC_POINT object | |
585 | * \param x BIGNUM with x-coordinate | |
586 | * \param y_bit integer with the y-Bit (either 0 or 1) | |
587 | * \param ctx BN_CTX object (optional) | |
588 | * \return 1 on success and 0 if an error occurred | |
589 | */ | |
590 | int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, | |
591 | const BIGNUM *x, int y_bit, | |
592 | BN_CTX *ctx); | |
593 | ||
594 | /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of | |
595 | * EC_POINT_set_compressed_coordinates | |
ba12070f NL |
596 | * \param group underlying EC_GROUP object |
597 | * \param p EC_POINT object | |
598 | * \param x BIGNUM with x-coordinate | |
599 | * \param y_bit integer with the y-Bit (either 0 or 1) | |
600 | * \param ctx BN_CTX object (optional) | |
478b50cf | 601 | * \return 1 on success and 0 if an error occurred |
ba12070f | 602 | */ |
672f943a RL |
603 | DEPRECATEDIN_3(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, |
604 | EC_POINT *p, | |
605 | const BIGNUM *x, | |
606 | int y_bit, | |
607 | BN_CTX *ctx)) | |
0f113f3e | 608 | # ifndef OPENSSL_NO_EC2M |
8e3cced7 MC |
609 | /** Sets the affine coordinates of an EC_POINT. A synonym of |
610 | * EC_POINT_set_affine_coordinates | |
ba12070f NL |
611 | * \param group underlying EC_GROUP object |
612 | * \param p EC_POINT object | |
613 | * \param x BIGNUM with the x-coordinate | |
614 | * \param y BIGNUM with the y-coordinate | |
615 | * \param ctx BN_CTX object (optional) | |
478b50cf | 616 | * \return 1 on success and 0 if an error occurred |
ba12070f | 617 | */ |
672f943a RL |
618 | DEPRECATEDIN_3(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, |
619 | EC_POINT *p, | |
620 | const BIGNUM *x, | |
621 | const BIGNUM *y, | |
622 | BN_CTX *ctx)) | |
ba12070f | 623 | |
8e3cced7 MC |
624 | /** Gets the affine coordinates of an EC_POINT. A synonym of |
625 | * EC_POINT_get_affine_coordinates | |
ba12070f NL |
626 | * \param group underlying EC_GROUP object |
627 | * \param p EC_POINT object | |
628 | * \param x BIGNUM for the x-coordinate | |
629 | * \param y BIGNUM for the y-coordinate | |
630 | * \param ctx BN_CTX object (optional) | |
478b50cf | 631 | * \return 1 on success and 0 if an error occurred |
ba12070f | 632 | */ |
672f943a RL |
633 | DEPRECATEDIN_3(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, |
634 | const EC_POINT *p, | |
635 | BIGNUM *x, | |
636 | BIGNUM *y, | |
637 | BN_CTX *ctx)) | |
ba12070f | 638 | |
8e3cced7 MC |
639 | /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of |
640 | * EC_POINT_set_compressed_coordinates | |
ba12070f NL |
641 | * \param group underlying EC_GROUP object |
642 | * \param p EC_POINT object | |
643 | * \param x BIGNUM with x-coordinate | |
644 | * \param y_bit integer with the y-Bit (either 0 or 1) | |
645 | * \param ctx BN_CTX object (optional) | |
478b50cf | 646 | * \return 1 on success and 0 if an error occurred |
ba12070f | 647 | */ |
672f943a RL |
648 | DEPRECATEDIN_3(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, |
649 | EC_POINT *p, | |
650 | const BIGNUM *x, | |
651 | int y_bit, | |
652 | BN_CTX *ctx)) | |
0f113f3e | 653 | # endif |
ba12070f NL |
654 | /** Encodes a EC_POINT object to a octet string |
655 | * \param group underlying EC_GROUP object | |
656 | * \param p EC_POINT object | |
657 | * \param form point conversion form | |
658 | * \param buf memory buffer for the result. If NULL the function returns | |
659 | * required buffer size. | |
660 | * \param len length of the memory buffer | |
661 | * \param ctx BN_CTX object (optional) | |
662 | * \return the length of the encoded octet string or 0 if an error occurred | |
663 | */ | |
664 | size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, | |
0f113f3e MC |
665 | point_conversion_form_t form, |
666 | unsigned char *buf, size_t len, BN_CTX *ctx); | |
ba12070f NL |
667 | |
668 | /** Decodes a EC_POINT from a octet string | |
669 | * \param group underlying EC_GROUP object | |
670 | * \param p EC_POINT object | |
671 | * \param buf memory buffer with the encoded ec point | |
672 | * \param len length of the encoded ec point | |
673 | * \param ctx BN_CTX object (optional) | |
478b50cf | 674 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
675 | */ |
676 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, | |
0f113f3e | 677 | const unsigned char *buf, size_t len, BN_CTX *ctx); |
7d7db13e | 678 | |
981bd8a2 DSH |
679 | /** Encodes an EC_POINT object to an allocated octet string |
680 | * \param group underlying EC_GROUP object | |
681 | * \param point EC_POINT object | |
682 | * \param form point conversion form | |
683 | * \param pbuf returns pointer to allocated buffer | |
981bd8a2 DSH |
684 | * \param ctx BN_CTX object (optional) |
685 | * \return the length of the encoded octet string or 0 if an error occurred | |
686 | */ | |
981bd8a2 DSH |
687 | size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, |
688 | point_conversion_form_t form, | |
689 | unsigned char **pbuf, BN_CTX *ctx); | |
690 | ||
6cbe6382 BM |
691 | /* other interfaces to point2oct/oct2point: */ |
692 | BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, | |
0f113f3e | 693 | point_conversion_form_t form, BIGNUM *, BN_CTX *); |
6cbe6382 | 694 | EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, |
0f113f3e | 695 | EC_POINT *, BN_CTX *); |
6cbe6382 | 696 | char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, |
0f113f3e | 697 | point_conversion_form_t form, BN_CTX *); |
6cbe6382 | 698 | EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, |
0f113f3e | 699 | EC_POINT *, BN_CTX *); |
3a12ce01 | 700 | |
ba12070f NL |
701 | /********************************************************************/ |
702 | /* functions for doing EC_POINT arithmetic */ | |
703 | /********************************************************************/ | |
704 | ||
0f113f3e | 705 | /** Computes the sum of two EC_POINT |
ba12070f NL |
706 | * \param group underlying EC_GROUP object |
707 | * \param r EC_POINT object for the result (r = a + b) | |
708 | * \param a EC_POINT object with the first summand | |
709 | * \param b EC_POINT object with the second summand | |
710 | * \param ctx BN_CTX object (optional) | |
478b50cf | 711 | * \return 1 on success and 0 if an error occurred |
ba12070f | 712 | */ |
0f113f3e MC |
713 | int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
714 | const EC_POINT *b, BN_CTX *ctx); | |
ba12070f NL |
715 | |
716 | /** Computes the double of a EC_POINT | |
717 | * \param group underlying EC_GROUP object | |
718 | * \param r EC_POINT object for the result (r = 2 * a) | |
0f113f3e | 719 | * \param a EC_POINT object |
ba12070f | 720 | * \param ctx BN_CTX object (optional) |
478b50cf | 721 | * \return 1 on success and 0 if an error occurred |
ba12070f | 722 | */ |
0f113f3e MC |
723 | int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
724 | BN_CTX *ctx); | |
ba12070f NL |
725 | |
726 | /** Computes the inverse of a EC_POINT | |
727 | * \param group underlying EC_GROUP object | |
728 | * \param a EC_POINT object to be inverted (it's used for the result as well) | |
729 | * \param ctx BN_CTX object (optional) | |
478b50cf | 730 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
731 | */ |
732 | int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); | |
733 | ||
734 | /** Checks whether the point is the neutral element of the group | |
735 | * \param group the underlying EC_GROUP object | |
736 | * \param p EC_POINT object | |
737 | * \return 1 if the point is the neutral element and 0 otherwise | |
738 | */ | |
739 | int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); | |
740 | ||
0f113f3e | 741 | /** Checks whether the point is on the curve |
ba12070f NL |
742 | * \param group underlying EC_GROUP object |
743 | * \param point EC_POINT object to check | |
744 | * \param ctx BN_CTX object (optional) | |
14f46560 | 745 | * \return 1 if the point is on the curve, 0 if not, or -1 on error |
ba12070f | 746 | */ |
0f113f3e MC |
747 | int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, |
748 | BN_CTX *ctx); | |
ba12070f | 749 | |
0f113f3e | 750 | /** Compares two EC_POINTs |
ba12070f NL |
751 | * \param group underlying EC_GROUP object |
752 | * \param a first EC_POINT object | |
753 | * \param b second EC_POINT object | |
754 | * \param ctx BN_CTX object (optional) | |
14f46560 | 755 | * \return 1 if the points are not equal, 0 if they are, or -1 on error |
ba12070f | 756 | */ |
0f113f3e MC |
757 | int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, |
758 | BN_CTX *ctx); | |
fb171e53 | 759 | |
9945b460 | 760 | int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); |
0f113f3e MC |
761 | int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, |
762 | EC_POINT *points[], BN_CTX *ctx); | |
fb171e53 | 763 | |
14f46560 | 764 | /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i] |
ba12070f NL |
765 | * \param group underlying EC_GROUP object |
766 | * \param r EC_POINT object for the result | |
767 | * \param n BIGNUM with the multiplier for the group generator (optional) | |
8483a003 | 768 | * \param num number further summands |
ba12070f NL |
769 | * \param p array of size num of EC_POINT objects |
770 | * \param m array of size num of BIGNUM objects | |
771 | * \param ctx BN_CTX object (optional) | |
478b50cf | 772 | * \return 1 on success and 0 if an error occurred |
ba12070f | 773 | */ |
0f113f3e MC |
774 | int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, |
775 | size_t num, const EC_POINT *p[], const BIGNUM *m[], | |
776 | BN_CTX *ctx); | |
ba12070f NL |
777 | |
778 | /** Computes r = generator * n + q * m | |
779 | * \param group underlying EC_GROUP object | |
780 | * \param r EC_POINT object for the result | |
781 | * \param n BIGNUM with the multiplier for the group generator (optional) | |
782 | * \param q EC_POINT object with the first factor of the second summand | |
783 | * \param m BIGNUM with the second factor of the second summand | |
784 | * \param ctx BN_CTX object (optional) | |
478b50cf | 785 | * \return 1 on success and 0 if an error occurred |
ba12070f | 786 | */ |
0f113f3e MC |
787 | int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, |
788 | const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); | |
3a12ce01 | 789 | |
ba12070f NL |
790 | /** Stores multiples of generator for faster point multiplication |
791 | * \param group EC_GROUP object | |
792 | * \param ctx BN_CTX object (optional) | |
478b50cf | 793 | * \return 1 on success and 0 if an error occurred |
ba12070f NL |
794 | */ |
795 | int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | |
6cc5e19d | 796 | |
ba12070f NL |
797 | /** Reports whether a precomputation has been done |
798 | * \param group EC_GROUP object | |
799 | * \return 1 if a pre-computation has been done and 0 otherwise | |
800 | */ | |
801 | int EC_GROUP_have_precompute_mult(const EC_GROUP *group); | |
6cc5e19d | 802 | |
ba12070f NL |
803 | /********************************************************************/ |
804 | /* ASN1 stuff */ | |
805 | /********************************************************************/ | |
8aefe253 | 806 | |
60b350a3 | 807 | DECLARE_ASN1_ITEM(ECPKPARAMETERS) |
9ba6f347 | 808 | DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS) |
60b350a3 | 809 | DECLARE_ASN1_ITEM(ECPARAMETERS) |
9ba6f347 | 810 | DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) |
60b350a3 | 811 | |
0f113f3e MC |
812 | /* |
813 | * EC_GROUP_get_basis_type() returns the NID of the basis type used to | |
814 | * represent the field elements | |
815 | */ | |
34f1f2a8 | 816 | int EC_GROUP_get_basis_type(const EC_GROUP *); |
0f113f3e | 817 | # ifndef OPENSSL_NO_EC2M |
34f1f2a8 | 818 | int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); |
0f113f3e MC |
819 | int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, |
820 | unsigned int *k2, unsigned int *k3); | |
821 | # endif | |
8aefe253 | 822 | |
86f300d3 DSH |
823 | # define OPENSSL_EC_EXPLICIT_CURVE 0x000 |
824 | # define OPENSSL_EC_NAMED_CURVE 0x001 | |
458c2917 | 825 | |
6343829a | 826 | EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); |
458c2917 BM |
827 | int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); |
828 | ||
0f113f3e | 829 | # define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x) |
9fdcc21f | 830 | # define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of(EC_GROUP,i2d_ECPKParameters,bp,x) |
0f113f3e | 831 | # define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \ |
5dbd3efc | 832 | (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x)) |
0f113f3e MC |
833 | # define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \ |
834 | (unsigned char *)(x)) | |
5f3d6f70 | 835 | |
0f113f3e | 836 | int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); |
0f113f3e MC |
837 | # ifndef OPENSSL_NO_STDIO |
838 | int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); | |
839 | # endif | |
ba12070f NL |
840 | |
841 | /********************************************************************/ | |
842 | /* EC_KEY functions */ | |
843 | /********************************************************************/ | |
844 | ||
14a7cfb3 | 845 | /* some values for the encoding_flag */ |
0f113f3e MC |
846 | # define EC_PKEY_NO_PARAMETERS 0x001 |
847 | # define EC_PKEY_NO_PUBKEY 0x002 | |
14a7cfb3 | 848 | |
cac4fb58 | 849 | /* some values for the flags field */ |
0f113f3e MC |
850 | # define EC_FLAG_NON_FIPS_ALLOW 0x1 |
851 | # define EC_FLAG_FIPS_CHECKED 0x2 | |
a22a7e70 | 852 | # define EC_FLAG_COFACTOR_ECDH 0x1000 |
cac4fb58 | 853 | |
a9612d6c MC |
854 | /** |
855 | * Creates a new EC_KEY object. | |
856 | * \param ctx The library context for to use for this EC_KEY. May be NULL in | |
857 | * which case the default library context is used. | |
858 | * \return EC_KEY object or NULL if an error occurred. | |
859 | */ | |
860 | EC_KEY *EC_KEY_new_ex(OPENSSL_CTX *ctx); | |
861 | ||
862 | /** | |
863 | * Creates a new EC_KEY object. Same as calling EC_KEY_new_ex with a NULL | |
864 | * library context | |
ba12070f NL |
865 | * \return EC_KEY object or NULL if an error occurred. |
866 | */ | |
14a7cfb3 | 867 | EC_KEY *EC_KEY_new(void); |
ba12070f | 868 | |
cac4fb58 DSH |
869 | int EC_KEY_get_flags(const EC_KEY *key); |
870 | ||
871 | void EC_KEY_set_flags(EC_KEY *key, int flags); | |
872 | ||
873 | void EC_KEY_clear_flags(EC_KEY *key, int flags); | |
874 | ||
a9612d6c MC |
875 | /** |
876 | * Creates a new EC_KEY object using a named curve as underlying | |
ba12070f | 877 | * EC_GROUP object. |
a9612d6c MC |
878 | * \param ctx The library context for to use for this EC_KEY. May be NULL in |
879 | * which case the default library context is used. | |
880 | * \param nid NID of the named curve. | |
881 | * \return EC_KEY object or NULL if an error occurred. | |
882 | */ | |
883 | EC_KEY *EC_KEY_new_by_curve_name_ex(OPENSSL_CTX *ctx, int nid); | |
884 | ||
885 | /** | |
886 | * Creates a new EC_KEY object using a named curve as underlying | |
887 | * EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL | |
888 | * library context. | |
ba12070f | 889 | * \param nid NID of the named curve. |
0f113f3e | 890 | * \return EC_KEY object or NULL if an error occurred. |
ba12070f | 891 | */ |
9dd84053 | 892 | EC_KEY *EC_KEY_new_by_curve_name(int nid); |
ba12070f | 893 | |
a9612d6c | 894 | |
ba12070f NL |
895 | /** Frees a EC_KEY object. |
896 | * \param key EC_KEY object to be freed. | |
897 | */ | |
898 | void EC_KEY_free(EC_KEY *key); | |
899 | ||
900 | /** Copies a EC_KEY object. | |
901 | * \param dst destination EC_KEY object | |
902 | * \param src src EC_KEY object | |
903 | * \return dst or NULL if an error occurred. | |
904 | */ | |
4a9a0d9b | 905 | EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); |
ba12070f NL |
906 | |
907 | /** Creates a new EC_KEY object and copies the content from src to it. | |
908 | * \param src the source EC_KEY object | |
909 | * \return newly created EC_KEY object or NULL if an error occurred. | |
910 | */ | |
4a9a0d9b | 911 | EC_KEY *EC_KEY_dup(const EC_KEY *src); |
ba12070f NL |
912 | |
913 | /** Increases the internal reference count of a EC_KEY object. | |
914 | * \param key EC_KEY object | |
915 | * \return 1 on success and 0 if an error occurred. | |
916 | */ | |
917 | int EC_KEY_up_ref(EC_KEY *key); | |
918 | ||
d1da335c | 919 | /** Returns the ENGINE object of a EC_KEY object |
28c0a61b | 920 | * \param eckey EC_KEY object |
d1da335c RL |
921 | * \return the ENGINE object (possibly NULL). |
922 | */ | |
923 | ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey); | |
924 | ||
ba12070f NL |
925 | /** Returns the EC_GROUP object of a EC_KEY object |
926 | * \param key EC_KEY object | |
927 | * \return the EC_GROUP object (possibly NULL). | |
928 | */ | |
929 | const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); | |
930 | ||
931 | /** Sets the EC_GROUP of a EC_KEY object. | |
932 | * \param key EC_KEY object | |
933 | * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY | |
934 | * object will use an own copy of the EC_GROUP). | |
935 | * \return 1 on success and 0 if an error occurred. | |
936 | */ | |
937 | int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); | |
938 | ||
939 | /** Returns the private key of a EC_KEY object. | |
940 | * \param key EC_KEY object | |
941 | * \return a BIGNUM with the private key (possibly NULL). | |
942 | */ | |
943 | const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); | |
944 | ||
945 | /** Sets the private key of a EC_KEY object. | |
946 | * \param key EC_KEY object | |
947 | * \param prv BIGNUM with the private key (note: the EC_KEY object | |
948 | * will use an own copy of the BIGNUM). | |
949 | * \return 1 on success and 0 if an error occurred. | |
950 | */ | |
951 | int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); | |
952 | ||
953 | /** Returns the public key of a EC_KEY object. | |
954 | * \param key the EC_KEY object | |
955 | * \return a EC_POINT object with the public key (possibly NULL) | |
956 | */ | |
957 | const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); | |
958 | ||
959 | /** Sets the public key of a EC_KEY object. | |
960 | * \param key EC_KEY object | |
961 | * \param pub EC_POINT object with the public key (note: the EC_KEY object | |
962 | * will use an own copy of the EC_POINT object). | |
963 | * \return 1 on success and 0 if an error occurred. | |
964 | */ | |
965 | int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); | |
966 | ||
967 | unsigned EC_KEY_get_enc_flags(const EC_KEY *key); | |
9945b460 DSH |
968 | void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); |
969 | point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); | |
970 | void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); | |
3aef36ff RS |
971 | |
972 | #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ | |
973 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) | |
974 | int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); | |
975 | void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); | |
976 | ||
9dd84053 | 977 | /* wrapper functions for the underlying EC_GROUP object */ |
9945b460 | 978 | void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); |
ba12070f | 979 | |
0f113f3e | 980 | /** Creates a table of pre-computed multiples of the generator to |
ba12070f NL |
981 | * accelerate further EC_KEY operations. |
982 | * \param key EC_KEY object | |
983 | * \param ctx BN_CTX object (optional) | |
984 | * \return 1 on success and 0 if an error occurred. | |
985 | */ | |
986 | int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); | |
987 | ||
988 | /** Creates a new ec private (and optional a new public) key. | |
989 | * \param key EC_KEY object | |
990 | * \return 1 on success and 0 if an error occurred. | |
991 | */ | |
992 | int EC_KEY_generate_key(EC_KEY *key); | |
993 | ||
994 | /** Verifies that a private and/or public key is valid. | |
995 | * \param key the EC_KEY object | |
996 | * \return 1 on success and 0 otherwise. | |
997 | */ | |
998 | int EC_KEY_check_key(const EC_KEY *key); | |
999 | ||
4b0555ec | 1000 | /** Indicates if an EC_KEY can be used for signing. |
f5fd3848 | 1001 | * \param eckey the EC_KEY object |
4b0555ec DSH |
1002 | * \return 1 if can can sign and 0 otherwise. |
1003 | */ | |
1004 | int EC_KEY_can_sign(const EC_KEY *eckey); | |
1005 | ||
8483a003 | 1006 | /** Sets a public key from affine coordinates performing |
478b50cf | 1007 | * necessary NIST PKV tests. |
fef1c40b DSH |
1008 | * \param key the EC_KEY object |
1009 | * \param x public key x coordinate | |
1010 | * \param y public key y coordinate | |
1011 | * \return 1 on success and 0 otherwise. | |
1012 | */ | |
0f113f3e MC |
1013 | int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, |
1014 | BIGNUM *y); | |
ba12070f | 1015 | |
981bd8a2 DSH |
1016 | /** Encodes an EC_KEY public key to an allocated octet string |
1017 | * \param key key to encode | |
1018 | * \param form point conversion form | |
1019 | * \param pbuf returns pointer to allocated buffer | |
981bd8a2 DSH |
1020 | * \param ctx BN_CTX object (optional) |
1021 | * \return the length of the encoded octet string or 0 if an error occurred | |
1022 | */ | |
981bd8a2 DSH |
1023 | size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form, |
1024 | unsigned char **pbuf, BN_CTX *ctx); | |
1025 | ||
1026 | /** Decodes a EC_KEY public key from a octet string | |
1027 | * \param key key to decode | |
1028 | * \param buf memory buffer with the encoded ec point | |
1029 | * \param len length of the encoded ec point | |
1030 | * \param ctx BN_CTX object (optional) | |
1031 | * \return 1 on success and 0 if an error occurred | |
1032 | */ | |
1033 | ||
1034 | int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len, | |
1035 | BN_CTX *ctx); | |
1036 | ||
cf241395 DSH |
1037 | /** Decodes an EC_KEY private key from an octet string |
1038 | * \param key key to decode | |
1039 | * \param buf memory buffer with the encoded private key | |
1040 | * \param len length of the encoded key | |
1041 | * \return 1 on success and 0 if an error occurred | |
1042 | */ | |
1043 | ||
25d57dc7 | 1044 | int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len); |
cf241395 DSH |
1045 | |
1046 | /** Encodes a EC_KEY private key to an octet string | |
1047 | * \param key key to encode | |
1048 | * \param buf memory buffer for the result. If NULL the function returns | |
1049 | * required buffer size. | |
1050 | * \param len length of the memory buffer | |
1051 | * \return the length of the encoded octet string or 0 if an error occurred | |
1052 | */ | |
1053 | ||
1054 | size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len); | |
1055 | ||
7fc7d1a7 | 1056 | /** Encodes an EC_KEY private key to an allocated octet string |
f5fd3848 | 1057 | * \param eckey key to encode |
7fc7d1a7 DSH |
1058 | * \param pbuf returns pointer to allocated buffer |
1059 | * \return the length of the encoded octet string or 0 if an error occurred | |
1060 | */ | |
7fc7d1a7 | 1061 | size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf); |
cf241395 | 1062 | |
ba12070f NL |
1063 | /********************************************************************/ |
1064 | /* de- and encoding functions for SEC1 ECPrivateKey */ | |
1065 | /********************************************************************/ | |
1066 | ||
1067 | /** Decodes a private key from a memory buffer. | |
1068 | * \param key a pointer to a EC_KEY object which should be used (or NULL) | |
1069 | * \param in pointer to memory with the DER encoded private key | |
1070 | * \param len length of the DER encoded private key | |
1071 | * \return the decoded private key or NULL if an error occurred. | |
1072 | */ | |
6343829a | 1073 | EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); |
ba12070f NL |
1074 | |
1075 | /** Encodes a private key object and stores the result in a buffer. | |
1076 | * \param key the EC_KEY object to encode | |
1077 | * \param out the buffer for the result (if NULL the function returns number | |
1078 | * of bytes needed). | |
1079 | * \return 1 on success and 0 if an error occurred. | |
1080 | */ | |
9fdcc21f | 1081 | int i2d_ECPrivateKey(const EC_KEY *key, unsigned char **out); |
ba12070f | 1082 | |
ba12070f NL |
1083 | /********************************************************************/ |
1084 | /* de- and encoding functions for EC parameters */ | |
1085 | /********************************************************************/ | |
1086 | ||
1087 | /** Decodes ec parameter from a memory buffer. | |
1088 | * \param key a pointer to a EC_KEY object which should be used (or NULL) | |
1089 | * \param in pointer to memory with the DER encoded ec parameters | |
1090 | * \param len length of the DER encoded ec parameters | |
1091 | * \return a EC_KEY object with the decoded parameters or NULL if an error | |
1092 | * occurred. | |
1093 | */ | |
1094 | EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); | |
1095 | ||
1096 | /** Encodes ec parameter and stores the result in a buffer. | |
1afd7fa9 | 1097 | * \param key the EC_KEY object with ec parameters to encode |
ba12070f NL |
1098 | * \param out the buffer for the result (if NULL the function returns number |
1099 | * of bytes needed). | |
1100 | * \return 1 on success and 0 if an error occurred. | |
1101 | */ | |
9fdcc21f | 1102 | int i2d_ECParameters(const EC_KEY *key, unsigned char **out); |
ba12070f | 1103 | |
ba12070f NL |
1104 | /********************************************************************/ |
1105 | /* de- and encoding functions for EC public key */ | |
1106 | /* (octet string, not DER -- hence 'o2i' and 'i2o') */ | |
1107 | /********************************************************************/ | |
1108 | ||
1109 | /** Decodes a ec public key from a octet string. | |
1110 | * \param key a pointer to a EC_KEY object which should be used | |
1111 | * \param in memory buffer with the encoded public key | |
1112 | * \param len length of the encoded public key | |
1113 | * \return EC_KEY object with decoded public key or NULL if an error | |
1114 | * occurred. | |
1115 | */ | |
1116 | EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); | |
1117 | ||
1118 | /** Encodes a ec public key in an octet string. | |
1119 | * \param key the EC_KEY object with the public key | |
1120 | * \param out the buffer for the result (if NULL the function returns number | |
1121 | * of bytes needed). | |
1122 | * \return 1 on success and 0 if an error occurred | |
1123 | */ | |
60c25873 | 1124 | int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); |
14a7cfb3 | 1125 | |
ba12070f NL |
1126 | /** Prints out the ec parameters on human readable form. |
1127 | * \param bp BIO object to which the information is printed | |
1128 | * \param key EC_KEY object | |
1129 | * \return 1 on success and 0 if an error occurred | |
1130 | */ | |
0f113f3e | 1131 | int ECParameters_print(BIO *bp, const EC_KEY *key); |
ba12070f NL |
1132 | |
1133 | /** Prints out the contents of a EC_KEY object | |
1134 | * \param bp BIO object to which the information is printed | |
1135 | * \param key EC_KEY object | |
0f113f3e | 1136 | * \param off line offset |
ba12070f NL |
1137 | * \return 1 on success and 0 if an error occurred |
1138 | */ | |
0f113f3e | 1139 | int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); |
ba12070f | 1140 | |
0f113f3e | 1141 | # ifndef OPENSSL_NO_STDIO |
ba12070f NL |
1142 | /** Prints out the ec parameters on human readable form. |
1143 | * \param fp file descriptor to which the information is printed | |
1144 | * \param key EC_KEY object | |
1145 | * \return 1 on success and 0 if an error occurred | |
1146 | */ | |
0f113f3e | 1147 | int ECParameters_print_fp(FILE *fp, const EC_KEY *key); |
ba12070f NL |
1148 | |
1149 | /** Prints out the contents of a EC_KEY object | |
1150 | * \param fp file descriptor to which the information is printed | |
1151 | * \param key EC_KEY object | |
0f113f3e | 1152 | * \param off line offset |
ba12070f NL |
1153 | * \return 1 on success and 0 if an error occurred |
1154 | */ | |
0f113f3e | 1155 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); |
ba12070f | 1156 | |
0f113f3e | 1157 | # endif |
0bee0e62 | 1158 | |
28572b57 DSH |
1159 | const EC_KEY_METHOD *EC_KEY_OpenSSL(void); |
1160 | const EC_KEY_METHOD *EC_KEY_get_default_method(void); | |
1161 | void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); | |
3aef36ff RS |
1162 | const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); |
1163 | int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); | |
28572b57 DSH |
1164 | EC_KEY *EC_KEY_new_method(ENGINE *engine); |
1165 | ||
ffd89124 AS |
1166 | /** The old name for ecdh_KDF_X9_63 |
1167 | * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, | |
1168 | * it is actually specified in ANSI X9.63. | |
1169 | * This identifier is retained for backwards compatibility | |
1170 | */ | |
672f943a RL |
1171 | DEPRECATEDIN_3(int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, |
1172 | const unsigned char *Z, size_t Zlen, | |
1173 | const unsigned char *sinfo, size_t sinfolen, | |
1174 | const EVP_MD *md)) | |
768c53e1 | 1175 | |
a22a7e70 | 1176 | int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, |
2c61a5ec DSH |
1177 | const EC_KEY *ecdh, |
1178 | void *(*KDF) (const void *in, size_t inlen, | |
1179 | void *out, size_t *outlen)); | |
a22a7e70 | 1180 | |
714b2abb DSH |
1181 | typedef struct ECDSA_SIG_st ECDSA_SIG; |
1182 | ||
ef5b2ba6 DSH |
1183 | /** Allocates and initialize a ECDSA_SIG structure |
1184 | * \return pointer to a ECDSA_SIG structure or NULL if an error occurred | |
1185 | */ | |
1186 | ECDSA_SIG *ECDSA_SIG_new(void); | |
1187 | ||
1188 | /** frees a ECDSA_SIG structure | |
1189 | * \param sig pointer to the ECDSA_SIG structure | |
1190 | */ | |
1191 | void ECDSA_SIG_free(ECDSA_SIG *sig); | |
1192 | ||
9fdcc21f | 1193 | /** i2d_ECDSA_SIG encodes content of ECDSA_SIG (note: this function modifies *pp |
ef5b2ba6 DSH |
1194 | * (*pp += length of the DER encoded signature)). |
1195 | * \param sig pointer to the ECDSA_SIG object | |
1196 | * \param pp pointer to a unsigned char pointer for the output or NULL | |
bbda7997 MC |
1197 | * \return the length of the DER encoded ECDSA_SIG object or a negative value |
1198 | * on error | |
ef5b2ba6 | 1199 | */ |
9fdcc21f | 1200 | DECLARE_ASN1_ENCODE_FUNCTIONS_only(ECDSA_SIG, ECDSA_SIG) |
ef5b2ba6 | 1201 | |
9fdcc21f | 1202 | /** d2i_ECDSA_SIG decodes an ECDSA signature (note: this function modifies *pp |
ef5b2ba6 DSH |
1203 | * (*pp += len)). |
1204 | * \param sig pointer to ECDSA_SIG pointer (may be NULL) | |
1205 | * \param pp memory buffer with the DER encoded signature | |
1206 | * \param len length of the buffer | |
1207 | * \return pointer to the decoded ECDSA_SIG structure (or NULL) | |
1208 | */ | |
ef5b2ba6 | 1209 | |
7236e3c8 | 1210 | /** Accessor for r and s fields of ECDSA_SIG |
0396401d | 1211 | * \param sig pointer to ECDSA_SIG structure |
7236e3c8 DSH |
1212 | * \param pr pointer to BIGNUM pointer for r (may be NULL) |
1213 | * \param ps pointer to BIGNUM pointer for s (may be NULL) | |
1214 | */ | |
9267c11b | 1215 | void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); |
7236e3c8 | 1216 | |
0396401d DMSP |
1217 | /** Accessor for r field of ECDSA_SIG |
1218 | * \param sig pointer to ECDSA_SIG structure | |
1219 | */ | |
1220 | const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig); | |
1221 | ||
1222 | /** Accessor for s field of ECDSA_SIG | |
1223 | * \param sig pointer to ECDSA_SIG structure | |
1224 | */ | |
1225 | const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig); | |
1226 | ||
6a571a18 | 1227 | /** Setter for r and s fields of ECDSA_SIG |
0396401d | 1228 | * \param sig pointer to ECDSA_SIG structure |
a0cef658 DMSP |
1229 | * \param r pointer to BIGNUM for r (may be NULL) |
1230 | * \param s pointer to BIGNUM for s (may be NULL) | |
6a571a18 | 1231 | */ |
1d454d58 | 1232 | int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); |
6a571a18 | 1233 | |
180eec16 DSH |
1234 | /** Computes the ECDSA signature of the given hash value using |
1235 | * the supplied private key and returns the created signature. | |
1236 | * \param dgst pointer to the hash value | |
1237 | * \param dgst_len length of the hash value | |
1238 | * \param eckey EC_KEY object containing a private EC key | |
1239 | * \return pointer to a ECDSA_SIG structure or NULL if an error occurred | |
1240 | */ | |
1241 | ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, | |
1242 | EC_KEY *eckey); | |
1243 | ||
1244 | /** Computes ECDSA signature of a given hash value using the supplied | |
1245 | * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | |
1246 | * \param dgst pointer to the hash value to sign | |
1247 | * \param dgstlen length of the hash value | |
1248 | * \param kinv BIGNUM with a pre-computed inverse k (optional) | |
8483a003 | 1249 | * \param rp BIGNUM with a pre-computed rp value (optional), |
180eec16 DSH |
1250 | * see ECDSA_sign_setup |
1251 | * \param eckey EC_KEY object containing a private EC key | |
1252 | * \return pointer to a ECDSA_SIG structure or NULL if an error occurred | |
1253 | */ | |
1254 | ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, | |
1255 | const BIGNUM *kinv, const BIGNUM *rp, | |
1256 | EC_KEY *eckey); | |
1257 | ||
1258 | /** Verifies that the supplied signature is a valid ECDSA | |
1259 | * signature of the supplied hash value using the supplied public key. | |
1260 | * \param dgst pointer to the hash value | |
1261 | * \param dgst_len length of the hash value | |
1262 | * \param sig ECDSA_SIG structure | |
1263 | * \param eckey EC_KEY object containing a public EC key | |
1264 | * \return 1 if the signature is valid, 0 if the signature is invalid | |
1265 | * and -1 on error | |
1266 | */ | |
1267 | int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, | |
1268 | const ECDSA_SIG *sig, EC_KEY *eckey); | |
1269 | ||
bd3602eb DSH |
1270 | /** Precompute parts of the signing operation |
1271 | * \param eckey EC_KEY object containing a private EC key | |
1272 | * \param ctx BN_CTX object (optional) | |
1273 | * \param kinv BIGNUM pointer for the inverse of k | |
1274 | * \param rp BIGNUM pointer for x coordinate of k * generator | |
1275 | * \return 1 on success and 0 otherwise | |
1276 | */ | |
1277 | int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); | |
1278 | ||
1279 | /** Computes ECDSA signature of a given hash value using the supplied | |
1280 | * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | |
1281 | * \param type this parameter is ignored | |
1282 | * \param dgst pointer to the hash value to sign | |
1283 | * \param dgstlen length of the hash value | |
1284 | * \param sig memory for the DER encoded created signature | |
1285 | * \param siglen pointer to the length of the returned signature | |
1286 | * \param eckey EC_KEY object containing a private EC key | |
1287 | * \return 1 on success and 0 otherwise | |
1288 | */ | |
1289 | int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, | |
1290 | unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); | |
1291 | ||
1292 | /** Computes ECDSA signature of a given hash value using the supplied | |
1293 | * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | |
1294 | * \param type this parameter is ignored | |
1295 | * \param dgst pointer to the hash value to sign | |
1296 | * \param dgstlen length of the hash value | |
1297 | * \param sig buffer to hold the DER encoded signature | |
1298 | * \param siglen pointer to the length of the returned signature | |
1299 | * \param kinv BIGNUM with a pre-computed inverse k (optional) | |
8483a003 | 1300 | * \param rp BIGNUM with a pre-computed rp value (optional), |
bd3602eb DSH |
1301 | * see ECDSA_sign_setup |
1302 | * \param eckey EC_KEY object containing a private EC key | |
1303 | * \return 1 on success and 0 otherwise | |
1304 | */ | |
1305 | int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, | |
1306 | unsigned char *sig, unsigned int *siglen, | |
1307 | const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); | |
1308 | ||
1309 | /** Verifies that the given signature is valid ECDSA signature | |
1310 | * of the supplied hash value using the specified public key. | |
1311 | * \param type this parameter is ignored | |
1312 | * \param dgst pointer to the hash value | |
1313 | * \param dgstlen length of the hash value | |
1314 | * \param sig pointer to the DER encoded signature | |
1315 | * \param siglen length of the DER encoded signature | |
1316 | * \param eckey EC_KEY object containing a public EC key | |
1317 | * \return 1 if the signature is valid, 0 if the signature is invalid | |
1318 | * and -1 on error | |
1319 | */ | |
1320 | int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, | |
1321 | const unsigned char *sig, int siglen, EC_KEY *eckey); | |
7236e3c8 | 1322 | |
cf517a6d DSH |
1323 | /** Returns the maximum length of the DER encoded signature |
1324 | * \param eckey EC_KEY object | |
1325 | * \return numbers of bytes required for the DER encoded signature | |
1326 | */ | |
1327 | int ECDSA_size(const EC_KEY *eckey); | |
1328 | ||
7bb75a5d DSH |
1329 | /********************************************************************/ |
1330 | /* EC_KEY_METHOD constructors, destructors, writers and accessors */ | |
1331 | /********************************************************************/ | |
1332 | ||
f8d7d2d6 DSH |
1333 | EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); |
1334 | void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); | |
1335 | void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | |
1336 | int (*init)(EC_KEY *key), | |
1337 | void (*finish)(EC_KEY *key), | |
1338 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | |
1339 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | |
1340 | int (*set_private)(EC_KEY *key, | |
1341 | const BIGNUM *priv_key), | |
1342 | int (*set_public)(EC_KEY *key, | |
1343 | const EC_POINT *pub_key)); | |
1344 | ||
1345 | void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, | |
1346 | int (*keygen)(EC_KEY *key)); | |
1347 | ||
1348 | void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, | |
e2285d87 DSH |
1349 | int (*ckey)(unsigned char **psec, |
1350 | size_t *pseclen, | |
f8d7d2d6 | 1351 | const EC_POINT *pub_key, |
e2285d87 | 1352 | const EC_KEY *ecdh)); |
f8d7d2d6 DSH |
1353 | |
1354 | void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | |
1355 | int (*sign)(int type, const unsigned char *dgst, | |
1356 | int dlen, unsigned char *sig, | |
1357 | unsigned int *siglen, | |
1358 | const BIGNUM *kinv, const BIGNUM *r, | |
1359 | EC_KEY *eckey), | |
1360 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | |
1361 | BIGNUM **kinvp, BIGNUM **rp), | |
1362 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | |
1363 | int dgst_len, | |
1364 | const BIGNUM *in_kinv, | |
1365 | const BIGNUM *in_r, | |
1366 | EC_KEY *eckey)); | |
1367 | ||
1368 | void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, | |
1369 | int (*verify)(int type, const unsigned | |
1370 | char *dgst, int dgst_len, | |
1371 | const unsigned char *sigbuf, | |
1372 | int sig_len, EC_KEY *eckey), | |
1373 | int (*verify_sig)(const unsigned char *dgst, | |
1374 | int dgst_len, | |
1375 | const ECDSA_SIG *sig, | |
1376 | EC_KEY *eckey)); | |
1377 | ||
4e9b720e | 1378 | void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, |
f8d7d2d6 DSH |
1379 | int (**pinit)(EC_KEY *key), |
1380 | void (**pfinish)(EC_KEY *key), | |
1381 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | |
1382 | int (**pset_group)(EC_KEY *key, | |
1383 | const EC_GROUP *grp), | |
1384 | int (**pset_private)(EC_KEY *key, | |
1385 | const BIGNUM *priv_key), | |
1386 | int (**pset_public)(EC_KEY *key, | |
1387 | const EC_POINT *pub_key)); | |
1388 | ||
4e9b720e | 1389 | void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, |
f8d7d2d6 DSH |
1390 | int (**pkeygen)(EC_KEY *key)); |
1391 | ||
4e9b720e | 1392 | void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, |
e2285d87 DSH |
1393 | int (**pck)(unsigned char **psec, |
1394 | size_t *pseclen, | |
f8d7d2d6 | 1395 | const EC_POINT *pub_key, |
e2285d87 | 1396 | const EC_KEY *ecdh)); |
f8d7d2d6 | 1397 | |
4e9b720e | 1398 | void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, |
f8d7d2d6 DSH |
1399 | int (**psign)(int type, const unsigned char *dgst, |
1400 | int dlen, unsigned char *sig, | |
1401 | unsigned int *siglen, | |
1402 | const BIGNUM *kinv, const BIGNUM *r, | |
1403 | EC_KEY *eckey), | |
1404 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | |
1405 | BIGNUM **kinvp, BIGNUM **rp), | |
1406 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | |
1407 | int dgst_len, | |
1408 | const BIGNUM *in_kinv, | |
1409 | const BIGNUM *in_r, | |
1410 | EC_KEY *eckey)); | |
1411 | ||
4e9b720e | 1412 | void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, |
f8d7d2d6 DSH |
1413 | int (**pverify)(int type, const unsigned |
1414 | char *dgst, int dgst_len, | |
1415 | const unsigned char *sigbuf, | |
1416 | int sig_len, EC_KEY *eckey), | |
1417 | int (**pverify_sig)(const unsigned char *dgst, | |
1418 | int dgst_len, | |
1419 | const ECDSA_SIG *sig, | |
1420 | EC_KEY *eckey)); | |
1421 | ||
0f113f3e | 1422 | # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) |
458c2917 | 1423 | |
0f113f3e MC |
1424 | # ifndef __cplusplus |
1425 | # if defined(__SUNPRO_C) | |
1426 | # if __SUNPRO_C >= 0x520 | |
1427 | # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) | |
1428 | # endif | |
ad0db060 DSH |
1429 | # endif |
1430 | # endif | |
ad0db060 | 1431 | |
0f113f3e MC |
1432 | # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ |
1433 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1434 | EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ | |
1435 | EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) | |
1436 | ||
1437 | # define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \ | |
1438 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1439 | EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ | |
1440 | EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL) | |
1441 | ||
1442 | # define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \ | |
1443 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1444 | EVP_PKEY_OP_DERIVE, \ | |
1445 | EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL) | |
1446 | ||
1447 | # define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \ | |
1448 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1449 | EVP_PKEY_OP_DERIVE, \ | |
1450 | EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL) | |
1451 | ||
1452 | # define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \ | |
1453 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1454 | EVP_PKEY_OP_DERIVE, \ | |
1455 | EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL) | |
1456 | ||
1457 | # define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \ | |
1458 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1459 | EVP_PKEY_OP_DERIVE, \ | |
1460 | EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL) | |
1461 | ||
1462 | # define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \ | |
1463 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1464 | EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 1465 | EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)(md)) |
0f113f3e MC |
1466 | |
1467 | # define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \ | |
1468 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1469 | EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 1470 | EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)(pmd)) |
0f113f3e MC |
1471 | |
1472 | # define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \ | |
1473 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1474 | EVP_PKEY_OP_DERIVE, \ | |
1475 | EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL) | |
1476 | ||
1477 | # define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \ | |
1478 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1479 | EVP_PKEY_OP_DERIVE, \ | |
37659ea4 BE |
1480 | EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, \ |
1481 | (void *)(plen)) | |
0f113f3e MC |
1482 | |
1483 | # define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \ | |
1484 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1485 | EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 1486 | EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)(p)) |
0f113f3e MC |
1487 | |
1488 | # define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \ | |
1489 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ | |
1490 | EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 1491 | EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)(p)) |
0f113f3e | 1492 | |
4803717f PY |
1493 | /* SM2 will skip the operation check so no need to pass operation here */ |
1494 | # define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \ | |
1495 | EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ | |
1496 | EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id)) | |
4803717f PY |
1497 | # define EVP_PKEY_CTX_get1_id(ctx, id) \ |
1498 | EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ | |
1499 | EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id)) | |
1500 | ||
1501 | # define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \ | |
1502 | EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ | |
1503 | EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len)) | |
1504 | ||
0f113f3e MC |
1505 | # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1) |
1506 | # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2) | |
1507 | # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3) | |
1508 | # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4) | |
1509 | # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5) | |
1510 | # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6) | |
1511 | # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7) | |
1512 | # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8) | |
1513 | # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9) | |
1514 | # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10) | |
4803717f PY |
1515 | # define EVP_PKEY_CTRL_SET1_ID (EVP_PKEY_ALG_CTRL + 11) |
1516 | # define EVP_PKEY_CTRL_GET1_ID (EVP_PKEY_ALG_CTRL + 12) | |
1517 | # define EVP_PKEY_CTRL_GET1_ID_LEN (EVP_PKEY_ALG_CTRL + 13) | |
25af7a5d | 1518 | /* KDF types */ |
0f113f3e | 1519 | # define EVP_PKEY_ECDH_KDF_NONE 1 |
ffd89124 AS |
1520 | # define EVP_PKEY_ECDH_KDF_X9_63 2 |
1521 | /** The old name for EVP_PKEY_ECDH_KDF_X9_63 | |
1522 | * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, | |
1523 | * it is actually specified in ANSI X9.63. | |
1524 | * This identifier is retained for backwards compatibility | |
1525 | */ | |
1526 | # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63 | |
9ca7047d | 1527 | |
6cc5e19d | 1528 | |
0cd0a820 | 1529 | # ifdef __cplusplus |
65e81670 | 1530 | } |
0cd0a820 | 1531 | # endif |
3c27208f | 1532 | # endif |
5acaa495 | 1533 | #endif |