xref: /onnv-gate/usr/src/common/openssl/crypto/ec/ec_lcl.h (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* crypto/ec/ec_lcl.h */
2*2139Sjp161948 /*
3*2139Sjp161948  * Originally written by Bodo Moeller for the OpenSSL project.
4*2139Sjp161948  */
50Sstevel@tonic-gate /* ====================================================================
6*2139Sjp161948  * 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  */
58*2139Sjp161948 /* ====================================================================
59*2139Sjp161948  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60*2139Sjp161948  *
61*2139Sjp161948  * Portions of the attached software ("Contribution") are developed by
62*2139Sjp161948  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63*2139Sjp161948  *
64*2139Sjp161948  * The Contribution is licensed pursuant to the OpenSSL open source
65*2139Sjp161948  * license provided above.
66*2139Sjp161948  *
67*2139Sjp161948  * The elliptic curve binary polynomial software is originally written by
68*2139Sjp161948  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69*2139Sjp161948  *
70*2139Sjp161948  */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #include <stdlib.h>
740Sstevel@tonic-gate 
75*2139Sjp161948 #include <openssl/obj_mac.h>
760Sstevel@tonic-gate #include <openssl/ec.h>
77*2139Sjp161948 #include <openssl/bn.h>
780Sstevel@tonic-gate 
79*2139Sjp161948 #if defined(__SUNPRO_C)
80*2139Sjp161948 # if __SUNPRO_C >= 0x520
81*2139Sjp161948 # pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
82*2139Sjp161948 # endif
83*2139Sjp161948 #endif
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /* Structure details are not part of the exported interface,
860Sstevel@tonic-gate  * so all this may change in future versions. */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate struct ec_method_st {
89*2139Sjp161948 	/* used by EC_METHOD_get_field_type: */
90*2139Sjp161948 	int field_type; /* a NID */
91*2139Sjp161948 
920Sstevel@tonic-gate 	/* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
930Sstevel@tonic-gate 	int (*group_init)(EC_GROUP *);
940Sstevel@tonic-gate 	void (*group_finish)(EC_GROUP *);
950Sstevel@tonic-gate 	void (*group_clear_finish)(EC_GROUP *);
960Sstevel@tonic-gate 	int (*group_copy)(EC_GROUP *, const EC_GROUP *);
970Sstevel@tonic-gate 
98*2139Sjp161948 	/* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */
99*2139Sjp161948 	/* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */
100*2139Sjp161948 	int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
101*2139Sjp161948 	int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
1020Sstevel@tonic-gate 
103*2139Sjp161948 	/* used by EC_GROUP_get_degree: */
104*2139Sjp161948 	int (*group_get_degree)(const EC_GROUP *);
105*2139Sjp161948 
106*2139Sjp161948 	/* used by EC_GROUP_check: */
107*2139Sjp161948 	int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	/* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
1100Sstevel@tonic-gate 	int (*point_init)(EC_POINT *);
1110Sstevel@tonic-gate 	void (*point_finish)(EC_POINT *);
1120Sstevel@tonic-gate 	void (*point_clear_finish)(EC_POINT *);
1130Sstevel@tonic-gate 	int (*point_copy)(EC_POINT *, const EC_POINT *);
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	/* used by EC_POINT_set_to_infinity,
116*2139Sjp161948 	 * EC_POINT_set_Jprojective_coordinates_GFp,
117*2139Sjp161948 	 * EC_POINT_get_Jprojective_coordinates_GFp,
118*2139Sjp161948 	 * EC_POINT_set_affine_coordinates_GFp,     ..._GF2m,
119*2139Sjp161948 	 * EC_POINT_get_affine_coordinates_GFp,     ..._GF2m,
120*2139Sjp161948 	 * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m:
1210Sstevel@tonic-gate 	 */
1220Sstevel@tonic-gate 	int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
1230Sstevel@tonic-gate 	int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
1240Sstevel@tonic-gate 		const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
1250Sstevel@tonic-gate 	int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
1260Sstevel@tonic-gate 		BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
127*2139Sjp161948 	int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *,
1280Sstevel@tonic-gate 		const BIGNUM *x, const BIGNUM *y, BN_CTX *);
129*2139Sjp161948 	int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *,
1300Sstevel@tonic-gate 		BIGNUM *x, BIGNUM *y, BN_CTX *);
131*2139Sjp161948 	int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *,
1320Sstevel@tonic-gate 		const BIGNUM *x, int y_bit, BN_CTX *);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	/* used by EC_POINT_point2oct, EC_POINT_oct2point: */
1350Sstevel@tonic-gate 	size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
1360Sstevel@tonic-gate 	        unsigned char *buf, size_t len, BN_CTX *);
1370Sstevel@tonic-gate 	int (*oct2point)(const EC_GROUP *, EC_POINT *,
1380Sstevel@tonic-gate 	        const unsigned char *buf, size_t len, BN_CTX *);
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	/* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */
1410Sstevel@tonic-gate 	int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
1420Sstevel@tonic-gate 	int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
1430Sstevel@tonic-gate 	int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	/* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */
1460Sstevel@tonic-gate 	int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *);
1470Sstevel@tonic-gate 	int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
1480Sstevel@tonic-gate 	int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	/* used by EC_POINT_make_affine, EC_POINTs_make_affine: */
1510Sstevel@tonic-gate 	int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
1520Sstevel@tonic-gate 	int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
1530Sstevel@tonic-gate 
154*2139Sjp161948 	/* used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, EC_POINT_have_precompute_mult
155*2139Sjp161948 	 * (default implementations are used if the 'mul' pointer is 0): */
156*2139Sjp161948 	int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
157*2139Sjp161948 		size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
158*2139Sjp161948 	int (*precompute_mult)(EC_GROUP *group, BN_CTX *);
159*2139Sjp161948 	int (*have_precompute_mult)(const EC_GROUP *group);
160*2139Sjp161948 
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	/* internal functions */
1630Sstevel@tonic-gate 
164*2139Sjp161948 	/* 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 'dbl' so that
1650Sstevel@tonic-gate 	 * the same implementations of point operations can be used with different
1660Sstevel@tonic-gate 	 * optimized implementations of expensive field operations: */
1670Sstevel@tonic-gate 	int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1680Sstevel@tonic-gate 	int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
169*2139Sjp161948 	int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
1720Sstevel@tonic-gate 	int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
1730Sstevel@tonic-gate 	int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *);
1740Sstevel@tonic-gate } /* EC_METHOD */;
1750Sstevel@tonic-gate 
176*2139Sjp161948 typedef struct ec_extra_data_st {
177*2139Sjp161948 	struct ec_extra_data_st *next;
178*2139Sjp161948 	void *data;
179*2139Sjp161948 	void *(*dup_func)(void *);
180*2139Sjp161948 	void (*free_func)(void *);
181*2139Sjp161948 	void (*clear_free_func)(void *);
182*2139Sjp161948 } EC_EXTRA_DATA; /* used in EC_GROUP */
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate struct ec_group_st {
1850Sstevel@tonic-gate 	const EC_METHOD *meth;
1860Sstevel@tonic-gate 
187*2139Sjp161948 	EC_POINT *generator; /* optional */
188*2139Sjp161948 	BIGNUM order, cofactor;
189*2139Sjp161948 
190*2139Sjp161948 	int curve_name;/* optional NID for named curve */
191*2139Sjp161948 	int asn1_flag; /* flag to control the asn1 encoding */
192*2139Sjp161948 	point_conversion_form_t asn1_form;
1930Sstevel@tonic-gate 
194*2139Sjp161948 	unsigned char *seed; /* optional seed for parameters (appears in ASN1) */
195*2139Sjp161948 	size_t seed_len;
196*2139Sjp161948 
197*2139Sjp161948 	EC_EXTRA_DATA *extra_data; /* linked list */
198*2139Sjp161948 
199*2139Sjp161948 	/* The following members are handled by the method functions,
200*2139Sjp161948 	 * even if they appear generic */
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	BIGNUM field; /* Field specification.
203*2139Sjp161948 	               * For curves over GF(p), this is the modulus;
204*2139Sjp161948 	               * for curves over GF(2^m), this is the
205*2139Sjp161948 	               * irreducible polynomial defining the field.
206*2139Sjp161948 	               */
207*2139Sjp161948 
208*2139Sjp161948 	unsigned int poly[5]; /* Field specification for curves over GF(2^m).
209*2139Sjp161948 	                       * The irreducible f(t) is then of the form:
210*2139Sjp161948 	                       *     t^poly[0] + t^poly[1] + ... + t^poly[k]
211*2139Sjp161948 	                       * where m = poly[0] > poly[1] > ... > poly[k] = 0.
212*2139Sjp161948 	                       */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	BIGNUM a, b; /* Curve coefficients.
2150Sstevel@tonic-gate 	              * (Here the assumption is that BIGNUMs can be used
2160Sstevel@tonic-gate 	              * or abused for all kinds of fields, not just GF(p).)
2170Sstevel@tonic-gate 	              * For characteristic  > 3,  the curve is defined
2180Sstevel@tonic-gate 	              * by a Weierstrass equation of the form
2190Sstevel@tonic-gate 	              *     y^2 = x^3 + a*x + b.
220*2139Sjp161948 	              * For characteristic  2,  the curve is defined by
221*2139Sjp161948 	              * an equation of the form
222*2139Sjp161948 	              *     y^2 + x*y = x^3 + a*x^2 + b.
2230Sstevel@tonic-gate 	              */
2240Sstevel@tonic-gate 
225*2139Sjp161948 	int a_is_minus3; /* enable optimized point arithmetics for special case */
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 	void *field_data1; /* method-specific (e.g., Montgomery structure) */
2280Sstevel@tonic-gate 	void *field_data2; /* method-specific */
229*2139Sjp161948 	int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *,	BN_CTX *); /* method-specific */
2300Sstevel@tonic-gate } /* EC_GROUP */;
2310Sstevel@tonic-gate 
232*2139Sjp161948 struct ec_key_st {
233*2139Sjp161948 	int version;
2340Sstevel@tonic-gate 
235*2139Sjp161948 	EC_GROUP *group;
236*2139Sjp161948 
237*2139Sjp161948 	EC_POINT *pub_key;
238*2139Sjp161948 	BIGNUM	 *priv_key;
239*2139Sjp161948 
240*2139Sjp161948 	unsigned int enc_flag;
241*2139Sjp161948 	point_conversion_form_t conv_form;
242*2139Sjp161948 
243*2139Sjp161948 	int 	references;
244*2139Sjp161948 
245*2139Sjp161948 	EC_EXTRA_DATA *method_data;
246*2139Sjp161948 } /* EC_KEY */;
247*2139Sjp161948 
248*2139Sjp161948 /* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only
2490Sstevel@tonic-gate  * (with visibility limited to 'package' level for now).
2500Sstevel@tonic-gate  * We use the function pointers as index for retrieval; this obviates
2510Sstevel@tonic-gate  * global ex_data-style index tables.
252*2139Sjp161948  */
253*2139Sjp161948 int EC_EX_DATA_set_data(EC_EXTRA_DATA **, void *data,
254*2139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
255*2139Sjp161948 void *EC_EX_DATA_get_data(const EC_EXTRA_DATA *,
256*2139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
257*2139Sjp161948 void EC_EX_DATA_free_data(EC_EXTRA_DATA **,
258*2139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
259*2139Sjp161948 void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **,
260*2139Sjp161948 	void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
261*2139Sjp161948 void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **);
262*2139Sjp161948 void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate struct ec_point_st {
2670Sstevel@tonic-gate 	const EC_METHOD *meth;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	/* All members except 'meth' are handled by the method functions,
2700Sstevel@tonic-gate 	 * even if they appear generic */
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	BIGNUM X;
2730Sstevel@tonic-gate 	BIGNUM Y;
2740Sstevel@tonic-gate 	BIGNUM Z; /* Jacobian projective coordinates:
2750Sstevel@tonic-gate 	           * (X, Y, Z)  represents  (X/Z^2, Y/Z^3)  if  Z != 0 */
2760Sstevel@tonic-gate 	int Z_is_one; /* enable optimized point arithmetics for special case */
2770Sstevel@tonic-gate } /* EC_POINT */;
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 
281*2139Sjp161948 /* method functions in ec_mult.c
282*2139Sjp161948  * (ec_lib.c uses these as defaults if group->method->mul is 0) */
283*2139Sjp161948 int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
284*2139Sjp161948 	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
285*2139Sjp161948 int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *);
286*2139Sjp161948 int ec_wNAF_have_precompute_mult(const EC_GROUP *group);
287*2139Sjp161948 
288*2139Sjp161948 
2890Sstevel@tonic-gate /* method functions in ecp_smpl.c */
2900Sstevel@tonic-gate int ec_GFp_simple_group_init(EC_GROUP *);
2910Sstevel@tonic-gate void ec_GFp_simple_group_finish(EC_GROUP *);
2920Sstevel@tonic-gate void ec_GFp_simple_group_clear_finish(EC_GROUP *);
2930Sstevel@tonic-gate int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
294*2139Sjp161948 int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
295*2139Sjp161948 int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
296*2139Sjp161948 int ec_GFp_simple_group_get_degree(const EC_GROUP *);
297*2139Sjp161948 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
2980Sstevel@tonic-gate int ec_GFp_simple_point_init(EC_POINT *);
2990Sstevel@tonic-gate void ec_GFp_simple_point_finish(EC_POINT *);
3000Sstevel@tonic-gate void ec_GFp_simple_point_clear_finish(EC_POINT *);
3010Sstevel@tonic-gate int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *);
3020Sstevel@tonic-gate int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
3030Sstevel@tonic-gate int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
3040Sstevel@tonic-gate 	const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
3050Sstevel@tonic-gate int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
3060Sstevel@tonic-gate 	BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
307*2139Sjp161948 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
3080Sstevel@tonic-gate 	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
309*2139Sjp161948 int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *,
3100Sstevel@tonic-gate 	BIGNUM *x, BIGNUM *y, BN_CTX *);
311*2139Sjp161948 int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
3120Sstevel@tonic-gate 	const BIGNUM *x, int y_bit, BN_CTX *);
3130Sstevel@tonic-gate size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
3140Sstevel@tonic-gate 	unsigned char *buf, size_t len, BN_CTX *);
3150Sstevel@tonic-gate int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *,
3160Sstevel@tonic-gate 	const unsigned char *buf, size_t len, BN_CTX *);
3170Sstevel@tonic-gate int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
3180Sstevel@tonic-gate int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
3190Sstevel@tonic-gate int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
3200Sstevel@tonic-gate int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
3210Sstevel@tonic-gate int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
3220Sstevel@tonic-gate int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
3230Sstevel@tonic-gate int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
3240Sstevel@tonic-gate int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
3250Sstevel@tonic-gate int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
3260Sstevel@tonic-gate int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate /* method functions in ecp_mont.c */
3300Sstevel@tonic-gate int ec_GFp_mont_group_init(EC_GROUP *);
331*2139Sjp161948 int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
3320Sstevel@tonic-gate void ec_GFp_mont_group_finish(EC_GROUP *);
3330Sstevel@tonic-gate void ec_GFp_mont_group_clear_finish(EC_GROUP *);
3340Sstevel@tonic-gate int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
3350Sstevel@tonic-gate int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
3360Sstevel@tonic-gate int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
3370Sstevel@tonic-gate int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
3380Sstevel@tonic-gate int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
3390Sstevel@tonic-gate int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 
342*2139Sjp161948 /* method functions in ecp_nist.c */
343*2139Sjp161948 int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
344*2139Sjp161948 int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
345*2139Sjp161948 int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
346*2139Sjp161948 int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate 
349*2139Sjp161948 /* method functions in ec2_smpl.c */
350*2139Sjp161948 int ec_GF2m_simple_group_init(EC_GROUP *);
351*2139Sjp161948 void ec_GF2m_simple_group_finish(EC_GROUP *);
352*2139Sjp161948 void ec_GF2m_simple_group_clear_finish(EC_GROUP *);
353*2139Sjp161948 int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *);
354*2139Sjp161948 int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
355*2139Sjp161948 int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
356*2139Sjp161948 int ec_GF2m_simple_group_get_degree(const EC_GROUP *);
357*2139Sjp161948 int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
358*2139Sjp161948 int ec_GF2m_simple_point_init(EC_POINT *);
359*2139Sjp161948 void ec_GF2m_simple_point_finish(EC_POINT *);
360*2139Sjp161948 void ec_GF2m_simple_point_clear_finish(EC_POINT *);
361*2139Sjp161948 int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *);
362*2139Sjp161948 int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
363*2139Sjp161948 int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
364*2139Sjp161948 	const BIGNUM *x, const BIGNUM *y, BN_CTX *);
365*2139Sjp161948 int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *,
366*2139Sjp161948 	BIGNUM *x, BIGNUM *y, BN_CTX *);
367*2139Sjp161948 int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
368*2139Sjp161948 	const BIGNUM *x, int y_bit, BN_CTX *);
369*2139Sjp161948 size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
370*2139Sjp161948 	unsigned char *buf, size_t len, BN_CTX *);
371*2139Sjp161948 int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *,
372*2139Sjp161948 	const unsigned char *buf, size_t len, BN_CTX *);
373*2139Sjp161948 int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
374*2139Sjp161948 int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
375*2139Sjp161948 int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
376*2139Sjp161948 int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
377*2139Sjp161948 int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
378*2139Sjp161948 int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
379*2139Sjp161948 int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
380*2139Sjp161948 int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
381*2139Sjp161948 int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
382*2139Sjp161948 int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
383*2139Sjp161948 int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
384*2139Sjp161948 
385*2139Sjp161948 
386*2139Sjp161948 /* method functions in ec2_mult.c */
387*2139Sjp161948 int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
388*2139Sjp161948 	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
389*2139Sjp161948 int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
390*2139Sjp161948 int ec_GF2m_have_precompute_mult(const EC_GROUP *group);
391