ec_lcl.h revision 160814
1109998Smarkm/* crypto/ec/ec_lcl.h */ 2160814Ssimon/* 3160814Ssimon * Originally written by Bodo Moeller for the OpenSSL project. 4160814Ssimon */ 5109998Smarkm/* ==================================================================== 6160814Ssimon * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 7109998Smarkm * 8109998Smarkm * Redistribution and use in source and binary forms, with or without 9109998Smarkm * modification, are permitted provided that the following conditions 10109998Smarkm * are met: 11109998Smarkm * 12109998Smarkm * 1. Redistributions of source code must retain the above copyright 13109998Smarkm * notice, this list of conditions and the following disclaimer. 14109998Smarkm * 15109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 16109998Smarkm * notice, this list of conditions and the following disclaimer in 17109998Smarkm * the documentation and/or other materials provided with the 18109998Smarkm * distribution. 19109998Smarkm * 20109998Smarkm * 3. All advertising materials mentioning features or use of this 21109998Smarkm * software must display the following acknowledgment: 22109998Smarkm * "This product includes software developed by the OpenSSL Project 23109998Smarkm * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24109998Smarkm * 25109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26109998Smarkm * endorse or promote products derived from this software without 27109998Smarkm * prior written permission. For written permission, please contact 28109998Smarkm * openssl-core@openssl.org. 29109998Smarkm * 30109998Smarkm * 5. Products derived from this software may not be called "OpenSSL" 31109998Smarkm * nor may "OpenSSL" appear in their names without prior written 32109998Smarkm * permission of the OpenSSL Project. 33109998Smarkm * 34109998Smarkm * 6. Redistributions of any form whatsoever must retain the following 35109998Smarkm * acknowledgment: 36109998Smarkm * "This product includes software developed by the OpenSSL Project 37109998Smarkm * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38109998Smarkm * 39109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42109998Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE. 51109998Smarkm * ==================================================================== 52109998Smarkm * 53109998Smarkm * This product includes cryptographic software written by Eric Young 54109998Smarkm * (eay@cryptsoft.com). This product includes software written by Tim 55109998Smarkm * Hudson (tjh@cryptsoft.com). 56109998Smarkm * 57109998Smarkm */ 58160814Ssimon/* ==================================================================== 59160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 60160814Ssimon * 61160814Ssimon * Portions of the attached software ("Contribution") are developed by 62160814Ssimon * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 63160814Ssimon * 64160814Ssimon * The Contribution is licensed pursuant to the OpenSSL open source 65160814Ssimon * license provided above. 66160814Ssimon * 67160814Ssimon * The elliptic curve binary polynomial software is originally written by 68160814Ssimon * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. 69160814Ssimon * 70160814Ssimon */ 71109998Smarkm 72109998Smarkm 73109998Smarkm#include <stdlib.h> 74109998Smarkm 75160814Ssimon#include <openssl/obj_mac.h> 76109998Smarkm#include <openssl/ec.h> 77160814Ssimon#include <openssl/bn.h> 78109998Smarkm 79160814Ssimon#if defined(__SUNPRO_C) 80160814Ssimon# if __SUNPRO_C >= 0x520 81160814Ssimon# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) 82160814Ssimon# endif 83160814Ssimon#endif 84109998Smarkm 85109998Smarkm/* Structure details are not part of the exported interface, 86109998Smarkm * so all this may change in future versions. */ 87109998Smarkm 88109998Smarkmstruct ec_method_st { 89160814Ssimon /* used by EC_METHOD_get_field_type: */ 90160814Ssimon int field_type; /* a NID */ 91160814Ssimon 92109998Smarkm /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */ 93109998Smarkm int (*group_init)(EC_GROUP *); 94109998Smarkm void (*group_finish)(EC_GROUP *); 95109998Smarkm void (*group_clear_finish)(EC_GROUP *); 96109998Smarkm int (*group_copy)(EC_GROUP *, const EC_GROUP *); 97109998Smarkm 98160814Ssimon /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */ 99160814Ssimon /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */ 100160814Ssimon int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 101160814Ssimon int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 102109998Smarkm 103160814Ssimon /* used by EC_GROUP_get_degree: */ 104160814Ssimon int (*group_get_degree)(const EC_GROUP *); 105109998Smarkm 106160814Ssimon /* used by EC_GROUP_check: */ 107160814Ssimon int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); 108160814Ssimon 109109998Smarkm /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */ 110109998Smarkm int (*point_init)(EC_POINT *); 111109998Smarkm void (*point_finish)(EC_POINT *); 112109998Smarkm void (*point_clear_finish)(EC_POINT *); 113109998Smarkm int (*point_copy)(EC_POINT *, const EC_POINT *); 114109998Smarkm 115109998Smarkm /* used by EC_POINT_set_to_infinity, 116160814Ssimon * EC_POINT_set_Jprojective_coordinates_GFp, 117160814Ssimon * EC_POINT_get_Jprojective_coordinates_GFp, 118160814Ssimon * EC_POINT_set_affine_coordinates_GFp, ..._GF2m, 119160814Ssimon * EC_POINT_get_affine_coordinates_GFp, ..._GF2m, 120160814Ssimon * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m: 121109998Smarkm */ 122109998Smarkm int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); 123109998Smarkm int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *, 124109998Smarkm const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 125109998Smarkm int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *, 126109998Smarkm BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 127160814Ssimon int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *, 128109998Smarkm const BIGNUM *x, const BIGNUM *y, BN_CTX *); 129160814Ssimon int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, 130109998Smarkm BIGNUM *x, BIGNUM *y, BN_CTX *); 131160814Ssimon int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *, 132109998Smarkm const BIGNUM *x, int y_bit, BN_CTX *); 133109998Smarkm 134109998Smarkm /* used by EC_POINT_point2oct, EC_POINT_oct2point: */ 135109998Smarkm size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 136109998Smarkm unsigned char *buf, size_t len, BN_CTX *); 137109998Smarkm int (*oct2point)(const EC_GROUP *, EC_POINT *, 138109998Smarkm const unsigned char *buf, size_t len, BN_CTX *); 139109998Smarkm 140109998Smarkm /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */ 141109998Smarkm int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 142109998Smarkm int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 143109998Smarkm int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *); 144109998Smarkm 145109998Smarkm /* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */ 146109998Smarkm int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *); 147109998Smarkm int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); 148109998Smarkm int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 149109998Smarkm 150109998Smarkm /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */ 151109998Smarkm int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *); 152109998Smarkm int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 153109998Smarkm 154160814Ssimon /* used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, EC_POINT_have_precompute_mult 155160814Ssimon * (default implementations are used if the 'mul' pointer is 0): */ 156160814Ssimon int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 157160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 158160814Ssimon int (*precompute_mult)(EC_GROUP *group, BN_CTX *); 159160814Ssimon int (*have_precompute_mult)(const EC_GROUP *group); 160109998Smarkm 161160814Ssimon 162109998Smarkm /* internal functions */ 163109998Smarkm 164160814Ssimon /* 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 'dbl' so that 165109998Smarkm * the same implementations of point operations can be used with different 166109998Smarkm * optimized implementations of expensive field operations: */ 167109998Smarkm int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 168109998Smarkm int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 169160814Ssimon int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 170109998Smarkm 171109998Smarkm int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */ 172109998Smarkm int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */ 173109998Smarkm int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *); 174109998Smarkm} /* EC_METHOD */; 175109998Smarkm 176160814Ssimontypedef struct ec_extra_data_st { 177160814Ssimon struct ec_extra_data_st *next; 178160814Ssimon void *data; 179160814Ssimon void *(*dup_func)(void *); 180160814Ssimon void (*free_func)(void *); 181160814Ssimon void (*clear_free_func)(void *); 182160814Ssimon} EC_EXTRA_DATA; /* used in EC_GROUP */ 183109998Smarkm 184109998Smarkmstruct ec_group_st { 185109998Smarkm const EC_METHOD *meth; 186109998Smarkm 187160814Ssimon EC_POINT *generator; /* optional */ 188160814Ssimon BIGNUM order, cofactor; 189109998Smarkm 190160814Ssimon int curve_name;/* optional NID for named curve */ 191160814Ssimon int asn1_flag; /* flag to control the asn1 encoding */ 192160814Ssimon point_conversion_form_t asn1_form; 193160814Ssimon 194160814Ssimon unsigned char *seed; /* optional seed for parameters (appears in ASN1) */ 195160814Ssimon size_t seed_len; 196160814Ssimon 197160814Ssimon EC_EXTRA_DATA *extra_data; /* linked list */ 198160814Ssimon 199160814Ssimon /* The following members are handled by the method functions, 200160814Ssimon * even if they appear generic */ 201109998Smarkm 202109998Smarkm BIGNUM field; /* Field specification. 203160814Ssimon * For curves over GF(p), this is the modulus; 204160814Ssimon * for curves over GF(2^m), this is the 205160814Ssimon * irreducible polynomial defining the field. 206160814Ssimon */ 207109998Smarkm 208160814Ssimon unsigned int poly[5]; /* Field specification for curves over GF(2^m). 209160814Ssimon * The irreducible f(t) is then of the form: 210160814Ssimon * t^poly[0] + t^poly[1] + ... + t^poly[k] 211160814Ssimon * where m = poly[0] > poly[1] > ... > poly[k] = 0. 212160814Ssimon */ 213160814Ssimon 214109998Smarkm BIGNUM a, b; /* Curve coefficients. 215109998Smarkm * (Here the assumption is that BIGNUMs can be used 216109998Smarkm * or abused for all kinds of fields, not just GF(p).) 217109998Smarkm * For characteristic > 3, the curve is defined 218109998Smarkm * by a Weierstrass equation of the form 219109998Smarkm * y^2 = x^3 + a*x + b. 220160814Ssimon * For characteristic 2, the curve is defined by 221160814Ssimon * an equation of the form 222160814Ssimon * y^2 + x*y = x^3 + a*x^2 + b. 223109998Smarkm */ 224160814Ssimon 225109998Smarkm int a_is_minus3; /* enable optimized point arithmetics for special case */ 226109998Smarkm 227109998Smarkm void *field_data1; /* method-specific (e.g., Montgomery structure) */ 228109998Smarkm void *field_data2; /* method-specific */ 229160814Ssimon int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); /* method-specific */ 230109998Smarkm} /* EC_GROUP */; 231109998Smarkm 232160814Ssimonstruct ec_key_st { 233160814Ssimon int version; 234109998Smarkm 235160814Ssimon EC_GROUP *group; 236160814Ssimon 237160814Ssimon EC_POINT *pub_key; 238160814Ssimon BIGNUM *priv_key; 239160814Ssimon 240160814Ssimon unsigned int enc_flag; 241160814Ssimon point_conversion_form_t conv_form; 242160814Ssimon 243160814Ssimon int references; 244160814Ssimon 245160814Ssimon EC_EXTRA_DATA *method_data; 246160814Ssimon} /* EC_KEY */; 247160814Ssimon 248160814Ssimon/* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only 249109998Smarkm * (with visibility limited to 'package' level for now). 250109998Smarkm * We use the function pointers as index for retrieval; this obviates 251109998Smarkm * global ex_data-style index tables. 252160814Ssimon */ 253160814Ssimonint EC_EX_DATA_set_data(EC_EXTRA_DATA **, void *data, 254160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 255160814Ssimonvoid *EC_EX_DATA_get_data(const EC_EXTRA_DATA *, 256160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 257160814Ssimonvoid EC_EX_DATA_free_data(EC_EXTRA_DATA **, 258160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 259160814Ssimonvoid EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **, 260160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 261160814Ssimonvoid EC_EX_DATA_free_all_data(EC_EXTRA_DATA **); 262160814Ssimonvoid EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **); 263109998Smarkm 264109998Smarkm 265109998Smarkm 266109998Smarkmstruct ec_point_st { 267109998Smarkm const EC_METHOD *meth; 268109998Smarkm 269109998Smarkm /* All members except 'meth' are handled by the method functions, 270109998Smarkm * even if they appear generic */ 271109998Smarkm 272109998Smarkm BIGNUM X; 273109998Smarkm BIGNUM Y; 274109998Smarkm BIGNUM Z; /* Jacobian projective coordinates: 275109998Smarkm * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */ 276109998Smarkm int Z_is_one; /* enable optimized point arithmetics for special case */ 277109998Smarkm} /* EC_POINT */; 278109998Smarkm 279109998Smarkm 280109998Smarkm 281160814Ssimon/* method functions in ec_mult.c 282160814Ssimon * (ec_lib.c uses these as defaults if group->method->mul is 0) */ 283160814Ssimonint ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 284160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 285160814Ssimonint ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *); 286160814Ssimonint ec_wNAF_have_precompute_mult(const EC_GROUP *group); 287160814Ssimon 288160814Ssimon 289109998Smarkm/* method functions in ecp_smpl.c */ 290109998Smarkmint ec_GFp_simple_group_init(EC_GROUP *); 291109998Smarkmvoid ec_GFp_simple_group_finish(EC_GROUP *); 292109998Smarkmvoid ec_GFp_simple_group_clear_finish(EC_GROUP *); 293109998Smarkmint ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); 294160814Ssimonint ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 295160814Ssimonint ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 296160814Ssimonint ec_GFp_simple_group_get_degree(const EC_GROUP *); 297160814Ssimonint ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 298109998Smarkmint ec_GFp_simple_point_init(EC_POINT *); 299109998Smarkmvoid ec_GFp_simple_point_finish(EC_POINT *); 300109998Smarkmvoid ec_GFp_simple_point_clear_finish(EC_POINT *); 301109998Smarkmint ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); 302109998Smarkmint ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 303109998Smarkmint ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *, 304109998Smarkm const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 305109998Smarkmint ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *, 306109998Smarkm BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 307160814Ssimonint ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 308109998Smarkm const BIGNUM *x, const BIGNUM *y, BN_CTX *); 309160814Ssimonint ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, 310109998Smarkm BIGNUM *x, BIGNUM *y, BN_CTX *); 311160814Ssimonint ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 312109998Smarkm const BIGNUM *x, int y_bit, BN_CTX *); 313109998Smarkmsize_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 314109998Smarkm unsigned char *buf, size_t len, BN_CTX *); 315109998Smarkmint ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *, 316109998Smarkm const unsigned char *buf, size_t len, BN_CTX *); 317109998Smarkmint ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 318109998Smarkmint ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 319109998Smarkmint ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 320109998Smarkmint ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 321109998Smarkmint ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 322109998Smarkmint ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 323109998Smarkmint ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 324109998Smarkmint ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 325109998Smarkmint ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 326109998Smarkmint ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 327109998Smarkm 328109998Smarkm 329109998Smarkm/* method functions in ecp_mont.c */ 330109998Smarkmint ec_GFp_mont_group_init(EC_GROUP *); 331160814Ssimonint ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 332109998Smarkmvoid ec_GFp_mont_group_finish(EC_GROUP *); 333109998Smarkmvoid ec_GFp_mont_group_clear_finish(EC_GROUP *); 334109998Smarkmint ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); 335109998Smarkmint ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 336109998Smarkmint ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 337109998Smarkmint ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 338109998Smarkmint ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 339109998Smarkmint ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); 340109998Smarkm 341109998Smarkm 342109998Smarkm/* method functions in ecp_nist.c */ 343160814Ssimonint ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); 344160814Ssimonint ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 345109998Smarkmint ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 346109998Smarkmint ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 347160814Ssimon 348160814Ssimon 349160814Ssimon/* method functions in ec2_smpl.c */ 350160814Ssimonint ec_GF2m_simple_group_init(EC_GROUP *); 351160814Ssimonvoid ec_GF2m_simple_group_finish(EC_GROUP *); 352160814Ssimonvoid ec_GF2m_simple_group_clear_finish(EC_GROUP *); 353160814Ssimonint ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); 354160814Ssimonint ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 355160814Ssimonint ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 356160814Ssimonint ec_GF2m_simple_group_get_degree(const EC_GROUP *); 357160814Ssimonint ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 358160814Ssimonint ec_GF2m_simple_point_init(EC_POINT *); 359160814Ssimonvoid ec_GF2m_simple_point_finish(EC_POINT *); 360160814Ssimonvoid ec_GF2m_simple_point_clear_finish(EC_POINT *); 361160814Ssimonint ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); 362160814Ssimonint ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 363160814Ssimonint ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 364160814Ssimon const BIGNUM *x, const BIGNUM *y, BN_CTX *); 365160814Ssimonint ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, 366160814Ssimon BIGNUM *x, BIGNUM *y, BN_CTX *); 367160814Ssimonint ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 368160814Ssimon const BIGNUM *x, int y_bit, BN_CTX *); 369160814Ssimonsize_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 370160814Ssimon unsigned char *buf, size_t len, BN_CTX *); 371160814Ssimonint ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, 372160814Ssimon const unsigned char *buf, size_t len, BN_CTX *); 373160814Ssimonint ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 374160814Ssimonint ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 375160814Ssimonint ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 376160814Ssimonint ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 377160814Ssimonint ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 378160814Ssimonint ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 379160814Ssimonint ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 380160814Ssimonint ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 381160814Ssimonint ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 382160814Ssimonint ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 383160814Ssimonint ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 384160814Ssimon 385160814Ssimon 386160814Ssimon/* method functions in ec2_mult.c */ 387160814Ssimonint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 388160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 389160814Ssimonint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 390160814Ssimonint ec_GF2m_have_precompute_mult(const EC_GROUP *group); 391