1109998Smarkm/* crypto/ec/ec_lcl.h */ 2160814Ssimon/* 3160814Ssimon * Originally written by Bodo Moeller for the OpenSSL project. 4160814Ssimon */ 5109998Smarkm/* ==================================================================== 6238405Sjkim * Copyright (c) 1998-2010 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 85238405Sjkim/* Use default functions for poin2oct, oct2point and compressed coordinates */ 86238405Sjkim#define EC_FLAGS_DEFAULT_OCT 0x1 87238405Sjkim 88109998Smarkm/* Structure details are not part of the exported interface, 89109998Smarkm * so all this may change in future versions. */ 90109998Smarkm 91109998Smarkmstruct ec_method_st { 92238405Sjkim /* Various method flags */ 93238405Sjkim int flags; 94160814Ssimon /* used by EC_METHOD_get_field_type: */ 95160814Ssimon int field_type; /* a NID */ 96160814Ssimon 97109998Smarkm /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */ 98109998Smarkm int (*group_init)(EC_GROUP *); 99109998Smarkm void (*group_finish)(EC_GROUP *); 100109998Smarkm void (*group_clear_finish)(EC_GROUP *); 101109998Smarkm int (*group_copy)(EC_GROUP *, const EC_GROUP *); 102109998Smarkm 103160814Ssimon /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */ 104160814Ssimon /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */ 105160814Ssimon int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 106160814Ssimon int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 107109998Smarkm 108160814Ssimon /* used by EC_GROUP_get_degree: */ 109160814Ssimon int (*group_get_degree)(const EC_GROUP *); 110109998Smarkm 111160814Ssimon /* used by EC_GROUP_check: */ 112160814Ssimon int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); 113160814Ssimon 114109998Smarkm /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */ 115109998Smarkm int (*point_init)(EC_POINT *); 116109998Smarkm void (*point_finish)(EC_POINT *); 117109998Smarkm void (*point_clear_finish)(EC_POINT *); 118109998Smarkm int (*point_copy)(EC_POINT *, const EC_POINT *); 119109998Smarkm 120109998Smarkm /* used by EC_POINT_set_to_infinity, 121160814Ssimon * EC_POINT_set_Jprojective_coordinates_GFp, 122160814Ssimon * EC_POINT_get_Jprojective_coordinates_GFp, 123160814Ssimon * EC_POINT_set_affine_coordinates_GFp, ..._GF2m, 124160814Ssimon * EC_POINT_get_affine_coordinates_GFp, ..._GF2m, 125160814Ssimon * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m: 126109998Smarkm */ 127109998Smarkm int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); 128109998Smarkm int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *, 129109998Smarkm const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 130109998Smarkm int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *, 131109998Smarkm BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 132160814Ssimon int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *, 133109998Smarkm const BIGNUM *x, const BIGNUM *y, BN_CTX *); 134160814Ssimon int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, 135109998Smarkm BIGNUM *x, BIGNUM *y, BN_CTX *); 136160814Ssimon int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *, 137109998Smarkm const BIGNUM *x, int y_bit, BN_CTX *); 138109998Smarkm 139109998Smarkm /* used by EC_POINT_point2oct, EC_POINT_oct2point: */ 140109998Smarkm size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 141109998Smarkm unsigned char *buf, size_t len, BN_CTX *); 142109998Smarkm int (*oct2point)(const EC_GROUP *, EC_POINT *, 143109998Smarkm const unsigned char *buf, size_t len, BN_CTX *); 144109998Smarkm 145109998Smarkm /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */ 146109998Smarkm int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 147109998Smarkm int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 148109998Smarkm int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *); 149109998Smarkm 150109998Smarkm /* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */ 151109998Smarkm int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *); 152109998Smarkm int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); 153109998Smarkm int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 154109998Smarkm 155109998Smarkm /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */ 156109998Smarkm int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *); 157109998Smarkm int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 158109998Smarkm 159160814Ssimon /* used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, EC_POINT_have_precompute_mult 160160814Ssimon * (default implementations are used if the 'mul' pointer is 0): */ 161160814Ssimon int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 162160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 163160814Ssimon int (*precompute_mult)(EC_GROUP *group, BN_CTX *); 164160814Ssimon int (*have_precompute_mult)(const EC_GROUP *group); 165109998Smarkm 166160814Ssimon 167109998Smarkm /* internal functions */ 168109998Smarkm 169160814Ssimon /* 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 'dbl' so that 170109998Smarkm * the same implementations of point operations can be used with different 171109998Smarkm * optimized implementations of expensive field operations: */ 172109998Smarkm int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 173109998Smarkm int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 174160814Ssimon int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 175109998Smarkm 176109998Smarkm int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */ 177109998Smarkm int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */ 178109998Smarkm int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *); 179109998Smarkm} /* EC_METHOD */; 180109998Smarkm 181160814Ssimontypedef struct ec_extra_data_st { 182160814Ssimon struct ec_extra_data_st *next; 183160814Ssimon void *data; 184160814Ssimon void *(*dup_func)(void *); 185160814Ssimon void (*free_func)(void *); 186160814Ssimon void (*clear_free_func)(void *); 187160814Ssimon} EC_EXTRA_DATA; /* used in EC_GROUP */ 188109998Smarkm 189109998Smarkmstruct ec_group_st { 190109998Smarkm const EC_METHOD *meth; 191109998Smarkm 192160814Ssimon EC_POINT *generator; /* optional */ 193160814Ssimon BIGNUM order, cofactor; 194109998Smarkm 195160814Ssimon int curve_name;/* optional NID for named curve */ 196160814Ssimon int asn1_flag; /* flag to control the asn1 encoding */ 197160814Ssimon point_conversion_form_t asn1_form; 198160814Ssimon 199160814Ssimon unsigned char *seed; /* optional seed for parameters (appears in ASN1) */ 200160814Ssimon size_t seed_len; 201160814Ssimon 202160814Ssimon EC_EXTRA_DATA *extra_data; /* linked list */ 203160814Ssimon 204160814Ssimon /* The following members are handled by the method functions, 205160814Ssimon * even if they appear generic */ 206109998Smarkm 207109998Smarkm BIGNUM field; /* Field specification. 208160814Ssimon * For curves over GF(p), this is the modulus; 209160814Ssimon * for curves over GF(2^m), this is the 210160814Ssimon * irreducible polynomial defining the field. 211160814Ssimon */ 212109998Smarkm 213238405Sjkim int poly[6]; /* Field specification for curves over GF(2^m). 214238405Sjkim * The irreducible f(t) is then of the form: 215238405Sjkim * t^poly[0] + t^poly[1] + ... + t^poly[k] 216238405Sjkim * where m = poly[0] > poly[1] > ... > poly[k] = 0. 217238405Sjkim * The array is terminated with poly[k+1]=-1. 218238405Sjkim * All elliptic curve irreducibles have at most 5 219238405Sjkim * non-zero terms. 220238405Sjkim */ 221160814Ssimon 222109998Smarkm BIGNUM a, b; /* Curve coefficients. 223109998Smarkm * (Here the assumption is that BIGNUMs can be used 224109998Smarkm * or abused for all kinds of fields, not just GF(p).) 225109998Smarkm * For characteristic > 3, the curve is defined 226109998Smarkm * by a Weierstrass equation of the form 227109998Smarkm * y^2 = x^3 + a*x + b. 228160814Ssimon * For characteristic 2, the curve is defined by 229160814Ssimon * an equation of the form 230160814Ssimon * y^2 + x*y = x^3 + a*x^2 + b. 231109998Smarkm */ 232160814Ssimon 233109998Smarkm int a_is_minus3; /* enable optimized point arithmetics for special case */ 234109998Smarkm 235109998Smarkm void *field_data1; /* method-specific (e.g., Montgomery structure) */ 236109998Smarkm void *field_data2; /* method-specific */ 237160814Ssimon int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); /* method-specific */ 238109998Smarkm} /* EC_GROUP */; 239109998Smarkm 240160814Ssimonstruct ec_key_st { 241160814Ssimon int version; 242109998Smarkm 243160814Ssimon EC_GROUP *group; 244160814Ssimon 245160814Ssimon EC_POINT *pub_key; 246160814Ssimon BIGNUM *priv_key; 247160814Ssimon 248160814Ssimon unsigned int enc_flag; 249160814Ssimon point_conversion_form_t conv_form; 250160814Ssimon 251160814Ssimon int references; 252238405Sjkim int flags; 253160814Ssimon 254160814Ssimon EC_EXTRA_DATA *method_data; 255160814Ssimon} /* EC_KEY */; 256160814Ssimon 257160814Ssimon/* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only 258109998Smarkm * (with visibility limited to 'package' level for now). 259109998Smarkm * We use the function pointers as index for retrieval; this obviates 260109998Smarkm * global ex_data-style index tables. 261160814Ssimon */ 262160814Ssimonint EC_EX_DATA_set_data(EC_EXTRA_DATA **, void *data, 263160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 264160814Ssimonvoid *EC_EX_DATA_get_data(const EC_EXTRA_DATA *, 265160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 266160814Ssimonvoid EC_EX_DATA_free_data(EC_EXTRA_DATA **, 267160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 268160814Ssimonvoid EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **, 269160814Ssimon void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 270160814Ssimonvoid EC_EX_DATA_free_all_data(EC_EXTRA_DATA **); 271160814Ssimonvoid EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **); 272109998Smarkm 273109998Smarkm 274109998Smarkm 275109998Smarkmstruct ec_point_st { 276109998Smarkm const EC_METHOD *meth; 277109998Smarkm 278109998Smarkm /* All members except 'meth' are handled by the method functions, 279109998Smarkm * even if they appear generic */ 280109998Smarkm 281109998Smarkm BIGNUM X; 282109998Smarkm BIGNUM Y; 283109998Smarkm BIGNUM Z; /* Jacobian projective coordinates: 284109998Smarkm * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */ 285109998Smarkm int Z_is_one; /* enable optimized point arithmetics for special case */ 286109998Smarkm} /* EC_POINT */; 287109998Smarkm 288109998Smarkm 289109998Smarkm 290160814Ssimon/* method functions in ec_mult.c 291160814Ssimon * (ec_lib.c uses these as defaults if group->method->mul is 0) */ 292160814Ssimonint ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 293160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 294160814Ssimonint ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *); 295160814Ssimonint ec_wNAF_have_precompute_mult(const EC_GROUP *group); 296160814Ssimon 297160814Ssimon 298109998Smarkm/* method functions in ecp_smpl.c */ 299109998Smarkmint ec_GFp_simple_group_init(EC_GROUP *); 300109998Smarkmvoid ec_GFp_simple_group_finish(EC_GROUP *); 301109998Smarkmvoid ec_GFp_simple_group_clear_finish(EC_GROUP *); 302109998Smarkmint ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); 303160814Ssimonint ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 304160814Ssimonint ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 305160814Ssimonint ec_GFp_simple_group_get_degree(const EC_GROUP *); 306160814Ssimonint ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 307109998Smarkmint ec_GFp_simple_point_init(EC_POINT *); 308109998Smarkmvoid ec_GFp_simple_point_finish(EC_POINT *); 309109998Smarkmvoid ec_GFp_simple_point_clear_finish(EC_POINT *); 310109998Smarkmint ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); 311109998Smarkmint ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 312109998Smarkmint ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *, 313109998Smarkm const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 314109998Smarkmint ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *, 315109998Smarkm BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 316160814Ssimonint ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 317109998Smarkm const BIGNUM *x, const BIGNUM *y, BN_CTX *); 318160814Ssimonint ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, 319109998Smarkm BIGNUM *x, BIGNUM *y, BN_CTX *); 320160814Ssimonint ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 321109998Smarkm const BIGNUM *x, int y_bit, BN_CTX *); 322109998Smarkmsize_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 323109998Smarkm unsigned char *buf, size_t len, BN_CTX *); 324109998Smarkmint ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *, 325109998Smarkm const unsigned char *buf, size_t len, BN_CTX *); 326109998Smarkmint ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 327109998Smarkmint ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 328109998Smarkmint ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 329109998Smarkmint ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 330109998Smarkmint ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 331109998Smarkmint ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 332109998Smarkmint ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 333109998Smarkmint ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 334109998Smarkmint ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 335109998Smarkmint ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 336109998Smarkm 337109998Smarkm 338109998Smarkm/* method functions in ecp_mont.c */ 339109998Smarkmint ec_GFp_mont_group_init(EC_GROUP *); 340160814Ssimonint ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 341109998Smarkmvoid ec_GFp_mont_group_finish(EC_GROUP *); 342109998Smarkmvoid ec_GFp_mont_group_clear_finish(EC_GROUP *); 343109998Smarkmint ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); 344109998Smarkmint ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 345109998Smarkmint ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 346109998Smarkmint ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 347109998Smarkmint ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 348109998Smarkmint ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); 349109998Smarkm 350109998Smarkm 351109998Smarkm/* method functions in ecp_nist.c */ 352160814Ssimonint ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); 353160814Ssimonint ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 354109998Smarkmint ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 355109998Smarkmint ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 356160814Ssimon 357160814Ssimon 358160814Ssimon/* method functions in ec2_smpl.c */ 359160814Ssimonint ec_GF2m_simple_group_init(EC_GROUP *); 360160814Ssimonvoid ec_GF2m_simple_group_finish(EC_GROUP *); 361160814Ssimonvoid ec_GF2m_simple_group_clear_finish(EC_GROUP *); 362160814Ssimonint ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); 363160814Ssimonint ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 364160814Ssimonint ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 365160814Ssimonint ec_GF2m_simple_group_get_degree(const EC_GROUP *); 366160814Ssimonint ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 367160814Ssimonint ec_GF2m_simple_point_init(EC_POINT *); 368160814Ssimonvoid ec_GF2m_simple_point_finish(EC_POINT *); 369160814Ssimonvoid ec_GF2m_simple_point_clear_finish(EC_POINT *); 370160814Ssimonint ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); 371160814Ssimonint ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 372160814Ssimonint ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 373160814Ssimon const BIGNUM *x, const BIGNUM *y, BN_CTX *); 374160814Ssimonint ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, 375160814Ssimon BIGNUM *x, BIGNUM *y, BN_CTX *); 376160814Ssimonint ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 377160814Ssimon const BIGNUM *x, int y_bit, BN_CTX *); 378160814Ssimonsize_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 379160814Ssimon unsigned char *buf, size_t len, BN_CTX *); 380160814Ssimonint ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, 381160814Ssimon const unsigned char *buf, size_t len, BN_CTX *); 382160814Ssimonint ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 383160814Ssimonint ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 384160814Ssimonint ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 385160814Ssimonint ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 386160814Ssimonint ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 387160814Ssimonint ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 388160814Ssimonint ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 389160814Ssimonint ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 390160814Ssimonint ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 391160814Ssimonint ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 392160814Ssimonint ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 393160814Ssimon 394160814Ssimon 395160814Ssimon/* method functions in ec2_mult.c */ 396160814Ssimonint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 397160814Ssimon size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 398160814Ssimonint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 399160814Ssimonint ec_GF2m_have_precompute_mult(const EC_GROUP *group); 400238405Sjkim 401238405Sjkim/* method functions in ec2_mult.c */ 402238405Sjkimint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 403238405Sjkim size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 404238405Sjkimint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 405238405Sjkimint ec_GF2m_have_precompute_mult(const EC_GROUP *group); 406238405Sjkim 407279264Sdelphij#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 408238405Sjkim/* method functions in ecp_nistp224.c */ 409238405Sjkimint ec_GFp_nistp224_group_init(EC_GROUP *group); 410238405Sjkimint ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *n, BN_CTX *); 411238405Sjkimint ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 412238405Sjkimint ec_GFp_nistp224_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 413238405Sjkimint ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx); 414238405Sjkimint ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 415238405Sjkimint ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group); 416238405Sjkim 417238405Sjkim/* method functions in ecp_nistp256.c */ 418238405Sjkimint ec_GFp_nistp256_group_init(EC_GROUP *group); 419238405Sjkimint ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *n, BN_CTX *); 420238405Sjkimint ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 421238405Sjkimint ec_GFp_nistp256_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 422238405Sjkimint ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx); 423238405Sjkimint ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 424238405Sjkimint ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group); 425238405Sjkim 426238405Sjkim/* method functions in ecp_nistp521.c */ 427238405Sjkimint ec_GFp_nistp521_group_init(EC_GROUP *group); 428238405Sjkimint ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *n, BN_CTX *); 429238405Sjkimint ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 430238405Sjkimint ec_GFp_nistp521_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *); 431238405Sjkimint ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx); 432238405Sjkimint ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 433238405Sjkimint ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group); 434238405Sjkim 435238405Sjkim/* utility functions in ecp_nistputil.c */ 436238405Sjkimvoid ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array, 437238405Sjkim size_t felem_size, void *tmp_felems, 438238405Sjkim void (*felem_one)(void *out), 439238405Sjkim int (*felem_is_zero)(const void *in), 440238405Sjkim void (*felem_assign)(void *out, const void *in), 441238405Sjkim void (*felem_square)(void *out, const void *in), 442238405Sjkim void (*felem_mul)(void *out, const void *in1, const void *in2), 443238405Sjkim void (*felem_inv)(void *out, const void *in), 444238405Sjkim void (*felem_contract)(void *out, const void *in)); 445238405Sjkimvoid ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, unsigned char *digit, unsigned char in); 446238405Sjkim#endif 447