xref: /onnv-gate/usr/src/common/openssl/crypto/ec/ec.h (revision 2864:0fad37eee08f)
10Sstevel@tonic-gate /* crypto/ec/ec.h */
22139Sjp161948 /*
32139Sjp161948  * Originally written by Bodo Moeller for the OpenSSL project.
42139Sjp161948  */
50Sstevel@tonic-gate /* ====================================================================
62139Sjp161948  * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
90Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
100Sstevel@tonic-gate  * are met:
110Sstevel@tonic-gate  *
120Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate  *
150Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in
170Sstevel@tonic-gate  *    the documentation and/or other materials provided with the
180Sstevel@tonic-gate  *    distribution.
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this
210Sstevel@tonic-gate  *    software must display the following acknowledgment:
220Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
230Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
260Sstevel@tonic-gate  *    endorse or promote products derived from this software without
270Sstevel@tonic-gate  *    prior written permission. For written permission, please contact
280Sstevel@tonic-gate  *    openssl-core@openssl.org.
290Sstevel@tonic-gate  *
300Sstevel@tonic-gate  * 5. Products derived from this software may not be called "OpenSSL"
310Sstevel@tonic-gate  *    nor may "OpenSSL" appear in their names without prior written
320Sstevel@tonic-gate  *    permission of the OpenSSL Project.
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * 6. Redistributions of any form whatsoever must retain the following
350Sstevel@tonic-gate  *    acknowledgment:
360Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
370Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
380Sstevel@tonic-gate  *
390Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
400Sstevel@tonic-gate  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
410Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
420Sstevel@tonic-gate  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
430Sstevel@tonic-gate  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
440Sstevel@tonic-gate  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
450Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
460Sstevel@tonic-gate  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
470Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
480Sstevel@tonic-gate  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
490Sstevel@tonic-gate  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
500Sstevel@tonic-gate  * OF THE POSSIBILITY OF SUCH DAMAGE.
510Sstevel@tonic-gate  * ====================================================================
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * This product includes cryptographic software written by Eric Young
540Sstevel@tonic-gate  * (eay@cryptsoft.com).  This product includes software written by Tim
550Sstevel@tonic-gate  * Hudson (tjh@cryptsoft.com).
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  */
582139Sjp161948 /* ====================================================================
592139Sjp161948  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
602139Sjp161948  *
612139Sjp161948  * Portions of the attached software ("Contribution") are developed by
622139Sjp161948  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
632139Sjp161948  *
642139Sjp161948  * The Contribution is licensed pursuant to the OpenSSL open source
652139Sjp161948  * license provided above.
662139Sjp161948  *
672139Sjp161948  * The elliptic curve binary polynomial software is originally written by
682139Sjp161948  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
692139Sjp161948  *
702139Sjp161948  */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #ifndef HEADER_EC_H
730Sstevel@tonic-gate #define HEADER_EC_H
740Sstevel@tonic-gate 
752139Sjp161948 #include <openssl/opensslconf.h>
762139Sjp161948 
770Sstevel@tonic-gate #ifdef OPENSSL_NO_EC
780Sstevel@tonic-gate #error EC is disabled.
790Sstevel@tonic-gate #endif
800Sstevel@tonic-gate 
812139Sjp161948 #include <openssl/asn1.h>
822139Sjp161948 #include <openssl/symhacks.h>
832139Sjp161948 #ifndef OPENSSL_NO_DEPRECATED
840Sstevel@tonic-gate #include <openssl/bn.h>
852139Sjp161948 #endif
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #ifdef  __cplusplus
880Sstevel@tonic-gate extern "C" {
892139Sjp161948 #elif defined(__SUNPRO_C)
902139Sjp161948 # if __SUNPRO_C >= 0x520
912139Sjp161948 # pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
922139Sjp161948 # endif
930Sstevel@tonic-gate #endif
940Sstevel@tonic-gate 
95*2864Sjp161948 #ifndef OPENSSL_ECC_MAX_FIELD_BITS
96*2864Sjp161948 # define OPENSSL_ECC_MAX_FIELD_BITS 661
97*2864Sjp161948 #endif
98*2864Sjp161948 
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate typedef enum {
1010Sstevel@tonic-gate 	/* values as defined in X9.62 (ECDSA) and elsewhere */
1020Sstevel@tonic-gate 	POINT_CONVERSION_COMPRESSED = 2,
1030Sstevel@tonic-gate 	POINT_CONVERSION_UNCOMPRESSED = 4,
1040Sstevel@tonic-gate 	POINT_CONVERSION_HYBRID = 6
1050Sstevel@tonic-gate } point_conversion_form_t;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate typedef struct ec_method_st EC_METHOD;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate typedef struct ec_group_st
1110Sstevel@tonic-gate 	/*
1120Sstevel@tonic-gate 	 EC_METHOD *meth;
1130Sstevel@tonic-gate 	 -- field definition
1140Sstevel@tonic-gate 	 -- curve coefficients
1150Sstevel@tonic-gate 	 -- optional generator with associated information (order, cofactor)
1162139Sjp161948 	 -- optional extra data (precomputed table for fast computation of multiples of generator)
1172139Sjp161948 	 -- ASN1 stuff
1180Sstevel@tonic-gate 	*/
1190Sstevel@tonic-gate 	EC_GROUP;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate typedef struct ec_point_st EC_POINT;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /* EC_METHODs for curves over GF(p).
1250Sstevel@tonic-gate  * EC_GFp_simple_method provides the basis for the optimized methods.
1260Sstevel@tonic-gate  */
1270Sstevel@tonic-gate const EC_METHOD *EC_GFp_simple_method(void);
1280Sstevel@tonic-gate const EC_METHOD *EC_GFp_mont_method(void);
1292139Sjp161948 const EC_METHOD *EC_GFp_nist_method(void);
1302139Sjp161948 
1312139Sjp161948 /* EC_METHOD for curves over GF(2^m).
1322139Sjp161948  */
1332139Sjp161948 const EC_METHOD *EC_GF2m_simple_method(void);
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate EC_GROUP *EC_GROUP_new(const EC_METHOD *);
1370Sstevel@tonic-gate void EC_GROUP_free(EC_GROUP *);
1380Sstevel@tonic-gate void EC_GROUP_clear_free(EC_GROUP *);
1390Sstevel@tonic-gate int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
1402139Sjp161948 EC_GROUP *EC_GROUP_dup(const EC_GROUP *);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
1432139Sjp161948 int EC_METHOD_get_field_type(const EC_METHOD *);
1442139Sjp161948 
1452139Sjp161948 int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
1462139Sjp161948 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
1472139Sjp161948 int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
1482139Sjp161948 int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
1492139Sjp161948 
1502139Sjp161948 void EC_GROUP_set_curve_name(EC_GROUP *, int nid);
1512139Sjp161948 int EC_GROUP_get_curve_name(const EC_GROUP *);
1520Sstevel@tonic-gate 
1532139Sjp161948 void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
1542139Sjp161948 int EC_GROUP_get_asn1_flag(const EC_GROUP *);
1552139Sjp161948 
1562139Sjp161948 void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
1572139Sjp161948 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
1582139Sjp161948 
1592139Sjp161948 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
1602139Sjp161948 size_t EC_GROUP_get_seed_len(const EC_GROUP *);
1612139Sjp161948 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
1622139Sjp161948 
1630Sstevel@tonic-gate int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1640Sstevel@tonic-gate int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
1652139Sjp161948 int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1662139Sjp161948 int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
1670Sstevel@tonic-gate 
1682139Sjp161948 /* returns the number of bits needed to represent a field element */
1692139Sjp161948 int EC_GROUP_get_degree(const EC_GROUP *);
1702139Sjp161948 
1712139Sjp161948 /* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
1722139Sjp161948 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
1732139Sjp161948 /* EC_GROUP_check_discriminant() returns 1 if the discriminant of the
1742139Sjp161948  * elliptic curve is not zero, 0 otherwise */
1752139Sjp161948 int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
1762139Sjp161948 
1772139Sjp161948 /* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */
1782139Sjp161948 int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
1792139Sjp161948 
1802139Sjp161948 /* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
1810Sstevel@tonic-gate  * after choosing an appropriate EC_METHOD */
1820Sstevel@tonic-gate EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1832139Sjp161948 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1840Sstevel@tonic-gate 
1852139Sjp161948 /* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure
1862139Sjp161948  * specified by a curve name (in form of a NID) */
1872139Sjp161948 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
1882139Sjp161948 /* handling of internal curves */
1892139Sjp161948 typedef struct {
1902139Sjp161948 	int nid;
1912139Sjp161948 	const char *comment;
1922139Sjp161948 	} EC_builtin_curve;
1932139Sjp161948 /* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
1942139Sjp161948  * of all available curves or zero if a error occurred.
1952139Sjp161948  * In case r ist not zero nitems EC_builtin_curve structures
1962139Sjp161948  * are filled with the data of the first nitems internal groups */
1972139Sjp161948 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
1982139Sjp161948 
1992139Sjp161948 
2002139Sjp161948 /* EC_POINT functions */
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate EC_POINT *EC_POINT_new(const EC_GROUP *);
2030Sstevel@tonic-gate void EC_POINT_free(EC_POINT *);
2040Sstevel@tonic-gate void EC_POINT_clear_free(EC_POINT *);
2050Sstevel@tonic-gate int EC_POINT_copy(EC_POINT *, const EC_POINT *);
2062139Sjp161948 EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
2110Sstevel@tonic-gate int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
2120Sstevel@tonic-gate 	const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
2130Sstevel@tonic-gate int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
2140Sstevel@tonic-gate 	BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
2150Sstevel@tonic-gate int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
2160Sstevel@tonic-gate 	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
2170Sstevel@tonic-gate int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
2180Sstevel@tonic-gate 	BIGNUM *x, BIGNUM *y, BN_CTX *);
2190Sstevel@tonic-gate int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
2200Sstevel@tonic-gate 	const BIGNUM *x, int y_bit, BN_CTX *);
2210Sstevel@tonic-gate 
2222139Sjp161948 int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
2232139Sjp161948 	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
2242139Sjp161948 int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
2252139Sjp161948 	BIGNUM *x, BIGNUM *y, BN_CTX *);
2262139Sjp161948 int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
2272139Sjp161948 	const BIGNUM *x, int y_bit, BN_CTX *);
2282139Sjp161948 
2290Sstevel@tonic-gate size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
2300Sstevel@tonic-gate         unsigned char *buf, size_t len, BN_CTX *);
2310Sstevel@tonic-gate int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
2320Sstevel@tonic-gate         const unsigned char *buf, size_t len, BN_CTX *);
2330Sstevel@tonic-gate 
2342139Sjp161948 /* other interfaces to point2oct/oct2point: */
2352139Sjp161948 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
2362139Sjp161948 	point_conversion_form_t form, BIGNUM *, BN_CTX *);
2372139Sjp161948 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
2382139Sjp161948 	EC_POINT *, BN_CTX *);
2392139Sjp161948 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
2402139Sjp161948 	point_conversion_form_t form, BN_CTX *);
2412139Sjp161948 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
2422139Sjp161948 	EC_POINT *, BN_CTX *);
2432139Sjp161948 
2440Sstevel@tonic-gate int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
2450Sstevel@tonic-gate int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
2460Sstevel@tonic-gate int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
2490Sstevel@tonic-gate int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
2500Sstevel@tonic-gate int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
2530Sstevel@tonic-gate int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
2570Sstevel@tonic-gate int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
2582139Sjp161948 
2592139Sjp161948 /* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */
2600Sstevel@tonic-gate int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
2612139Sjp161948 /* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */
2622139Sjp161948 int EC_GROUP_have_precompute_mult(const EC_GROUP *);
2632139Sjp161948 
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 
2662139Sjp161948 /* ASN1 stuff */
2672139Sjp161948 
2682139Sjp161948 /* EC_GROUP_get_basis_type() returns the NID of the basis type
2692139Sjp161948  * used to represent the field elements */
2702139Sjp161948 int EC_GROUP_get_basis_type(const EC_GROUP *);
2712139Sjp161948 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
2722139Sjp161948 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
2732139Sjp161948 	unsigned int *k2, unsigned int *k3);
2742139Sjp161948 
2752139Sjp161948 #define OPENSSL_EC_NAMED_CURVE	0x001
2762139Sjp161948 
2772139Sjp161948 typedef struct ecpk_parameters_st ECPKPARAMETERS;
2782139Sjp161948 
2792139Sjp161948 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
2802139Sjp161948 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
2812139Sjp161948 
2822139Sjp161948 #define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
2832139Sjp161948 #define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
2842139Sjp161948 #define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
2852139Sjp161948                 (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
2862139Sjp161948 #define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
2872139Sjp161948 		(unsigned char *)(x))
2882139Sjp161948 
2892139Sjp161948 #ifndef OPENSSL_NO_BIO
2902139Sjp161948 int     ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
2912139Sjp161948 #endif
2922139Sjp161948 #ifndef OPENSSL_NO_FP_API
2932139Sjp161948 int     ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
2942139Sjp161948 #endif
2952139Sjp161948 
2962139Sjp161948 /* the EC_KEY stuff */
2972139Sjp161948 typedef struct ec_key_st EC_KEY;
2982139Sjp161948 
2992139Sjp161948 /* some values for the encoding_flag */
3002139Sjp161948 #define EC_PKEY_NO_PARAMETERS	0x001
3012139Sjp161948 #define EC_PKEY_NO_PUBKEY	0x002
3022139Sjp161948 
3032139Sjp161948 EC_KEY *EC_KEY_new(void);
3042139Sjp161948 EC_KEY *EC_KEY_new_by_curve_name(int nid);
3052139Sjp161948 void EC_KEY_free(EC_KEY *);
3062139Sjp161948 EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
3072139Sjp161948 EC_KEY *EC_KEY_dup(const EC_KEY *);
3082139Sjp161948 
3092139Sjp161948 int EC_KEY_up_ref(EC_KEY *);
3102139Sjp161948 
3112139Sjp161948 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
3122139Sjp161948 int EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
3132139Sjp161948 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
3142139Sjp161948 int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
3152139Sjp161948 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
3162139Sjp161948 int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
3172139Sjp161948 unsigned EC_KEY_get_enc_flags(const EC_KEY *);
3182139Sjp161948 void EC_KEY_set_enc_flags(EC_KEY *, unsigned int);
3192139Sjp161948 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);
3202139Sjp161948 void EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);
3212139Sjp161948 /* functions to set/get method specific data  */
3222139Sjp161948 void *EC_KEY_get_key_method_data(EC_KEY *,
3232139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
3242139Sjp161948 void EC_KEY_insert_key_method_data(EC_KEY *, void *data,
3252139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
3262139Sjp161948 /* wrapper functions for the underlying EC_GROUP object */
3272139Sjp161948 void EC_KEY_set_asn1_flag(EC_KEY *, int);
3282139Sjp161948 int EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);
3292139Sjp161948 
3302139Sjp161948 /* EC_KEY_generate_key() creates a ec private (public) key */
3312139Sjp161948 int EC_KEY_generate_key(EC_KEY *);
3322139Sjp161948 /* EC_KEY_check_key() */
3332139Sjp161948 int EC_KEY_check_key(const EC_KEY *);
3342139Sjp161948 
3352139Sjp161948 /* de- and encoding functions for SEC1 ECPrivateKey */
3362139Sjp161948 EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
3372139Sjp161948 int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
3382139Sjp161948 /* de- and encoding functions for EC parameters */
3392139Sjp161948 EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
3402139Sjp161948 int i2d_ECParameters(EC_KEY *a, unsigned char **out);
3412139Sjp161948 /* de- and encoding functions for EC public key
3422139Sjp161948  * (octet string, not DER -- hence 'o2i' and 'i2o') */
3432139Sjp161948 EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
3442139Sjp161948 int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
3452139Sjp161948 
3462139Sjp161948 #ifndef OPENSSL_NO_BIO
3472139Sjp161948 int	ECParameters_print(BIO *bp, const EC_KEY *x);
3482139Sjp161948 int	EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
3492139Sjp161948 #endif
3502139Sjp161948 #ifndef OPENSSL_NO_FP_API
3512139Sjp161948 int	ECParameters_print_fp(FILE *fp, const EC_KEY *x);
3522139Sjp161948 int	EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
3532139Sjp161948 #endif
3542139Sjp161948 
3552139Sjp161948 #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
3562139Sjp161948 
3572139Sjp161948 #ifndef __cplusplus
3582139Sjp161948 #if defined(__SUNPRO_C)
3592139Sjp161948 #  if __SUNPRO_C >= 0x520
3602139Sjp161948 # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
3612139Sjp161948 #  endif
3622139Sjp161948 # endif
3632139Sjp161948 #endif
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate /* BEGIN ERROR CODES */
3660Sstevel@tonic-gate /* The following lines are auto generated by the script mkerr.pl. Any changes
3670Sstevel@tonic-gate  * made after this point may be overwritten when the script is next run.
3680Sstevel@tonic-gate  */
3690Sstevel@tonic-gate void ERR_load_EC_strings(void);
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate /* Error codes for the EC functions. */
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate /* Function codes. */
3740Sstevel@tonic-gate #define EC_F_COMPUTE_WNAF				 143
3752139Sjp161948 #define EC_F_D2I_ECPARAMETERS				 144
3762139Sjp161948 #define EC_F_D2I_ECPKPARAMETERS				 145
3772139Sjp161948 #define EC_F_D2I_ECPRIVATEKEY				 146
3782139Sjp161948 #define EC_F_ECPARAMETERS_PRINT				 147
3792139Sjp161948 #define EC_F_ECPARAMETERS_PRINT_FP			 148
3802139Sjp161948 #define EC_F_ECPKPARAMETERS_PRINT			 149
3812139Sjp161948 #define EC_F_ECPKPARAMETERS_PRINT_FP			 150
3822139Sjp161948 #define EC_F_ECP_NIST_MOD_192				 203
3832139Sjp161948 #define EC_F_ECP_NIST_MOD_224				 204
3842139Sjp161948 #define EC_F_ECP_NIST_MOD_256				 205
3852139Sjp161948 #define EC_F_ECP_NIST_MOD_521				 206
3862139Sjp161948 #define EC_F_EC_ASN1_GROUP2CURVE			 153
3872139Sjp161948 #define EC_F_EC_ASN1_GROUP2FIELDID			 154
3882139Sjp161948 #define EC_F_EC_ASN1_GROUP2PARAMETERS			 155
3892139Sjp161948 #define EC_F_EC_ASN1_GROUP2PKPARAMETERS			 156
3902139Sjp161948 #define EC_F_EC_ASN1_PARAMETERS2GROUP			 157
3912139Sjp161948 #define EC_F_EC_ASN1_PKPARAMETERS2GROUP			 158
3922139Sjp161948 #define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY		 208
3932139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT	 159
3942139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE		 195
3952139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_OCT2POINT			 160
3962139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_POINT2OCT			 161
3972139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
3982139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
3992139Sjp161948 #define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES	 164
4000Sstevel@tonic-gate #define EC_F_EC_GFP_MONT_FIELD_DECODE			 133
4010Sstevel@tonic-gate #define EC_F_EC_GFP_MONT_FIELD_ENCODE			 134
4020Sstevel@tonic-gate #define EC_F_EC_GFP_MONT_FIELD_MUL			 131
4032139Sjp161948 #define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE		 209
4040Sstevel@tonic-gate #define EC_F_EC_GFP_MONT_FIELD_SQR			 132
4052139Sjp161948 #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE		 189
4062139Sjp161948 #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP		 135
4072139Sjp161948 #define EC_F_EC_GFP_NIST_FIELD_MUL			 200
4082139Sjp161948 #define EC_F_EC_GFP_NIST_FIELD_SQR			 201
4092139Sjp161948 #define EC_F_EC_GFP_NIST_GROUP_SET_CURVE		 202
4102139Sjp161948 #define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT	 165
4112139Sjp161948 #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE		 166
4120Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP		 100
4130Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR		 101
4140Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE			 102
4150Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_OCT2POINT			 103
4160Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_POINT2OCT			 104
4170Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE		 137
4182139Sjp161948 #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES	 167
4190Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
4202139Sjp161948 #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES	 168
4210Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
4222139Sjp161948 #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES	 169
4230Sstevel@tonic-gate #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
4242139Sjp161948 #define EC_F_EC_GROUP_CHECK				 170
4252139Sjp161948 #define EC_F_EC_GROUP_CHECK_DISCRIMINANT		 171
4260Sstevel@tonic-gate #define EC_F_EC_GROUP_COPY				 106
4270Sstevel@tonic-gate #define EC_F_EC_GROUP_GET0_GENERATOR			 139
4280Sstevel@tonic-gate #define EC_F_EC_GROUP_GET_COFACTOR			 140
4292139Sjp161948 #define EC_F_EC_GROUP_GET_CURVE_GF2M			 172
4300Sstevel@tonic-gate #define EC_F_EC_GROUP_GET_CURVE_GFP			 130
4312139Sjp161948 #define EC_F_EC_GROUP_GET_DEGREE			 173
4320Sstevel@tonic-gate #define EC_F_EC_GROUP_GET_ORDER				 141
4332139Sjp161948 #define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS		 193
4342139Sjp161948 #define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS		 194
4352139Sjp161948 #define EC_F_EC_GROUP_GROUP2NID				 147
4360Sstevel@tonic-gate #define EC_F_EC_GROUP_NEW				 108
4372139Sjp161948 #define EC_F_EC_GROUP_NEW_BY_CURVE_NAME			 174
4382139Sjp161948 #define EC_F_EC_GROUP_NEW_FROM_DATA			 175
4390Sstevel@tonic-gate #define EC_F_EC_GROUP_PRECOMPUTE_MULT			 142
4402139Sjp161948 #define EC_F_EC_GROUP_SET_CURVE_GF2M			 176
4410Sstevel@tonic-gate #define EC_F_EC_GROUP_SET_CURVE_GFP			 109
4420Sstevel@tonic-gate #define EC_F_EC_GROUP_SET_EXTRA_DATA			 110
4430Sstevel@tonic-gate #define EC_F_EC_GROUP_SET_GENERATOR			 111
4442139Sjp161948 #define EC_F_EC_KEY_CHECK_KEY				 177
4452139Sjp161948 #define EC_F_EC_KEY_COPY				 178
4462139Sjp161948 #define EC_F_EC_KEY_GENERATE_KEY			 179
4472139Sjp161948 #define EC_F_EC_KEY_NEW					 182
4482139Sjp161948 #define EC_F_EC_KEY_PRINT				 180
4492139Sjp161948 #define EC_F_EC_KEY_PRINT_FP				 181
4500Sstevel@tonic-gate #define EC_F_EC_POINTS_MAKE_AFFINE			 136
4510Sstevel@tonic-gate #define EC_F_EC_POINTS_MUL				 138
4520Sstevel@tonic-gate #define EC_F_EC_POINT_ADD				 112
4530Sstevel@tonic-gate #define EC_F_EC_POINT_CMP				 113
4540Sstevel@tonic-gate #define EC_F_EC_POINT_COPY				 114
4550Sstevel@tonic-gate #define EC_F_EC_POINT_DBL				 115
4562139Sjp161948 #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M	 183
4570Sstevel@tonic-gate #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP	 116
4580Sstevel@tonic-gate #define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP	 117
4592139Sjp161948 #define EC_F_EC_POINT_INVERT				 210
4600Sstevel@tonic-gate #define EC_F_EC_POINT_IS_AT_INFINITY			 118
4610Sstevel@tonic-gate #define EC_F_EC_POINT_IS_ON_CURVE			 119
4620Sstevel@tonic-gate #define EC_F_EC_POINT_MAKE_AFFINE			 120
4632139Sjp161948 #define EC_F_EC_POINT_MUL				 184
4640Sstevel@tonic-gate #define EC_F_EC_POINT_NEW				 121
4650Sstevel@tonic-gate #define EC_F_EC_POINT_OCT2POINT				 122
4660Sstevel@tonic-gate #define EC_F_EC_POINT_POINT2OCT				 123
4672139Sjp161948 #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M	 185
4680Sstevel@tonic-gate #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP	 124
4692139Sjp161948 #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M	 186
4700Sstevel@tonic-gate #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP	 125
4710Sstevel@tonic-gate #define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP	 126
4720Sstevel@tonic-gate #define EC_F_EC_POINT_SET_TO_INFINITY			 127
4732139Sjp161948 #define EC_F_EC_PRE_COMP_DUP				 207
4742139Sjp161948 #define EC_F_EC_WNAF_MUL				 187
4752139Sjp161948 #define EC_F_EC_WNAF_PRECOMPUTE_MULT			 188
4762139Sjp161948 #define EC_F_I2D_ECPARAMETERS				 190
4772139Sjp161948 #define EC_F_I2D_ECPKPARAMETERS				 191
4782139Sjp161948 #define EC_F_I2D_ECPRIVATEKEY				 192
4792139Sjp161948 #define EC_F_I2O_ECPUBLICKEY				 151
4802139Sjp161948 #define EC_F_O2I_ECPUBLICKEY				 152
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate /* Reason codes. */
4832139Sjp161948 #define EC_R_ASN1_ERROR					 115
4842139Sjp161948 #define EC_R_ASN1_UNKNOWN_FIELD				 116
4850Sstevel@tonic-gate #define EC_R_BUFFER_TOO_SMALL				 100
4862139Sjp161948 #define EC_R_D2I_ECPKPARAMETERS_FAILURE			 117
4872139Sjp161948 #define EC_R_DISCRIMINANT_IS_ZERO			 118
4882139Sjp161948 #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE		 119
489*2864Sjp161948 #define EC_R_FIELD_TOO_LARGE				 138
4902139Sjp161948 #define EC_R_GROUP2PKPARAMETERS_FAILURE			 120
4912139Sjp161948 #define EC_R_I2D_ECPKPARAMETERS_FAILURE			 121
4920Sstevel@tonic-gate #define EC_R_INCOMPATIBLE_OBJECTS			 101
4930Sstevel@tonic-gate #define EC_R_INVALID_ARGUMENT				 112
4940Sstevel@tonic-gate #define EC_R_INVALID_COMPRESSED_POINT			 110
4950Sstevel@tonic-gate #define EC_R_INVALID_COMPRESSION_BIT			 109
4960Sstevel@tonic-gate #define EC_R_INVALID_ENCODING				 102
4970Sstevel@tonic-gate #define EC_R_INVALID_FIELD				 103
4980Sstevel@tonic-gate #define EC_R_INVALID_FORM				 104
4992139Sjp161948 #define EC_R_INVALID_GROUP_ORDER			 122
500*2864Sjp161948 #define EC_R_INVALID_PENTANOMIAL_BASIS			 132
5012139Sjp161948 #define EC_R_INVALID_PRIVATE_KEY			 123
502*2864Sjp161948 #define EC_R_INVALID_TRINOMIAL_BASIS			 137
5032139Sjp161948 #define EC_R_MISSING_PARAMETERS				 124
5042139Sjp161948 #define EC_R_MISSING_PRIVATE_KEY			 125
5052139Sjp161948 #define EC_R_NOT_A_NIST_PRIME				 135
5062139Sjp161948 #define EC_R_NOT_A_SUPPORTED_NIST_PRIME			 136
5072139Sjp161948 #define EC_R_NOT_IMPLEMENTED				 126
5080Sstevel@tonic-gate #define EC_R_NOT_INITIALIZED				 111
5092139Sjp161948 #define EC_R_NO_FIELD_MOD				 133
5102139Sjp161948 #define EC_R_PASSED_NULL_PARAMETER			 134
5112139Sjp161948 #define EC_R_PKPARAMETERS2GROUP_FAILURE			 127
5120Sstevel@tonic-gate #define EC_R_POINT_AT_INFINITY				 106
5130Sstevel@tonic-gate #define EC_R_POINT_IS_NOT_ON_CURVE			 107
5140Sstevel@tonic-gate #define EC_R_SLOT_FULL					 108
5150Sstevel@tonic-gate #define EC_R_UNDEFINED_GENERATOR			 113
5162139Sjp161948 #define EC_R_UNDEFINED_ORDER				 128
5172139Sjp161948 #define EC_R_UNKNOWN_GROUP				 129
5180Sstevel@tonic-gate #define EC_R_UNKNOWN_ORDER				 114
5192139Sjp161948 #define EC_R_UNSUPPORTED_FIELD				 131
5202139Sjp161948 #define EC_R_WRONG_ORDER				 130
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate #ifdef  __cplusplus
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate #endif
5250Sstevel@tonic-gate #endif
526