RT3676: Expose ECgroup i2d functions
[openssl.git] / include / openssl / ec.h
1
2 /* crypto/ec/ec.h */
3 /*
4  * Originally written by Bodo Moeller for the OpenSSL project.
5  */
6 /**
7  * \file crypto/ec/ec.h Include file for the OpenSSL EC functions
8  * \author Originally written by Bodo Moeller for the OpenSSL project
9  */
10 /* ====================================================================
11  * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  *
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in
22  *    the documentation and/or other materials provided with the
23  *    distribution.
24  *
25  * 3. All advertising materials mentioning features or use of this
26  *    software must display the following acknowledgment:
27  *    "This product includes software developed by the OpenSSL Project
28  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29  *
30  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31  *    endorse or promote products derived from this software without
32  *    prior written permission. For written permission, please contact
33  *    openssl-core@openssl.org.
34  *
35  * 5. Products derived from this software may not be called "OpenSSL"
36  *    nor may "OpenSSL" appear in their names without prior written
37  *    permission of the OpenSSL Project.
38  *
39  * 6. Redistributions of any form whatsoever must retain the following
40  *    acknowledgment:
41  *    "This product includes software developed by the OpenSSL Project
42  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43  *
44  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
48  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55  * OF THE POSSIBILITY OF SUCH DAMAGE.
56  * ====================================================================
57  *
58  * This product includes cryptographic software written by Eric Young
59  * (eay@cryptsoft.com).  This product includes software written by Tim
60  * Hudson (tjh@cryptsoft.com).
61  *
62  */
63 /* ====================================================================
64  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
65  *
66  * Portions of the attached software ("Contribution") are developed by
67  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
68  *
69  * The Contribution is licensed pursuant to the OpenSSL open source
70  * license provided above.
71  *
72  * The elliptic curve binary polynomial software is originally written by
73  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
74  *
75  */
76
77 #ifndef HEADER_EC_H
78 # define HEADER_EC_H
79
80 # include <openssl/opensslconf.h>
81
82 # ifdef OPENSSL_NO_EC
83 #  error EC is disabled.
84 # endif
85
86 # include <openssl/asn1.h>
87 # include <openssl/symhacks.h>
88 # if OPENSSL_API_COMPAT < 0x10100000L
89 #  include <openssl/bn.h>
90 # endif
91
92 # ifdef  __cplusplus
93 extern "C" {
94 # elif defined(__SUNPRO_C)
95 #  if __SUNPRO_C >= 0x520
96 #   pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
97 #  endif
98 # endif
99
100 # ifndef OPENSSL_ECC_MAX_FIELD_BITS
101 #  define OPENSSL_ECC_MAX_FIELD_BITS 661
102 # endif
103
104 /** Enum for the point conversion form as defined in X9.62 (ECDSA)
105  *  for the encoding of a elliptic curve point (x,y) */
106 typedef enum {
107         /** the point is encoded as z||x, where the octet z specifies
108          *  which solution of the quadratic equation y is  */
109     POINT_CONVERSION_COMPRESSED = 2,
110         /** the point is encoded as z||x||y, where z is the octet 0x04  */
111     POINT_CONVERSION_UNCOMPRESSED = 4,
112         /** the point is encoded as z||x||y, where the octet z specifies
113          *  which solution of the quadratic equation y is  */
114     POINT_CONVERSION_HYBRID = 6
115 } point_conversion_form_t;
116
117 typedef struct ec_method_st EC_METHOD;
118 typedef struct ec_group_st EC_GROUP;
119 typedef struct ec_point_st EC_POINT;
120 typedef struct ecpk_parameters_st ECPKPARAMETERS;
121 typedef struct ec_parameters_st ECPARAMETERS;
122
123 /********************************************************************/
124 /*               EC_METHODs for curves over GF(p)                   */
125 /********************************************************************/
126
127 /** Returns the basic GFp ec methods which provides the basis for the
128  *  optimized methods.
129  *  \return  EC_METHOD object
130  */
131 const EC_METHOD *EC_GFp_simple_method(void);
132
133 /** Returns GFp methods using montgomery multiplication.
134  *  \return  EC_METHOD object
135  */
136 const EC_METHOD *EC_GFp_mont_method(void);
137
138 /** Returns GFp methods using optimized methods for NIST recommended curves
139  *  \return  EC_METHOD object
140  */
141 const EC_METHOD *EC_GFp_nist_method(void);
142
143 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
144 #  ifndef OPENSSL_SYS_WIN32
145 /** Returns 64-bit optimized methods for nistp224
146  *  \return  EC_METHOD object
147  */
148 const EC_METHOD *EC_GFp_nistp224_method(void);
149
150 /** Returns 64-bit optimized methods for nistp256
151  *  \return  EC_METHOD object
152  */
153 const EC_METHOD *EC_GFp_nistp256_method(void);
154
155 /** Returns 64-bit optimized methods for nistp521
156  *  \return  EC_METHOD object
157  */
158 const EC_METHOD *EC_GFp_nistp521_method(void);
159 #  endif
160 # endif
161
162 # ifndef OPENSSL_NO_EC2M
163 /********************************************************************/
164 /*           EC_METHOD for curves over GF(2^m)                      */
165 /********************************************************************/
166
167 /** Returns the basic GF2m ec method
168  *  \return  EC_METHOD object
169  */
170 const EC_METHOD *EC_GF2m_simple_method(void);
171
172 # endif
173
174 /********************************************************************/
175 /*                   EC_GROUP functions                             */
176 /********************************************************************/
177
178 /** Creates a new EC_GROUP object
179  *  \param   meth  EC_METHOD to use
180  *  \return  newly created EC_GROUP object or NULL in case of an error.
181  */
182 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
183
184 /** Frees a EC_GROUP object
185  *  \param  group  EC_GROUP object to be freed.
186  */
187 void EC_GROUP_free(EC_GROUP *group);
188
189 /** Clears and frees a EC_GROUP object
190  *  \param  group  EC_GROUP object to be cleared and freed.
191  */
192 void EC_GROUP_clear_free(EC_GROUP *group);
193
194 /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
195  *  \param  dst  destination EC_GROUP object
196  *  \param  src  source EC_GROUP object
197  *  \return 1 on success and 0 if an error occurred.
198  */
199 int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
200
201 /** Creates a new EC_GROUP object and copies the copies the content
202  *  form src to the newly created EC_KEY object
203  *  \param  src  source EC_GROUP object
204  *  \return newly created EC_GROUP object or NULL in case of an error.
205  */
206 EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
207
208 /** Returns the EC_METHOD of the EC_GROUP object.
209  *  \param  group  EC_GROUP object
210  *  \return EC_METHOD used in this EC_GROUP object.
211  */
212 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
213
214 /** Returns the field type of the EC_METHOD.
215  *  \param  meth  EC_METHOD object
216  *  \return NID of the underlying field type OID.
217  */
218 int EC_METHOD_get_field_type(const EC_METHOD *meth);
219
220 /** Sets the generator and it's order/cofactor of a EC_GROUP object.
221  *  \param  group      EC_GROUP object
222  *  \param  generator  EC_POINT object with the generator.
223  *  \param  order      the order of the group generated by the generator.
224  *  \param  cofactor   the index of the sub-group generated by the generator
225  *                     in the group of all points on the elliptic curve.
226  *  \return 1 on success and 0 if an error occurred
227  */
228 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
229                            const BIGNUM *order, const BIGNUM *cofactor);
230
231 /** Returns the generator of a EC_GROUP object.
232  *  \param  group  EC_GROUP object
233  *  \return the currently used generator (possibly NULL).
234  */
235 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
236
237 /** Returns the montgomery data for order(Generator)
238  *  \param  group  EC_GROUP object
239  *  \return the currently used generator (possibly NULL).
240 */
241 BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group);
242
243 /** Gets the order of a EC_GROUP
244  *  \param  group  EC_GROUP object
245  *  \param  order  BIGNUM to which the order is copied
246  *  \param  ctx    unused
247  *  \return 1 on success and 0 if an error occurred
248  */
249 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
250
251 /** Gets the order of an EC_GROUP
252  *  \param  group  EC_GROUP object
253  *  \return the group order
254  */
255
256 const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
257
258 /** Gets the number of bits of ther order of an EC_GROUP
259  *  \param  group  EC_GROUP object
260  *  \return number of bits of group order.
261  */
262
263 int EC_GROUP_order_bits(const EC_GROUP *group);
264
265 /** Gets the cofactor of a EC_GROUP
266  *  \param  group     EC_GROUP object
267  *  \param  cofactor  BIGNUM to which the cofactor is copied
268  *  \param  ctx       unused
269  *  \return 1 on success and 0 if an error occurred
270  */
271 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
272                           BN_CTX *ctx);
273
274 /** Gets the cofactor of an EC_GROUP
275  *  \param  group  EC_GROUP object
276  *  \return the group cofactor
277  */
278
279 const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
280
281 /** Sets the name of a EC_GROUP object
282  *  \param  group  EC_GROUP object
283  *  \param  nid    NID of the curve name OID
284  */
285 void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
286
287 /** Returns the curve name of a EC_GROUP object
288  *  \param  group  EC_GROUP object
289  *  \return NID of the curve name OID or 0 if not set.
290  */
291 int EC_GROUP_get_curve_name(const EC_GROUP *group);
292
293 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
294 int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
295
296 void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
297                                         point_conversion_form_t form);
298 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
299
300 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
301 size_t EC_GROUP_get_seed_len(const EC_GROUP *);
302 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
303
304 /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b
305  *  \param  group  EC_GROUP object
306  *  \param  p      BIGNUM with the prime number
307  *  \param  a      BIGNUM with parameter a of the equation
308  *  \param  b      BIGNUM with parameter b of the equation
309  *  \param  ctx    BN_CTX object (optional)
310  *  \return 1 on success and 0 if an error occurred
311  */
312 int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
313                            const BIGNUM *b, BN_CTX *ctx);
314
315 /** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b
316  *  \param  group  EC_GROUP object
317  *  \param  p      BIGNUM for the prime number
318  *  \param  a      BIGNUM for parameter a of the equation
319  *  \param  b      BIGNUM for parameter b of the equation
320  *  \param  ctx    BN_CTX object (optional)
321  *  \return 1 on success and 0 if an error occurred
322  */
323 int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
324                            BIGNUM *b, BN_CTX *ctx);
325
326 # ifndef OPENSSL_NO_EC2M
327 /** Sets the parameter of a ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
328  *  \param  group  EC_GROUP object
329  *  \param  p      BIGNUM with the polynomial defining the underlying field
330  *  \param  a      BIGNUM with parameter a of the equation
331  *  \param  b      BIGNUM with parameter b of the equation
332  *  \param  ctx    BN_CTX object (optional)
333  *  \return 1 on success and 0 if an error occurred
334  */
335 int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
336                             const BIGNUM *b, BN_CTX *ctx);
337
338 /** Gets the parameter of the ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
339  *  \param  group  EC_GROUP object
340  *  \param  p      BIGNUM for the polynomial defining the underlying field
341  *  \param  a      BIGNUM for parameter a of the equation
342  *  \param  b      BIGNUM for parameter b of the equation
343  *  \param  ctx    BN_CTX object (optional)
344  *  \return 1 on success and 0 if an error occurred
345  */
346 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
347                             BIGNUM *b, BN_CTX *ctx);
348 # endif
349 /** Returns the number of bits needed to represent a field element
350  *  \param  group  EC_GROUP object
351  *  \return number of bits needed to represent a field element
352  */
353 int EC_GROUP_get_degree(const EC_GROUP *group);
354
355 /** Checks whether the parameter in the EC_GROUP define a valid ec group
356  *  \param  group  EC_GROUP object
357  *  \param  ctx    BN_CTX object (optional)
358  *  \return 1 if group is a valid ec group and 0 otherwise
359  */
360 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
361
362 /** Checks whether the discriminant of the elliptic curve is zero or not
363  *  \param  group  EC_GROUP object
364  *  \param  ctx    BN_CTX object (optional)
365  *  \return 1 if the discriminant is not zero and 0 otherwise
366  */
367 int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
368
369 /** Compares two EC_GROUP objects
370  *  \param  a    first EC_GROUP object
371  *  \param  b    second EC_GROUP object
372  *  \param  ctx  BN_CTX object (optional)
373  *  \return 0 if both groups are equal and 1 otherwise
374  */
375 int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
376
377 /*
378  * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
379  * choosing an appropriate EC_METHOD
380  */
381
382 /** Creates a new EC_GROUP object with the specified parameters defined
383  *  over GFp (defined by the equation y^2 = x^3 + a*x + b)
384  *  \param  p    BIGNUM with the prime number
385  *  \param  a    BIGNUM with the parameter a of the equation
386  *  \param  b    BIGNUM with the parameter b of the equation
387  *  \param  ctx  BN_CTX object (optional)
388  *  \return newly created EC_GROUP object with the specified parameters
389  */
390 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
391                                  const BIGNUM *b, BN_CTX *ctx);
392 # ifndef OPENSSL_NO_EC2M
393 /** Creates a new EC_GROUP object with the specified parameters defined
394  *  over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)
395  *  \param  p    BIGNUM with the polynomial defining the underlying field
396  *  \param  a    BIGNUM with the parameter a of the equation
397  *  \param  b    BIGNUM with the parameter b of the equation
398  *  \param  ctx  BN_CTX object (optional)
399  *  \return newly created EC_GROUP object with the specified parameters
400  */
401 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
402                                   const BIGNUM *b, BN_CTX *ctx);
403 # endif
404
405 /** Creates a EC_GROUP object with a curve specified by a NID
406  *  \param  nid  NID of the OID of the curve name
407  *  \return newly created EC_GROUP object with specified curve or NULL
408  *          if an error occurred
409  */
410 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
411
412 /** Creates a new EC_GROUP object from an ECPARAMETERS object
413  *  \param  params  pointer to the ECPARAMETERS object
414  *  \return newly created EC_GROUP object with specified curve or NULL
415  *          if an error occurred
416  */
417 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);
418
419 /** Creates an ECPARAMETERS object for the the given EC_GROUP object.
420  *  \param  group   pointer to the EC_GROUP object
421  *  \param  params  pointer to an existing ECPARAMETERS object or NULL
422  *  \return pointer to the new ECPARAMETERS object or NULL
423  *          if an error occurred.
424  */
425 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
426                                         ECPARAMETERS *params);
427
428 /** Creates a new EC_GROUP object from an ECPKPARAMETERS object
429  *  \param  params  pointer to an existing ECPKPARAMETERS object, or NULL
430  *  \return newly created EC_GROUP object with specified curve, or NULL
431  *          if an error occurred
432  */
433 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);
434
435 /** Creates an ECPKPARAMETERS object for the the given EC_GROUP object.
436  *  \param  group   pointer to the EC_GROUP object
437  *  \param  params  pointer to an existing ECPKPARAMETERS object or NULL
438  *  \return pointer to the new ECPKPARAMETERS object or NULL
439  *          if an error occurred.
440  */
441 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,
442                                             ECPKPARAMETERS *params);
443
444 /********************************************************************/
445 /*               handling of internal curves                        */
446 /********************************************************************/
447
448 typedef struct {
449     int nid;
450     const char *comment;
451 } EC_builtin_curve;
452
453 /*
454  * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
455  * available curves or zero if a error occurred. In case r ist not zero
456  * nitems EC_builtin_curve structures are filled with the data of the first
457  * nitems internal groups
458  */
459 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
460
461 const char *EC_curve_nid2nist(int nid);
462 int EC_curve_nist2nid(const char *name);
463
464 /********************************************************************/
465 /*                    EC_POINT functions                            */
466 /********************************************************************/
467
468 /** Creates a new EC_POINT object for the specified EC_GROUP
469  *  \param  group  EC_GROUP the underlying EC_GROUP object
470  *  \return newly created EC_POINT object or NULL if an error occurred
471  */
472 EC_POINT *EC_POINT_new(const EC_GROUP *group);
473
474 /** Frees a EC_POINT object
475  *  \param  point  EC_POINT object to be freed
476  */
477 void EC_POINT_free(EC_POINT *point);
478
479 /** Clears and frees a EC_POINT object
480  *  \param  point  EC_POINT object to be cleared and freed
481  */
482 void EC_POINT_clear_free(EC_POINT *point);
483
484 /** Copies EC_POINT object
485  *  \param  dst  destination EC_POINT object
486  *  \param  src  source EC_POINT object
487  *  \return 1 on success and 0 if an error occurred
488  */
489 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
490
491 /** Creates a new EC_POINT object and copies the content of the supplied
492  *  EC_POINT
493  *  \param  src    source EC_POINT object
494  *  \param  group  underlying the EC_GROUP object
495  *  \return newly created EC_POINT object or NULL if an error occurred
496  */
497 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
498
499 /** Returns the EC_METHOD used in EC_POINT object
500  *  \param  point  EC_POINT object
501  *  \return the EC_METHOD used
502  */
503 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
504
505 /** Sets a point to infinity (neutral element)
506  *  \param  group  underlying EC_GROUP object
507  *  \param  point  EC_POINT to set to infinity
508  *  \return 1 on success and 0 if an error occurred
509  */
510 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
511
512 /** Sets the jacobian projective coordinates of a EC_POINT over GFp
513  *  \param  group  underlying EC_GROUP object
514  *  \param  p      EC_POINT object
515  *  \param  x      BIGNUM with the x-coordinate
516  *  \param  y      BIGNUM with the y-coordinate
517  *  \param  z      BIGNUM with the z-coordinate
518  *  \param  ctx    BN_CTX object (optional)
519  *  \return 1 on success and 0 if an error occurred
520  */
521 int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
522                                              EC_POINT *p, const BIGNUM *x,
523                                              const BIGNUM *y, const BIGNUM *z,
524                                              BN_CTX *ctx);
525
526 /** Gets the jacobian projective coordinates of a EC_POINT over GFp
527  *  \param  group  underlying EC_GROUP object
528  *  \param  p      EC_POINT object
529  *  \param  x      BIGNUM for the x-coordinate
530  *  \param  y      BIGNUM for the y-coordinate
531  *  \param  z      BIGNUM for the z-coordinate
532  *  \param  ctx    BN_CTX object (optional)
533  *  \return 1 on success and 0 if an error occurred
534  */
535 int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
536                                              const EC_POINT *p, BIGNUM *x,
537                                              BIGNUM *y, BIGNUM *z,
538                                              BN_CTX *ctx);
539
540 /** Sets the affine coordinates of a EC_POINT over GFp
541  *  \param  group  underlying EC_GROUP object
542  *  \param  p      EC_POINT object
543  *  \param  x      BIGNUM with the x-coordinate
544  *  \param  y      BIGNUM with the y-coordinate
545  *  \param  ctx    BN_CTX object (optional)
546  *  \return 1 on success and 0 if an error occurred
547  */
548 int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
549                                         const BIGNUM *x, const BIGNUM *y,
550                                         BN_CTX *ctx);
551
552 /** Gets the affine coordinates of a EC_POINT over GFp
553  *  \param  group  underlying EC_GROUP object
554  *  \param  p      EC_POINT object
555  *  \param  x      BIGNUM for the x-coordinate
556  *  \param  y      BIGNUM for the y-coordinate
557  *  \param  ctx    BN_CTX object (optional)
558  *  \return 1 on success and 0 if an error occurred
559  */
560 int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
561                                         const EC_POINT *p, BIGNUM *x,
562                                         BIGNUM *y, BN_CTX *ctx);
563
564 /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp
565  *  \param  group  underlying EC_GROUP object
566  *  \param  p      EC_POINT object
567  *  \param  x      BIGNUM with x-coordinate
568  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
569  *  \param  ctx    BN_CTX object (optional)
570  *  \return 1 on success and 0 if an error occurred
571  */
572 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
573                                             EC_POINT *p, const BIGNUM *x,
574                                             int y_bit, BN_CTX *ctx);
575 # ifndef OPENSSL_NO_EC2M
576 /** Sets the affine coordinates of a EC_POINT over GF2m
577  *  \param  group  underlying EC_GROUP object
578  *  \param  p      EC_POINT object
579  *  \param  x      BIGNUM with the x-coordinate
580  *  \param  y      BIGNUM with the y-coordinate
581  *  \param  ctx    BN_CTX object (optional)
582  *  \return 1 on success and 0 if an error occurred
583  */
584 int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
585                                          const BIGNUM *x, const BIGNUM *y,
586                                          BN_CTX *ctx);
587
588 /** Gets the affine coordinates of a EC_POINT over GF2m
589  *  \param  group  underlying EC_GROUP object
590  *  \param  p      EC_POINT object
591  *  \param  x      BIGNUM for the x-coordinate
592  *  \param  y      BIGNUM for the y-coordinate
593  *  \param  ctx    BN_CTX object (optional)
594  *  \return 1 on success and 0 if an error occurred
595  */
596 int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
597                                          const EC_POINT *p, BIGNUM *x,
598                                          BIGNUM *y, BN_CTX *ctx);
599
600 /** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m
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 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
609                                              EC_POINT *p, const BIGNUM *x,
610                                              int y_bit, BN_CTX *ctx);
611 # endif
612 /** Encodes a EC_POINT object to a octet string
613  *  \param  group  underlying EC_GROUP object
614  *  \param  p      EC_POINT object
615  *  \param  form   point conversion form
616  *  \param  buf    memory buffer for the result. If NULL the function returns
617  *                 required buffer size.
618  *  \param  len    length of the memory buffer
619  *  \param  ctx    BN_CTX object (optional)
620  *  \return the length of the encoded octet string or 0 if an error occurred
621  */
622 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
623                           point_conversion_form_t form,
624                           unsigned char *buf, size_t len, BN_CTX *ctx);
625
626 /** Decodes a EC_POINT from a octet string
627  *  \param  group  underlying EC_GROUP object
628  *  \param  p      EC_POINT object
629  *  \param  buf    memory buffer with the encoded ec point
630  *  \param  len    length of the encoded ec point
631  *  \param  ctx    BN_CTX object (optional)
632  *  \return 1 on success and 0 if an error occurred
633  */
634 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
635                        const unsigned char *buf, size_t len, BN_CTX *ctx);
636
637 /** Encodes an EC_POINT object to an allocated octet string
638  *  \param  group  underlying EC_GROUP object
639  *  \param  point  EC_POINT object
640  *  \param  form   point conversion form
641  *  \param  pbuf   returns pointer to allocated buffer
642  *  \param  len    length of the memory buffer
643  *  \param  ctx    BN_CTX object (optional)
644  *  \return the length of the encoded octet string or 0 if an error occurred
645  */
646
647 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
648                           point_conversion_form_t form,
649                           unsigned char **pbuf, BN_CTX *ctx);
650
651 /* other interfaces to point2oct/oct2point: */
652 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
653                           point_conversion_form_t form, BIGNUM *, BN_CTX *);
654 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
655                             EC_POINT *, BN_CTX *);
656 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
657                          point_conversion_form_t form, BN_CTX *);
658 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
659                              EC_POINT *, BN_CTX *);
660
661 /********************************************************************/
662 /*         functions for doing EC_POINT arithmetic                  */
663 /********************************************************************/
664
665 /** Computes the sum of two EC_POINT
666  *  \param  group  underlying EC_GROUP object
667  *  \param  r      EC_POINT object for the result (r = a + b)
668  *  \param  a      EC_POINT object with the first summand
669  *  \param  b      EC_POINT object with the second summand
670  *  \param  ctx    BN_CTX object (optional)
671  *  \return 1 on success and 0 if an error occurred
672  */
673 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
674                  const EC_POINT *b, BN_CTX *ctx);
675
676 /** Computes the double of a EC_POINT
677  *  \param  group  underlying EC_GROUP object
678  *  \param  r      EC_POINT object for the result (r = 2 * a)
679  *  \param  a      EC_POINT object
680  *  \param  ctx    BN_CTX object (optional)
681  *  \return 1 on success and 0 if an error occurred
682  */
683 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
684                  BN_CTX *ctx);
685
686 /** Computes the inverse of a EC_POINT
687  *  \param  group  underlying EC_GROUP object
688  *  \param  a      EC_POINT object to be inverted (it's used for the result as well)
689  *  \param  ctx    BN_CTX object (optional)
690  *  \return 1 on success and 0 if an error occurred
691  */
692 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
693
694 /** Checks whether the point is the neutral element of the group
695  *  \param  group  the underlying EC_GROUP object
696  *  \param  p      EC_POINT object
697  *  \return 1 if the point is the neutral element and 0 otherwise
698  */
699 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
700
701 /** Checks whether the point is on the curve
702  *  \param  group  underlying EC_GROUP object
703  *  \param  point  EC_POINT object to check
704  *  \param  ctx    BN_CTX object (optional)
705  *  \return 1 if point if on the curve and 0 otherwise
706  */
707 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
708                          BN_CTX *ctx);
709
710 /** Compares two EC_POINTs
711  *  \param  group  underlying EC_GROUP object
712  *  \param  a      first EC_POINT object
713  *  \param  b      second EC_POINT object
714  *  \param  ctx    BN_CTX object (optional)
715  *  \return 0 if both points are equal and a value != 0 otherwise
716  */
717 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
718                  BN_CTX *ctx);
719
720 int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
721 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
722                           EC_POINT *points[], BN_CTX *ctx);
723
724 /** Computes r = generator * n sum_{i=0}^{num-1} p[i] * m[i]
725  *  \param  group  underlying EC_GROUP object
726  *  \param  r      EC_POINT object for the result
727  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
728  *  \param  num    number futher summands
729  *  \param  p      array of size num of EC_POINT objects
730  *  \param  m      array of size num of BIGNUM objects
731  *  \param  ctx    BN_CTX object (optional)
732  *  \return 1 on success and 0 if an error occurred
733  */
734 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
735                   size_t num, const EC_POINT *p[], const BIGNUM *m[],
736                   BN_CTX *ctx);
737
738 /** Computes r = generator * n + q * m
739  *  \param  group  underlying EC_GROUP object
740  *  \param  r      EC_POINT object for the result
741  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
742  *  \param  q      EC_POINT object with the first factor of the second summand
743  *  \param  m      BIGNUM with the second factor of the second summand
744  *  \param  ctx    BN_CTX object (optional)
745  *  \return 1 on success and 0 if an error occurred
746  */
747 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
748                  const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
749
750 /** Stores multiples of generator for faster point multiplication
751  *  \param  group  EC_GROUP object
752  *  \param  ctx    BN_CTX object (optional)
753  *  \return 1 on success and 0 if an error occurred
754  */
755 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
756
757 /** Reports whether a precomputation has been done
758  *  \param  group  EC_GROUP object
759  *  \return 1 if a pre-computation has been done and 0 otherwise
760  */
761 int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
762
763 /********************************************************************/
764 /*                       ASN1 stuff                                 */
765 /********************************************************************/
766
767 DECLARE_ASN1_ITEM(ECPKPARAMETERS)
768 DECLARE_ASN1_ITEM(ECPARAMETERS)
769
770 /*
771  * EC_GROUP_get_basis_type() returns the NID of the basis type used to
772  * represent the field elements
773  */
774 int EC_GROUP_get_basis_type(const EC_GROUP *);
775 # ifndef OPENSSL_NO_EC2M
776 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
777 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
778                                    unsigned int *k2, unsigned int *k3);
779 # endif
780
781 # define OPENSSL_EC_EXPLICIT_CURVE  0x000
782 # define OPENSSL_EC_NAMED_CURVE     0x001
783
784 typedef struct ecpk_parameters_st ECPKPARAMETERS;
785
786 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
787 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
788
789 # define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
790 # define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
791 # define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
792                 (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
793 # define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
794                 (unsigned char *)(x))
795
796 int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
797 # ifndef OPENSSL_NO_STDIO
798 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
799 # endif
800
801 /********************************************************************/
802 /*                      EC_KEY functions                            */
803 /********************************************************************/
804
805 /* some values for the encoding_flag */
806 # define EC_PKEY_NO_PARAMETERS   0x001
807 # define EC_PKEY_NO_PUBKEY       0x002
808
809 /* some values for the flags field */
810 # define EC_FLAG_NON_FIPS_ALLOW  0x1
811 # define EC_FLAG_FIPS_CHECKED    0x2
812 # define EC_FLAG_COFACTOR_ECDH   0x1000
813
814 /** Creates a new EC_KEY object.
815  *  \return EC_KEY object or NULL if an error occurred.
816  */
817 EC_KEY *EC_KEY_new(void);
818
819 int EC_KEY_get_flags(const EC_KEY *key);
820
821 void EC_KEY_set_flags(EC_KEY *key, int flags);
822
823 void EC_KEY_clear_flags(EC_KEY *key, int flags);
824
825 /** Creates a new EC_KEY object using a named curve as underlying
826  *  EC_GROUP object.
827  *  \param  nid  NID of the named curve.
828  *  \return EC_KEY object or NULL if an error occurred.
829  */
830 EC_KEY *EC_KEY_new_by_curve_name(int nid);
831
832 /** Frees a EC_KEY object.
833  *  \param  key  EC_KEY object to be freed.
834  */
835 void EC_KEY_free(EC_KEY *key);
836
837 /** Copies a EC_KEY object.
838  *  \param  dst  destination EC_KEY object
839  *  \param  src  src EC_KEY object
840  *  \return dst or NULL if an error occurred.
841  */
842 EC_KEY *EC_KEY_copy(EC_KEY *dst, EC_KEY *src);
843
844 /** Creates a new EC_KEY object and copies the content from src to it.
845  *  \param  src  the source EC_KEY object
846  *  \return newly created EC_KEY object or NULL if an error occurred.
847  */
848 EC_KEY *EC_KEY_dup(EC_KEY *src);
849
850 /** Increases the internal reference count of a EC_KEY object.
851  *  \param  key  EC_KEY object
852  *  \return 1 on success and 0 if an error occurred.
853  */
854 int EC_KEY_up_ref(EC_KEY *key);
855
856 /** Returns the EC_GROUP object of a EC_KEY object
857  *  \param  key  EC_KEY object
858  *  \return the EC_GROUP object (possibly NULL).
859  */
860 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
861
862 /** Sets the EC_GROUP of a EC_KEY object.
863  *  \param  key    EC_KEY object
864  *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY
865  *                 object will use an own copy of the EC_GROUP).
866  *  \return 1 on success and 0 if an error occurred.
867  */
868 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
869
870 /** Returns the private key of a EC_KEY object.
871  *  \param  key  EC_KEY object
872  *  \return a BIGNUM with the private key (possibly NULL).
873  */
874 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
875
876 /** Sets the private key of a EC_KEY object.
877  *  \param  key  EC_KEY object
878  *  \param  prv  BIGNUM with the private key (note: the EC_KEY object
879  *               will use an own copy of the BIGNUM).
880  *  \return 1 on success and 0 if an error occurred.
881  */
882 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
883
884 /** Returns the public key of a EC_KEY object.
885  *  \param  key  the EC_KEY object
886  *  \return a EC_POINT object with the public key (possibly NULL)
887  */
888 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
889
890 /** Sets the public key of a EC_KEY object.
891  *  \param  key  EC_KEY object
892  *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object
893  *               will use an own copy of the EC_POINT object).
894  *  \return 1 on success and 0 if an error occurred.
895  */
896 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
897
898 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
899 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
900 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
901 void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
902
903 #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
904     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
905 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);
906 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);
907
908 /* wrapper functions for the underlying EC_GROUP object */
909 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
910
911 /** Creates a table of pre-computed multiples of the generator to
912  *  accelerate further EC_KEY operations.
913  *  \param  key  EC_KEY object
914  *  \param  ctx  BN_CTX object (optional)
915  *  \return 1 on success and 0 if an error occurred.
916  */
917 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
918
919 /** Creates a new ec private (and optional a new public) key.
920  *  \param  key  EC_KEY object
921  *  \return 1 on success and 0 if an error occurred.
922  */
923 int EC_KEY_generate_key(EC_KEY *key);
924
925 /** Verifies that a private and/or public key is valid.
926  *  \param  key  the EC_KEY object
927  *  \return 1 on success and 0 otherwise.
928  */
929 int EC_KEY_check_key(const EC_KEY *key);
930
931 /** Indicates if an EC_KEY can be used for signing.
932  *  \param  key  the EC_KEY object
933  *  \return 1 if can can sign and 0 otherwise.
934  */
935 int EC_KEY_can_sign(const EC_KEY *eckey);
936
937 /** Sets a public key from affine coordindates performing
938  *  necessary NIST PKV tests.
939  *  \param  key  the EC_KEY object
940  *  \param  x    public key x coordinate
941  *  \param  y    public key y coordinate
942  *  \return 1 on success and 0 otherwise.
943  */
944 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
945                                              BIGNUM *y);
946
947 /** Encodes an EC_KEY public key to an allocated octet string
948  *  \param  key    key to encode
949  *  \param  form   point conversion form
950  *  \param  pbuf   returns pointer to allocated buffer
951  *  \param  len    length of the memory buffer
952  *  \param  ctx    BN_CTX object (optional)
953  *  \return the length of the encoded octet string or 0 if an error occurred
954  */
955
956 size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form,
957                       unsigned char **pbuf, BN_CTX *ctx);
958
959 /** Decodes a EC_KEY public key from a octet string
960  *  \param  key    key to decode
961  *  \param  buf    memory buffer with the encoded ec point
962  *  \param  len    length of the encoded ec point
963  *  \param  ctx    BN_CTX object (optional)
964  *  \return 1 on success and 0 if an error occurred
965  */
966
967 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
968                    BN_CTX *ctx);
969
970 /** Decodes an EC_KEY private key from an octet string
971  *  \param  key    key to decode
972  *  \param  buf    memory buffer with the encoded private key
973  *  \param  len    length of the encoded key
974  *  \return 1 on success and 0 if an error occurred
975  */
976
977 int EC_KEY_oct2priv(EC_KEY *key, unsigned char *buf, size_t len);
978
979 /** Encodes a EC_KEY private key to an octet string
980  *  \param  key    key to encode
981  *  \param  buf    memory buffer for the result. If NULL the function returns
982  *                 required buffer size.
983  *  \param  len    length of the memory buffer
984  *  \return the length of the encoded octet string or 0 if an error occurred
985  */
986
987 size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len);
988
989 /** Encodes an EC_KEY private key to an allocated octet string
990  *  \param  key    key to encode
991  *  \param  pbuf   returns pointer to allocated buffer
992  *  \return the length of the encoded octet string or 0 if an error occurred
993  */
994
995 size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf);
996
997 /********************************************************************/
998 /*        de- and encoding functions for SEC1 ECPrivateKey          */
999 /********************************************************************/
1000
1001 /** Decodes a private key from a memory buffer.
1002  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1003  *  \param  in   pointer to memory with the DER encoded private key
1004  *  \param  len  length of the DER encoded private key
1005  *  \return the decoded private key or NULL if an error occurred.
1006  */
1007 EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
1008
1009 /** Encodes a private key object and stores the result in a buffer.
1010  *  \param  key  the EC_KEY object to encode
1011  *  \param  out  the buffer for the result (if NULL the function returns number
1012  *               of bytes needed).
1013  *  \return 1 on success and 0 if an error occurred.
1014  */
1015 int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
1016
1017 /********************************************************************/
1018 /*        de- and encoding functions for EC parameters              */
1019 /********************************************************************/
1020
1021 /** Decodes ec parameter from a memory buffer.
1022  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1023  *  \param  in   pointer to memory with the DER encoded ec parameters
1024  *  \param  len  length of the DER encoded ec parameters
1025  *  \return a EC_KEY object with the decoded parameters or NULL if an error
1026  *          occurred.
1027  */
1028 EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
1029
1030 /** Encodes ec parameter and stores the result in a buffer.
1031  *  \param  key  the EC_KEY object with ec parameters to encode
1032  *  \param  out  the buffer for the result (if NULL the function returns number
1033  *               of bytes needed).
1034  *  \return 1 on success and 0 if an error occurred.
1035  */
1036 int i2d_ECParameters(EC_KEY *key, unsigned char **out);
1037
1038 /********************************************************************/
1039 /*         de- and encoding functions for EC public key             */
1040 /*         (octet string, not DER -- hence 'o2i' and 'i2o')         */
1041 /********************************************************************/
1042
1043 /** Decodes a ec public key from a octet string.
1044  *  \param  key  a pointer to a EC_KEY object which should be used
1045  *  \param  in   memory buffer with the encoded public key
1046  *  \param  len  length of the encoded public key
1047  *  \return EC_KEY object with decoded public key or NULL if an error
1048  *          occurred.
1049  */
1050 EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
1051
1052 /** Encodes a ec public key in an octet string.
1053  *  \param  key  the EC_KEY object with the public key
1054  *  \param  out  the buffer for the result (if NULL the function returns number
1055  *               of bytes needed).
1056  *  \return 1 on success and 0 if an error occurred
1057  */
1058 int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
1059
1060 /** Prints out the ec parameters on human readable form.
1061  *  \param  bp   BIO object to which the information is printed
1062  *  \param  key  EC_KEY object
1063  *  \return 1 on success and 0 if an error occurred
1064  */
1065 int ECParameters_print(BIO *bp, const EC_KEY *key);
1066
1067 /** Prints out the contents of a EC_KEY object
1068  *  \param  bp   BIO object to which the information is printed
1069  *  \param  key  EC_KEY object
1070  *  \param  off  line offset
1071  *  \return 1 on success and 0 if an error occurred
1072  */
1073 int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
1074
1075 # ifndef OPENSSL_NO_STDIO
1076 /** Prints out the ec parameters on human readable form.
1077  *  \param  fp   file descriptor to which the information is printed
1078  *  \param  key  EC_KEY object
1079  *  \return 1 on success and 0 if an error occurred
1080  */
1081 int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
1082
1083 /** Prints out the contents of a EC_KEY object
1084  *  \param  fp   file descriptor to which the information is printed
1085  *  \param  key  EC_KEY object
1086  *  \param  off  line offset
1087  *  \return 1 on success and 0 if an error occurred
1088  */
1089 int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
1090
1091 # endif
1092
1093 const EC_KEY_METHOD *EC_KEY_OpenSSL(void);
1094 const EC_KEY_METHOD *EC_KEY_get_default_method(void);
1095 void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
1096 const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
1097 int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
1098 EC_KEY *EC_KEY_new_method(ENGINE *engine);
1099
1100 int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
1101                    const unsigned char *Z, size_t Zlen,
1102                    const unsigned char *sinfo, size_t sinfolen,
1103                    const EVP_MD *md);
1104
1105 int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
1106                      const EC_KEY *ecdh,
1107                      void *(*KDF) (const void *in, size_t inlen,
1108                                    void *out, size_t *outlen));
1109
1110 typedef struct ECDSA_SIG_st ECDSA_SIG;
1111
1112 /** Allocates and initialize a ECDSA_SIG structure
1113  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1114  */
1115 ECDSA_SIG *ECDSA_SIG_new(void);
1116
1117 /** frees a ECDSA_SIG structure
1118  *  \param  sig  pointer to the ECDSA_SIG structure
1119  */
1120 void ECDSA_SIG_free(ECDSA_SIG *sig);
1121
1122 /** DER encode content of ECDSA_SIG object (note: this function modifies *pp
1123  *  (*pp += length of the DER encoded signature)).
1124  *  \param  sig  pointer to the ECDSA_SIG object
1125  *  \param  pp   pointer to a unsigned char pointer for the output or NULL
1126  *  \return the length of the DER encoded ECDSA_SIG object or 0
1127  */
1128 int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
1129
1130 /** Decodes a DER encoded ECDSA signature (note: this function changes *pp
1131  *  (*pp += len)).
1132  *  \param  sig  pointer to ECDSA_SIG pointer (may be NULL)
1133  *  \param  pp   memory buffer with the DER encoded signature
1134  *  \param  len  length of the buffer
1135  *  \return pointer to the decoded ECDSA_SIG structure (or NULL)
1136  */
1137 ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
1138
1139 /** Accessor for r and s fields of ECDSA_SIG
1140  *  \param  sig  pointer to ECDSA_SIG pointer
1141  *  \param  pr   pointer to BIGNUM pointer for r (may be NULL)
1142  *  \param  ps   pointer to BIGNUM pointer for s (may be NULL)
1143  */
1144 void ECDSA_SIG_get0(BIGNUM **pr, BIGNUM **ps, ECDSA_SIG *sig);
1145
1146 /** Computes the ECDSA signature of the given hash value using
1147  *  the supplied private key and returns the created signature.
1148  *  \param  dgst      pointer to the hash value
1149  *  \param  dgst_len  length of the hash value
1150  *  \param  eckey     EC_KEY object containing a private EC key
1151  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1152  */
1153 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
1154                          EC_KEY *eckey);
1155
1156 /** Computes ECDSA signature of a given hash value using the supplied
1157  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1158  *  \param  dgst     pointer to the hash value to sign
1159  *  \param  dgstlen  length of the hash value
1160  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1161  *  \param  rp       BIGNUM with a pre-computed rp value (optioanl),
1162  *                   see ECDSA_sign_setup
1163  *  \param  eckey    EC_KEY object containing a private EC key
1164  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1165  */
1166 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
1167                             const BIGNUM *kinv, const BIGNUM *rp,
1168                             EC_KEY *eckey);
1169
1170 /** Verifies that the supplied signature is a valid ECDSA
1171  *  signature of the supplied hash value using the supplied public key.
1172  *  \param  dgst      pointer to the hash value
1173  *  \param  dgst_len  length of the hash value
1174  *  \param  sig       ECDSA_SIG structure
1175  *  \param  eckey     EC_KEY object containing a public EC key
1176  *  \return 1 if the signature is valid, 0 if the signature is invalid
1177  *          and -1 on error
1178  */
1179 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
1180                     const ECDSA_SIG *sig, EC_KEY *eckey);
1181
1182 /** Precompute parts of the signing operation
1183  *  \param  eckey  EC_KEY object containing a private EC key
1184  *  \param  ctx    BN_CTX object (optional)
1185  *  \param  kinv   BIGNUM pointer for the inverse of k
1186  *  \param  rp     BIGNUM pointer for x coordinate of k * generator
1187  *  \return 1 on success and 0 otherwise
1188  */
1189 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
1190
1191 /** Computes ECDSA signature of a given hash value using the supplied
1192  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1193  *  \param  type     this parameter is ignored
1194  *  \param  dgst     pointer to the hash value to sign
1195  *  \param  dgstlen  length of the hash value
1196  *  \param  sig      memory for the DER encoded created signature
1197  *  \param  siglen   pointer to the length of the returned signature
1198  *  \param  eckey    EC_KEY object containing a private EC key
1199  *  \return 1 on success and 0 otherwise
1200  */
1201 int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
1202                unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
1203
1204 /** Computes ECDSA signature of a given hash value using the supplied
1205  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1206  *  \param  type     this parameter is ignored
1207  *  \param  dgst     pointer to the hash value to sign
1208  *  \param  dgstlen  length of the hash value
1209  *  \param  sig      buffer to hold the DER encoded signature
1210  *  \param  siglen   pointer to the length of the returned signature
1211  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1212  *  \param  rp       BIGNUM with a pre-computed rp value (optioanl),
1213  *                   see ECDSA_sign_setup
1214  *  \param  eckey    EC_KEY object containing a private EC key
1215  *  \return 1 on success and 0 otherwise
1216  */
1217 int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
1218                   unsigned char *sig, unsigned int *siglen,
1219                   const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
1220
1221 /** Verifies that the given signature is valid ECDSA signature
1222  *  of the supplied hash value using the specified public key.
1223  *  \param  type     this parameter is ignored
1224  *  \param  dgst     pointer to the hash value
1225  *  \param  dgstlen  length of the hash value
1226  *  \param  sig      pointer to the DER encoded signature
1227  *  \param  siglen   length of the DER encoded signature
1228  *  \param  eckey    EC_KEY object containing a public EC key
1229  *  \return 1 if the signature is valid, 0 if the signature is invalid
1230  *          and -1 on error
1231  */
1232 int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
1233                  const unsigned char *sig, int siglen, EC_KEY *eckey);
1234
1235 /** Returns the maximum length of the DER encoded signature
1236  *  \param  eckey  EC_KEY object
1237  *  \return numbers of bytes required for the DER encoded signature
1238  */
1239 int ECDSA_size(const EC_KEY *eckey);
1240
1241 /********************************************************************/
1242 /*  EC_KEY_METHOD constructors, destructors, writers and accessors  */
1243 /********************************************************************/
1244
1245 EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
1246 void EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
1247 void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
1248                             int (*init)(EC_KEY *key),
1249                             void (*finish)(EC_KEY *key),
1250                             int (*copy)(EC_KEY *dest, const EC_KEY *src),
1251                             int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
1252                             int (*set_private)(EC_KEY *key,
1253                                                const BIGNUM *priv_key),
1254                             int (*set_public)(EC_KEY *key,
1255                                               const EC_POINT *pub_key));
1256
1257 void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
1258                               int (*keygen)(EC_KEY *key));
1259
1260 void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
1261                                    int (*ckey)(unsigned char **psec,
1262                                                size_t *pseclen,
1263                                                const EC_POINT *pub_key,
1264                                                const EC_KEY *ecdh));
1265
1266 void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
1267                             int (*sign)(int type, const unsigned char *dgst,
1268                                         int dlen, unsigned char *sig,
1269                                         unsigned int *siglen,
1270                                         const BIGNUM *kinv, const BIGNUM *r,
1271                                         EC_KEY *eckey),
1272                             int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1273                                               BIGNUM **kinvp, BIGNUM **rp),
1274                             ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
1275                                                    int dgst_len,
1276                                                    const BIGNUM *in_kinv,
1277                                                    const BIGNUM *in_r,
1278                                                    EC_KEY *eckey));
1279
1280 void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
1281                               int (*verify)(int type, const unsigned
1282                                             char *dgst, int dgst_len,
1283                                             const unsigned char *sigbuf,
1284                                             int sig_len, EC_KEY *eckey),
1285                               int (*verify_sig)(const unsigned char *dgst,
1286                                                 int dgst_len,
1287                                                 const ECDSA_SIG *sig,
1288                                                 EC_KEY *eckey));
1289
1290 void EC_KEY_METHOD_get_init(EC_KEY_METHOD *meth,
1291                             int (**pinit)(EC_KEY *key),
1292                             void (**pfinish)(EC_KEY *key),
1293                             int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
1294                             int (**pset_group)(EC_KEY *key,
1295                                                const EC_GROUP *grp),
1296                             int (**pset_private)(EC_KEY *key,
1297                                                  const BIGNUM *priv_key),
1298                             int (**pset_public)(EC_KEY *key,
1299                                                 const EC_POINT *pub_key));
1300
1301 void EC_KEY_METHOD_get_keygen(EC_KEY_METHOD *meth,
1302                               int (**pkeygen)(EC_KEY *key));
1303
1304 void EC_KEY_METHOD_get_compute_key(EC_KEY_METHOD *meth,
1305                                    int (**pck)(unsigned char **psec,
1306                                                size_t *pseclen,
1307                                                const EC_POINT *pub_key,
1308                                                const EC_KEY *ecdh));
1309
1310 void EC_KEY_METHOD_get_sign(EC_KEY_METHOD *meth,
1311                             int (**psign)(int type, const unsigned char *dgst,
1312                                           int dlen, unsigned char *sig,
1313                                           unsigned int *siglen,
1314                                           const BIGNUM *kinv, const BIGNUM *r,
1315                                           EC_KEY *eckey),
1316                             int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1317                                                 BIGNUM **kinvp, BIGNUM **rp),
1318                             ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
1319                                                      int dgst_len,
1320                                                      const BIGNUM *in_kinv,
1321                                                      const BIGNUM *in_r,
1322                                                      EC_KEY *eckey));
1323
1324 void EC_KEY_METHOD_get_verify(EC_KEY_METHOD *meth,
1325                               int (**pverify)(int type, const unsigned
1326                                               char *dgst, int dgst_len,
1327                                               const unsigned char *sigbuf,
1328                                               int sig_len, EC_KEY *eckey),
1329                               int (**pverify_sig)(const unsigned char *dgst,
1330                                                   int dgst_len,
1331                                                   const ECDSA_SIG *sig,
1332                                                   EC_KEY *eckey));
1333
1334 # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
1335
1336 # ifndef __cplusplus
1337 #  if defined(__SUNPRO_C)
1338 #   if __SUNPRO_C >= 0x520
1339 #    pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
1340 #   endif
1341 #  endif
1342 # endif
1343
1344 # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
1345         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1346                                 EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
1347                                 EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
1348
1349 # define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \
1350         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1351                                 EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
1352                                 EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL)
1353
1354 # define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \
1355         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1356                                 EVP_PKEY_OP_DERIVE, \
1357                                 EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL)
1358
1359 # define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \
1360         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1361                                 EVP_PKEY_OP_DERIVE, \
1362                                 EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL)
1363
1364 # define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \
1365         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1366                                 EVP_PKEY_OP_DERIVE, \
1367                                 EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL)
1368
1369 # define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \
1370         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1371                                 EVP_PKEY_OP_DERIVE, \
1372                                 EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL)
1373
1374 # define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \
1375         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1376                                 EVP_PKEY_OP_DERIVE, \
1377                                 EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)md)
1378
1379 # define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \
1380         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1381                                 EVP_PKEY_OP_DERIVE, \
1382                                 EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)pmd)
1383
1384 # define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \
1385         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1386                                 EVP_PKEY_OP_DERIVE, \
1387                                 EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL)
1388
1389 # define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \
1390         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1391                                 EVP_PKEY_OP_DERIVE, \
1392                         EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, (void *)plen)
1393
1394 # define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \
1395         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1396                                 EVP_PKEY_OP_DERIVE, \
1397                                 EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)p)
1398
1399 # define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \
1400         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
1401                                 EVP_PKEY_OP_DERIVE, \
1402                                 EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)p)
1403
1404 # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID             (EVP_PKEY_ALG_CTRL + 1)
1405 # define EVP_PKEY_CTRL_EC_PARAM_ENC                      (EVP_PKEY_ALG_CTRL + 2)
1406 # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR                  (EVP_PKEY_ALG_CTRL + 3)
1407 # define EVP_PKEY_CTRL_EC_KDF_TYPE                       (EVP_PKEY_ALG_CTRL + 4)
1408 # define EVP_PKEY_CTRL_EC_KDF_MD                         (EVP_PKEY_ALG_CTRL + 5)
1409 # define EVP_PKEY_CTRL_GET_EC_KDF_MD                     (EVP_PKEY_ALG_CTRL + 6)
1410 # define EVP_PKEY_CTRL_EC_KDF_OUTLEN                     (EVP_PKEY_ALG_CTRL + 7)
1411 # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN                 (EVP_PKEY_ALG_CTRL + 8)
1412 # define EVP_PKEY_CTRL_EC_KDF_UKM                        (EVP_PKEY_ALG_CTRL + 9)
1413 # define EVP_PKEY_CTRL_GET_EC_KDF_UKM                    (EVP_PKEY_ALG_CTRL + 10)
1414 /* KDF types */
1415 # define EVP_PKEY_ECDH_KDF_NONE                          1
1416 # define EVP_PKEY_ECDH_KDF_X9_62                         2
1417
1418 /* BEGIN ERROR CODES */
1419 /*
1420  * The following lines are auto generated by the script mkerr.pl. Any changes
1421  * made after this point may be overwritten when the script is next run.
1422  */
1423 void ERR_load_EC_strings(void);
1424
1425 /* Error codes for the EC functions. */
1426
1427 /* Function codes. */
1428 # define EC_F_BN_TO_FELEM                                 224
1429 # define EC_F_COMPUTE_WNAF                                143
1430 # define EC_F_D2I_ECPARAMETERS                            144
1431 # define EC_F_D2I_ECPKPARAMETERS                          145
1432 # define EC_F_D2I_ECPRIVATEKEY                            146
1433 # define EC_F_DO_EC_KEY_PRINT                             221
1434 # define EC_F_ECDH_CMS_DECRYPT                            238
1435 # define EC_F_ECDH_CMS_SET_SHARED_INFO                    239
1436 # define EC_F_ECDH_COMPUTE_KEY                            246
1437 # define EC_F_ECDH_SIMPLE_COMPUTE_KEY                     257
1438 # define EC_F_ECDSA_DO_SIGN_EX                            251
1439 # define EC_F_ECDSA_DO_VERIFY                             252
1440 # define EC_F_ECDSA_SIGN_EX                               254
1441 # define EC_F_ECDSA_SIGN_SETUP                            248
1442 # define EC_F_ECDSA_VERIFY                                253
1443 # define EC_F_ECKEY_PARAM2TYPE                            223
1444 # define EC_F_ECKEY_PARAM_DECODE                          212
1445 # define EC_F_ECKEY_PRIV_DECODE                           213
1446 # define EC_F_ECKEY_PRIV_ENCODE                           214
1447 # define EC_F_ECKEY_PUB_DECODE                            215
1448 # define EC_F_ECKEY_PUB_ENCODE                            216
1449 # define EC_F_ECKEY_TYPE2PARAM                            220
1450 # define EC_F_ECPARAMETERS_PRINT                          147
1451 # define EC_F_ECPARAMETERS_PRINT_FP                       148
1452 # define EC_F_ECPKPARAMETERS_PRINT                        149
1453 # define EC_F_ECPKPARAMETERS_PRINT_FP                     150
1454 # define EC_F_ECP_NISTZ256_GET_AFFINE                     240
1455 # define EC_F_ECP_NISTZ256_MULT_PRECOMPUTE                243
1456 # define EC_F_ECP_NISTZ256_POINTS_MUL                     241
1457 # define EC_F_ECP_NISTZ256_PRE_COMP_NEW                   244
1458 # define EC_F_ECP_NISTZ256_WINDOWED_MUL                   242
1459 # define EC_F_ECP_NIST_MOD_192                            203
1460 # define EC_F_ECP_NIST_MOD_224                            204
1461 # define EC_F_ECP_NIST_MOD_256                            205
1462 # define EC_F_ECP_NIST_MOD_521                            206
1463 # define EC_F_EC_ASN1_GROUP2CURVE                         153
1464 # define EC_F_EC_ASN1_GROUP2FIELDID                       154
1465 # define EC_F_EC_ASN1_GROUP2PARAMETERS                    155
1466 # define EC_F_EC_ASN1_GROUP2PKPARAMETERS                  156
1467 # define EC_F_EC_ASN1_PARAMETERS2GROUP                    157
1468 # define EC_F_EC_ASN1_PKPARAMETERS2GROUP                  158
1469 # define EC_F_EC_EX_DATA_SET_DATA                         211
1470 # define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY           208
1471 # define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT     159
1472 # define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE              195
1473 # define EC_F_EC_GF2M_SIMPLE_OCT2POINT                    160
1474 # define EC_F_EC_GF2M_SIMPLE_POINT2OCT                    161
1475 # define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
1476 # define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
1477 # define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES   164
1478 # define EC_F_EC_GFP_MONT_FIELD_DECODE                    133
1479 # define EC_F_EC_GFP_MONT_FIELD_ENCODE                    134
1480 # define EC_F_EC_GFP_MONT_FIELD_MUL                       131
1481 # define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE                209
1482 # define EC_F_EC_GFP_MONT_FIELD_SQR                       132
1483 # define EC_F_EC_GFP_MONT_GROUP_SET_CURVE                 189
1484 # define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP             135
1485 # define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE             225
1486 # define EC_F_EC_GFP_NISTP224_POINTS_MUL                  228
1487 # define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226
1488 # define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE             230
1489 # define EC_F_EC_GFP_NISTP256_POINTS_MUL                  231
1490 # define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232
1491 # define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE             233
1492 # define EC_F_EC_GFP_NISTP521_POINTS_MUL                  234
1493 # define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235
1494 # define EC_F_EC_GFP_NIST_FIELD_MUL                       200
1495 # define EC_F_EC_GFP_NIST_FIELD_SQR                       201
1496 # define EC_F_EC_GFP_NIST_GROUP_SET_CURVE                 202
1497 # define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT      165
1498 # define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE               166
1499 # define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP           100
1500 # define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR           101
1501 # define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE                   102
1502 # define EC_F_EC_GFP_SIMPLE_OCT2POINT                     103
1503 # define EC_F_EC_GFP_SIMPLE_POINT2OCT                     104
1504 # define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE            137
1505 # define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES  167
1506 # define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
1507 # define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES  168
1508 # define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
1509 # define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES    169
1510 # define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
1511 # define EC_F_EC_GROUP_CHECK                              170
1512 # define EC_F_EC_GROUP_CHECK_DISCRIMINANT                 171
1513 # define EC_F_EC_GROUP_COPY                               106
1514 # define EC_F_EC_GROUP_GET0_GENERATOR                     139
1515 # define EC_F_EC_GROUP_GET_COFACTOR                       140
1516 # define EC_F_EC_GROUP_GET_CURVE_GF2M                     172
1517 # define EC_F_EC_GROUP_GET_CURVE_GFP                      130
1518 # define EC_F_EC_GROUP_GET_DEGREE                         173
1519 # define EC_F_EC_GROUP_GET_ECPARAMETERS                   261
1520 # define EC_F_EC_GROUP_GET_ECPKPARAMETERS                 262
1521 # define EC_F_EC_GROUP_GET_ORDER                          141
1522 # define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS              193
1523 # define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS                194
1524 # define EC_F_EC_GROUP_NEW                                108
1525 # define EC_F_EC_GROUP_NEW_BY_CURVE_NAME                  174
1526 # define EC_F_EC_GROUP_NEW_FROM_DATA                      175
1527 # define EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS              263
1528 # define EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS            264
1529 # define EC_F_EC_GROUP_PRECOMPUTE_MULT                    142
1530 # define EC_F_EC_GROUP_SET_CURVE_GF2M                     176
1531 # define EC_F_EC_GROUP_SET_CURVE_GFP                      109
1532 # define EC_F_EC_GROUP_SET_EXTRA_DATA                     110
1533 # define EC_F_EC_GROUP_SET_GENERATOR                      111
1534 # define EC_F_EC_KEY_CHECK_KEY                            177
1535 # define EC_F_EC_KEY_COPY                                 178
1536 # define EC_F_EC_KEY_GENERATE_KEY                         179
1537 # define EC_F_EC_KEY_NEW                                  182
1538 # define EC_F_EC_KEY_NEW_METHOD                           245
1539 # define EC_F_EC_KEY_OCT2PRIV                             255
1540 # define EC_F_EC_KEY_PRINT                                180
1541 # define EC_F_EC_KEY_PRINT_FP                             181
1542 # define EC_F_EC_KEY_PRIV2OCT                             256
1543 # define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES    229
1544 # define EC_F_EC_KEY_SIMPLE_CHECK_KEY                     258
1545 # define EC_F_EC_KEY_SIMPLE_OCT2PRIV                      259
1546 # define EC_F_EC_KEY_SIMPLE_PRIV2OCT                      260
1547 # define EC_F_EC_POINTS_MAKE_AFFINE                       136
1548 # define EC_F_EC_POINT_ADD                                112
1549 # define EC_F_EC_POINT_CMP                                113
1550 # define EC_F_EC_POINT_COPY                               114
1551 # define EC_F_EC_POINT_DBL                                115
1552 # define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M        183
1553 # define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP         116
1554 # define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP    117
1555 # define EC_F_EC_POINT_INVERT                             210
1556 # define EC_F_EC_POINT_IS_AT_INFINITY                     118
1557 # define EC_F_EC_POINT_IS_ON_CURVE                        119
1558 # define EC_F_EC_POINT_MAKE_AFFINE                        120
1559 # define EC_F_EC_POINT_MUL                                184
1560 # define EC_F_EC_POINT_NEW                                121
1561 # define EC_F_EC_POINT_OCT2POINT                          122
1562 # define EC_F_EC_POINT_POINT2OCT                          123
1563 # define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M        185
1564 # define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP         124
1565 # define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M    186
1566 # define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP     125
1567 # define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP    126
1568 # define EC_F_EC_POINT_SET_TO_INFINITY                    127
1569 # define EC_F_EC_PRE_COMP_DUP                             207
1570 # define EC_F_EC_PRE_COMP_NEW                             196
1571 # define EC_F_EC_WNAF_MUL                                 187
1572 # define EC_F_EC_WNAF_PRECOMPUTE_MULT                     188
1573 # define EC_F_I2D_ECPARAMETERS                            190
1574 # define EC_F_I2D_ECPKPARAMETERS                          191
1575 # define EC_F_I2D_ECPRIVATEKEY                            192
1576 # define EC_F_I2O_ECPUBLICKEY                             151
1577 # define EC_F_NISTP224_PRE_COMP_NEW                       227
1578 # define EC_F_NISTP256_PRE_COMP_NEW                       236
1579 # define EC_F_NISTP521_PRE_COMP_NEW                       237
1580 # define EC_F_O2I_ECPUBLICKEY                             152
1581 # define EC_F_OLD_EC_PRIV_DECODE                          222
1582 # define EC_F_OSSL_ECDH_COMPUTE_KEY                       247
1583 # define EC_F_OSSL_ECDSA_SIGN_SIG                         249
1584 # define EC_F_OSSL_ECDSA_VERIFY_SIG                       250
1585 # define EC_F_PKEY_EC_CTRL                                197
1586 # define EC_F_PKEY_EC_CTRL_STR                            198
1587 # define EC_F_PKEY_EC_DERIVE                              217
1588 # define EC_F_PKEY_EC_KEYGEN                              199
1589 # define EC_F_PKEY_EC_PARAMGEN                            219
1590 # define EC_F_PKEY_EC_SIGN                                218
1591
1592 /* Reason codes. */
1593 # define EC_R_ASN1_ERROR                                  115
1594 # define EC_R_ASN1_UNKNOWN_FIELD                          116
1595 # define EC_R_BAD_SIGNATURE                               156
1596 # define EC_R_BIGNUM_OUT_OF_RANGE                         144
1597 # define EC_R_BUFFER_TOO_SMALL                            100
1598 # define EC_R_COORDINATES_OUT_OF_RANGE                    146
1599 # define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH                 160
1600 # define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING              159
1601 # define EC_R_D2I_ECPKPARAMETERS_FAILURE                  117
1602 # define EC_R_DECODE_ERROR                                142
1603 # define EC_R_DISCRIMINANT_IS_ZERO                        118
1604 # define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE                119
1605 # define EC_R_FIELD_TOO_LARGE                             143
1606 # define EC_R_GF2M_NOT_SUPPORTED                          147
1607 # define EC_R_GROUP2PKPARAMETERS_FAILURE                  120
1608 # define EC_R_I2D_ECPKPARAMETERS_FAILURE                  121
1609 # define EC_R_INCOMPATIBLE_OBJECTS                        101
1610 # define EC_R_INVALID_ARGUMENT                            112
1611 # define EC_R_INVALID_COMPRESSED_POINT                    110
1612 # define EC_R_INVALID_COMPRESSION_BIT                     109
1613 # define EC_R_INVALID_CURVE                               141
1614 # define EC_R_INVALID_DIGEST                              151
1615 # define EC_R_INVALID_DIGEST_TYPE                         138
1616 # define EC_R_INVALID_ENCODING                            102
1617 # define EC_R_INVALID_FIELD                               103
1618 # define EC_R_INVALID_FORM                                104
1619 # define EC_R_INVALID_GROUP_ORDER                         122
1620 # define EC_R_INVALID_OUTPUT_LENGTH                       161
1621 # define EC_R_INVALID_PENTANOMIAL_BASIS                   132
1622 # define EC_R_INVALID_PRIVATE_KEY                         123
1623 # define EC_R_INVALID_TRINOMIAL_BASIS                     137
1624 # define EC_R_KDF_FAILED                                  153
1625 # define EC_R_KDF_PARAMETER_ERROR                         148
1626 # define EC_R_KEYS_NOT_SET                                140
1627 # define EC_R_MISSING_PARAMETERS                          124
1628 # define EC_R_MISSING_PRIVATE_KEY                         125
1629 # define EC_R_NEED_NEW_SETUP_VALUES                       157
1630 # define EC_R_NOT_A_NIST_PRIME                            135
1631 # define EC_R_NOT_A_SUPPORTED_NIST_PRIME                  136
1632 # define EC_R_NOT_IMPLEMENTED                             126
1633 # define EC_R_NOT_INITIALIZED                             111
1634 # define EC_R_NO_FIELD_MOD                                133
1635 # define EC_R_NO_PARAMETERS_SET                           139
1636 # define EC_R_NO_PRIVATE_VALUE                            154
1637 # define EC_R_OPERATION_NOT_SUPPORTED                     152
1638 # define EC_R_PASSED_NULL_PARAMETER                       134
1639 # define EC_R_PEER_KEY_ERROR                              149
1640 # define EC_R_PKPARAMETERS2GROUP_FAILURE                  127
1641 # define EC_R_POINT_ARITHMETIC_FAILURE                    155
1642 # define EC_R_POINT_AT_INFINITY                           106
1643 # define EC_R_POINT_IS_NOT_ON_CURVE                       107
1644 # define EC_R_RANDOM_NUMBER_GENERATION_FAILED             158
1645 # define EC_R_SHARED_INFO_ERROR                           150
1646 # define EC_R_SLOT_FULL                                   108
1647 # define EC_R_UNDEFINED_GENERATOR                         113
1648 # define EC_R_UNDEFINED_ORDER                             128
1649 # define EC_R_UNKNOWN_GROUP                               129
1650 # define EC_R_UNKNOWN_ORDER                               114
1651 # define EC_R_UNSUPPORTED_FIELD                           131
1652 # define EC_R_WRONG_CURVE_PARAMETERS                      145
1653 # define EC_R_WRONG_ORDER                                 130
1654
1655 #ifdef  __cplusplus
1656 }
1657 #endif
1658 #endif