OSDN Git Service

Update OpenSSL to 1.0.1j.
[ffftp/ffftp.git] / contrib / openssl / include / openssl / ec.h
1 /* crypto/ec/ec.h */\r
2 /*\r
3  * Originally written by Bodo Moeller for the OpenSSL project.\r
4  */\r
5 /**\r
6  * \file crypto/ec/ec.h Include file for the OpenSSL EC functions\r
7  * \author Originally written by Bodo Moeller for the OpenSSL project\r
8  */\r
9 /* ====================================================================\r
10  * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.\r
11  *\r
12  * Redistribution and use in source and binary forms, with or without\r
13  * modification, are permitted provided that the following conditions\r
14  * are met:\r
15  *\r
16  * 1. Redistributions of source code must retain the above copyright\r
17  *    notice, this list of conditions and the following disclaimer.\r
18  *\r
19  * 2. Redistributions in binary form must reproduce the above copyright\r
20  *    notice, this list of conditions and the following disclaimer in\r
21  *    the documentation and/or other materials provided with the\r
22  *    distribution.\r
23  *\r
24  * 3. All advertising materials mentioning features or use of this\r
25  *    software must display the following acknowledgment:\r
26  *    "This product includes software developed by the OpenSSL Project\r
27  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"\r
28  *\r
29  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to\r
30  *    endorse or promote products derived from this software without\r
31  *    prior written permission. For written permission, please contact\r
32  *    openssl-core@openssl.org.\r
33  *\r
34  * 5. Products derived from this software may not be called "OpenSSL"\r
35  *    nor may "OpenSSL" appear in their names without prior written\r
36  *    permission of the OpenSSL Project.\r
37  *\r
38  * 6. Redistributions of any form whatsoever must retain the following\r
39  *    acknowledgment:\r
40  *    "This product includes software developed by the OpenSSL Project\r
41  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"\r
42  *\r
43  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\r
44  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
46  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\r
47  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
49  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
50  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
51  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
52  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
53  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
54  * OF THE POSSIBILITY OF SUCH DAMAGE.\r
55  * ====================================================================\r
56  *\r
57  * This product includes cryptographic software written by Eric Young\r
58  * (eay@cryptsoft.com).  This product includes software written by Tim\r
59  * Hudson (tjh@cryptsoft.com).\r
60  *\r
61  */\r
62 /* ====================================================================\r
63  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.\r
64  *\r
65  * Portions of the attached software ("Contribution") are developed by\r
66  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.\r
67  *\r
68  * The Contribution is licensed pursuant to the OpenSSL open source\r
69  * license provided above.\r
70  *\r
71  * The elliptic curve binary polynomial software is originally written by\r
72  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.\r
73  *\r
74  */\r
75 \r
76 #ifndef HEADER_EC_H\r
77 #define HEADER_EC_H\r
78 \r
79 #include <openssl/opensslconf.h>\r
80 \r
81 #ifdef OPENSSL_NO_EC\r
82 #error EC is disabled.\r
83 #endif\r
84 \r
85 #include <openssl/asn1.h>\r
86 #include <openssl/symhacks.h>\r
87 #ifndef OPENSSL_NO_DEPRECATED\r
88 #include <openssl/bn.h>\r
89 #endif\r
90 \r
91 #ifdef  __cplusplus\r
92 extern "C" {\r
93 #elif defined(__SUNPRO_C)\r
94 # if __SUNPRO_C >= 0x520\r
95 # pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)\r
96 # endif\r
97 #endif\r
98 \r
99 \r
100 #ifndef OPENSSL_ECC_MAX_FIELD_BITS\r
101 # define OPENSSL_ECC_MAX_FIELD_BITS 661\r
102 #endif\r
103 \r
104 /** Enum for the point conversion form as defined in X9.62 (ECDSA)\r
105  *  for the encoding of a elliptic curve point (x,y) */\r
106 typedef enum {\r
107         /** the point is encoded as z||x, where the octet z specifies\r
108          *  which solution of the quadratic equation y is  */\r
109         POINT_CONVERSION_COMPRESSED = 2,\r
110         /** the point is encoded as z||x||y, where z is the octet 0x02  */\r
111         POINT_CONVERSION_UNCOMPRESSED = 4,\r
112         /** the point is encoded as z||x||y, where the octet z specifies\r
113          *  which solution of the quadratic equation y is  */\r
114         POINT_CONVERSION_HYBRID = 6\r
115 } point_conversion_form_t;\r
116 \r
117 \r
118 typedef struct ec_method_st EC_METHOD;\r
119 \r
120 typedef struct ec_group_st\r
121         /*\r
122          EC_METHOD *meth;\r
123          -- field definition\r
124          -- curve coefficients\r
125          -- optional generator with associated information (order, cofactor)\r
126          -- optional extra data (precomputed table for fast computation of multiples of generator)\r
127          -- ASN1 stuff\r
128         */\r
129         EC_GROUP;\r
130 \r
131 typedef struct ec_point_st EC_POINT;\r
132 \r
133 \r
134 /********************************************************************/\r
135 /*               EC_METHODs for curves over GF(p)                   */\r
136 /********************************************************************/\r
137 \r
138 /** Returns the basic GFp ec methods which provides the basis for the\r
139  *  optimized methods.\r
140  *  \return  EC_METHOD object\r
141  */\r
142 const EC_METHOD *EC_GFp_simple_method(void);\r
143 \r
144 /** Returns GFp methods using montgomery multiplication.\r
145  *  \return  EC_METHOD object\r
146  */\r
147 const EC_METHOD *EC_GFp_mont_method(void);\r
148 \r
149 /** Returns GFp methods using optimized methods for NIST recommended curves\r
150  *  \return  EC_METHOD object\r
151  */\r
152 const EC_METHOD *EC_GFp_nist_method(void);\r
153 \r
154 #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\r
155 /** Returns 64-bit optimized methods for nistp224\r
156  *  \return  EC_METHOD object\r
157  */\r
158 const EC_METHOD *EC_GFp_nistp224_method(void);\r
159 \r
160 /** Returns 64-bit optimized methods for nistp256\r
161  *  \return  EC_METHOD object\r
162  */\r
163 const EC_METHOD *EC_GFp_nistp256_method(void);\r
164 \r
165 /** Returns 64-bit optimized methods for nistp521\r
166  *  \return  EC_METHOD object\r
167  */\r
168 const EC_METHOD *EC_GFp_nistp521_method(void);\r
169 #endif\r
170 \r
171 #ifndef OPENSSL_NO_EC2M\r
172 /********************************************************************/\r
173 /*           EC_METHOD for curves over GF(2^m)                      */\r
174 /********************************************************************/\r
175 \r
176 /** Returns the basic GF2m ec method\r
177  *  \return  EC_METHOD object\r
178  */\r
179 const EC_METHOD *EC_GF2m_simple_method(void);\r
180 \r
181 #endif\r
182 \r
183 \r
184 /********************************************************************/\r
185 /*                   EC_GROUP functions                             */\r
186 /********************************************************************/\r
187 \r
188 /** Creates a new EC_GROUP object\r
189  *  \param   meth  EC_METHOD to use\r
190  *  \return  newly created EC_GROUP object or NULL in case of an error.\r
191  */\r
192 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);\r
193 \r
194 /** Frees a EC_GROUP object\r
195  *  \param  group  EC_GROUP object to be freed.\r
196  */\r
197 void EC_GROUP_free(EC_GROUP *group);\r
198 \r
199 /** Clears and frees a EC_GROUP object\r
200  *  \param  group  EC_GROUP object to be cleared and freed.\r
201  */\r
202 void EC_GROUP_clear_free(EC_GROUP *group);\r
203 \r
204 /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.\r
205  *  \param  dst  destination EC_GROUP object\r
206  *  \param  src  source EC_GROUP object\r
207  *  \return 1 on success and 0 if an error occurred.\r
208  */\r
209 int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);\r
210 \r
211 /** Creates a new EC_GROUP object and copies the copies the content\r
212  *  form src to the newly created EC_KEY object\r
213  *  \param  src  source EC_GROUP object\r
214  *  \return newly created EC_GROUP object or NULL in case of an error.\r
215  */\r
216 EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);\r
217 \r
218 /** Returns the EC_METHOD of the EC_GROUP object.\r
219  *  \param  group  EC_GROUP object\r
220  *  \return EC_METHOD used in this EC_GROUP object.\r
221  */\r
222 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);\r
223 \r
224 /** Returns the field type of the EC_METHOD.\r
225  *  \param  meth  EC_METHOD object\r
226  *  \return NID of the underlying field type OID.\r
227  */\r
228 int EC_METHOD_get_field_type(const EC_METHOD *meth);\r
229 \r
230 /** Sets the generator and it's order/cofactor of a EC_GROUP object.\r
231  *  \param  group      EC_GROUP object\r
232  *  \param  generator  EC_POINT object with the generator.\r
233  *  \param  order      the order of the group generated by the generator.\r
234  *  \param  cofactor   the index of the sub-group generated by the generator\r
235  *                     in the group of all points on the elliptic curve.\r
236  *  \return 1 on success and 0 if an error occured\r
237  */\r
238 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);\r
239 \r
240 /** Returns the generator of a EC_GROUP object.\r
241  *  \param  group  EC_GROUP object\r
242  *  \return the currently used generator (possibly NULL).\r
243  */\r
244 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);\r
245 \r
246 /** Gets the order of a EC_GROUP\r
247  *  \param  group  EC_GROUP object\r
248  *  \param  order  BIGNUM to which the order is copied\r
249  *  \param  ctx    BN_CTX object (optional)\r
250  *  \return 1 on success and 0 if an error occured\r
251  */\r
252 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);\r
253 \r
254 /** Gets the cofactor of a EC_GROUP\r
255  *  \param  group     EC_GROUP object\r
256  *  \param  cofactor  BIGNUM to which the cofactor is copied\r
257  *  \param  ctx       BN_CTX object (optional)\r
258  *  \return 1 on success and 0 if an error occured\r
259  */\r
260 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);\r
261 \r
262 /** Sets the name of a EC_GROUP object\r
263  *  \param  group  EC_GROUP object\r
264  *  \param  nid    NID of the curve name OID\r
265  */\r
266 void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);\r
267 \r
268 /** Returns the curve name of a EC_GROUP object\r
269  *  \param  group  EC_GROUP object\r
270  *  \return NID of the curve name OID or 0 if not set.\r
271  */\r
272 int EC_GROUP_get_curve_name(const EC_GROUP *group);\r
273 \r
274 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);\r
275 int EC_GROUP_get_asn1_flag(const EC_GROUP *group);\r
276 \r
277 void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form);\r
278 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);\r
279 \r
280 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);\r
281 size_t EC_GROUP_get_seed_len(const EC_GROUP *);\r
282 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);\r
283 \r
284 /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b\r
285  *  \param  group  EC_GROUP object\r
286  *  \param  p      BIGNUM with the prime number\r
287  *  \param  a      BIGNUM with parameter a of the equation\r
288  *  \param  b      BIGNUM with parameter b of the equation\r
289  *  \param  ctx    BN_CTX object (optional)\r
290  *  \return 1 on success and 0 if an error occured\r
291  */\r
292 int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);\r
293 \r
294 /** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b\r
295  *  \param  group  EC_GROUP object\r
296  *  \param  p      BIGNUM for the prime number\r
297  *  \param  a      BIGNUM for parameter a of the equation\r
298  *  \param  b      BIGNUM for parameter b of the equation\r
299  *  \param  ctx    BN_CTX object (optional)\r
300  *  \return 1 on success and 0 if an error occured\r
301  */\r
302 int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);\r
303 \r
304 #ifndef OPENSSL_NO_EC2M\r
305 /** Sets the parameter of a ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b\r
306  *  \param  group  EC_GROUP object\r
307  *  \param  p      BIGNUM with the polynomial defining the underlying field\r
308  *  \param  a      BIGNUM with parameter a of the equation\r
309  *  \param  b      BIGNUM with parameter b of the equation\r
310  *  \param  ctx    BN_CTX object (optional)\r
311  *  \return 1 on success and 0 if an error occured\r
312  */\r
313 int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);\r
314 \r
315 /** Gets the parameter of the ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b\r
316  *  \param  group  EC_GROUP object\r
317  *  \param  p      BIGNUM for the polynomial defining the underlying field\r
318  *  \param  a      BIGNUM for parameter a of the equation\r
319  *  \param  b      BIGNUM for parameter b of the equation\r
320  *  \param  ctx    BN_CTX object (optional)\r
321  *  \return 1 on success and 0 if an error occured\r
322  */\r
323 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);\r
324 #endif\r
325 /** Returns the number of bits needed to represent a field element\r
326  *  \param  group  EC_GROUP object\r
327  *  \return number of bits needed to represent a field element\r
328  */\r
329 int EC_GROUP_get_degree(const EC_GROUP *group);\r
330 \r
331 /** Checks whether the parameter in the EC_GROUP define a valid ec group\r
332  *  \param  group  EC_GROUP object\r
333  *  \param  ctx    BN_CTX object (optional)\r
334  *  \return 1 if group is a valid ec group and 0 otherwise\r
335  */\r
336 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);\r
337 \r
338 /** Checks whether the discriminant of the elliptic curve is zero or not\r
339  *  \param  group  EC_GROUP object\r
340  *  \param  ctx    BN_CTX object (optional)\r
341  *  \return 1 if the discriminant is not zero and 0 otherwise\r
342  */\r
343 int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);\r
344 \r
345 /** Compares two EC_GROUP objects\r
346  *  \param  a    first EC_GROUP object\r
347  *  \param  b    second EC_GROUP object\r
348  *  \param  ctx  BN_CTX object (optional)\r
349  *  \return 0 if both groups are equal and 1 otherwise\r
350  */\r
351 int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);\r
352 \r
353 /* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()\r
354  * after choosing an appropriate EC_METHOD */\r
355 \r
356 /** Creates a new EC_GROUP object with the specified parameters defined\r
357  *  over GFp (defined by the equation y^2 = x^3 + a*x + b)\r
358  *  \param  p    BIGNUM with the prime number\r
359  *  \param  a    BIGNUM with the parameter a of the equation\r
360  *  \param  b    BIGNUM with the parameter b of the equation\r
361  *  \param  ctx  BN_CTX object (optional)\r
362  *  \return newly created EC_GROUP object with the specified parameters\r
363  */\r
364 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);\r
365 #ifndef OPENSSL_NO_EC2M\r
366 /** Creates a new EC_GROUP object with the specified parameters defined\r
367  *  over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)\r
368  *  \param  p    BIGNUM with the polynomial defining the underlying field\r
369  *  \param  a    BIGNUM with the parameter a of the equation\r
370  *  \param  b    BIGNUM with the parameter b of the equation\r
371  *  \param  ctx  BN_CTX object (optional)\r
372  *  \return newly created EC_GROUP object with the specified parameters\r
373  */\r
374 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);\r
375 #endif\r
376 /** Creates a EC_GROUP object with a curve specified by a NID\r
377  *  \param  nid  NID of the OID of the curve name\r
378  *  \return newly created EC_GROUP object with specified curve or NULL\r
379  *          if an error occurred\r
380  */\r
381 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);\r
382 \r
383 \r
384 /********************************************************************/\r
385 /*               handling of internal curves                        */\r
386 /********************************************************************/\r
387 \r
388 typedef struct {\r
389         int nid;\r
390         const char *comment;\r
391         } EC_builtin_curve;\r
392 \r
393 /* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number\r
394  * of all available curves or zero if a error occurred.\r
395  * In case r ist not zero nitems EC_builtin_curve structures\r
396  * are filled with the data of the first nitems internal groups */\r
397 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);\r
398 \r
399 \r
400 /********************************************************************/\r
401 /*                    EC_POINT functions                            */\r
402 /********************************************************************/\r
403 \r
404 /** Creates a new EC_POINT object for the specified EC_GROUP\r
405  *  \param  group  EC_GROUP the underlying EC_GROUP object\r
406  *  \return newly created EC_POINT object or NULL if an error occurred\r
407  */\r
408 EC_POINT *EC_POINT_new(const EC_GROUP *group);\r
409 \r
410 /** Frees a EC_POINT object\r
411  *  \param  point  EC_POINT object to be freed\r
412  */\r
413 void EC_POINT_free(EC_POINT *point);\r
414 \r
415 /** Clears and frees a EC_POINT object\r
416  *  \param  point  EC_POINT object to be cleared and freed\r
417  */\r
418 void EC_POINT_clear_free(EC_POINT *point);\r
419 \r
420 /** Copies EC_POINT object\r
421  *  \param  dst  destination EC_POINT object\r
422  *  \param  src  source EC_POINT object\r
423  *  \return 1 on success and 0 if an error occured\r
424  */\r
425 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);\r
426 \r
427 /** Creates a new EC_POINT object and copies the content of the supplied\r
428  *  EC_POINT\r
429  *  \param  src    source EC_POINT object\r
430  *  \param  group  underlying the EC_GROUP object\r
431  *  \return newly created EC_POINT object or NULL if an error occurred\r
432  */\r
433 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);\r
434 \r
435 /** Returns the EC_METHOD used in EC_POINT object\r
436  *  \param  point  EC_POINT object\r
437  *  \return the EC_METHOD used\r
438  */\r
439 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);\r
440 \r
441 /** Sets a point to infinity (neutral element)\r
442  *  \param  group  underlying EC_GROUP object\r
443  *  \param  point  EC_POINT to set to infinity\r
444  *  \return 1 on success and 0 if an error occured\r
445  */\r
446 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);\r
447 \r
448 /** Sets the jacobian projective coordinates of a EC_POINT over GFp\r
449  *  \param  group  underlying EC_GROUP object\r
450  *  \param  p      EC_POINT object\r
451  *  \param  x      BIGNUM with the x-coordinate\r
452  *  \param  y      BIGNUM with the y-coordinate\r
453  *  \param  z      BIGNUM with the z-coordinate\r
454  *  \param  ctx    BN_CTX object (optional)\r
455  *  \return 1 on success and 0 if an error occured\r
456  */\r
457 int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,\r
458         const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx);\r
459 \r
460 /** Gets the jacobian projective coordinates of a EC_POINT over GFp\r
461  *  \param  group  underlying EC_GROUP object\r
462  *  \param  p      EC_POINT object\r
463  *  \param  x      BIGNUM for the x-coordinate\r
464  *  \param  y      BIGNUM for the y-coordinate\r
465  *  \param  z      BIGNUM for the z-coordinate\r
466  *  \param  ctx    BN_CTX object (optional)\r
467  *  \return 1 on success and 0 if an error occured\r
468  */\r
469 int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,\r
470         const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);\r
471 \r
472 /** Sets the affine coordinates of a EC_POINT over GFp\r
473  *  \param  group  underlying EC_GROUP object\r
474  *  \param  p      EC_POINT object\r
475  *  \param  x      BIGNUM with the x-coordinate\r
476  *  \param  y      BIGNUM with the y-coordinate\r
477  *  \param  ctx    BN_CTX object (optional)\r
478  *  \return 1 on success and 0 if an error occured\r
479  */\r
480 int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,\r
481         const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);\r
482 \r
483 /** Gets the affine coordinates of a EC_POINT over GFp\r
484  *  \param  group  underlying EC_GROUP object\r
485  *  \param  p      EC_POINT object\r
486  *  \param  x      BIGNUM for the x-coordinate\r
487  *  \param  y      BIGNUM for the y-coordinate\r
488  *  \param  ctx    BN_CTX object (optional)\r
489  *  \return 1 on success and 0 if an error occured\r
490  */\r
491 int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,\r
492         const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);\r
493 \r
494 /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp\r
495  *  \param  group  underlying EC_GROUP object\r
496  *  \param  p      EC_POINT object\r
497  *  \param  x      BIGNUM with x-coordinate\r
498  *  \param  y_bit  integer with the y-Bit (either 0 or 1)\r
499  *  \param  ctx    BN_CTX object (optional)\r
500  *  \return 1 on success and 0 if an error occured\r
501  */\r
502 int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,\r
503         const BIGNUM *x, int y_bit, BN_CTX *ctx);\r
504 #ifndef OPENSSL_NO_EC2M\r
505 /** Sets the affine coordinates of a EC_POINT over GF2m\r
506  *  \param  group  underlying EC_GROUP object\r
507  *  \param  p      EC_POINT object\r
508  *  \param  x      BIGNUM with the x-coordinate\r
509  *  \param  y      BIGNUM with the y-coordinate\r
510  *  \param  ctx    BN_CTX object (optional)\r
511  *  \return 1 on success and 0 if an error occured\r
512  */\r
513 int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,\r
514         const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);\r
515 \r
516 /** Gets the affine coordinates of a EC_POINT over GF2m\r
517  *  \param  group  underlying EC_GROUP object\r
518  *  \param  p      EC_POINT object\r
519  *  \param  x      BIGNUM for the x-coordinate\r
520  *  \param  y      BIGNUM for the y-coordinate\r
521  *  \param  ctx    BN_CTX object (optional)\r
522  *  \return 1 on success and 0 if an error occured\r
523  */\r
524 int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,\r
525         const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);\r
526 \r
527 /** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m\r
528  *  \param  group  underlying EC_GROUP object\r
529  *  \param  p      EC_POINT object\r
530  *  \param  x      BIGNUM with x-coordinate\r
531  *  \param  y_bit  integer with the y-Bit (either 0 or 1)\r
532  *  \param  ctx    BN_CTX object (optional)\r
533  *  \return 1 on success and 0 if an error occured\r
534  */\r
535 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,\r
536         const BIGNUM *x, int y_bit, BN_CTX *ctx);\r
537 #endif\r
538 /** Encodes a EC_POINT object to a octet string\r
539  *  \param  group  underlying EC_GROUP object\r
540  *  \param  p      EC_POINT object\r
541  *  \param  form   point conversion form\r
542  *  \param  buf    memory buffer for the result. If NULL the function returns\r
543  *                 required buffer size.\r
544  *  \param  len    length of the memory buffer\r
545  *  \param  ctx    BN_CTX object (optional)\r
546  *  \return the length of the encoded octet string or 0 if an error occurred\r
547  */\r
548 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,\r
549         point_conversion_form_t form,\r
550         unsigned char *buf, size_t len, BN_CTX *ctx);\r
551 \r
552 /** Decodes a EC_POINT from a octet string\r
553  *  \param  group  underlying EC_GROUP object\r
554  *  \param  p      EC_POINT object\r
555  *  \param  buf    memory buffer with the encoded ec point\r
556  *  \param  len    length of the encoded ec point\r
557  *  \param  ctx    BN_CTX object (optional)\r
558  *  \return 1 on success and 0 if an error occured\r
559  */\r
560 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,\r
561         const unsigned char *buf, size_t len, BN_CTX *ctx);\r
562 \r
563 /* other interfaces to point2oct/oct2point: */\r
564 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,\r
565         point_conversion_form_t form, BIGNUM *, BN_CTX *);\r
566 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,\r
567         EC_POINT *, BN_CTX *);\r
568 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,\r
569         point_conversion_form_t form, BN_CTX *);\r
570 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,\r
571         EC_POINT *, BN_CTX *);\r
572 \r
573 \r
574 /********************************************************************/\r
575 /*         functions for doing EC_POINT arithmetic                  */\r
576 /********************************************************************/\r
577 \r
578 /** Computes the sum of two EC_POINT\r
579  *  \param  group  underlying EC_GROUP object\r
580  *  \param  r      EC_POINT object for the result (r = a + b)\r
581  *  \param  a      EC_POINT object with the first summand\r
582  *  \param  b      EC_POINT object with the second summand\r
583  *  \param  ctx    BN_CTX object (optional)\r
584  *  \return 1 on success and 0 if an error occured\r
585  */\r
586 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);\r
587 \r
588 /** Computes the double of a EC_POINT\r
589  *  \param  group  underlying EC_GROUP object\r
590  *  \param  r      EC_POINT object for the result (r = 2 * a)\r
591  *  \param  a      EC_POINT object\r
592  *  \param  ctx    BN_CTX object (optional)\r
593  *  \return 1 on success and 0 if an error occured\r
594  */\r
595 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx);\r
596 \r
597 /** Computes the inverse of a EC_POINT\r
598  *  \param  group  underlying EC_GROUP object\r
599  *  \param  a      EC_POINT object to be inverted (it's used for the result as well)\r
600  *  \param  ctx    BN_CTX object (optional)\r
601  *  \return 1 on success and 0 if an error occured\r
602  */\r
603 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);\r
604 \r
605 /** Checks whether the point is the neutral element of the group\r
606  *  \param  group  the underlying EC_GROUP object\r
607  *  \param  p      EC_POINT object\r
608  *  \return 1 if the point is the neutral element and 0 otherwise\r
609  */\r
610 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);\r
611 \r
612 /** Checks whether the point is on the curve\r
613  *  \param  group  underlying EC_GROUP object\r
614  *  \param  point  EC_POINT object to check\r
615  *  \param  ctx    BN_CTX object (optional)\r
616  *  \return 1 if point if on the curve and 0 otherwise\r
617  */\r
618 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);\r
619 \r
620 /** Compares two EC_POINTs\r
621  *  \param  group  underlying EC_GROUP object\r
622  *  \param  a      first EC_POINT object\r
623  *  \param  b      second EC_POINT object\r
624  *  \param  ctx    BN_CTX object (optional)\r
625  *  \return 0 if both points are equal and a value != 0 otherwise\r
626  */\r
627 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);\r
628 \r
629 int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);\r
630 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx);\r
631 \r
632 /** Computes r = generator * n sum_{i=0}^{num-1} p[i] * m[i]\r
633  *  \param  group  underlying EC_GROUP object\r
634  *  \param  r      EC_POINT object for the result\r
635  *  \param  n      BIGNUM with the multiplier for the group generator (optional)\r
636  *  \param  num    number futher summands\r
637  *  \param  p      array of size num of EC_POINT objects\r
638  *  \param  m      array of size num of BIGNUM objects\r
639  *  \param  ctx    BN_CTX object (optional)\r
640  *  \return 1 on success and 0 if an error occured\r
641  */\r
642 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx);\r
643 \r
644 /** Computes r = generator * n + q * m\r
645  *  \param  group  underlying EC_GROUP object\r
646  *  \param  r      EC_POINT object for the result\r
647  *  \param  n      BIGNUM with the multiplier for the group generator (optional)\r
648  *  \param  q      EC_POINT object with the first factor of the second summand\r
649  *  \param  m      BIGNUM with the second factor of the second summand\r
650  *  \param  ctx    BN_CTX object (optional)\r
651  *  \return 1 on success and 0 if an error occured\r
652  */\r
653 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);\r
654 \r
655 /** Stores multiples of generator for faster point multiplication\r
656  *  \param  group  EC_GROUP object\r
657  *  \param  ctx    BN_CTX object (optional)\r
658  *  \return 1 on success and 0 if an error occured\r
659  */\r
660 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);\r
661 \r
662 /** Reports whether a precomputation has been done\r
663  *  \param  group  EC_GROUP object\r
664  *  \return 1 if a pre-computation has been done and 0 otherwise\r
665  */\r
666 int EC_GROUP_have_precompute_mult(const EC_GROUP *group);\r
667 \r
668 \r
669 /********************************************************************/\r
670 /*                       ASN1 stuff                                 */\r
671 /********************************************************************/\r
672 \r
673 /* EC_GROUP_get_basis_type() returns the NID of the basis type\r
674  * used to represent the field elements */\r
675 int EC_GROUP_get_basis_type(const EC_GROUP *);\r
676 #ifndef OPENSSL_NO_EC2M\r
677 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);\r
678 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,\r
679         unsigned int *k2, unsigned int *k3);\r
680 #endif\r
681 \r
682 #define OPENSSL_EC_NAMED_CURVE  0x001\r
683 \r
684 typedef struct ecpk_parameters_st ECPKPARAMETERS;\r
685 \r
686 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);\r
687 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);\r
688 \r
689 #define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)\r
690 #define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)\r
691 #define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \\r
692                 (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))\r
693 #define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \\r
694                 (unsigned char *)(x))\r
695 \r
696 #ifndef OPENSSL_NO_BIO\r
697 int     ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);\r
698 #endif\r
699 #ifndef OPENSSL_NO_FP_API\r
700 int     ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);\r
701 #endif\r
702 \r
703 \r
704 /********************************************************************/\r
705 /*                      EC_KEY functions                            */\r
706 /********************************************************************/\r
707 \r
708 typedef struct ec_key_st EC_KEY;\r
709 \r
710 /* some values for the encoding_flag */\r
711 #define EC_PKEY_NO_PARAMETERS   0x001\r
712 #define EC_PKEY_NO_PUBKEY       0x002\r
713 \r
714 /* some values for the flags field */\r
715 #define EC_FLAG_NON_FIPS_ALLOW  0x1\r
716 #define EC_FLAG_FIPS_CHECKED    0x2\r
717 \r
718 /** Creates a new EC_KEY object.\r
719  *  \return EC_KEY object or NULL if an error occurred.\r
720  */\r
721 EC_KEY *EC_KEY_new(void);\r
722 \r
723 int EC_KEY_get_flags(const EC_KEY *key);\r
724 \r
725 void EC_KEY_set_flags(EC_KEY *key, int flags);\r
726 \r
727 void EC_KEY_clear_flags(EC_KEY *key, int flags);\r
728 \r
729 /** Creates a new EC_KEY object using a named curve as underlying\r
730  *  EC_GROUP object.\r
731  *  \param  nid  NID of the named curve.\r
732  *  \return EC_KEY object or NULL if an error occurred.\r
733  */\r
734 EC_KEY *EC_KEY_new_by_curve_name(int nid);\r
735 \r
736 /** Frees a EC_KEY object.\r
737  *  \param  key  EC_KEY object to be freed.\r
738  */\r
739 void EC_KEY_free(EC_KEY *key);\r
740 \r
741 /** Copies a EC_KEY object.\r
742  *  \param  dst  destination EC_KEY object\r
743  *  \param  src  src EC_KEY object\r
744  *  \return dst or NULL if an error occurred.\r
745  */\r
746 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);\r
747 \r
748 /** Creates a new EC_KEY object and copies the content from src to it.\r
749  *  \param  src  the source EC_KEY object\r
750  *  \return newly created EC_KEY object or NULL if an error occurred.\r
751  */\r
752 EC_KEY *EC_KEY_dup(const EC_KEY *src);\r
753 \r
754 /** Increases the internal reference count of a EC_KEY object.\r
755  *  \param  key  EC_KEY object\r
756  *  \return 1 on success and 0 if an error occurred.\r
757  */\r
758 int EC_KEY_up_ref(EC_KEY *key);\r
759 \r
760 /** Returns the EC_GROUP object of a EC_KEY object\r
761  *  \param  key  EC_KEY object\r
762  *  \return the EC_GROUP object (possibly NULL).\r
763  */\r
764 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);\r
765 \r
766 /** Sets the EC_GROUP of a EC_KEY object.\r
767  *  \param  key    EC_KEY object\r
768  *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY\r
769  *                 object will use an own copy of the EC_GROUP).\r
770  *  \return 1 on success and 0 if an error occurred.\r
771  */\r
772 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);\r
773 \r
774 /** Returns the private key of a EC_KEY object.\r
775  *  \param  key  EC_KEY object\r
776  *  \return a BIGNUM with the private key (possibly NULL).\r
777  */\r
778 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);\r
779 \r
780 /** Sets the private key of a EC_KEY object.\r
781  *  \param  key  EC_KEY object\r
782  *  \param  prv  BIGNUM with the private key (note: the EC_KEY object\r
783  *               will use an own copy of the BIGNUM).\r
784  *  \return 1 on success and 0 if an error occurred.\r
785  */\r
786 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);\r
787 \r
788 /** Returns the public key of a EC_KEY object.\r
789  *  \param  key  the EC_KEY object\r
790  *  \return a EC_POINT object with the public key (possibly NULL)\r
791  */\r
792 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);\r
793 \r
794 /** Sets the public key of a EC_KEY object.\r
795  *  \param  key  EC_KEY object\r
796  *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object\r
797  *               will use an own copy of the EC_POINT object).\r
798  *  \return 1 on success and 0 if an error occurred.\r
799  */\r
800 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);\r
801 \r
802 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);\r
803 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);\r
804 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);\r
805 void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);\r
806 /* functions to set/get method specific data  */\r
807 void *EC_KEY_get_key_method_data(EC_KEY *key,\r
808         void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));\r
809 /** Sets the key method data of an EC_KEY object, if none has yet been set.\r
810  *  \param  key              EC_KEY object\r
811  *  \param  data             opaque data to install.\r
812  *  \param  dup_func         a function that duplicates |data|.\r
813  *  \param  free_func        a function that frees |data|.\r
814  *  \param  clear_free_func  a function that wipes and frees |data|.\r
815  *  \return the previously set data pointer, or NULL if |data| was inserted.\r
816  */\r
817 void *EC_KEY_insert_key_method_data(EC_KEY *key, void *data,\r
818         void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));\r
819 /* wrapper functions for the underlying EC_GROUP object */\r
820 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);\r
821 \r
822 /** Creates a table of pre-computed multiples of the generator to\r
823  *  accelerate further EC_KEY operations.\r
824  *  \param  key  EC_KEY object\r
825  *  \param  ctx  BN_CTX object (optional)\r
826  *  \return 1 on success and 0 if an error occurred.\r
827  */\r
828 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);\r
829 \r
830 /** Creates a new ec private (and optional a new public) key.\r
831  *  \param  key  EC_KEY object\r
832  *  \return 1 on success and 0 if an error occurred.\r
833  */\r
834 int EC_KEY_generate_key(EC_KEY *key);\r
835 \r
836 /** Verifies that a private and/or public key is valid.\r
837  *  \param  key  the EC_KEY object\r
838  *  \return 1 on success and 0 otherwise.\r
839  */\r
840 int EC_KEY_check_key(const EC_KEY *key);\r
841 \r
842 /** Sets a public key from affine coordindates performing\r
843  *  neccessary NIST PKV tests.\r
844  *  \param  key  the EC_KEY object\r
845  *  \param  x    public key x coordinate\r
846  *  \param  y    public key y coordinate\r
847  *  \return 1 on success and 0 otherwise.\r
848  */\r
849 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y);\r
850 \r
851 \r
852 /********************************************************************/\r
853 /*        de- and encoding functions for SEC1 ECPrivateKey          */\r
854 /********************************************************************/\r
855 \r
856 /** Decodes a private key from a memory buffer.\r
857  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)\r
858  *  \param  in   pointer to memory with the DER encoded private key\r
859  *  \param  len  length of the DER encoded private key\r
860  *  \return the decoded private key or NULL if an error occurred.\r
861  */\r
862 EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);\r
863 \r
864 /** Encodes a private key object and stores the result in a buffer.\r
865  *  \param  key  the EC_KEY object to encode\r
866  *  \param  out  the buffer for the result (if NULL the function returns number\r
867  *               of bytes needed).\r
868  *  \return 1 on success and 0 if an error occurred.\r
869  */\r
870 int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);\r
871 \r
872 \r
873 /********************************************************************/\r
874 /*        de- and encoding functions for EC parameters              */\r
875 /********************************************************************/\r
876 \r
877 /** Decodes ec parameter from a memory buffer.\r
878  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)\r
879  *  \param  in   pointer to memory with the DER encoded ec parameters\r
880  *  \param  len  length of the DER encoded ec parameters\r
881  *  \return a EC_KEY object with the decoded parameters or NULL if an error\r
882  *          occurred.\r
883  */\r
884 EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);\r
885 \r
886 /** Encodes ec parameter and stores the result in a buffer.\r
887  *  \param  key  the EC_KEY object with ec paramters to encode\r
888  *  \param  out  the buffer for the result (if NULL the function returns number\r
889  *               of bytes needed).\r
890  *  \return 1 on success and 0 if an error occurred.\r
891  */\r
892 int i2d_ECParameters(EC_KEY *key, unsigned char **out);\r
893 \r
894 \r
895 /********************************************************************/\r
896 /*         de- and encoding functions for EC public key             */\r
897 /*         (octet string, not DER -- hence 'o2i' and 'i2o')         */\r
898 /********************************************************************/\r
899 \r
900 /** Decodes a ec public key from a octet string.\r
901  *  \param  key  a pointer to a EC_KEY object which should be used\r
902  *  \param  in   memory buffer with the encoded public key\r
903  *  \param  len  length of the encoded public key\r
904  *  \return EC_KEY object with decoded public key or NULL if an error\r
905  *          occurred.\r
906  */\r
907 EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);\r
908 \r
909 /** Encodes a ec public key in an octet string.\r
910  *  \param  key  the EC_KEY object with the public key\r
911  *  \param  out  the buffer for the result (if NULL the function returns number\r
912  *               of bytes needed).\r
913  *  \return 1 on success and 0 if an error occurred\r
914  */\r
915 int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);\r
916 \r
917 #ifndef OPENSSL_NO_BIO\r
918 /** Prints out the ec parameters on human readable form.\r
919  *  \param  bp   BIO object to which the information is printed\r
920  *  \param  key  EC_KEY object\r
921  *  \return 1 on success and 0 if an error occurred\r
922  */\r
923 int     ECParameters_print(BIO *bp, const EC_KEY *key);\r
924 \r
925 /** Prints out the contents of a EC_KEY object\r
926  *  \param  bp   BIO object to which the information is printed\r
927  *  \param  key  EC_KEY object\r
928  *  \param  off  line offset\r
929  *  \return 1 on success and 0 if an error occurred\r
930  */\r
931 int     EC_KEY_print(BIO *bp, const EC_KEY *key, int off);\r
932 \r
933 #endif\r
934 #ifndef OPENSSL_NO_FP_API\r
935 /** Prints out the ec parameters on human readable form.\r
936  *  \param  fp   file descriptor to which the information is printed\r
937  *  \param  key  EC_KEY object\r
938  *  \return 1 on success and 0 if an error occurred\r
939  */\r
940 int     ECParameters_print_fp(FILE *fp, const EC_KEY *key);\r
941 \r
942 /** Prints out the contents of a EC_KEY object\r
943  *  \param  fp   file descriptor to which the information is printed\r
944  *  \param  key  EC_KEY object\r
945  *  \param  off  line offset\r
946  *  \return 1 on success and 0 if an error occurred\r
947  */\r
948 int     EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);\r
949 \r
950 #endif\r
951 \r
952 #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)\r
953 \r
954 #ifndef __cplusplus\r
955 #if defined(__SUNPRO_C)\r
956 #  if __SUNPRO_C >= 0x520\r
957 # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)\r
958 #  endif\r
959 # endif\r
960 #endif\r
961 \r
962 #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \\r
963         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \\r
964                                 EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)\r
965 \r
966 \r
967 #define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID             (EVP_PKEY_ALG_CTRL + 1)\r
968 \r
969 /* BEGIN ERROR CODES */\r
970 /* The following lines are auto generated by the script mkerr.pl. Any changes\r
971  * made after this point may be overwritten when the script is next run.\r
972  */\r
973 void ERR_load_EC_strings(void);\r
974 \r
975 /* Error codes for the EC functions. */\r
976 \r
977 /* Function codes. */\r
978 #define EC_F_BN_TO_FELEM                                 224\r
979 #define EC_F_COMPUTE_WNAF                                143\r
980 #define EC_F_D2I_ECPARAMETERS                            144\r
981 #define EC_F_D2I_ECPKPARAMETERS                          145\r
982 #define EC_F_D2I_ECPRIVATEKEY                            146\r
983 #define EC_F_DO_EC_KEY_PRINT                             221\r
984 #define EC_F_ECKEY_PARAM2TYPE                            223\r
985 #define EC_F_ECKEY_PARAM_DECODE                          212\r
986 #define EC_F_ECKEY_PRIV_DECODE                           213\r
987 #define EC_F_ECKEY_PRIV_ENCODE                           214\r
988 #define EC_F_ECKEY_PUB_DECODE                            215\r
989 #define EC_F_ECKEY_PUB_ENCODE                            216\r
990 #define EC_F_ECKEY_TYPE2PARAM                            220\r
991 #define EC_F_ECPARAMETERS_PRINT                          147\r
992 #define EC_F_ECPARAMETERS_PRINT_FP                       148\r
993 #define EC_F_ECPKPARAMETERS_PRINT                        149\r
994 #define EC_F_ECPKPARAMETERS_PRINT_FP                     150\r
995 #define EC_F_ECP_NIST_MOD_192                            203\r
996 #define EC_F_ECP_NIST_MOD_224                            204\r
997 #define EC_F_ECP_NIST_MOD_256                            205\r
998 #define EC_F_ECP_NIST_MOD_521                            206\r
999 #define EC_F_EC_ASN1_GROUP2CURVE                         153\r
1000 #define EC_F_EC_ASN1_GROUP2FIELDID                       154\r
1001 #define EC_F_EC_ASN1_GROUP2PARAMETERS                    155\r
1002 #define EC_F_EC_ASN1_GROUP2PKPARAMETERS                  156\r
1003 #define EC_F_EC_ASN1_PARAMETERS2GROUP                    157\r
1004 #define EC_F_EC_ASN1_PKPARAMETERS2GROUP                  158\r
1005 #define EC_F_EC_EX_DATA_SET_DATA                         211\r
1006 #define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY           208\r
1007 #define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT     159\r
1008 #define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE              195\r
1009 #define EC_F_EC_GF2M_SIMPLE_OCT2POINT                    160\r
1010 #define EC_F_EC_GF2M_SIMPLE_POINT2OCT                    161\r
1011 #define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162\r
1012 #define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163\r
1013 #define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES   164\r
1014 #define EC_F_EC_GFP_MONT_FIELD_DECODE                    133\r
1015 #define EC_F_EC_GFP_MONT_FIELD_ENCODE                    134\r
1016 #define EC_F_EC_GFP_MONT_FIELD_MUL                       131\r
1017 #define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE                209\r
1018 #define EC_F_EC_GFP_MONT_FIELD_SQR                       132\r
1019 #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE                 189\r
1020 #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP             135\r
1021 #define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE             225\r
1022 #define EC_F_EC_GFP_NISTP224_POINTS_MUL                  228\r
1023 #define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226\r
1024 #define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE             230\r
1025 #define EC_F_EC_GFP_NISTP256_POINTS_MUL                  231\r
1026 #define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232\r
1027 #define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE             233\r
1028 #define EC_F_EC_GFP_NISTP521_POINTS_MUL                  234\r
1029 #define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235\r
1030 #define EC_F_EC_GFP_NIST_FIELD_MUL                       200\r
1031 #define EC_F_EC_GFP_NIST_FIELD_SQR                       201\r
1032 #define EC_F_EC_GFP_NIST_GROUP_SET_CURVE                 202\r
1033 #define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT      165\r
1034 #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE               166\r
1035 #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP           100\r
1036 #define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR           101\r
1037 #define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE                   102\r
1038 #define EC_F_EC_GFP_SIMPLE_OCT2POINT                     103\r
1039 #define EC_F_EC_GFP_SIMPLE_POINT2OCT                     104\r
1040 #define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE            137\r
1041 #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES  167\r
1042 #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105\r
1043 #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES  168\r
1044 #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128\r
1045 #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES    169\r
1046 #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129\r
1047 #define EC_F_EC_GROUP_CHECK                              170\r
1048 #define EC_F_EC_GROUP_CHECK_DISCRIMINANT                 171\r
1049 #define EC_F_EC_GROUP_COPY                               106\r
1050 #define EC_F_EC_GROUP_GET0_GENERATOR                     139\r
1051 #define EC_F_EC_GROUP_GET_COFACTOR                       140\r
1052 #define EC_F_EC_GROUP_GET_CURVE_GF2M                     172\r
1053 #define EC_F_EC_GROUP_GET_CURVE_GFP                      130\r
1054 #define EC_F_EC_GROUP_GET_DEGREE                         173\r
1055 #define EC_F_EC_GROUP_GET_ORDER                          141\r
1056 #define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS              193\r
1057 #define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS                194\r
1058 #define EC_F_EC_GROUP_NEW                                108\r
1059 #define EC_F_EC_GROUP_NEW_BY_CURVE_NAME                  174\r
1060 #define EC_F_EC_GROUP_NEW_FROM_DATA                      175\r
1061 #define EC_F_EC_GROUP_PRECOMPUTE_MULT                    142\r
1062 #define EC_F_EC_GROUP_SET_CURVE_GF2M                     176\r
1063 #define EC_F_EC_GROUP_SET_CURVE_GFP                      109\r
1064 #define EC_F_EC_GROUP_SET_EXTRA_DATA                     110\r
1065 #define EC_F_EC_GROUP_SET_GENERATOR                      111\r
1066 #define EC_F_EC_KEY_CHECK_KEY                            177\r
1067 #define EC_F_EC_KEY_COPY                                 178\r
1068 #define EC_F_EC_KEY_GENERATE_KEY                         179\r
1069 #define EC_F_EC_KEY_NEW                                  182\r
1070 #define EC_F_EC_KEY_PRINT                                180\r
1071 #define EC_F_EC_KEY_PRINT_FP                             181\r
1072 #define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES    229\r
1073 #define EC_F_EC_POINTS_MAKE_AFFINE                       136\r
1074 #define EC_F_EC_POINT_ADD                                112\r
1075 #define EC_F_EC_POINT_CMP                                113\r
1076 #define EC_F_EC_POINT_COPY                               114\r
1077 #define EC_F_EC_POINT_DBL                                115\r
1078 #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M        183\r
1079 #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP         116\r
1080 #define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP    117\r
1081 #define EC_F_EC_POINT_INVERT                             210\r
1082 #define EC_F_EC_POINT_IS_AT_INFINITY                     118\r
1083 #define EC_F_EC_POINT_IS_ON_CURVE                        119\r
1084 #define EC_F_EC_POINT_MAKE_AFFINE                        120\r
1085 #define EC_F_EC_POINT_MUL                                184\r
1086 #define EC_F_EC_POINT_NEW                                121\r
1087 #define EC_F_EC_POINT_OCT2POINT                          122\r
1088 #define EC_F_EC_POINT_POINT2OCT                          123\r
1089 #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M        185\r
1090 #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP         124\r
1091 #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M    186\r
1092 #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP     125\r
1093 #define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP    126\r
1094 #define EC_F_EC_POINT_SET_TO_INFINITY                    127\r
1095 #define EC_F_EC_PRE_COMP_DUP                             207\r
1096 #define EC_F_EC_PRE_COMP_NEW                             196\r
1097 #define EC_F_EC_WNAF_MUL                                 187\r
1098 #define EC_F_EC_WNAF_PRECOMPUTE_MULT                     188\r
1099 #define EC_F_I2D_ECPARAMETERS                            190\r
1100 #define EC_F_I2D_ECPKPARAMETERS                          191\r
1101 #define EC_F_I2D_ECPRIVATEKEY                            192\r
1102 #define EC_F_I2O_ECPUBLICKEY                             151\r
1103 #define EC_F_NISTP224_PRE_COMP_NEW                       227\r
1104 #define EC_F_NISTP256_PRE_COMP_NEW                       236\r
1105 #define EC_F_NISTP521_PRE_COMP_NEW                       237\r
1106 #define EC_F_O2I_ECPUBLICKEY                             152\r
1107 #define EC_F_OLD_EC_PRIV_DECODE                          222\r
1108 #define EC_F_PKEY_EC_CTRL                                197\r
1109 #define EC_F_PKEY_EC_CTRL_STR                            198\r
1110 #define EC_F_PKEY_EC_DERIVE                              217\r
1111 #define EC_F_PKEY_EC_KEYGEN                              199\r
1112 #define EC_F_PKEY_EC_PARAMGEN                            219\r
1113 #define EC_F_PKEY_EC_SIGN                                218\r
1114 \r
1115 /* Reason codes. */\r
1116 #define EC_R_ASN1_ERROR                                  115\r
1117 #define EC_R_ASN1_UNKNOWN_FIELD                          116\r
1118 #define EC_R_BIGNUM_OUT_OF_RANGE                         144\r
1119 #define EC_R_BUFFER_TOO_SMALL                            100\r
1120 #define EC_R_COORDINATES_OUT_OF_RANGE                    146\r
1121 #define EC_R_D2I_ECPKPARAMETERS_FAILURE                  117\r
1122 #define EC_R_DECODE_ERROR                                142\r
1123 #define EC_R_DISCRIMINANT_IS_ZERO                        118\r
1124 #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE                119\r
1125 #define EC_R_FIELD_TOO_LARGE                             143\r
1126 #define EC_R_GF2M_NOT_SUPPORTED                          147\r
1127 #define EC_R_GROUP2PKPARAMETERS_FAILURE                  120\r
1128 #define EC_R_I2D_ECPKPARAMETERS_FAILURE                  121\r
1129 #define EC_R_INCOMPATIBLE_OBJECTS                        101\r
1130 #define EC_R_INVALID_ARGUMENT                            112\r
1131 #define EC_R_INVALID_COMPRESSED_POINT                    110\r
1132 #define EC_R_INVALID_COMPRESSION_BIT                     109\r
1133 #define EC_R_INVALID_CURVE                               141\r
1134 #define EC_R_INVALID_DIGEST_TYPE                         138\r
1135 #define EC_R_INVALID_ENCODING                            102\r
1136 #define EC_R_INVALID_FIELD                               103\r
1137 #define EC_R_INVALID_FORM                                104\r
1138 #define EC_R_INVALID_GROUP_ORDER                         122\r
1139 #define EC_R_INVALID_PENTANOMIAL_BASIS                   132\r
1140 #define EC_R_INVALID_PRIVATE_KEY                         123\r
1141 #define EC_R_INVALID_TRINOMIAL_BASIS                     137\r
1142 #define EC_R_KEYS_NOT_SET                                140\r
1143 #define EC_R_MISSING_PARAMETERS                          124\r
1144 #define EC_R_MISSING_PRIVATE_KEY                         125\r
1145 #define EC_R_NOT_A_NIST_PRIME                            135\r
1146 #define EC_R_NOT_A_SUPPORTED_NIST_PRIME                  136\r
1147 #define EC_R_NOT_IMPLEMENTED                             126\r
1148 #define EC_R_NOT_INITIALIZED                             111\r
1149 #define EC_R_NO_FIELD_MOD                                133\r
1150 #define EC_R_NO_PARAMETERS_SET                           139\r
1151 #define EC_R_PASSED_NULL_PARAMETER                       134\r
1152 #define EC_R_PKPARAMETERS2GROUP_FAILURE                  127\r
1153 #define EC_R_POINT_AT_INFINITY                           106\r
1154 #define EC_R_POINT_IS_NOT_ON_CURVE                       107\r
1155 #define EC_R_SLOT_FULL                                   108\r
1156 #define EC_R_UNDEFINED_GENERATOR                         113\r
1157 #define EC_R_UNDEFINED_ORDER                             128\r
1158 #define EC_R_UNKNOWN_GROUP                               129\r
1159 #define EC_R_UNKNOWN_ORDER                               114\r
1160 #define EC_R_UNSUPPORTED_FIELD                           131\r
1161 #define EC_R_WRONG_CURVE_PARAMETERS                      145\r
1162 #define EC_R_WRONG_ORDER                                 130\r
1163 \r
1164 #ifdef  __cplusplus\r
1165 }\r
1166 #endif\r
1167 #endif\r