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 13296341Sdelphij * 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 * 61296341Sdelphij * 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 * 67296341Sdelphij * 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#include <stdlib.h> 73109998Smarkm 74160814Ssimon#include <openssl/obj_mac.h> 75109998Smarkm#include <openssl/ec.h> 76160814Ssimon#include <openssl/bn.h> 77109998Smarkm 78160814Ssimon#if defined(__SUNPRO_C) 79160814Ssimon# if __SUNPRO_C >= 0x520 80296341Sdelphij# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) 81160814Ssimon# endif 82160814Ssimon#endif 83109998Smarkm 84238405Sjkim/* Use default functions for poin2oct, oct2point and compressed coordinates */ 85296341Sdelphij#define EC_FLAGS_DEFAULT_OCT 0x1 86238405Sjkim 87296341Sdelphij/* 88296341Sdelphij * Structure details are not part of the exported interface, so all this may 89296341Sdelphij * change in future versions. 90296341Sdelphij */ 91109998Smarkm 92109998Smarkmstruct ec_method_st { 93296341Sdelphij /* Various method flags */ 94296341Sdelphij int flags; 95296341Sdelphij /* used by EC_METHOD_get_field_type: */ 96296341Sdelphij int field_type; /* a NID */ 97296341Sdelphij /* 98296341Sdelphij * used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, 99296341Sdelphij * EC_GROUP_copy: 100296341Sdelphij */ 101296341Sdelphij int (*group_init) (EC_GROUP *); 102296341Sdelphij void (*group_finish) (EC_GROUP *); 103296341Sdelphij void (*group_clear_finish) (EC_GROUP *); 104296341Sdelphij int (*group_copy) (EC_GROUP *, const EC_GROUP *); 105296341Sdelphij /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */ 106296341Sdelphij /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */ 107296341Sdelphij int (*group_set_curve) (EC_GROUP *, const BIGNUM *p, const BIGNUM *a, 108296341Sdelphij const BIGNUM *b, BN_CTX *); 109296341Sdelphij int (*group_get_curve) (const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, 110296341Sdelphij BN_CTX *); 111296341Sdelphij /* used by EC_GROUP_get_degree: */ 112296341Sdelphij int (*group_get_degree) (const EC_GROUP *); 113296341Sdelphij /* used by EC_GROUP_check: */ 114296341Sdelphij int (*group_check_discriminant) (const EC_GROUP *, BN_CTX *); 115296341Sdelphij /* 116296341Sdelphij * used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, 117296341Sdelphij * EC_POINT_copy: 118296341Sdelphij */ 119296341Sdelphij int (*point_init) (EC_POINT *); 120296341Sdelphij void (*point_finish) (EC_POINT *); 121296341Sdelphij void (*point_clear_finish) (EC_POINT *); 122296341Sdelphij int (*point_copy) (EC_POINT *, const EC_POINT *); 123296341Sdelphij /*- 124296341Sdelphij * used by EC_POINT_set_to_infinity, 125296341Sdelphij * EC_POINT_set_Jprojective_coordinates_GFp, 126296341Sdelphij * EC_POINT_get_Jprojective_coordinates_GFp, 127296341Sdelphij * EC_POINT_set_affine_coordinates_GFp, ..._GF2m, 128296341Sdelphij * EC_POINT_get_affine_coordinates_GFp, ..._GF2m, 129296341Sdelphij * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m: 130296341Sdelphij */ 131296341Sdelphij int (*point_set_to_infinity) (const EC_GROUP *, EC_POINT *); 132296341Sdelphij int (*point_set_Jprojective_coordinates_GFp) (const EC_GROUP *, 133296341Sdelphij EC_POINT *, const BIGNUM *x, 134296341Sdelphij const BIGNUM *y, 135296341Sdelphij const BIGNUM *z, BN_CTX *); 136296341Sdelphij int (*point_get_Jprojective_coordinates_GFp) (const EC_GROUP *, 137296341Sdelphij const EC_POINT *, BIGNUM *x, 138296341Sdelphij BIGNUM *y, BIGNUM *z, 139296341Sdelphij BN_CTX *); 140296341Sdelphij int (*point_set_affine_coordinates) (const EC_GROUP *, EC_POINT *, 141296341Sdelphij const BIGNUM *x, const BIGNUM *y, 142296341Sdelphij BN_CTX *); 143296341Sdelphij int (*point_get_affine_coordinates) (const EC_GROUP *, const EC_POINT *, 144296341Sdelphij BIGNUM *x, BIGNUM *y, BN_CTX *); 145296341Sdelphij int (*point_set_compressed_coordinates) (const EC_GROUP *, EC_POINT *, 146296341Sdelphij const BIGNUM *x, int y_bit, 147296341Sdelphij BN_CTX *); 148296341Sdelphij /* used by EC_POINT_point2oct, EC_POINT_oct2point: */ 149296341Sdelphij size_t (*point2oct) (const EC_GROUP *, const EC_POINT *, 150296341Sdelphij point_conversion_form_t form, unsigned char *buf, 151296341Sdelphij size_t len, BN_CTX *); 152296341Sdelphij int (*oct2point) (const EC_GROUP *, EC_POINT *, const unsigned char *buf, 153296341Sdelphij size_t len, BN_CTX *); 154296341Sdelphij /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */ 155296341Sdelphij int (*add) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 156296341Sdelphij const EC_POINT *b, BN_CTX *); 157296341Sdelphij int (*dbl) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 158296341Sdelphij int (*invert) (const EC_GROUP *, EC_POINT *, BN_CTX *); 159296341Sdelphij /* 160296341Sdelphij * used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: 161296341Sdelphij */ 162296341Sdelphij int (*is_at_infinity) (const EC_GROUP *, const EC_POINT *); 163296341Sdelphij int (*is_on_curve) (const EC_GROUP *, const EC_POINT *, BN_CTX *); 164296341Sdelphij int (*point_cmp) (const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, 165296341Sdelphij BN_CTX *); 166296341Sdelphij /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */ 167296341Sdelphij int (*make_affine) (const EC_GROUP *, EC_POINT *, BN_CTX *); 168296341Sdelphij int (*points_make_affine) (const EC_GROUP *, size_t num, EC_POINT *[], 169296341Sdelphij BN_CTX *); 170296341Sdelphij /* 171296341Sdelphij * used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, 172296341Sdelphij * EC_POINT_have_precompute_mult (default implementations are used if the 173296341Sdelphij * 'mul' pointer is 0): 174296341Sdelphij */ 175296341Sdelphij int (*mul) (const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 176296341Sdelphij size_t num, const EC_POINT *points[], const BIGNUM *scalars[], 177296341Sdelphij BN_CTX *); 178296341Sdelphij int (*precompute_mult) (EC_GROUP *group, BN_CTX *); 179296341Sdelphij int (*have_precompute_mult) (const EC_GROUP *group); 180296341Sdelphij /* internal functions */ 181296341Sdelphij /* 182296341Sdelphij * 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 183296341Sdelphij * 'dbl' so that the same implementations of point operations can be used 184296341Sdelphij * with different optimized implementations of expensive field 185296341Sdelphij * operations: 186296341Sdelphij */ 187296341Sdelphij int (*field_mul) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 188296341Sdelphij const BIGNUM *b, BN_CTX *); 189296341Sdelphij int (*field_sqr) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 190296341Sdelphij int (*field_div) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 191296341Sdelphij const BIGNUM *b, BN_CTX *); 192296341Sdelphij /* e.g. to Montgomery */ 193296341Sdelphij int (*field_encode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 194296341Sdelphij BN_CTX *); 195296341Sdelphij /* e.g. from Montgomery */ 196296341Sdelphij int (*field_decode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 197296341Sdelphij BN_CTX *); 198296341Sdelphij int (*field_set_to_one) (const EC_GROUP *, BIGNUM *r, BN_CTX *); 199296341Sdelphij} /* EC_METHOD */ ; 200160814Ssimon 201160814Ssimontypedef struct ec_extra_data_st { 202296341Sdelphij struct ec_extra_data_st *next; 203296341Sdelphij void *data; 204296341Sdelphij void *(*dup_func) (void *); 205296341Sdelphij void (*free_func) (void *); 206296341Sdelphij void (*clear_free_func) (void *); 207296341Sdelphij} EC_EXTRA_DATA; /* used in EC_GROUP */ 208109998Smarkm 209109998Smarkmstruct ec_group_st { 210296341Sdelphij const EC_METHOD *meth; 211296341Sdelphij EC_POINT *generator; /* optional */ 212296341Sdelphij BIGNUM order, cofactor; 213296341Sdelphij int curve_name; /* optional NID for named curve */ 214296341Sdelphij int asn1_flag; /* flag to control the asn1 encoding */ 215296341Sdelphij point_conversion_form_t asn1_form; 216296341Sdelphij unsigned char *seed; /* optional seed for parameters (appears in 217296341Sdelphij * ASN1) */ 218296341Sdelphij size_t seed_len; 219296341Sdelphij EC_EXTRA_DATA *extra_data; /* linked list */ 220296341Sdelphij /* 221296341Sdelphij * The following members are handled by the method functions, even if 222296341Sdelphij * they appear generic 223296341Sdelphij */ 224296341Sdelphij /* 225296341Sdelphij * Field specification. For curves over GF(p), this is the modulus; for 226296341Sdelphij * curves over GF(2^m), this is the irreducible polynomial defining the 227296341Sdelphij * field. 228296341Sdelphij */ 229296341Sdelphij BIGNUM field; 230296341Sdelphij /* 231296341Sdelphij * Field specification for curves over GF(2^m). The irreducible f(t) is 232296341Sdelphij * then of the form: t^poly[0] + t^poly[1] + ... + t^poly[k] where m = 233296341Sdelphij * poly[0] > poly[1] > ... > poly[k] = 0. The array is terminated with 234296341Sdelphij * poly[k+1]=-1. All elliptic curve irreducibles have at most 5 non-zero 235296341Sdelphij * terms. 236296341Sdelphij */ 237296341Sdelphij int poly[6]; 238296341Sdelphij /* 239296341Sdelphij * Curve coefficients. (Here the assumption is that BIGNUMs can be used 240296341Sdelphij * or abused for all kinds of fields, not just GF(p).) For characteristic 241296341Sdelphij * > 3, the curve is defined by a Weierstrass equation of the form y^2 = 242296341Sdelphij * x^3 + a*x + b. For characteristic 2, the curve is defined by an 243296341Sdelphij * equation of the form y^2 + x*y = x^3 + a*x^2 + b. 244296341Sdelphij */ 245296341Sdelphij BIGNUM a, b; 246296341Sdelphij /* enable optimized point arithmetics for special case */ 247296341Sdelphij int a_is_minus3; 248296341Sdelphij /* method-specific (e.g., Montgomery structure) */ 249296341Sdelphij void *field_data1; 250296341Sdelphij /* method-specific */ 251296341Sdelphij void *field_data2; 252296341Sdelphij /* method-specific */ 253296341Sdelphij int (*field_mod_func) (BIGNUM *, const BIGNUM *, const BIGNUM *, 254296341Sdelphij BN_CTX *); 255296341Sdelphij} /* EC_GROUP */ ; 256109998Smarkm 257160814Ssimonstruct ec_key_st { 258296341Sdelphij int version; 259296341Sdelphij EC_GROUP *group; 260296341Sdelphij EC_POINT *pub_key; 261296341Sdelphij BIGNUM *priv_key; 262296341Sdelphij unsigned int enc_flag; 263296341Sdelphij point_conversion_form_t conv_form; 264296341Sdelphij int references; 265296341Sdelphij int flags; 266296341Sdelphij EC_EXTRA_DATA *method_data; 267296341Sdelphij} /* EC_KEY */ ; 268109998Smarkm 269296341Sdelphij/* 270296341Sdelphij * Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs 271296341Sdelphij * only (with visibility limited to 'package' level for now). We use the 272296341Sdelphij * function pointers as index for retrieval; this obviates global 273296341Sdelphij * ex_data-style index tables. 274160814Ssimon */ 275160814Ssimonint EC_EX_DATA_set_data(EC_EXTRA_DATA **, void *data, 276296341Sdelphij void *(*dup_func) (void *), 277296341Sdelphij void (*free_func) (void *), 278296341Sdelphij void (*clear_free_func) (void *)); 279296341Sdelphijvoid *EC_EX_DATA_get_data(const EC_EXTRA_DATA *, void *(*dup_func) (void *), 280296341Sdelphij void (*free_func) (void *), 281296341Sdelphij void (*clear_free_func) (void *)); 282296341Sdelphijvoid EC_EX_DATA_free_data(EC_EXTRA_DATA **, void *(*dup_func) (void *), 283296341Sdelphij void (*free_func) (void *), 284296341Sdelphij void (*clear_free_func) (void *)); 285296341Sdelphijvoid EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **, void *(*dup_func) (void *), 286296341Sdelphij void (*free_func) (void *), 287296341Sdelphij void (*clear_free_func) (void *)); 288160814Ssimonvoid EC_EX_DATA_free_all_data(EC_EXTRA_DATA **); 289160814Ssimonvoid EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **); 290109998Smarkm 291109998Smarkmstruct ec_point_st { 292296341Sdelphij const EC_METHOD *meth; 293296341Sdelphij /* 294296341Sdelphij * All members except 'meth' are handled by the method functions, even if 295296341Sdelphij * they appear generic 296296341Sdelphij */ 297296341Sdelphij BIGNUM X; 298296341Sdelphij BIGNUM Y; 299296341Sdelphij BIGNUM Z; /* Jacobian projective coordinates: (X, Y, Z) 300296341Sdelphij * represents (X/Z^2, Y/Z^3) if Z != 0 */ 301296341Sdelphij int Z_is_one; /* enable optimized point arithmetics for 302296341Sdelphij * special case */ 303296341Sdelphij} /* EC_POINT */ ; 304109998Smarkm 305296341Sdelphij/* 306296341Sdelphij * method functions in ec_mult.c (ec_lib.c uses these as defaults if 307296341Sdelphij * group->method->mul is 0) 308296341Sdelphij */ 309160814Ssimonint ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 310296341Sdelphij size_t num, const EC_POINT *points[], const BIGNUM *scalars[], 311296341Sdelphij BN_CTX *); 312160814Ssimonint ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *); 313160814Ssimonint ec_wNAF_have_precompute_mult(const EC_GROUP *group); 314160814Ssimon 315109998Smarkm/* method functions in ecp_smpl.c */ 316109998Smarkmint ec_GFp_simple_group_init(EC_GROUP *); 317109998Smarkmvoid ec_GFp_simple_group_finish(EC_GROUP *); 318109998Smarkmvoid ec_GFp_simple_group_clear_finish(EC_GROUP *); 319109998Smarkmint ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); 320296341Sdelphijint ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, 321296341Sdelphij const BIGNUM *a, const BIGNUM *b, BN_CTX *); 322296341Sdelphijint ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, 323296341Sdelphij BIGNUM *b, BN_CTX *); 324160814Ssimonint ec_GFp_simple_group_get_degree(const EC_GROUP *); 325160814Ssimonint ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 326109998Smarkmint ec_GFp_simple_point_init(EC_POINT *); 327109998Smarkmvoid ec_GFp_simple_point_finish(EC_POINT *); 328109998Smarkmvoid ec_GFp_simple_point_clear_finish(EC_POINT *); 329109998Smarkmint ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); 330109998Smarkmint ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 331296341Sdelphijint ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, 332296341Sdelphij EC_POINT *, const BIGNUM *x, 333296341Sdelphij const BIGNUM *y, 334296341Sdelphij const BIGNUM *z, BN_CTX *); 335296341Sdelphijint ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, 336296341Sdelphij const EC_POINT *, BIGNUM *x, 337296341Sdelphij BIGNUM *y, BIGNUM *z, 338296341Sdelphij BN_CTX *); 339160814Ssimonint ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 340296341Sdelphij const BIGNUM *x, 341296341Sdelphij const BIGNUM *y, BN_CTX *); 342296341Sdelphijint ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, 343296341Sdelphij const EC_POINT *, BIGNUM *x, 344296341Sdelphij BIGNUM *y, BN_CTX *); 345160814Ssimonint ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 346296341Sdelphij const BIGNUM *x, int y_bit, 347296341Sdelphij BN_CTX *); 348296341Sdelphijsize_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, 349296341Sdelphij point_conversion_form_t form, 350296341Sdelphij unsigned char *buf, size_t len, BN_CTX *); 351109998Smarkmint ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *, 352296341Sdelphij const unsigned char *buf, size_t len, BN_CTX *); 353296341Sdelphijint ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 354296341Sdelphij const EC_POINT *b, BN_CTX *); 355296341Sdelphijint ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 356296341Sdelphij BN_CTX *); 357109998Smarkmint ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 358109998Smarkmint ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 359109998Smarkmint ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 360296341Sdelphijint ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, 361296341Sdelphij BN_CTX *); 362109998Smarkmint ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 363296341Sdelphijint ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, 364296341Sdelphij EC_POINT *[], BN_CTX *); 365296341Sdelphijint ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 366296341Sdelphij const BIGNUM *b, BN_CTX *); 367296341Sdelphijint ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 368296341Sdelphij BN_CTX *); 369109998Smarkm 370109998Smarkm/* method functions in ecp_mont.c */ 371109998Smarkmint ec_GFp_mont_group_init(EC_GROUP *); 372296341Sdelphijint ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, 373296341Sdelphij const BIGNUM *b, BN_CTX *); 374109998Smarkmvoid ec_GFp_mont_group_finish(EC_GROUP *); 375109998Smarkmvoid ec_GFp_mont_group_clear_finish(EC_GROUP *); 376109998Smarkmint ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); 377296341Sdelphijint ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 378296341Sdelphij const BIGNUM *b, BN_CTX *); 379296341Sdelphijint ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 380296341Sdelphij BN_CTX *); 381296341Sdelphijint ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 382296341Sdelphij BN_CTX *); 383296341Sdelphijint ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 384296341Sdelphij BN_CTX *); 385109998Smarkmint ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); 386109998Smarkm 387109998Smarkm/* method functions in ecp_nist.c */ 388160814Ssimonint ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); 389296341Sdelphijint ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, 390296341Sdelphij const BIGNUM *b, BN_CTX *); 391296341Sdelphijint ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 392296341Sdelphij const BIGNUM *b, BN_CTX *); 393296341Sdelphijint ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 394296341Sdelphij BN_CTX *); 395160814Ssimon 396160814Ssimon/* method functions in ec2_smpl.c */ 397160814Ssimonint ec_GF2m_simple_group_init(EC_GROUP *); 398160814Ssimonvoid ec_GF2m_simple_group_finish(EC_GROUP *); 399160814Ssimonvoid ec_GF2m_simple_group_clear_finish(EC_GROUP *); 400160814Ssimonint ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); 401296341Sdelphijint ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, 402296341Sdelphij const BIGNUM *a, const BIGNUM *b, 403296341Sdelphij BN_CTX *); 404296341Sdelphijint ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, 405296341Sdelphij BIGNUM *b, BN_CTX *); 406160814Ssimonint ec_GF2m_simple_group_get_degree(const EC_GROUP *); 407160814Ssimonint ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 408160814Ssimonint ec_GF2m_simple_point_init(EC_POINT *); 409160814Ssimonvoid ec_GF2m_simple_point_finish(EC_POINT *); 410160814Ssimonvoid ec_GF2m_simple_point_clear_finish(EC_POINT *); 411160814Ssimonint ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); 412160814Ssimonint ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); 413160814Ssimonint ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 414296341Sdelphij const BIGNUM *x, 415296341Sdelphij const BIGNUM *y, BN_CTX *); 416296341Sdelphijint ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, 417296341Sdelphij const EC_POINT *, BIGNUM *x, 418296341Sdelphij BIGNUM *y, BN_CTX *); 419160814Ssimonint ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 420296341Sdelphij const BIGNUM *x, int y_bit, 421296341Sdelphij BN_CTX *); 422296341Sdelphijsize_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, 423296341Sdelphij point_conversion_form_t form, 424296341Sdelphij unsigned char *buf, size_t len, BN_CTX *); 425160814Ssimonint ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, 426296341Sdelphij const unsigned char *buf, size_t len, BN_CTX *); 427296341Sdelphijint ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 428296341Sdelphij const EC_POINT *b, BN_CTX *); 429296341Sdelphijint ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, 430296341Sdelphij BN_CTX *); 431160814Ssimonint ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 432160814Ssimonint ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); 433160814Ssimonint ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); 434296341Sdelphijint ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, 435296341Sdelphij BN_CTX *); 436160814Ssimonint ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); 437296341Sdelphijint ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, 438296341Sdelphij EC_POINT *[], BN_CTX *); 439296341Sdelphijint ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 440296341Sdelphij const BIGNUM *b, BN_CTX *); 441296341Sdelphijint ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 442296341Sdelphij BN_CTX *); 443296341Sdelphijint ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, 444296341Sdelphij const BIGNUM *b, BN_CTX *); 445160814Ssimon 446160814Ssimon/* method functions in ec2_mult.c */ 447296341Sdelphijint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, 448296341Sdelphij const BIGNUM *scalar, size_t num, 449296341Sdelphij const EC_POINT *points[], const BIGNUM *scalars[], 450296341Sdelphij BN_CTX *); 451160814Ssimonint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 452160814Ssimonint ec_GF2m_have_precompute_mult(const EC_GROUP *group); 453238405Sjkim 454267258Sjkim#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 455238405Sjkim/* method functions in ecp_nistp224.c */ 456238405Sjkimint ec_GFp_nistp224_group_init(EC_GROUP *group); 457296341Sdelphijint ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, 458296341Sdelphij const BIGNUM *a, const BIGNUM *n, 459296341Sdelphij BN_CTX *); 460296341Sdelphijint ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP *group, 461296341Sdelphij const EC_POINT *point, 462296341Sdelphij BIGNUM *x, BIGNUM *y, 463296341Sdelphij BN_CTX *ctx); 464296341Sdelphijint ec_GFp_nistp224_mul(const EC_GROUP *group, EC_POINT *r, 465296341Sdelphij const BIGNUM *scalar, size_t num, 466296341Sdelphij const EC_POINT *points[], const BIGNUM *scalars[], 467296341Sdelphij BN_CTX *); 468296341Sdelphijint ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r, 469296341Sdelphij const BIGNUM *scalar, size_t num, 470296341Sdelphij const EC_POINT *points[], 471296341Sdelphij const BIGNUM *scalars[], BN_CTX *ctx); 472238405Sjkimint ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 473238405Sjkimint ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group); 474238405Sjkim 475238405Sjkim/* method functions in ecp_nistp256.c */ 476238405Sjkimint ec_GFp_nistp256_group_init(EC_GROUP *group); 477296341Sdelphijint ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, 478296341Sdelphij const BIGNUM *a, const BIGNUM *n, 479296341Sdelphij BN_CTX *); 480296341Sdelphijint ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group, 481296341Sdelphij const EC_POINT *point, 482296341Sdelphij BIGNUM *x, BIGNUM *y, 483296341Sdelphij BN_CTX *ctx); 484296341Sdelphijint ec_GFp_nistp256_mul(const EC_GROUP *group, EC_POINT *r, 485296341Sdelphij const BIGNUM *scalar, size_t num, 486296341Sdelphij const EC_POINT *points[], const BIGNUM *scalars[], 487296341Sdelphij BN_CTX *); 488296341Sdelphijint ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r, 489296341Sdelphij const BIGNUM *scalar, size_t num, 490296341Sdelphij const EC_POINT *points[], 491296341Sdelphij const BIGNUM *scalars[], BN_CTX *ctx); 492238405Sjkimint ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 493238405Sjkimint ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group); 494238405Sjkim 495238405Sjkim/* method functions in ecp_nistp521.c */ 496238405Sjkimint ec_GFp_nistp521_group_init(EC_GROUP *group); 497296341Sdelphijint ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, 498296341Sdelphij const BIGNUM *a, const BIGNUM *n, 499296341Sdelphij BN_CTX *); 500296341Sdelphijint ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP *group, 501296341Sdelphij const EC_POINT *point, 502296341Sdelphij BIGNUM *x, BIGNUM *y, 503296341Sdelphij BN_CTX *ctx); 504296341Sdelphijint ec_GFp_nistp521_mul(const EC_GROUP *group, EC_POINT *r, 505296341Sdelphij const BIGNUM *scalar, size_t num, 506296341Sdelphij const EC_POINT *points[], const BIGNUM *scalars[], 507296341Sdelphij BN_CTX *); 508296341Sdelphijint ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r, 509296341Sdelphij const BIGNUM *scalar, size_t num, 510296341Sdelphij const EC_POINT *points[], 511296341Sdelphij const BIGNUM *scalars[], BN_CTX *ctx); 512238405Sjkimint ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 513238405Sjkimint ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group); 514238405Sjkim 515238405Sjkim/* utility functions in ecp_nistputil.c */ 516238405Sjkimvoid ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array, 517296341Sdelphij size_t felem_size, 518296341Sdelphij void *tmp_felems, 519296341Sdelphij void (*felem_one) (void *out), 520296341Sdelphij int (*felem_is_zero) (const void 521296341Sdelphij *in), 522296341Sdelphij void (*felem_assign) (void *out, 523296341Sdelphij const void 524296341Sdelphij *in), 525296341Sdelphij void (*felem_square) (void *out, 526296341Sdelphij const void 527296341Sdelphij *in), 528296341Sdelphij void (*felem_mul) (void *out, 529296341Sdelphij const void 530296341Sdelphij *in1, 531296341Sdelphij const void 532296341Sdelphij *in2), 533296341Sdelphij void (*felem_inv) (void *out, 534296341Sdelphij const void 535296341Sdelphij *in), 536296341Sdelphij void (*felem_contract) (void 537296341Sdelphij *out, 538296341Sdelphij const 539296341Sdelphij void 540296341Sdelphij *in)); 541296341Sdelphijvoid ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, 542296341Sdelphij unsigned char *digit, unsigned char in); 543238405Sjkim#endif 544