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