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