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
13296465Sdelphij *    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 *
61296465Sdelphij * 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 *
67296465Sdelphij * 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
73296465Sdelphij# define HEADER_EC_H
74109998Smarkm
75296465Sdelphij# include <openssl/opensslconf.h>
76160814Ssimon
77296465Sdelphij# ifdef OPENSSL_NO_EC
78296465Sdelphij#  error EC is disabled.
79296465Sdelphij# endif
80109998Smarkm
81296465Sdelphij# include <openssl/asn1.h>
82296465Sdelphij# include <openssl/symhacks.h>
83296465Sdelphij# ifndef OPENSSL_NO_DEPRECATED
84296465Sdelphij#  include <openssl/bn.h>
85296465Sdelphij# endif
86109998Smarkm
87296465Sdelphij# ifdef  __cplusplus
88109998Smarkmextern "C" {
89296465Sdelphij# elif defined(__SUNPRO_C)
90296465Sdelphij#  if __SUNPRO_C >= 0x520
91296465Sdelphij#   pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
92296465Sdelphij#  endif
93160814Ssimon# endif
94109998Smarkm
95296465Sdelphij# ifndef OPENSSL_ECC_MAX_FIELD_BITS
96296465Sdelphij#  define OPENSSL_ECC_MAX_FIELD_BITS 661
97296465Sdelphij# endif
98109998Smarkm
99109998Smarkmtypedef enum {
100296465Sdelphij    /* values as defined in X9.62 (ECDSA) and elsewhere */
101296465Sdelphij    POINT_CONVERSION_COMPRESSED = 2,
102296465Sdelphij    POINT_CONVERSION_UNCOMPRESSED = 4,
103296465Sdelphij    POINT_CONVERSION_HYBRID = 6
104109998Smarkm} point_conversion_form_t;
105109998Smarkm
106109998Smarkmtypedef struct ec_method_st EC_METHOD;
107109998Smarkm
108109998Smarkmtypedef struct ec_group_st
109296465Sdelphij    /*-
110296465Sdelphij     EC_METHOD *meth;
111296465Sdelphij     -- field definition
112296465Sdelphij     -- curve coefficients
113296465Sdelphij     -- optional generator with associated information (order, cofactor)
114296465Sdelphij     -- optional extra data (precomputed table for fast computation of multiples of generator)
115296465Sdelphij     -- ASN1 stuff
116296465Sdelphij    */
117296465Sdelphij    EC_GROUP;
118109998Smarkm
119109998Smarkmtypedef struct ec_point_st EC_POINT;
120109998Smarkm
121296465Sdelphij/*
122296465Sdelphij * EC_METHODs for curves over GF(p). EC_GFp_simple_method provides the basis
123296465Sdelphij * for the optimized methods.
124109998Smarkm */
125109998Smarkmconst EC_METHOD *EC_GFp_simple_method(void);
126109998Smarkmconst EC_METHOD *EC_GFp_mont_method(void);
127160814Ssimonconst EC_METHOD *EC_GFp_nist_method(void);
128109998Smarkm
129296465Sdelphij/*
130296465Sdelphij * EC_METHOD for curves over GF(2^m).
131160814Ssimon */
132160814Ssimonconst EC_METHOD *EC_GF2m_simple_method(void);
133109998Smarkm
134109998SmarkmEC_GROUP *EC_GROUP_new(const EC_METHOD *);
135109998Smarkmvoid EC_GROUP_free(EC_GROUP *);
136109998Smarkmvoid EC_GROUP_clear_free(EC_GROUP *);
137109998Smarkmint EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
138160814SsimonEC_GROUP *EC_GROUP_dup(const EC_GROUP *);
139109998Smarkm
140109998Smarkmconst EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
141160814Ssimonint EC_METHOD_get_field_type(const EC_METHOD *);
142109998Smarkm
143296465Sdelphijint EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator,
144296465Sdelphij                           const BIGNUM *order, const BIGNUM *cofactor);
145160814Ssimonconst EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
146160814Ssimonint EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
147160814Ssimonint EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
148160814Ssimon
149160814Ssimonvoid EC_GROUP_set_curve_name(EC_GROUP *, int nid);
150160814Ssimonint EC_GROUP_get_curve_name(const EC_GROUP *);
151160814Ssimon
152160814Ssimonvoid EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
153160814Ssimonint EC_GROUP_get_asn1_flag(const EC_GROUP *);
154160814Ssimon
155160814Ssimonvoid EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
156160814Ssimonpoint_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
157160814Ssimon
158160814Ssimonunsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
159160814Ssimonsize_t EC_GROUP_get_seed_len(const EC_GROUP *);
160160814Ssimonsize_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
161160814Ssimon
162296465Sdelphijint EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
163296465Sdelphij                           const BIGNUM *b, BN_CTX *);
164296465Sdelphijint EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b,
165296465Sdelphij                           BN_CTX *);
166296465Sdelphijint EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
167296465Sdelphij                            const BIGNUM *b, BN_CTX *);
168296465Sdelphijint EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b,
169296465Sdelphij                            BN_CTX *);
170109998Smarkm
171160814Ssimon/* returns the number of bits needed to represent a field element */
172160814Ssimonint EC_GROUP_get_degree(const EC_GROUP *);
173160814Ssimon
174160814Ssimon/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
175160814Ssimonint EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
176296465Sdelphij/*
177296465Sdelphij * EC_GROUP_check_discriminant() returns 1 if the discriminant of the
178296465Sdelphij * elliptic curve is not zero, 0 otherwise
179296465Sdelphij */
180160814Ssimonint EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
181160814Ssimon
182160814Ssimon/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */
183160814Ssimonint EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
184160814Ssimon
185296465Sdelphij/*
186296465Sdelphij * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
187296465Sdelphij * choosing an appropriate EC_METHOD
188296465Sdelphij */
189296465SdelphijEC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
190296465Sdelphij                                 const BIGNUM *b, BN_CTX *);
191296465SdelphijEC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
192296465Sdelphij                                  const BIGNUM *b, BN_CTX *);
193109998Smarkm
194296465Sdelphij/*
195296465Sdelphij * EC_GROUP_new_by_curve_name() creates a EC_GROUP structure specified by a
196296465Sdelphij * curve name (in form of a NID)
197296465Sdelphij */
198160814SsimonEC_GROUP *EC_GROUP_new_by_curve_name(int nid);
199160814Ssimon/* handling of internal curves */
200296465Sdelphijtypedef struct {
201296465Sdelphij    int nid;
202296465Sdelphij    const char *comment;
203296465Sdelphij} EC_builtin_curve;
204296465Sdelphij/*
205296465Sdelphij * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
206296465Sdelphij * available curves or zero if a error occurred. In case r ist not zero
207296465Sdelphij * nitems EC_builtin_curve structures are filled with the data of the first
208296465Sdelphij * nitems internal groups
209296465Sdelphij */
210160814Ssimonsize_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
211109998Smarkm
212160814Ssimon/* EC_POINT functions */
213160814Ssimon
214109998SmarkmEC_POINT *EC_POINT_new(const EC_GROUP *);
215109998Smarkmvoid EC_POINT_free(EC_POINT *);
216109998Smarkmvoid EC_POINT_clear_free(EC_POINT *);
217109998Smarkmint EC_POINT_copy(EC_POINT *, const EC_POINT *);
218160814SsimonEC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
219296465Sdelphij
220109998Smarkmconst EC_METHOD *EC_POINT_method_of(const EC_POINT *);
221109998Smarkm
222109998Smarkmint EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
223109998Smarkmint EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
224296465Sdelphij                                             const BIGNUM *x, const BIGNUM *y,
225296465Sdelphij                                             const BIGNUM *z, BN_CTX *);
226296465Sdelphijint EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *,
227296465Sdelphij                                             const EC_POINT *, BIGNUM *x,
228296465Sdelphij                                             BIGNUM *y, BIGNUM *z, BN_CTX *);
229109998Smarkmint EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
230296465Sdelphij                                        const BIGNUM *x, const BIGNUM *y,
231296465Sdelphij                                        BN_CTX *);
232109998Smarkmint EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
233296465Sdelphij                                        BIGNUM *x, BIGNUM *y, BN_CTX *);
234109998Smarkmint EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
235296465Sdelphij                                            const BIGNUM *x, int y_bit,
236296465Sdelphij                                            BN_CTX *);
237109998Smarkm
238160814Ssimonint EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
239296465Sdelphij                                         const BIGNUM *x, const BIGNUM *y,
240296465Sdelphij                                         BN_CTX *);
241160814Ssimonint EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
242296465Sdelphij                                         BIGNUM *x, BIGNUM *y, BN_CTX *);
243160814Ssimonint EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
244296465Sdelphij                                             const BIGNUM *x, int y_bit,
245296465Sdelphij                                             BN_CTX *);
246160814Ssimon
247296465Sdelphijsize_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *,
248296465Sdelphij                          point_conversion_form_t form, unsigned char *buf,
249296465Sdelphij                          size_t len, BN_CTX *);
250296465Sdelphijint EC_POINT_oct2point(const EC_GROUP *, EC_POINT *, const unsigned char *buf,
251296465Sdelphij                       size_t len, BN_CTX *);
252109998Smarkm
253160814Ssimon/* other interfaces to point2oct/oct2point: */
254160814SsimonBIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
255296465Sdelphij                          point_conversion_form_t form, BIGNUM *, BN_CTX *);
256160814SsimonEC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
257296465Sdelphij                            EC_POINT *, BN_CTX *);
258160814Ssimonchar *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
259296465Sdelphij                         point_conversion_form_t form, BN_CTX *);
260160814SsimonEC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
261296465Sdelphij                             EC_POINT *, BN_CTX *);
262160814Ssimon
263296465Sdelphijint EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
264296465Sdelphij                 const EC_POINT *b, BN_CTX *);
265109998Smarkmint EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
266109998Smarkmint EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
267109998Smarkm
268109998Smarkmint EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
269109998Smarkmint EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
270296465Sdelphijint EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
271296465Sdelphij                 BN_CTX *);
272109998Smarkm
273109998Smarkmint EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
274296465Sdelphijint EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[],
275296465Sdelphij                          BN_CTX *);
276109998Smarkm
277296465Sdelphijint EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num,
278296465Sdelphij                  const EC_POINT *[], const BIGNUM *[], BN_CTX *);
279296465Sdelphijint EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *,
280296465Sdelphij                 const EC_POINT *, const BIGNUM *, BN_CTX *);
281109998Smarkm
282296465Sdelphij/*
283296465Sdelphij * EC_GROUP_precompute_mult() stores multiples of generator for faster point
284296465Sdelphij * multiplication
285296465Sdelphij */
286109998Smarkmint EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
287296465Sdelphij/*
288296465Sdelphij * EC_GROUP_have_precompute_mult() reports whether such precomputation has
289296465Sdelphij * been done
290296465Sdelphij */
291160814Ssimonint EC_GROUP_have_precompute_mult(const EC_GROUP *);
292109998Smarkm
293160814Ssimon/* ASN1 stuff */
294160814Ssimon
295296465Sdelphij/*
296296465Sdelphij * EC_GROUP_get_basis_type() returns the NID of the basis type used to
297296465Sdelphij * represent the field elements
298296465Sdelphij */
299160814Ssimonint EC_GROUP_get_basis_type(const EC_GROUP *);
300160814Ssimonint EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
301296465Sdelphijint EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
302296465Sdelphij                                   unsigned int *k2, unsigned int *k3);
303160814Ssimon
304296465Sdelphij# define OPENSSL_EC_NAMED_CURVE  0x001
305160814Ssimon
306160814Ssimontypedef struct ecpk_parameters_st ECPKPARAMETERS;
307160814Ssimon
308160814SsimonEC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
309160814Ssimonint i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
310160814Ssimon
311296465Sdelphij# define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
312296465Sdelphij# define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
313296465Sdelphij# define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
314160814Ssimon                (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
315296465Sdelphij# define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
316296465Sdelphij                (unsigned char *)(x))
317160814Ssimon
318296465Sdelphij# ifndef OPENSSL_NO_BIO
319296465Sdelphijint ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
320296465Sdelphij# endif
321296465Sdelphij# ifndef OPENSSL_NO_FP_API
322296465Sdelphijint ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
323296465Sdelphij# endif
324160814Ssimon
325160814Ssimon/* the EC_KEY stuff */
326160814Ssimontypedef struct ec_key_st EC_KEY;
327160814Ssimon
328160814Ssimon/* some values for the encoding_flag */
329296465Sdelphij# define EC_PKEY_NO_PARAMETERS   0x001
330296465Sdelphij# define EC_PKEY_NO_PUBKEY       0x002
331160814Ssimon
332160814SsimonEC_KEY *EC_KEY_new(void);
333160814SsimonEC_KEY *EC_KEY_new_by_curve_name(int nid);
334160814Ssimonvoid EC_KEY_free(EC_KEY *);
335160814SsimonEC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
336160814SsimonEC_KEY *EC_KEY_dup(const EC_KEY *);
337160814Ssimon
338160814Ssimonint EC_KEY_up_ref(EC_KEY *);
339160814Ssimon
340160814Ssimonconst EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
341160814Ssimonint EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
342160814Ssimonconst BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
343160814Ssimonint EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
344160814Ssimonconst EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
345160814Ssimonint EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
346160814Ssimonunsigned EC_KEY_get_enc_flags(const EC_KEY *);
347160814Ssimonvoid EC_KEY_set_enc_flags(EC_KEY *, unsigned int);
348160814Ssimonpoint_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);
349160814Ssimonvoid EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);
350160814Ssimon/* functions to set/get method specific data  */
351296465Sdelphijvoid *EC_KEY_get_key_method_data(EC_KEY *,
352296465Sdelphij                                 void *(*dup_func) (void *),
353296465Sdelphij                                 void (*free_func) (void *),
354296465Sdelphij                                 void (*clear_free_func) (void *));
355248272Sdelphij/** Sets the key method data of an EC_KEY object, if none has yet been set.
356248272Sdelphij *  \param  key              EC_KEY object
357248272Sdelphij *  \param  data             opaque data to install.
358248272Sdelphij *  \param  dup_func         a function that duplicates |data|.
359248272Sdelphij *  \param  free_func        a function that frees |data|.
360248272Sdelphij *  \param  clear_free_func  a function that wipes and frees |data|.
361248272Sdelphij *  \return the previously set data pointer, or NULL if |data| was inserted.
362248272Sdelphij */
363248272Sdelphijvoid *EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
364296465Sdelphij                                    void *(*dup_func) (void *),
365296465Sdelphij                                    void (*free_func) (void *),
366296465Sdelphij                                    void (*clear_free_func) (void *));
367160814Ssimon/* wrapper functions for the underlying EC_GROUP object */
368160814Ssimonvoid EC_KEY_set_asn1_flag(EC_KEY *, int);
369160814Ssimonint EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);
370160814Ssimon
371160814Ssimon/* EC_KEY_generate_key() creates a ec private (public) key */
372160814Ssimonint EC_KEY_generate_key(EC_KEY *);
373160814Ssimon/* EC_KEY_check_key() */
374160814Ssimonint EC_KEY_check_key(const EC_KEY *);
375160814Ssimon
376160814Ssimon/* de- and encoding functions for SEC1 ECPrivateKey */
377160814SsimonEC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
378160814Ssimonint i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
379160814Ssimon/* de- and encoding functions for EC parameters */
380160814SsimonEC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
381160814Ssimonint i2d_ECParameters(EC_KEY *a, unsigned char **out);
382296465Sdelphij/*
383296465Sdelphij * de- and encoding functions for EC public key (octet string, not DER --
384296465Sdelphij * hence 'o2i' and 'i2o')
385296465Sdelphij */
386160814SsimonEC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
387160814Ssimonint i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
388160814Ssimon
389296465Sdelphij# ifndef OPENSSL_NO_BIO
390296465Sdelphijint ECParameters_print(BIO *bp, const EC_KEY *x);
391296465Sdelphijint EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
392296465Sdelphij# endif
393296465Sdelphij# ifndef OPENSSL_NO_FP_API
394296465Sdelphijint ECParameters_print_fp(FILE *fp, const EC_KEY *x);
395296465Sdelphijint EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
396296465Sdelphij# endif
397160814Ssimon
398296465Sdelphij# define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
399160814Ssimon
400296465Sdelphij# ifndef __cplusplus
401296465Sdelphij#  if defined(__SUNPRO_C)
402296465Sdelphij#   if __SUNPRO_C >= 0x520
403296465Sdelphij#    pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
404296465Sdelphij#   endif
405160814Ssimon#  endif
406160814Ssimon# endif
407160814Ssimon
408109998Smarkm/* BEGIN ERROR CODES */
409296465Sdelphij/*
410296465Sdelphij * The following lines are auto generated by the script mkerr.pl. Any changes
411109998Smarkm * made after this point may be overwritten when the script is next run.
412109998Smarkm */
413109998Smarkmvoid ERR_load_EC_strings(void);
414109998Smarkm
415109998Smarkm/* Error codes for the EC functions. */
416109998Smarkm
417109998Smarkm/* Function codes. */
418296465Sdelphij# define EC_F_COMPUTE_WNAF                                143
419296465Sdelphij# define EC_F_D2I_ECPARAMETERS                            144
420296465Sdelphij# define EC_F_D2I_ECPKPARAMETERS                          145
421296465Sdelphij# define EC_F_D2I_ECPRIVATEKEY                            146
422296465Sdelphij# define EC_F_ECPARAMETERS_PRINT                          147
423296465Sdelphij# define EC_F_ECPARAMETERS_PRINT_FP                       148
424296465Sdelphij# define EC_F_ECPKPARAMETERS_PRINT                        149
425296465Sdelphij# define EC_F_ECPKPARAMETERS_PRINT_FP                     150
426296465Sdelphij# define EC_F_ECP_NIST_MOD_192                            203
427296465Sdelphij# define EC_F_ECP_NIST_MOD_224                            204
428296465Sdelphij# define EC_F_ECP_NIST_MOD_256                            205
429296465Sdelphij# define EC_F_ECP_NIST_MOD_521                            206
430296465Sdelphij# define EC_F_EC_ASN1_GROUP2CURVE                         153
431296465Sdelphij# define EC_F_EC_ASN1_GROUP2FIELDID                       154
432296465Sdelphij# define EC_F_EC_ASN1_GROUP2PARAMETERS                    155
433296465Sdelphij# define EC_F_EC_ASN1_GROUP2PKPARAMETERS                  156
434296465Sdelphij# define EC_F_EC_ASN1_PARAMETERS2GROUP                    157
435296465Sdelphij# define EC_F_EC_ASN1_PKPARAMETERS2GROUP                  158
436296465Sdelphij# define EC_F_EC_EX_DATA_SET_DATA                         211
437296465Sdelphij# define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY           208
438296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT     159
439296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE              195
440296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_OCT2POINT                    160
441296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_POINT2OCT                    161
442296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
443296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
444296465Sdelphij# define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES   164
445296465Sdelphij# define EC_F_EC_GFP_MONT_FIELD_DECODE                    133
446296465Sdelphij# define EC_F_EC_GFP_MONT_FIELD_ENCODE                    134
447296465Sdelphij# define EC_F_EC_GFP_MONT_FIELD_MUL                       131
448296465Sdelphij# define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE                209
449296465Sdelphij# define EC_F_EC_GFP_MONT_FIELD_SQR                       132
450296465Sdelphij# define EC_F_EC_GFP_MONT_GROUP_SET_CURVE                 189
451296465Sdelphij# define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP             135
452296465Sdelphij# define EC_F_EC_GFP_NIST_FIELD_MUL                       200
453296465Sdelphij# define EC_F_EC_GFP_NIST_FIELD_SQR                       201
454296465Sdelphij# define EC_F_EC_GFP_NIST_GROUP_SET_CURVE                 202
455296465Sdelphij# define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT      165
456296465Sdelphij# define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE               166
457296465Sdelphij# define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP           100
458296465Sdelphij# define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR           101
459296465Sdelphij# define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE                   102
460296465Sdelphij# define EC_F_EC_GFP_SIMPLE_OCT2POINT                     103
461296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINT2OCT                     104
462296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE            137
463296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES  167
464296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
465296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES  168
466296465Sdelphij# define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
467296465Sdelphij# define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES    169
468296465Sdelphij# define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
469296465Sdelphij# define EC_F_EC_GROUP_CHECK                              170
470296465Sdelphij# define EC_F_EC_GROUP_CHECK_DISCRIMINANT                 171
471296465Sdelphij# define EC_F_EC_GROUP_COPY                               106
472296465Sdelphij# define EC_F_EC_GROUP_GET0_GENERATOR                     139
473296465Sdelphij# define EC_F_EC_GROUP_GET_COFACTOR                       140
474296465Sdelphij# define EC_F_EC_GROUP_GET_CURVE_GF2M                     172
475296465Sdelphij# define EC_F_EC_GROUP_GET_CURVE_GFP                      130
476296465Sdelphij# define EC_F_EC_GROUP_GET_DEGREE                         173
477296465Sdelphij# define EC_F_EC_GROUP_GET_ORDER                          141
478296465Sdelphij# define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS              193
479296465Sdelphij# define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS                194
480296465Sdelphij# define EC_F_EC_GROUP_NEW                                108
481296465Sdelphij# define EC_F_EC_GROUP_NEW_BY_CURVE_NAME                  174
482296465Sdelphij# define EC_F_EC_GROUP_NEW_FROM_DATA                      175
483296465Sdelphij# define EC_F_EC_GROUP_PRECOMPUTE_MULT                    142
484296465Sdelphij# define EC_F_EC_GROUP_SET_CURVE_GF2M                     176
485296465Sdelphij# define EC_F_EC_GROUP_SET_CURVE_GFP                      109
486296465Sdelphij# define EC_F_EC_GROUP_SET_EXTRA_DATA                     110
487296465Sdelphij# define EC_F_EC_GROUP_SET_GENERATOR                      111
488296465Sdelphij# define EC_F_EC_KEY_CHECK_KEY                            177
489296465Sdelphij# define EC_F_EC_KEY_COPY                                 178
490296465Sdelphij# define EC_F_EC_KEY_GENERATE_KEY                         179
491296465Sdelphij# define EC_F_EC_KEY_NEW                                  182
492296465Sdelphij# define EC_F_EC_KEY_PRINT                                180
493296465Sdelphij# define EC_F_EC_KEY_PRINT_FP                             181
494296465Sdelphij# define EC_F_EC_POINTS_MAKE_AFFINE                       136
495296465Sdelphij# define EC_F_EC_POINTS_MUL                               138
496296465Sdelphij# define EC_F_EC_POINT_ADD                                112
497296465Sdelphij# define EC_F_EC_POINT_CMP                                113
498296465Sdelphij# define EC_F_EC_POINT_COPY                               114
499296465Sdelphij# define EC_F_EC_POINT_DBL                                115
500296465Sdelphij# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M        183
501296465Sdelphij# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP         116
502296465Sdelphij# define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP    117
503296465Sdelphij# define EC_F_EC_POINT_INVERT                             210
504296465Sdelphij# define EC_F_EC_POINT_IS_AT_INFINITY                     118
505296465Sdelphij# define EC_F_EC_POINT_IS_ON_CURVE                        119
506296465Sdelphij# define EC_F_EC_POINT_MAKE_AFFINE                        120
507296465Sdelphij# define EC_F_EC_POINT_MUL                                184
508296465Sdelphij# define EC_F_EC_POINT_NEW                                121
509296465Sdelphij# define EC_F_EC_POINT_OCT2POINT                          122
510296465Sdelphij# define EC_F_EC_POINT_POINT2OCT                          123
511296465Sdelphij# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M        185
512296465Sdelphij# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP         124
513296465Sdelphij# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M    186
514296465Sdelphij# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP     125
515296465Sdelphij# define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP    126
516296465Sdelphij# define EC_F_EC_POINT_SET_TO_INFINITY                    127
517296465Sdelphij# define EC_F_EC_PRE_COMP_DUP                             207
518296465Sdelphij# define EC_F_EC_PRE_COMP_NEW                             196
519296465Sdelphij# define EC_F_EC_WNAF_MUL                                 187
520296465Sdelphij# define EC_F_EC_WNAF_PRECOMPUTE_MULT                     188
521296465Sdelphij# define EC_F_I2D_ECPARAMETERS                            190
522296465Sdelphij# define EC_F_I2D_ECPKPARAMETERS                          191
523296465Sdelphij# define EC_F_I2D_ECPRIVATEKEY                            192
524296465Sdelphij# define EC_F_I2O_ECPUBLICKEY                             151
525296465Sdelphij# define EC_F_O2I_ECPUBLICKEY                             152
526109998Smarkm
527109998Smarkm/* Reason codes. */
528296465Sdelphij# define EC_R_ASN1_ERROR                                  115
529296465Sdelphij# define EC_R_ASN1_UNKNOWN_FIELD                          116
530296465Sdelphij# define EC_R_BUFFER_TOO_SMALL                            100
531296465Sdelphij# define EC_R_D2I_ECPKPARAMETERS_FAILURE                  117
532296465Sdelphij# define EC_R_DISCRIMINANT_IS_ZERO                        118
533296465Sdelphij# define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE                119
534296465Sdelphij# define EC_R_FIELD_TOO_LARGE                             138
535296465Sdelphij# define EC_R_GROUP2PKPARAMETERS_FAILURE                  120
536296465Sdelphij# define EC_R_I2D_ECPKPARAMETERS_FAILURE                  121
537296465Sdelphij# define EC_R_INCOMPATIBLE_OBJECTS                        101
538296465Sdelphij# define EC_R_INVALID_ARGUMENT                            112
539296465Sdelphij# define EC_R_INVALID_COMPRESSED_POINT                    110
540296465Sdelphij# define EC_R_INVALID_COMPRESSION_BIT                     109
541296465Sdelphij# define EC_R_INVALID_ENCODING                            102
542296465Sdelphij# define EC_R_INVALID_FIELD                               103
543296465Sdelphij# define EC_R_INVALID_FORM                                104
544296465Sdelphij# define EC_R_INVALID_GROUP_ORDER                         122
545296465Sdelphij# define EC_R_INVALID_PENTANOMIAL_BASIS                   132
546296465Sdelphij# define EC_R_INVALID_PRIVATE_KEY                         123
547296465Sdelphij# define EC_R_INVALID_TRINOMIAL_BASIS                     137
548296465Sdelphij# define EC_R_MISSING_PARAMETERS                          124
549296465Sdelphij# define EC_R_MISSING_PRIVATE_KEY                         125
550296465Sdelphij# define EC_R_NOT_A_NIST_PRIME                            135
551296465Sdelphij# define EC_R_NOT_A_SUPPORTED_NIST_PRIME                  136
552296465Sdelphij# define EC_R_NOT_IMPLEMENTED                             126
553296465Sdelphij# define EC_R_NOT_INITIALIZED                             111
554296465Sdelphij# define EC_R_NO_FIELD_MOD                                133
555296465Sdelphij# define EC_R_PASSED_NULL_PARAMETER                       134
556296465Sdelphij# define EC_R_PKPARAMETERS2GROUP_FAILURE                  127
557296465Sdelphij# define EC_R_POINT_AT_INFINITY                           106
558296465Sdelphij# define EC_R_POINT_IS_NOT_ON_CURVE                       107
559296465Sdelphij# define EC_R_SLOT_FULL                                   108
560296465Sdelphij# define EC_R_UNDEFINED_GENERATOR                         113
561296465Sdelphij# define EC_R_UNDEFINED_ORDER                             128
562296465Sdelphij# define EC_R_UNKNOWN_GROUP                               129
563296465Sdelphij# define EC_R_UNKNOWN_ORDER                               114
564296465Sdelphij# define EC_R_UNSUPPORTED_FIELD                           131
565296465Sdelphij# define EC_R_WRONG_ORDER                                 130
566109998Smarkm
567109998Smarkm#ifdef  __cplusplus
568109998Smarkm}
569109998Smarkm#endif
570109998Smarkm#endif
571