ec.h revision 160814
1109998Smarkm/* crypto/ec/ec.h */
2160814Ssimon/*
3160814Ssimon * Originally written by Bodo Moeller for the OpenSSL project.
4160814Ssimon */
5109998Smarkm/* ====================================================================
6160814Ssimon * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
7109998Smarkm *
8109998Smarkm * Redistribution and use in source and binary forms, with or without
9109998Smarkm * modification, are permitted provided that the following conditions
10109998Smarkm * are met:
11109998Smarkm *
12109998Smarkm * 1. Redistributions of source code must retain the above copyright
13109998Smarkm *    notice, this list of conditions and the following disclaimer.
14109998Smarkm *
15109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright
16109998Smarkm *    notice, this list of conditions and the following disclaimer in
17109998Smarkm *    the documentation and/or other materials provided with the
18109998Smarkm *    distribution.
19109998Smarkm *
20109998Smarkm * 3. All advertising materials mentioning features or use of this
21109998Smarkm *    software must display the following acknowledgment:
22109998Smarkm *    "This product includes software developed by the OpenSSL Project
23109998Smarkm *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24109998Smarkm *
25109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26109998Smarkm *    endorse or promote products derived from this software without
27109998Smarkm *    prior written permission. For written permission, please contact
28109998Smarkm *    openssl-core@openssl.org.
29109998Smarkm *
30109998Smarkm * 5. Products derived from this software may not be called "OpenSSL"
31109998Smarkm *    nor may "OpenSSL" appear in their names without prior written
32109998Smarkm *    permission of the OpenSSL Project.
33109998Smarkm *
34109998Smarkm * 6. Redistributions of any form whatsoever must retain the following
35109998Smarkm *    acknowledgment:
36109998Smarkm *    "This product includes software developed by the OpenSSL Project
37109998Smarkm *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38109998Smarkm *
39109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42109998Smarkm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE.
51109998Smarkm * ====================================================================
52109998Smarkm *
53109998Smarkm * This product includes cryptographic software written by Eric Young
54109998Smarkm * (eay@cryptsoft.com).  This product includes software written by Tim
55109998Smarkm * Hudson (tjh@cryptsoft.com).
56109998Smarkm *
57109998Smarkm */
58160814Ssimon/* ====================================================================
59160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60160814Ssimon *
61160814Ssimon * Portions of the attached software ("Contribution") are developed by
62160814Ssimon * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63160814Ssimon *
64160814Ssimon * The Contribution is licensed pursuant to the OpenSSL open source
65160814Ssimon * license provided above.
66160814Ssimon *
67160814Ssimon * The elliptic curve binary polynomial software is originally written by
68160814Ssimon * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69160814Ssimon *
70160814Ssimon */
71109998Smarkm
72109998Smarkm#ifndef HEADER_EC_H
73109998Smarkm#define HEADER_EC_H
74109998Smarkm
75160814Ssimon#include <openssl/opensslconf.h>
76160814Ssimon
77109998Smarkm#ifdef OPENSSL_NO_EC
78109998Smarkm#error EC is disabled.
79109998Smarkm#endif
80109998Smarkm
81160814Ssimon#include <openssl/asn1.h>
82160814Ssimon#include <openssl/symhacks.h>
83160814Ssimon#ifndef OPENSSL_NO_DEPRECATED
84109998Smarkm#include <openssl/bn.h>
85160814Ssimon#endif
86109998Smarkm
87109998Smarkm#ifdef  __cplusplus
88109998Smarkmextern "C" {
89160814Ssimon#elif defined(__SUNPRO_C)
90160814Ssimon# if __SUNPRO_C >= 0x520
91160814Ssimon# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
92160814Ssimon# endif
93109998Smarkm#endif
94109998Smarkm
95109998Smarkm
96109998Smarkmtypedef enum {
97109998Smarkm	/* values as defined in X9.62 (ECDSA) and elsewhere */
98109998Smarkm	POINT_CONVERSION_COMPRESSED = 2,
99109998Smarkm	POINT_CONVERSION_UNCOMPRESSED = 4,
100109998Smarkm	POINT_CONVERSION_HYBRID = 6
101109998Smarkm} point_conversion_form_t;
102109998Smarkm
103109998Smarkm
104109998Smarkmtypedef struct ec_method_st EC_METHOD;
105109998Smarkm
106109998Smarkmtypedef struct ec_group_st
107109998Smarkm	/*
108109998Smarkm	 EC_METHOD *meth;
109109998Smarkm	 -- field definition
110109998Smarkm	 -- curve coefficients
111109998Smarkm	 -- optional generator with associated information (order, cofactor)
112160814Ssimon	 -- optional extra data (precomputed table for fast computation of multiples of generator)
113160814Ssimon	 -- ASN1 stuff
114109998Smarkm	*/
115109998Smarkm	EC_GROUP;
116109998Smarkm
117109998Smarkmtypedef struct ec_point_st EC_POINT;
118109998Smarkm
119109998Smarkm
120109998Smarkm/* EC_METHODs for curves over GF(p).
121109998Smarkm * EC_GFp_simple_method provides the basis for the optimized methods.
122109998Smarkm */
123109998Smarkmconst EC_METHOD *EC_GFp_simple_method(void);
124109998Smarkmconst EC_METHOD *EC_GFp_mont_method(void);
125160814Ssimonconst EC_METHOD *EC_GFp_nist_method(void);
126109998Smarkm
127160814Ssimon/* EC_METHOD for curves over GF(2^m).
128160814Ssimon */
129160814Ssimonconst EC_METHOD *EC_GF2m_simple_method(void);
130109998Smarkm
131160814Ssimon
132109998SmarkmEC_GROUP *EC_GROUP_new(const EC_METHOD *);
133109998Smarkmvoid EC_GROUP_free(EC_GROUP *);
134109998Smarkmvoid EC_GROUP_clear_free(EC_GROUP *);
135109998Smarkmint EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
136160814SsimonEC_GROUP *EC_GROUP_dup(const EC_GROUP *);
137109998Smarkm
138109998Smarkmconst EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
139160814Ssimonint EC_METHOD_get_field_type(const EC_METHOD *);
140109998Smarkm
141160814Ssimonint EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
142160814Ssimonconst EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
143160814Ssimonint EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
144160814Ssimonint EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
145160814Ssimon
146160814Ssimonvoid EC_GROUP_set_curve_name(EC_GROUP *, int nid);
147160814Ssimonint EC_GROUP_get_curve_name(const EC_GROUP *);
148160814Ssimon
149160814Ssimonvoid EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
150160814Ssimonint EC_GROUP_get_asn1_flag(const EC_GROUP *);
151160814Ssimon
152160814Ssimonvoid EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
153160814Ssimonpoint_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
154160814Ssimon
155160814Ssimonunsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
156160814Ssimonsize_t EC_GROUP_get_seed_len(const EC_GROUP *);
157160814Ssimonsize_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
158160814Ssimon
159109998Smarkmint EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
160109998Smarkmint EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
161160814Ssimonint EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
162160814Ssimonint EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
163109998Smarkm
164160814Ssimon/* returns the number of bits needed to represent a field element */
165160814Ssimonint EC_GROUP_get_degree(const EC_GROUP *);
166160814Ssimon
167160814Ssimon/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
168160814Ssimonint EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
169160814Ssimon/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the
170160814Ssimon * elliptic curve is not zero, 0 otherwise */
171160814Ssimonint EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
172160814Ssimon
173160814Ssimon/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */
174160814Ssimonint EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
175160814Ssimon
176160814Ssimon/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
177109998Smarkm * after choosing an appropriate EC_METHOD */
178109998SmarkmEC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
179160814SsimonEC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
180109998Smarkm
181160814Ssimon/* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure
182160814Ssimon * specified by a curve name (in form of a NID) */
183160814SsimonEC_GROUP *EC_GROUP_new_by_curve_name(int nid);
184160814Ssimon/* handling of internal curves */
185160814Ssimontypedef struct {
186160814Ssimon	int nid;
187160814Ssimon	const char *comment;
188160814Ssimon	} EC_builtin_curve;
189160814Ssimon/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
190160814Ssimon * of all available curves or zero if a error occurred.
191160814Ssimon * In case r ist not zero nitems EC_builtin_curve structures
192160814Ssimon * are filled with the data of the first nitems internal groups */
193160814Ssimonsize_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
194109998Smarkm
195160814Ssimon
196160814Ssimon/* EC_POINT functions */
197160814Ssimon
198109998SmarkmEC_POINT *EC_POINT_new(const EC_GROUP *);
199109998Smarkmvoid EC_POINT_free(EC_POINT *);
200109998Smarkmvoid EC_POINT_clear_free(EC_POINT *);
201109998Smarkmint EC_POINT_copy(EC_POINT *, const EC_POINT *);
202160814SsimonEC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
203109998Smarkm
204109998Smarkmconst EC_METHOD *EC_POINT_method_of(const EC_POINT *);
205109998Smarkm
206109998Smarkmint EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
207109998Smarkmint EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
208109998Smarkm	const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
209109998Smarkmint EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
210109998Smarkm	BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
211109998Smarkmint EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
212109998Smarkm	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
213109998Smarkmint EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
214109998Smarkm	BIGNUM *x, BIGNUM *y, BN_CTX *);
215109998Smarkmint EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
216109998Smarkm	const BIGNUM *x, int y_bit, BN_CTX *);
217109998Smarkm
218160814Ssimonint EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
219160814Ssimon	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
220160814Ssimonint EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
221160814Ssimon	BIGNUM *x, BIGNUM *y, BN_CTX *);
222160814Ssimonint EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
223160814Ssimon	const BIGNUM *x, int y_bit, BN_CTX *);
224160814Ssimon
225109998Smarkmsize_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
226109998Smarkm        unsigned char *buf, size_t len, BN_CTX *);
227109998Smarkmint EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
228109998Smarkm        const unsigned char *buf, size_t len, BN_CTX *);
229109998Smarkm
230160814Ssimon/* other interfaces to point2oct/oct2point: */
231160814SsimonBIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
232160814Ssimon	point_conversion_form_t form, BIGNUM *, BN_CTX *);
233160814SsimonEC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
234160814Ssimon	EC_POINT *, BN_CTX *);
235160814Ssimonchar *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
236160814Ssimon	point_conversion_form_t form, BN_CTX *);
237160814SsimonEC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
238160814Ssimon	EC_POINT *, BN_CTX *);
239160814Ssimon
240109998Smarkmint EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
241109998Smarkmint EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
242109998Smarkmint EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
243109998Smarkm
244109998Smarkmint EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
245109998Smarkmint EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
246109998Smarkmint EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
247109998Smarkm
248109998Smarkmint EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
249109998Smarkmint EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
250109998Smarkm
251109998Smarkm
252109998Smarkmint EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
253109998Smarkmint EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
254160814Ssimon
255160814Ssimon/* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */
256109998Smarkmint EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
257160814Ssimon/* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */
258160814Ssimonint EC_GROUP_have_precompute_mult(const EC_GROUP *);
259109998Smarkm
260109998Smarkm
261109998Smarkm
262160814Ssimon/* ASN1 stuff */
263160814Ssimon
264160814Ssimon/* EC_GROUP_get_basis_type() returns the NID of the basis type
265160814Ssimon * used to represent the field elements */
266160814Ssimonint EC_GROUP_get_basis_type(const EC_GROUP *);
267160814Ssimonint EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
268160814Ssimonint EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
269160814Ssimon	unsigned int *k2, unsigned int *k3);
270160814Ssimon
271160814Ssimon#define OPENSSL_EC_NAMED_CURVE	0x001
272160814Ssimon
273160814Ssimontypedef struct ecpk_parameters_st ECPKPARAMETERS;
274160814Ssimon
275160814SsimonEC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
276160814Ssimonint i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
277160814Ssimon
278160814Ssimon#define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
279160814Ssimon#define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
280160814Ssimon#define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
281160814Ssimon                (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
282160814Ssimon#define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
283160814Ssimon		(unsigned char *)(x))
284160814Ssimon
285160814Ssimon#ifndef OPENSSL_NO_BIO
286160814Ssimonint     ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
287160814Ssimon#endif
288160814Ssimon#ifndef OPENSSL_NO_FP_API
289160814Ssimonint     ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
290160814Ssimon#endif
291160814Ssimon
292160814Ssimon/* the EC_KEY stuff */
293160814Ssimontypedef struct ec_key_st EC_KEY;
294160814Ssimon
295160814Ssimon/* some values for the encoding_flag */
296160814Ssimon#define EC_PKEY_NO_PARAMETERS	0x001
297160814Ssimon#define EC_PKEY_NO_PUBKEY	0x002
298160814Ssimon
299160814SsimonEC_KEY *EC_KEY_new(void);
300160814SsimonEC_KEY *EC_KEY_new_by_curve_name(int nid);
301160814Ssimonvoid EC_KEY_free(EC_KEY *);
302160814SsimonEC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
303160814SsimonEC_KEY *EC_KEY_dup(const EC_KEY *);
304160814Ssimon
305160814Ssimonint EC_KEY_up_ref(EC_KEY *);
306160814Ssimon
307160814Ssimonconst EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
308160814Ssimonint EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
309160814Ssimonconst BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
310160814Ssimonint EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
311160814Ssimonconst EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
312160814Ssimonint EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
313160814Ssimonunsigned EC_KEY_get_enc_flags(const EC_KEY *);
314160814Ssimonvoid EC_KEY_set_enc_flags(EC_KEY *, unsigned int);
315160814Ssimonpoint_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);
316160814Ssimonvoid EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);
317160814Ssimon/* functions to set/get method specific data  */
318160814Ssimonvoid *EC_KEY_get_key_method_data(EC_KEY *,
319160814Ssimon	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
320160814Ssimonvoid EC_KEY_insert_key_method_data(EC_KEY *, void *data,
321160814Ssimon	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
322160814Ssimon/* wrapper functions for the underlying EC_GROUP object */
323160814Ssimonvoid EC_KEY_set_asn1_flag(EC_KEY *, int);
324160814Ssimonint EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);
325160814Ssimon
326160814Ssimon/* EC_KEY_generate_key() creates a ec private (public) key */
327160814Ssimonint EC_KEY_generate_key(EC_KEY *);
328160814Ssimon/* EC_KEY_check_key() */
329160814Ssimonint EC_KEY_check_key(const EC_KEY *);
330160814Ssimon
331160814Ssimon/* de- and encoding functions for SEC1 ECPrivateKey */
332160814SsimonEC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
333160814Ssimonint i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
334160814Ssimon/* de- and encoding functions for EC parameters */
335160814SsimonEC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
336160814Ssimonint i2d_ECParameters(EC_KEY *a, unsigned char **out);
337160814Ssimon/* de- and encoding functions for EC public key
338160814Ssimon * (octet string, not DER -- hence 'o2i' and 'i2o') */
339160814SsimonEC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
340160814Ssimonint i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
341160814Ssimon
342160814Ssimon#ifndef OPENSSL_NO_BIO
343160814Ssimonint	ECParameters_print(BIO *bp, const EC_KEY *x);
344160814Ssimonint	EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
345160814Ssimon#endif
346160814Ssimon#ifndef OPENSSL_NO_FP_API
347160814Ssimonint	ECParameters_print_fp(FILE *fp, const EC_KEY *x);
348160814Ssimonint	EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
349160814Ssimon#endif
350160814Ssimon
351160814Ssimon#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
352160814Ssimon
353160814Ssimon#ifndef __cplusplus
354160814Ssimon#if defined(__SUNPRO_C)
355160814Ssimon#  if __SUNPRO_C >= 0x520
356160814Ssimon# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
357160814Ssimon#  endif
358160814Ssimon# endif
359160814Ssimon#endif
360160814Ssimon
361109998Smarkm/* BEGIN ERROR CODES */
362109998Smarkm/* The following lines are auto generated by the script mkerr.pl. Any changes
363109998Smarkm * made after this point may be overwritten when the script is next run.
364109998Smarkm */
365109998Smarkmvoid ERR_load_EC_strings(void);
366109998Smarkm
367109998Smarkm/* Error codes for the EC functions. */
368109998Smarkm
369109998Smarkm/* Function codes. */
370109998Smarkm#define EC_F_COMPUTE_WNAF				 143
371160814Ssimon#define EC_F_D2I_ECPARAMETERS				 144
372160814Ssimon#define EC_F_D2I_ECPKPARAMETERS				 145
373160814Ssimon#define EC_F_D2I_ECPRIVATEKEY				 146
374160814Ssimon#define EC_F_ECPARAMETERS_PRINT				 147
375160814Ssimon#define EC_F_ECPARAMETERS_PRINT_FP			 148
376160814Ssimon#define EC_F_ECPKPARAMETERS_PRINT			 149
377160814Ssimon#define EC_F_ECPKPARAMETERS_PRINT_FP			 150
378160814Ssimon#define EC_F_ECP_NIST_MOD_192				 203
379160814Ssimon#define EC_F_ECP_NIST_MOD_224				 204
380160814Ssimon#define EC_F_ECP_NIST_MOD_256				 205
381160814Ssimon#define EC_F_ECP_NIST_MOD_521				 206
382160814Ssimon#define EC_F_EC_ASN1_GROUP2CURVE			 153
383160814Ssimon#define EC_F_EC_ASN1_GROUP2FIELDID			 154
384160814Ssimon#define EC_F_EC_ASN1_GROUP2PARAMETERS			 155
385160814Ssimon#define EC_F_EC_ASN1_GROUP2PKPARAMETERS			 156
386160814Ssimon#define EC_F_EC_ASN1_PARAMETERS2GROUP			 157
387160814Ssimon#define EC_F_EC_ASN1_PKPARAMETERS2GROUP			 158
388160814Ssimon#define EC_F_EC_EX_DATA_SET_DATA			 211
389160814Ssimon#define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY		 208
390160814Ssimon#define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT	 159
391160814Ssimon#define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE		 195
392160814Ssimon#define EC_F_EC_GF2M_SIMPLE_OCT2POINT			 160
393160814Ssimon#define EC_F_EC_GF2M_SIMPLE_POINT2OCT			 161
394160814Ssimon#define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
395160814Ssimon#define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
396160814Ssimon#define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES	 164
397109998Smarkm#define EC_F_EC_GFP_MONT_FIELD_DECODE			 133
398109998Smarkm#define EC_F_EC_GFP_MONT_FIELD_ENCODE			 134
399109998Smarkm#define EC_F_EC_GFP_MONT_FIELD_MUL			 131
400160814Ssimon#define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE		 209
401109998Smarkm#define EC_F_EC_GFP_MONT_FIELD_SQR			 132
402160814Ssimon#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE		 189
403160814Ssimon#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP		 135
404160814Ssimon#define EC_F_EC_GFP_NIST_FIELD_MUL			 200
405160814Ssimon#define EC_F_EC_GFP_NIST_FIELD_SQR			 201
406160814Ssimon#define EC_F_EC_GFP_NIST_GROUP_SET_CURVE		 202
407160814Ssimon#define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT	 165
408160814Ssimon#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE		 166
409109998Smarkm#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP		 100
410109998Smarkm#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR		 101
411109998Smarkm#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE			 102
412109998Smarkm#define EC_F_EC_GFP_SIMPLE_OCT2POINT			 103
413109998Smarkm#define EC_F_EC_GFP_SIMPLE_POINT2OCT			 104
414109998Smarkm#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE		 137
415160814Ssimon#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES	 167
416109998Smarkm#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
417160814Ssimon#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES	 168
418109998Smarkm#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
419160814Ssimon#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES	 169
420109998Smarkm#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
421160814Ssimon#define EC_F_EC_GROUP_CHECK				 170
422160814Ssimon#define EC_F_EC_GROUP_CHECK_DISCRIMINANT		 171
423109998Smarkm#define EC_F_EC_GROUP_COPY				 106
424109998Smarkm#define EC_F_EC_GROUP_GET0_GENERATOR			 139
425109998Smarkm#define EC_F_EC_GROUP_GET_COFACTOR			 140
426160814Ssimon#define EC_F_EC_GROUP_GET_CURVE_GF2M			 172
427109998Smarkm#define EC_F_EC_GROUP_GET_CURVE_GFP			 130
428160814Ssimon#define EC_F_EC_GROUP_GET_DEGREE			 173
429109998Smarkm#define EC_F_EC_GROUP_GET_ORDER				 141
430160814Ssimon#define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS		 193
431160814Ssimon#define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS		 194
432109998Smarkm#define EC_F_EC_GROUP_NEW				 108
433160814Ssimon#define EC_F_EC_GROUP_NEW_BY_CURVE_NAME			 174
434160814Ssimon#define EC_F_EC_GROUP_NEW_FROM_DATA			 175
435109998Smarkm#define EC_F_EC_GROUP_PRECOMPUTE_MULT			 142
436160814Ssimon#define EC_F_EC_GROUP_SET_CURVE_GF2M			 176
437109998Smarkm#define EC_F_EC_GROUP_SET_CURVE_GFP			 109
438109998Smarkm#define EC_F_EC_GROUP_SET_EXTRA_DATA			 110
439109998Smarkm#define EC_F_EC_GROUP_SET_GENERATOR			 111
440160814Ssimon#define EC_F_EC_KEY_CHECK_KEY				 177
441160814Ssimon#define EC_F_EC_KEY_COPY				 178
442160814Ssimon#define EC_F_EC_KEY_GENERATE_KEY			 179
443160814Ssimon#define EC_F_EC_KEY_NEW					 182
444160814Ssimon#define EC_F_EC_KEY_PRINT				 180
445160814Ssimon#define EC_F_EC_KEY_PRINT_FP				 181
446109998Smarkm#define EC_F_EC_POINTS_MAKE_AFFINE			 136
447109998Smarkm#define EC_F_EC_POINTS_MUL				 138
448109998Smarkm#define EC_F_EC_POINT_ADD				 112
449109998Smarkm#define EC_F_EC_POINT_CMP				 113
450109998Smarkm#define EC_F_EC_POINT_COPY				 114
451109998Smarkm#define EC_F_EC_POINT_DBL				 115
452160814Ssimon#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M	 183
453109998Smarkm#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP	 116
454109998Smarkm#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP	 117
455160814Ssimon#define EC_F_EC_POINT_INVERT				 210
456109998Smarkm#define EC_F_EC_POINT_IS_AT_INFINITY			 118
457109998Smarkm#define EC_F_EC_POINT_IS_ON_CURVE			 119
458109998Smarkm#define EC_F_EC_POINT_MAKE_AFFINE			 120
459160814Ssimon#define EC_F_EC_POINT_MUL				 184
460109998Smarkm#define EC_F_EC_POINT_NEW				 121
461109998Smarkm#define EC_F_EC_POINT_OCT2POINT				 122
462109998Smarkm#define EC_F_EC_POINT_POINT2OCT				 123
463160814Ssimon#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M	 185
464109998Smarkm#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP	 124
465160814Ssimon#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M	 186
466109998Smarkm#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP	 125
467109998Smarkm#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP	 126
468109998Smarkm#define EC_F_EC_POINT_SET_TO_INFINITY			 127
469160814Ssimon#define EC_F_EC_PRE_COMP_DUP				 207
470160814Ssimon#define EC_F_EC_WNAF_MUL				 187
471160814Ssimon#define EC_F_EC_WNAF_PRECOMPUTE_MULT			 188
472160814Ssimon#define EC_F_I2D_ECPARAMETERS				 190
473160814Ssimon#define EC_F_I2D_ECPKPARAMETERS				 191
474160814Ssimon#define EC_F_I2D_ECPRIVATEKEY				 192
475160814Ssimon#define EC_F_I2O_ECPUBLICKEY				 151
476160814Ssimon#define EC_F_O2I_ECPUBLICKEY				 152
477109998Smarkm
478109998Smarkm/* Reason codes. */
479160814Ssimon#define EC_R_ASN1_ERROR					 115
480160814Ssimon#define EC_R_ASN1_UNKNOWN_FIELD				 116
481109998Smarkm#define EC_R_BUFFER_TOO_SMALL				 100
482160814Ssimon#define EC_R_D2I_ECPKPARAMETERS_FAILURE			 117
483160814Ssimon#define EC_R_DISCRIMINANT_IS_ZERO			 118
484160814Ssimon#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE		 119
485160814Ssimon#define EC_R_GROUP2PKPARAMETERS_FAILURE			 120
486160814Ssimon#define EC_R_I2D_ECPKPARAMETERS_FAILURE			 121
487109998Smarkm#define EC_R_INCOMPATIBLE_OBJECTS			 101
488109998Smarkm#define EC_R_INVALID_ARGUMENT				 112
489109998Smarkm#define EC_R_INVALID_COMPRESSED_POINT			 110
490109998Smarkm#define EC_R_INVALID_COMPRESSION_BIT			 109
491109998Smarkm#define EC_R_INVALID_ENCODING				 102
492109998Smarkm#define EC_R_INVALID_FIELD				 103
493109998Smarkm#define EC_R_INVALID_FORM				 104
494160814Ssimon#define EC_R_INVALID_GROUP_ORDER			 122
495160814Ssimon#define EC_R_INVALID_PRIVATE_KEY			 123
496160814Ssimon#define EC_R_MISSING_PARAMETERS				 124
497160814Ssimon#define EC_R_MISSING_PRIVATE_KEY			 125
498160814Ssimon#define EC_R_NOT_A_NIST_PRIME				 135
499160814Ssimon#define EC_R_NOT_A_SUPPORTED_NIST_PRIME			 136
500160814Ssimon#define EC_R_NOT_IMPLEMENTED				 126
501109998Smarkm#define EC_R_NOT_INITIALIZED				 111
502160814Ssimon#define EC_R_NO_FIELD_MOD				 133
503160814Ssimon#define EC_R_PASSED_NULL_PARAMETER			 134
504160814Ssimon#define EC_R_PKPARAMETERS2GROUP_FAILURE			 127
505109998Smarkm#define EC_R_POINT_AT_INFINITY				 106
506109998Smarkm#define EC_R_POINT_IS_NOT_ON_CURVE			 107
507109998Smarkm#define EC_R_SLOT_FULL					 108
508109998Smarkm#define EC_R_UNDEFINED_GENERATOR			 113
509160814Ssimon#define EC_R_UNDEFINED_ORDER				 128
510160814Ssimon#define EC_R_UNKNOWN_GROUP				 129
511109998Smarkm#define EC_R_UNKNOWN_ORDER				 114
512160814Ssimon#define EC_R_UNSUPPORTED_FIELD				 131
513160814Ssimon#define EC_R_WRONG_ORDER				 130
514109998Smarkm
515109998Smarkm#ifdef  __cplusplus
516109998Smarkm}
517109998Smarkm#endif
518109998Smarkm#endif
519