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