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