Add more complete support for libctx/propq in the EC code
[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  propq  A property query string
387  *  \param  nid    NID of the OID of the curve name
388  *  \return newly created EC_GROUP object with specified curve or NULL
389  *          if an error occurred
390  */
391 EC_GROUP *EC_GROUP_new_by_curve_name_with_libctx(OPENSSL_CTX *libctx,
392                                                  const char *propq, int nid);
393
394 /**
395  * Creates a EC_GROUP object with a curve specified by a NID. Same as
396  * EC_GROUP_new_by_curve_name_with_libctx but the libctx and propq are always
397  * NULL.
398  *  \param  nid    NID of the OID of the curve name
399  *  \return newly created EC_GROUP object with specified curve or NULL
400  *          if an error occurred
401  */
402 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
403
404 /** Creates a new EC_GROUP object from an ECPARAMETERS object
405  *  \param  params  pointer to the ECPARAMETERS object
406  *  \return newly created EC_GROUP object with specified curve or NULL
407  *          if an error occurred
408  */
409 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);
410
411 /** Creates an ECPARAMETERS object for the given EC_GROUP object.
412  *  \param  group   pointer to the EC_GROUP object
413  *  \param  params  pointer to an existing ECPARAMETERS object or NULL
414  *  \return pointer to the new ECPARAMETERS object or NULL
415  *          if an error occurred.
416  */
417 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
418                                         ECPARAMETERS *params);
419
420 /** Creates a new EC_GROUP object from an ECPKPARAMETERS object
421  *  \param  params  pointer to an existing ECPKPARAMETERS object, or NULL
422  *  \return newly created EC_GROUP object with specified curve, or NULL
423  *          if an error occurred
424  */
425 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);
426
427 /** Creates an ECPKPARAMETERS object for the given EC_GROUP object.
428  *  \param  group   pointer to the EC_GROUP object
429  *  \param  params  pointer to an existing ECPKPARAMETERS object or NULL
430  *  \return pointer to the new ECPKPARAMETERS object or NULL
431  *          if an error occurred.
432  */
433 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,
434                                             ECPKPARAMETERS *params);
435
436 /********************************************************************/
437 /*               handling of internal curves                        */
438 /********************************************************************/
439
440 typedef struct {
441     int nid;
442     const char *comment;
443 } EC_builtin_curve;
444
445 /*
446  * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
447  * available curves or zero if a error occurred. In case r is not zero,
448  * nitems EC_builtin_curve structures are filled with the data of the first
449  * nitems internal groups
450  */
451 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
452
453 const char *EC_curve_nid2nist(int nid);
454 int EC_curve_nist2nid(const char *name);
455 int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only,
456                                BN_CTX *ctx);
457
458 /********************************************************************/
459 /*                    EC_POINT functions                            */
460 /********************************************************************/
461
462 /** Creates a new EC_POINT object for the specified EC_GROUP
463  *  \param  group  EC_GROUP the underlying EC_GROUP object
464  *  \return newly created EC_POINT object or NULL if an error occurred
465  */
466 EC_POINT *EC_POINT_new(const EC_GROUP *group);
467
468 /** Frees a EC_POINT object
469  *  \param  point  EC_POINT object to be freed
470  */
471 void EC_POINT_free(EC_POINT *point);
472
473 /** Clears and frees a EC_POINT object
474  *  \param  point  EC_POINT object to be cleared and freed
475  */
476 void EC_POINT_clear_free(EC_POINT *point);
477
478 /** Copies EC_POINT object
479  *  \param  dst  destination EC_POINT object
480  *  \param  src  source EC_POINT object
481  *  \return 1 on success and 0 if an error occurred
482  */
483 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
484
485 /** Creates a new EC_POINT object and copies the content of the supplied
486  *  EC_POINT
487  *  \param  src    source EC_POINT object
488  *  \param  group  underlying the EC_GROUP object
489  *  \return newly created EC_POINT object or NULL if an error occurred
490  */
491 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
492
493 /** Returns the EC_METHOD used in EC_POINT object
494  *  \param  point  EC_POINT object
495  *  \return the EC_METHOD used
496  */
497 DEPRECATEDIN_3_0(const EC_METHOD *EC_POINT_method_of(const EC_POINT *point))
498
499 /** Sets a point to infinity (neutral element)
500  *  \param  group  underlying EC_GROUP object
501  *  \param  point  EC_POINT to set to infinity
502  *  \return 1 on success and 0 if an error occurred
503  */
504 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
505
506 /** Sets the jacobian projective coordinates of a EC_POINT over GFp
507  *  \param  group  underlying EC_GROUP object
508  *  \param  p      EC_POINT object
509  *  \param  x      BIGNUM with the x-coordinate
510  *  \param  y      BIGNUM with the y-coordinate
511  *  \param  z      BIGNUM with the z-coordinate
512  *  \param  ctx    BN_CTX object (optional)
513  *  \return 1 on success and 0 if an error occurred
514  */
515 DEPRECATEDIN_3_0(int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
516                                              EC_POINT *p, const BIGNUM *x,
517                                              const BIGNUM *y, const BIGNUM *z,
518                                              BN_CTX *ctx))
519
520 /** Gets the jacobian projective coordinates of a EC_POINT over GFp
521  *  \param  group  underlying EC_GROUP object
522  *  \param  p      EC_POINT object
523  *  \param  x      BIGNUM for the x-coordinate
524  *  \param  y      BIGNUM for the y-coordinate
525  *  \param  z      BIGNUM for the z-coordinate
526  *  \param  ctx    BN_CTX object (optional)
527  *  \return 1 on success and 0 if an error occurred
528  */
529 DEPRECATEDIN_3_0(int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
530                                              const EC_POINT *p, BIGNUM *x,
531                                              BIGNUM *y, BIGNUM *z,
532                                              BN_CTX *ctx))
533
534 /** Sets the affine coordinates of an EC_POINT
535  *  \param  group  underlying EC_GROUP object
536  *  \param  p      EC_POINT object
537  *  \param  x      BIGNUM with the x-coordinate
538  *  \param  y      BIGNUM with the y-coordinate
539  *  \param  ctx    BN_CTX object (optional)
540  *  \return 1 on success and 0 if an error occurred
541  */
542 int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p,
543                                     const BIGNUM *x, const BIGNUM *y,
544                                     BN_CTX *ctx);
545
546 /** Gets the affine coordinates of an EC_POINT.
547  *  \param  group  underlying EC_GROUP object
548  *  \param  p      EC_POINT object
549  *  \param  x      BIGNUM for the x-coordinate
550  *  \param  y      BIGNUM for the y-coordinate
551  *  \param  ctx    BN_CTX object (optional)
552  *  \return 1 on success and 0 if an error occurred
553  */
554 int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p,
555                                     BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
556
557 /** Sets the affine coordinates of an EC_POINT. A synonym of
558  *  EC_POINT_set_affine_coordinates
559  *  \param  group  underlying EC_GROUP object
560  *  \param  p      EC_POINT object
561  *  \param  x      BIGNUM with the x-coordinate
562  *  \param  y      BIGNUM with the y-coordinate
563  *  \param  ctx    BN_CTX object (optional)
564  *  \return 1 on success and 0 if an error occurred
565  */
566 DEPRECATEDIN_3_0(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
567                                                        EC_POINT *p,
568                                                        const BIGNUM *x,
569                                                        const BIGNUM *y,
570                                                        BN_CTX *ctx))
571
572 /** Gets the affine coordinates of an EC_POINT. A synonym of
573  *  EC_POINT_get_affine_coordinates
574  *  \param  group  underlying EC_GROUP object
575  *  \param  p      EC_POINT object
576  *  \param  x      BIGNUM for the x-coordinate
577  *  \param  y      BIGNUM for the y-coordinate
578  *  \param  ctx    BN_CTX object (optional)
579  *  \return 1 on success and 0 if an error occurred
580  */
581 DEPRECATEDIN_3_0(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
582                                                        const EC_POINT *p,
583                                                        BIGNUM *x,
584                                                        BIGNUM *y,
585                                                        BN_CTX *ctx))
586
587 /** Sets the x9.62 compressed coordinates of a EC_POINT
588  *  \param  group  underlying EC_GROUP object
589  *  \param  p      EC_POINT object
590  *  \param  x      BIGNUM with x-coordinate
591  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
592  *  \param  ctx    BN_CTX object (optional)
593  *  \return 1 on success and 0 if an error occurred
594  */
595 int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p,
596                                         const BIGNUM *x, int y_bit,
597                                         BN_CTX *ctx);
598
599 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
600  *  EC_POINT_set_compressed_coordinates
601  *  \param  group  underlying EC_GROUP object
602  *  \param  p      EC_POINT object
603  *  \param  x      BIGNUM with x-coordinate
604  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
605  *  \param  ctx    BN_CTX object (optional)
606  *  \return 1 on success and 0 if an error occurred
607  */
608 DEPRECATEDIN_3_0(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
609                                                            EC_POINT *p,
610                                                            const BIGNUM *x,
611                                                            int y_bit,
612                                                            BN_CTX *ctx))
613 #  ifndef OPENSSL_NO_EC2M
614 /** Sets the affine coordinates of an EC_POINT. A synonym of
615  *  EC_POINT_set_affine_coordinates
616  *  \param  group  underlying EC_GROUP object
617  *  \param  p      EC_POINT object
618  *  \param  x      BIGNUM with the x-coordinate
619  *  \param  y      BIGNUM with the y-coordinate
620  *  \param  ctx    BN_CTX object (optional)
621  *  \return 1 on success and 0 if an error occurred
622  */
623 DEPRECATEDIN_3_0(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group,
624                                                         EC_POINT *p,
625                                                         const BIGNUM *x,
626                                                         const BIGNUM *y,
627                                                         BN_CTX *ctx))
628
629 /** Gets the affine coordinates of an EC_POINT. A synonym of
630  *  EC_POINT_get_affine_coordinates
631  *  \param  group  underlying EC_GROUP object
632  *  \param  p      EC_POINT object
633  *  \param  x      BIGNUM for the x-coordinate
634  *  \param  y      BIGNUM for the y-coordinate
635  *  \param  ctx    BN_CTX object (optional)
636  *  \return 1 on success and 0 if an error occurred
637  */
638 DEPRECATEDIN_3_0(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
639                                                         const EC_POINT *p,
640                                                         BIGNUM *x,
641                                                         BIGNUM *y,
642                                                         BN_CTX *ctx))
643
644 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
645  *  EC_POINT_set_compressed_coordinates
646  *  \param  group  underlying EC_GROUP object
647  *  \param  p      EC_POINT object
648  *  \param  x      BIGNUM with x-coordinate
649  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
650  *  \param  ctx    BN_CTX object (optional)
651  *  \return 1 on success and 0 if an error occurred
652  */
653 DEPRECATEDIN_3_0(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
654                                                             EC_POINT *p,
655                                                             const BIGNUM *x,
656                                                             int y_bit,
657                                                             BN_CTX *ctx))
658 #  endif
659 /** Encodes a EC_POINT object to a octet string
660  *  \param  group  underlying EC_GROUP object
661  *  \param  p      EC_POINT object
662  *  \param  form   point conversion form
663  *  \param  buf    memory buffer for the result. If NULL the function returns
664  *                 required buffer size.
665  *  \param  len    length of the memory buffer
666  *  \param  ctx    BN_CTX object (optional)
667  *  \return the length of the encoded octet string or 0 if an error occurred
668  */
669 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
670                           point_conversion_form_t form,
671                           unsigned char *buf, size_t len, BN_CTX *ctx);
672
673 /** Decodes a EC_POINT from a octet string
674  *  \param  group  underlying EC_GROUP object
675  *  \param  p      EC_POINT object
676  *  \param  buf    memory buffer with the encoded ec point
677  *  \param  len    length of the encoded ec point
678  *  \param  ctx    BN_CTX object (optional)
679  *  \return 1 on success and 0 if an error occurred
680  */
681 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
682                        const unsigned char *buf, size_t len, BN_CTX *ctx);
683
684 /** Encodes an EC_POINT object to an allocated octet string
685  *  \param  group  underlying EC_GROUP object
686  *  \param  point  EC_POINT object
687  *  \param  form   point conversion form
688  *  \param  pbuf   returns pointer to allocated buffer
689  *  \param  ctx    BN_CTX object (optional)
690  *  \return the length of the encoded octet string or 0 if an error occurred
691  */
692 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
693                           point_conversion_form_t form,
694                           unsigned char **pbuf, BN_CTX *ctx);
695
696 /* other interfaces to point2oct/oct2point: */
697 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
698                           point_conversion_form_t form, BIGNUM *, BN_CTX *);
699 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
700                             EC_POINT *, BN_CTX *);
701 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
702                          point_conversion_form_t form, BN_CTX *);
703 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
704                              EC_POINT *, BN_CTX *);
705
706 /********************************************************************/
707 /*         functions for doing EC_POINT arithmetic                  */
708 /********************************************************************/
709
710 /** Computes the sum of two EC_POINT
711  *  \param  group  underlying EC_GROUP object
712  *  \param  r      EC_POINT object for the result (r = a + b)
713  *  \param  a      EC_POINT object with the first summand
714  *  \param  b      EC_POINT object with the second summand
715  *  \param  ctx    BN_CTX object (optional)
716  *  \return 1 on success and 0 if an error occurred
717  */
718 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
719                  const EC_POINT *b, BN_CTX *ctx);
720
721 /** Computes the double of a EC_POINT
722  *  \param  group  underlying EC_GROUP object
723  *  \param  r      EC_POINT object for the result (r = 2 * a)
724  *  \param  a      EC_POINT object
725  *  \param  ctx    BN_CTX object (optional)
726  *  \return 1 on success and 0 if an error occurred
727  */
728 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
729                  BN_CTX *ctx);
730
731 /** Computes the inverse of a EC_POINT
732  *  \param  group  underlying EC_GROUP object
733  *  \param  a      EC_POINT object to be inverted (it's used for the result as well)
734  *  \param  ctx    BN_CTX object (optional)
735  *  \return 1 on success and 0 if an error occurred
736  */
737 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
738
739 /** Checks whether the point is the neutral element of the group
740  *  \param  group  the underlying EC_GROUP object
741  *  \param  p      EC_POINT object
742  *  \return 1 if the point is the neutral element and 0 otherwise
743  */
744 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
745
746 /** Checks whether the point is on the curve
747  *  \param  group  underlying EC_GROUP object
748  *  \param  point  EC_POINT object to check
749  *  \param  ctx    BN_CTX object (optional)
750  *  \return 1 if the point is on the curve, 0 if not, or -1 on error
751  */
752 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
753                          BN_CTX *ctx);
754
755 /** Compares two EC_POINTs
756  *  \param  group  underlying EC_GROUP object
757  *  \param  a      first EC_POINT object
758  *  \param  b      second EC_POINT object
759  *  \param  ctx    BN_CTX object (optional)
760  *  \return 1 if the points are not equal, 0 if they are, or -1 on error
761  */
762 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
763                  BN_CTX *ctx);
764
765 DEPRECATEDIN_3_0(int EC_POINT_make_affine(const EC_GROUP *group,
766                                           EC_POINT *point, BN_CTX *ctx))
767 DEPRECATEDIN_3_0(int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
768                                            EC_POINT *points[], BN_CTX *ctx))
769
770 /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i]
771  *  \param  group  underlying EC_GROUP object
772  *  \param  r      EC_POINT object for the result
773  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
774  *  \param  num    number further summands
775  *  \param  p      array of size num of EC_POINT objects
776  *  \param  m      array of size num of BIGNUM objects
777  *  \param  ctx    BN_CTX object (optional)
778  *  \return 1 on success and 0 if an error occurred
779  */
780 DEPRECATEDIN_3_0(int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r,
781                                    const BIGNUM *n, size_t num,
782                                    const EC_POINT *p[], const BIGNUM *m[],
783                                    BN_CTX *ctx))
784
785 /** Computes r = generator * n + q * m
786  *  \param  group  underlying EC_GROUP object
787  *  \param  r      EC_POINT object for the result
788  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
789  *  \param  q      EC_POINT object with the first factor of the second summand
790  *  \param  m      BIGNUM with the second factor of the second summand
791  *  \param  ctx    BN_CTX object (optional)
792  *  \return 1 on success and 0 if an error occurred
793  */
794 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
795                  const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
796
797 /** Stores multiples of generator for faster point multiplication
798  *  \param  group  EC_GROUP object
799  *  \param  ctx    BN_CTX object (optional)
800  *  \return 1 on success and 0 if an error occurred
801  */
802 DEPRECATEDIN_3_0(int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx))
803
804 /** Reports whether a precomputation has been done
805  *  \param  group  EC_GROUP object
806  *  \return 1 if a pre-computation has been done and 0 otherwise
807  */
808 DEPRECATEDIN_3_0(int EC_GROUP_have_precompute_mult(const EC_GROUP *group))
809
810 /********************************************************************/
811 /*                       ASN1 stuff                                 */
812 /********************************************************************/
813
814 DECLARE_ASN1_ITEM(ECPKPARAMETERS)
815 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS)
816 DECLARE_ASN1_ITEM(ECPARAMETERS)
817 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS)
818
819 /*
820  * EC_GROUP_get_basis_type() returns the NID of the basis type used to
821  * represent the field elements
822  */
823 int EC_GROUP_get_basis_type(const EC_GROUP *);
824 #  ifndef OPENSSL_NO_EC2M
825 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
826 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
827                                    unsigned int *k2, unsigned int *k3);
828 #  endif
829
830 #  define OPENSSL_EC_EXPLICIT_CURVE  0x000
831 #  define OPENSSL_EC_NAMED_CURVE     0x001
832
833 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
834 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
835
836 #  define d2i_ECPKParameters_bio(bp,x) \
837     ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x)
838 #  define i2d_ECPKParameters_bio(bp,x) \
839     ASN1_i2d_bio_of(EC_GROUP, i2d_ECPKParameters, bp, x)
840 #  define d2i_ECPKParameters_fp(fp,x) \
841     (EC_GROUP *)ASN1_d2i_fp(NULL, (char *(*)())d2i_ECPKParameters, (fp), \
842                             (unsigned char **)(x))
843 #  define i2d_ECPKParameters_fp(fp,x) \
844     ASN1_i2d_fp(i2d_ECPKParameters,(fp), (unsigned char *)(x))
845
846 int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
847 #  ifndef OPENSSL_NO_STDIO
848 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
849 #  endif
850
851 /********************************************************************/
852 /*                      EC_KEY functions                            */
853 /********************************************************************/
854
855 /* some values for the encoding_flag */
856 #  define EC_PKEY_NO_PARAMETERS   0x001
857 #  define EC_PKEY_NO_PUBKEY       0x002
858
859 /* some values for the flags field */
860 #  define EC_FLAG_NON_FIPS_ALLOW  0x1
861 #  define EC_FLAG_FIPS_CHECKED    0x2
862 #  define EC_FLAG_COFACTOR_ECDH   0x1000
863
864 /**
865  *  Creates a new EC_KEY object.
866  *  \param  ctx  The library context for to use for this EC_KEY. May be NULL in
867  *               which case the default library context is used.
868  *  \return EC_KEY object or NULL if an error occurred.
869  */
870 EC_KEY *EC_KEY_new_with_libctx(OPENSSL_CTX *ctx, const char *propq);
871
872 /**
873  *  Creates a new EC_KEY object. Same as calling EC_KEY_new_with_libctx with a
874  *  NULL library context
875  *  \return EC_KEY object or NULL if an error occurred.
876  */
877 EC_KEY *EC_KEY_new(void);
878
879 int EC_KEY_get_flags(const EC_KEY *key);
880
881 void EC_KEY_set_flags(EC_KEY *key, int flags);
882
883 void EC_KEY_clear_flags(EC_KEY *key, int flags);
884
885 /**
886  *  Creates a new EC_KEY object using a named curve as underlying
887  *  EC_GROUP object.
888  *  \param  ctx   The library context for to use for this EC_KEY. May be NULL in
889  *                which case the default library context is used.
890  *  \param  propq Any property query string
891  *  \param  nid   NID of the named curve.
892  *  \return EC_KEY object or NULL if an error occurred.
893  */
894 EC_KEY *EC_KEY_new_by_curve_name_with_libctx(OPENSSL_CTX *ctx, const char *propq,
895                                              int nid);
896
897 /**
898  *  Creates a new EC_KEY object using a named curve as underlying
899  *  EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL
900  *  library context and property query string.
901  *  \param  nid  NID of the named curve.
902  *  \return EC_KEY object or NULL if an error occurred.
903  */
904 EC_KEY *EC_KEY_new_by_curve_name(int nid);
905
906
907 /** Frees a EC_KEY object.
908  *  \param  key  EC_KEY object to be freed.
909  */
910 void EC_KEY_free(EC_KEY *key);
911
912 /** Copies a EC_KEY object.
913  *  \param  dst  destination EC_KEY object
914  *  \param  src  src EC_KEY object
915  *  \return dst or NULL if an error occurred.
916  */
917 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
918
919 /** Creates a new EC_KEY object and copies the content from src to it.
920  *  \param  src  the source EC_KEY object
921  *  \return newly created EC_KEY object or NULL if an error occurred.
922  */
923 EC_KEY *EC_KEY_dup(const EC_KEY *src);
924
925 /** Increases the internal reference count of a EC_KEY object.
926  *  \param  key  EC_KEY object
927  *  \return 1 on success and 0 if an error occurred.
928  */
929 int EC_KEY_up_ref(EC_KEY *key);
930
931 /** Returns the ENGINE object of a EC_KEY object
932  *  \param  eckey  EC_KEY object
933  *  \return the ENGINE object (possibly NULL).
934  */
935 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey);
936
937 /** Returns the EC_GROUP object of a EC_KEY object
938  *  \param  key  EC_KEY object
939  *  \return the EC_GROUP object (possibly NULL).
940  */
941 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
942
943 /** Sets the EC_GROUP of a EC_KEY object.
944  *  \param  key    EC_KEY object
945  *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY
946  *                 object will use an own copy of the EC_GROUP).
947  *  \return 1 on success and 0 if an error occurred.
948  */
949 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
950
951 /** Returns the private key of a EC_KEY object.
952  *  \param  key  EC_KEY object
953  *  \return a BIGNUM with the private key (possibly NULL).
954  */
955 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
956
957 /** Sets the private key of a EC_KEY object.
958  *  \param  key  EC_KEY object
959  *  \param  prv  BIGNUM with the private key (note: the EC_KEY object
960  *               will use an own copy of the BIGNUM).
961  *  \return 1 on success and 0 if an error occurred.
962  */
963 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
964
965 /** Returns the public key of a EC_KEY object.
966  *  \param  key  the EC_KEY object
967  *  \return a EC_POINT object with the public key (possibly NULL)
968  */
969 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
970
971 /** Sets the public key of a EC_KEY object.
972  *  \param  key  EC_KEY object
973  *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object
974  *               will use an own copy of the EC_POINT object).
975  *  \return 1 on success and 0 if an error occurred.
976  */
977 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
978
979 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
980 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
981 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
982 void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
983
984 # define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
985     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
986 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);
987 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);
988
989 /* wrapper functions for the underlying EC_GROUP object */
990 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
991
992 /** Creates a table of pre-computed multiples of the generator to
993  *  accelerate further EC_KEY operations.
994  *  \param  key  EC_KEY object
995  *  \param  ctx  BN_CTX object (optional)
996  *  \return 1 on success and 0 if an error occurred.
997  */
998 DEPRECATEDIN_3_0(int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx))
999
1000 /** Creates a new ec private (and optional a new public) key.
1001  *  \param  key  EC_KEY object
1002  *  \return 1 on success and 0 if an error occurred.
1003  */
1004 int EC_KEY_generate_key(EC_KEY *key);
1005
1006 /** Verifies that a private and/or public key is valid.
1007  *  \param  key  the EC_KEY object
1008  *  \return 1 on success and 0 otherwise.
1009  */
1010 int EC_KEY_check_key(const EC_KEY *key);
1011
1012 /** Indicates if an EC_KEY can be used for signing.
1013  *  \param  eckey  the EC_KEY object
1014  *  \return 1 if can can sign and 0 otherwise.
1015  */
1016 int EC_KEY_can_sign(const EC_KEY *eckey);
1017
1018 /** Sets a public key from affine coordinates performing
1019  *  necessary NIST PKV tests.
1020  *  \param  key  the EC_KEY object
1021  *  \param  x    public key x coordinate
1022  *  \param  y    public key y coordinate
1023  *  \return 1 on success and 0 otherwise.
1024  */
1025 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
1026                                              BIGNUM *y);
1027
1028 /** Encodes an EC_KEY public key to an allocated octet string
1029  *  \param  key    key to encode
1030  *  \param  form   point conversion form
1031  *  \param  pbuf   returns pointer to allocated buffer
1032  *  \param  ctx    BN_CTX object (optional)
1033  *  \return the length of the encoded octet string or 0 if an error occurred
1034  */
1035 size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form,
1036                       unsigned char **pbuf, BN_CTX *ctx);
1037
1038 /** Decodes a EC_KEY public key from a octet string
1039  *  \param  key    key to decode
1040  *  \param  buf    memory buffer with the encoded ec point
1041  *  \param  len    length of the encoded ec point
1042  *  \param  ctx    BN_CTX object (optional)
1043  *  \return 1 on success and 0 if an error occurred
1044  */
1045
1046 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
1047                    BN_CTX *ctx);
1048
1049 /** Decodes an EC_KEY private key from an octet string
1050  *  \param  key    key to decode
1051  *  \param  buf    memory buffer with the encoded private key
1052  *  \param  len    length of the encoded key
1053  *  \return 1 on success and 0 if an error occurred
1054  */
1055
1056 int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len);
1057
1058 /** Encodes a EC_KEY private key to an octet string
1059  *  \param  key    key to encode
1060  *  \param  buf    memory buffer for the result. If NULL the function returns
1061  *                 required buffer size.
1062  *  \param  len    length of the memory buffer
1063  *  \return the length of the encoded octet string or 0 if an error occurred
1064  */
1065
1066 size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len);
1067
1068 /** Encodes an EC_KEY private key to an allocated octet string
1069  *  \param  eckey  key to encode
1070  *  \param  pbuf   returns pointer to allocated buffer
1071  *  \return the length of the encoded octet string or 0 if an error occurred
1072  */
1073 size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf);
1074
1075 /********************************************************************/
1076 /*        de- and encoding functions for SEC1 ECPrivateKey          */
1077 /********************************************************************/
1078
1079 /** Decodes a private key from a memory buffer.
1080  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1081  *  \param  in   pointer to memory with the DER encoded private key
1082  *  \param  len  length of the DER encoded private key
1083  *  \return the decoded private key or NULL if an error occurred.
1084  */
1085 EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
1086
1087 /** Encodes a private key object and stores the result in a buffer.
1088  *  \param  key  the EC_KEY object to encode
1089  *  \param  out  the buffer for the result (if NULL the function returns number
1090  *               of bytes needed).
1091  *  \return 1 on success and 0 if an error occurred.
1092  */
1093 int i2d_ECPrivateKey(const EC_KEY *key, unsigned char **out);
1094
1095 /********************************************************************/
1096 /*        de- and encoding functions for EC parameters              */
1097 /********************************************************************/
1098
1099 /** Decodes ec parameter from a memory buffer.
1100  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1101  *  \param  in   pointer to memory with the DER encoded ec parameters
1102  *  \param  len  length of the DER encoded ec parameters
1103  *  \return a EC_KEY object with the decoded parameters or NULL if an error
1104  *          occurred.
1105  */
1106 EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
1107
1108 /** Encodes ec parameter and stores the result in a buffer.
1109  *  \param  key  the EC_KEY object with ec parameters to encode
1110  *  \param  out  the buffer for the result (if NULL the function returns number
1111  *               of bytes needed).
1112  *  \return 1 on success and 0 if an error occurred.
1113  */
1114 int i2d_ECParameters(const EC_KEY *key, unsigned char **out);
1115
1116 /********************************************************************/
1117 /*         de- and encoding functions for EC public key             */
1118 /*         (octet string, not DER -- hence 'o2i' and 'i2o')         */
1119 /********************************************************************/
1120
1121 /** Decodes a ec public key from a octet string.
1122  *  \param  key  a pointer to a EC_KEY object which should be used
1123  *  \param  in   memory buffer with the encoded public key
1124  *  \param  len  length of the encoded public key
1125  *  \return EC_KEY object with decoded public key or NULL if an error
1126  *          occurred.
1127  */
1128 EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
1129
1130 /** Encodes a ec public key in an octet string.
1131  *  \param  key  the EC_KEY object with the public key
1132  *  \param  out  the buffer for the result (if NULL the function returns number
1133  *               of bytes needed).
1134  *  \return 1 on success and 0 if an error occurred
1135  */
1136 int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out);
1137
1138 /** Prints out the ec parameters on human readable form.
1139  *  \param  bp   BIO object to which the information is printed
1140  *  \param  key  EC_KEY object
1141  *  \return 1 on success and 0 if an error occurred
1142  */
1143 int ECParameters_print(BIO *bp, const EC_KEY *key);
1144
1145 /** Prints out the contents of a EC_KEY object
1146  *  \param  bp   BIO object to which the information is printed
1147  *  \param  key  EC_KEY object
1148  *  \param  off  line offset
1149  *  \return 1 on success and 0 if an error occurred
1150  */
1151 int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
1152
1153 #  ifndef OPENSSL_NO_STDIO
1154 /** Prints out the ec parameters on human readable form.
1155  *  \param  fp   file descriptor to which the information is printed
1156  *  \param  key  EC_KEY object
1157  *  \return 1 on success and 0 if an error occurred
1158  */
1159 int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
1160
1161 /** Prints out the contents of a EC_KEY object
1162  *  \param  fp   file descriptor to which the information is printed
1163  *  \param  key  EC_KEY object
1164  *  \param  off  line offset
1165  *  \return 1 on success and 0 if an error occurred
1166  */
1167 int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
1168
1169 #  endif
1170
1171 const EC_KEY_METHOD *EC_KEY_OpenSSL(void);
1172 const EC_KEY_METHOD *EC_KEY_get_default_method(void);
1173 void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
1174 const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
1175 int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
1176 EC_KEY *EC_KEY_new_method(ENGINE *engine);
1177
1178 /** The old name for ecdh_KDF_X9_63
1179  *  The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
1180  *  it is actually specified in ANSI X9.63.
1181  *  This identifier is retained for backwards compatibility
1182  */
1183 DEPRECATEDIN_3_0(int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
1184                                     const unsigned char *Z, size_t Zlen,
1185                                     const unsigned char *sinfo, size_t sinfolen,
1186                                     const EVP_MD *md))
1187
1188 DEPRECATEDIN_3_0(int ECDH_compute_key(void *out, size_t outlen,
1189                                       const EC_POINT *pub_key,
1190                                       const EC_KEY *ecdh,
1191                                       void *(*KDF)(const void *in, size_t inlen,
1192                                                    void *out, size_t *outlen)))
1193
1194 typedef struct ECDSA_SIG_st ECDSA_SIG;
1195
1196 /** Allocates and initialize a ECDSA_SIG structure
1197  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1198  */
1199 ECDSA_SIG *ECDSA_SIG_new(void);
1200
1201 /** frees a ECDSA_SIG structure
1202  *  \param  sig  pointer to the ECDSA_SIG structure
1203  */
1204 void ECDSA_SIG_free(ECDSA_SIG *sig);
1205
1206 /** i2d_ECDSA_SIG encodes content of ECDSA_SIG (note: this function modifies *pp
1207  *  (*pp += length of the DER encoded signature)).
1208  *  \param  sig  pointer to the ECDSA_SIG object
1209  *  \param  pp   pointer to a unsigned char pointer for the output or NULL
1210  *  \return the length of the DER encoded ECDSA_SIG object or a negative value
1211  *          on error
1212  */
1213 DECLARE_ASN1_ENCODE_FUNCTIONS_only(ECDSA_SIG, ECDSA_SIG)
1214
1215 /** d2i_ECDSA_SIG decodes an ECDSA signature (note: this function modifies *pp
1216  *  (*pp += len)).
1217  *  \param  sig  pointer to ECDSA_SIG pointer (may be NULL)
1218  *  \param  pp   memory buffer with the DER encoded signature
1219  *  \param  len  length of the buffer
1220  *  \return pointer to the decoded ECDSA_SIG structure (or NULL)
1221  */
1222
1223 /** Accessor for r and s fields of ECDSA_SIG
1224  *  \param  sig  pointer to ECDSA_SIG structure
1225  *  \param  pr   pointer to BIGNUM pointer for r (may be NULL)
1226  *  \param  ps   pointer to BIGNUM pointer for s (may be NULL)
1227  */
1228 void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
1229
1230 /** Accessor for r field of ECDSA_SIG
1231  *  \param  sig  pointer to ECDSA_SIG structure
1232  */
1233 const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
1234
1235 /** Accessor for s field of ECDSA_SIG
1236  *  \param  sig  pointer to ECDSA_SIG structure
1237  */
1238 const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
1239
1240 /** Setter for r and s fields of ECDSA_SIG
1241  *  \param  sig  pointer to ECDSA_SIG structure
1242  *  \param  r    pointer to BIGNUM for r (may be NULL)
1243  *  \param  s    pointer to BIGNUM for s (may be NULL)
1244  */
1245 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
1246
1247 /** Computes the ECDSA signature of the given hash value using
1248  *  the supplied private key and returns the created signature.
1249  *  \param  dgst      pointer to the hash value
1250  *  \param  dgst_len  length of the hash value
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 DEPRECATEDIN_3_0(ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,
1255                                           int dgst_len, EC_KEY *eckey))
1256
1257 /** Computes ECDSA signature of a given hash value using the supplied
1258  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1259  *  \param  dgst     pointer to the hash value to sign
1260  *  \param  dgstlen  length of the hash value
1261  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1262  *  \param  rp       BIGNUM with a pre-computed rp value (optional),
1263  *                   see ECDSA_sign_setup
1264  *  \param  eckey    EC_KEY object containing a private EC key
1265  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1266  */
1267 DEPRECATEDIN_3_0(ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst,
1268                                              int dgstlen, const BIGNUM *kinv,
1269                                              const BIGNUM *rp, EC_KEY *eckey))
1270
1271 /** Verifies that the supplied signature is a valid ECDSA
1272  *  signature of the supplied hash value using the supplied public key.
1273  *  \param  dgst      pointer to the hash value
1274  *  \param  dgst_len  length of the hash value
1275  *  \param  sig       ECDSA_SIG structure
1276  *  \param  eckey     EC_KEY object containing a public EC key
1277  *  \return 1 if the signature is valid, 0 if the signature is invalid
1278  *          and -1 on error
1279  */
1280 DEPRECATEDIN_3_0(int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
1281                                      const ECDSA_SIG *sig, EC_KEY *eckey))
1282
1283 /** Precompute parts of the signing operation
1284  *  \param  eckey  EC_KEY object containing a private EC key
1285  *  \param  ctx    BN_CTX object (optional)
1286  *  \param  kinv   BIGNUM pointer for the inverse of k
1287  *  \param  rp     BIGNUM pointer for x coordinate of k * generator
1288  *  \return 1 on success and 0 otherwise
1289  */
1290 DEPRECATEDIN_3_0(int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
1291                                       BIGNUM **kinv, BIGNUM **rp))
1292
1293 /** Computes ECDSA signature of a given hash value using the supplied
1294  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1295  *  \param  type     this parameter is ignored
1296  *  \param  dgst     pointer to the hash value to sign
1297  *  \param  dgstlen  length of the hash value
1298  *  \param  sig      memory for the DER encoded created signature
1299  *  \param  siglen   pointer to the length of the returned signature
1300  *  \param  eckey    EC_KEY object containing a private EC key
1301  *  \return 1 on success and 0 otherwise
1302  */
1303 DEPRECATEDIN_3_0(int ECDSA_sign(int type, const unsigned char *dgst,
1304                                 int dgstlen, unsigned char *sig,
1305                                 unsigned int *siglen, EC_KEY *eckey))
1306
1307 /** Computes ECDSA signature of a given hash value using the supplied
1308  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1309  *  \param  type     this parameter is ignored
1310  *  \param  dgst     pointer to the hash value to sign
1311  *  \param  dgstlen  length of the hash value
1312  *  \param  sig      buffer to hold the DER encoded signature
1313  *  \param  siglen   pointer to the length of the returned signature
1314  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1315  *  \param  rp       BIGNUM with a pre-computed rp value (optional),
1316  *                   see ECDSA_sign_setup
1317  *  \param  eckey    EC_KEY object containing a private EC key
1318  *  \return 1 on success and 0 otherwise
1319  */
1320 DEPRECATEDIN_3_0(int ECDSA_sign_ex(int type, const unsigned char *dgst,
1321                                    int dgstlen, unsigned char *sig,
1322                                    unsigned int *siglen, const BIGNUM *kinv,
1323                                    const BIGNUM *rp, EC_KEY *eckey))
1324
1325 /** Verifies that the given signature is valid ECDSA signature
1326  *  of the supplied hash value using the specified public key.
1327  *  \param  type     this parameter is ignored
1328  *  \param  dgst     pointer to the hash value
1329  *  \param  dgstlen  length of the hash value
1330  *  \param  sig      pointer to the DER encoded signature
1331  *  \param  siglen   length of the DER encoded signature
1332  *  \param  eckey    EC_KEY object containing a public EC key
1333  *  \return 1 if the signature is valid, 0 if the signature is invalid
1334  *          and -1 on error
1335  */
1336 DEPRECATEDIN_3_0(int ECDSA_verify(int type, const unsigned char *dgst,
1337                                   int dgstlen, const unsigned char *sig,
1338                                   int siglen, EC_KEY *eckey))
1339
1340 /** Returns the maximum length of the DER encoded signature
1341  *  \param  eckey  EC_KEY object
1342  *  \return numbers of bytes required for the DER encoded signature
1343  */
1344 DEPRECATEDIN_3_0(int ECDSA_size(const EC_KEY *eckey))
1345
1346 /********************************************************************/
1347 /*  EC_KEY_METHOD constructors, destructors, writers and accessors  */
1348 /********************************************************************/
1349
1350 DEPRECATEDIN_3_0(EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth))
1351 DEPRECATEDIN_3_0(void EC_KEY_METHOD_free(EC_KEY_METHOD *meth))
1352 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_init
1353                  (EC_KEY_METHOD *meth,
1354                   int (*init)(EC_KEY *key),
1355                   void (*finish)(EC_KEY *key),
1356                   int (*copy)(EC_KEY *dest, const EC_KEY *src),
1357                   int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
1358                   int (*set_private)(EC_KEY *key,
1359                                      const BIGNUM *priv_key),
1360                   int (*set_public)(EC_KEY *key,
1361                                     const EC_POINT *pub_key)))
1362
1363 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
1364                                                int (*keygen)(EC_KEY *key)))
1365
1366 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_compute_key
1367                  (EC_KEY_METHOD *meth,
1368                   int (*ckey)(unsigned char **psec,
1369                               size_t *pseclen,
1370                               const EC_POINT *pub_key,
1371                               const EC_KEY *ecdh)))
1372
1373 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_sign
1374                  (EC_KEY_METHOD *meth,
1375                   int (*sign)(int type, const unsigned char *dgst,
1376                               int dlen, unsigned char *sig,
1377                               unsigned int *siglen,
1378                               const BIGNUM *kinv, const BIGNUM *r,
1379                               EC_KEY *eckey),
1380                   int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1381                                     BIGNUM **kinvp, BIGNUM **rp),
1382                   ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
1383                                          int dgst_len,
1384                                          const BIGNUM *in_kinv,
1385                                          const BIGNUM *in_r,
1386                                          EC_KEY *eckey)))
1387
1388 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_verify
1389                  (EC_KEY_METHOD *meth,
1390                   int (*verify)(int type, const unsigned
1391                                 char *dgst, int dgst_len,
1392                                 const unsigned char *sigbuf,
1393                                 int sig_len, EC_KEY *eckey),
1394                   int (*verify_sig)(const unsigned char *dgst,
1395                                     int dgst_len,
1396                                     const ECDSA_SIG *sig,
1397                                     EC_KEY *eckey)))
1398
1399 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_init
1400                  (const EC_KEY_METHOD *meth,
1401                   int (**pinit)(EC_KEY *key),
1402                   void (**pfinish)(EC_KEY *key),
1403                   int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
1404                   int (**pset_group)(EC_KEY *key,
1405                                      const EC_GROUP *grp),
1406                   int (**pset_private)(EC_KEY *key,
1407                                        const BIGNUM *priv_key),
1408                   int (**pset_public)(EC_KEY *key,
1409                                       const EC_POINT *pub_key)))
1410
1411 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
1412                                                int (**pkeygen)(EC_KEY *key)))
1413
1414 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_compute_key
1415                  (const EC_KEY_METHOD *meth,
1416                   int (**pck)(unsigned char **psec,
1417                               size_t *pseclen,
1418                               const EC_POINT *pub_key,
1419                               const EC_KEY *ecdh)))
1420
1421 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_sign
1422                  (const EC_KEY_METHOD *meth,
1423                   int (**psign)(int type, const unsigned char *dgst,
1424                                 int dlen, unsigned char *sig,
1425                                 unsigned int *siglen,
1426                                 const BIGNUM *kinv, const BIGNUM *r,
1427                                 EC_KEY *eckey),
1428                   int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1429                                       BIGNUM **kinvp, BIGNUM **rp),
1430                   ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
1431                                            int dgst_len,
1432                                            const BIGNUM *in_kinv,
1433                                            const BIGNUM *in_r,
1434                                            EC_KEY *eckey)))
1435
1436 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_verify
1437                  (const EC_KEY_METHOD *meth,
1438                   int (**pverify)(int type, const unsigned
1439                                   char *dgst, int dgst_len,
1440                                   const unsigned char *sigbuf,
1441                                   int sig_len, EC_KEY *eckey),
1442                   int (**pverify_sig)(const unsigned char *dgst,
1443                                       int dgst_len,
1444                                       const ECDSA_SIG *sig,
1445                                       EC_KEY *eckey)))
1446
1447 #  define ECParameters_dup(x) ASN1_dup_of(EC_KEY, i2d_ECParameters, \
1448                                            d2i_ECParameters, x)
1449
1450 #  ifndef __cplusplus
1451 #   if defined(__SUNPRO_C)
1452 #    if __SUNPRO_C >= 0x520
1453 #     pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
1454 #    endif
1455 #   endif
1456 #  endif
1457
1458 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
1459
1460 #  define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \
1461         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1462                           EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
1463                           EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL)
1464
1465 int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode);
1466 int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx);
1467
1468 int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf);
1469 int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx);
1470
1471 int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
1472 int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
1473
1474 int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len);
1475 int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len);
1476
1477 int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
1478                                    int len);
1479 int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
1480
1481 /* SM2 will skip the operation check so no need to pass operation here */
1482 #  define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
1483         EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
1484                           EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
1485 #  define EVP_PKEY_CTX_get1_id(ctx, id) \
1486         EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
1487                           EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
1488
1489 #  define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \
1490         EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
1491                           EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len))
1492
1493 #  define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID         (EVP_PKEY_ALG_CTRL + 1)
1494 #  define EVP_PKEY_CTRL_EC_PARAM_ENC                  (EVP_PKEY_ALG_CTRL + 2)
1495 #  define EVP_PKEY_CTRL_EC_ECDH_COFACTOR              (EVP_PKEY_ALG_CTRL + 3)
1496 #  define EVP_PKEY_CTRL_EC_KDF_TYPE                   (EVP_PKEY_ALG_CTRL + 4)
1497 #  define EVP_PKEY_CTRL_EC_KDF_MD                     (EVP_PKEY_ALG_CTRL + 5)
1498 #  define EVP_PKEY_CTRL_GET_EC_KDF_MD                 (EVP_PKEY_ALG_CTRL + 6)
1499 #  define EVP_PKEY_CTRL_EC_KDF_OUTLEN                 (EVP_PKEY_ALG_CTRL + 7)
1500 #  define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN             (EVP_PKEY_ALG_CTRL + 8)
1501 #  define EVP_PKEY_CTRL_EC_KDF_UKM                    (EVP_PKEY_ALG_CTRL + 9)
1502 #  define EVP_PKEY_CTRL_GET_EC_KDF_UKM                (EVP_PKEY_ALG_CTRL + 10)
1503 #  define EVP_PKEY_CTRL_SET1_ID                       (EVP_PKEY_ALG_CTRL + 11)
1504 #  define EVP_PKEY_CTRL_GET1_ID                       (EVP_PKEY_ALG_CTRL + 12)
1505 #  define EVP_PKEY_CTRL_GET1_ID_LEN                   (EVP_PKEY_ALG_CTRL + 13)
1506
1507 /* KDF types */
1508 #  define EVP_PKEY_ECDH_KDF_NONE                      1
1509 #  define EVP_PKEY_ECDH_KDF_X9_63                     2
1510 /** The old name for EVP_PKEY_ECDH_KDF_X9_63
1511  *  The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
1512  *  it is actually specified in ANSI X9.63.
1513  *  This identifier is retained for backwards compatibility
1514  */
1515 #  define EVP_PKEY_ECDH_KDF_X9_62   EVP_PKEY_ECDH_KDF_X9_63
1516
1517 #  ifdef  __cplusplus
1518 }
1519 #  endif
1520 # endif
1521 #endif