1e71b7053SJung-uk Kim /* 2*da327cd2SJung-uk Kim * Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved. 3e71b7053SJung-uk Kim * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved 4e71b7053SJung-uk Kim * 5e71b7053SJung-uk Kim * Licensed under the OpenSSL license (the "License"). You may not use 6e71b7053SJung-uk Kim * this file except in compliance with the License. You can obtain a copy 7e71b7053SJung-uk Kim * in the file LICENSE in the source distribution or at 8e71b7053SJung-uk Kim * https://www.openssl.org/source/license.html 9e71b7053SJung-uk Kim */ 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #ifndef HEADER_EC_H 12e71b7053SJung-uk Kim # define HEADER_EC_H 13e71b7053SJung-uk Kim 14e71b7053SJung-uk Kim # include <openssl/opensslconf.h> 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC 17e71b7053SJung-uk Kim # include <openssl/asn1.h> 18e71b7053SJung-uk Kim # include <openssl/symhacks.h> 19e71b7053SJung-uk Kim # if OPENSSL_API_COMPAT < 0x10100000L 20e71b7053SJung-uk Kim # include <openssl/bn.h> 21e71b7053SJung-uk Kim # endif 22e71b7053SJung-uk Kim # include <openssl/ecerr.h> 23e71b7053SJung-uk Kim # ifdef __cplusplus 24e71b7053SJung-uk Kim extern "C" { 25e71b7053SJung-uk Kim # endif 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim # ifndef OPENSSL_ECC_MAX_FIELD_BITS 28e71b7053SJung-uk Kim # define OPENSSL_ECC_MAX_FIELD_BITS 661 29e71b7053SJung-uk Kim # endif 30e71b7053SJung-uk Kim 31e71b7053SJung-uk Kim /** Enum for the point conversion form as defined in X9.62 (ECDSA) 32e71b7053SJung-uk Kim * for the encoding of a elliptic curve point (x,y) */ 33e71b7053SJung-uk Kim typedef enum { 34e71b7053SJung-uk Kim /** the point is encoded as z||x, where the octet z specifies 35e71b7053SJung-uk Kim * which solution of the quadratic equation y is */ 36e71b7053SJung-uk Kim POINT_CONVERSION_COMPRESSED = 2, 37e71b7053SJung-uk Kim /** the point is encoded as z||x||y, where z is the octet 0x04 */ 38e71b7053SJung-uk Kim POINT_CONVERSION_UNCOMPRESSED = 4, 39e71b7053SJung-uk Kim /** the point is encoded as z||x||y, where the octet z specifies 40e71b7053SJung-uk Kim * which solution of the quadratic equation y is */ 41e71b7053SJung-uk Kim POINT_CONVERSION_HYBRID = 6 42e71b7053SJung-uk Kim } point_conversion_form_t; 43e71b7053SJung-uk Kim 44e71b7053SJung-uk Kim typedef struct ec_method_st EC_METHOD; 45e71b7053SJung-uk Kim typedef struct ec_group_st EC_GROUP; 46e71b7053SJung-uk Kim typedef struct ec_point_st EC_POINT; 47e71b7053SJung-uk Kim typedef struct ecpk_parameters_st ECPKPARAMETERS; 48e71b7053SJung-uk Kim typedef struct ec_parameters_st ECPARAMETERS; 49e71b7053SJung-uk Kim 50e71b7053SJung-uk Kim /********************************************************************/ 51e71b7053SJung-uk Kim /* EC_METHODs for curves over GF(p) */ 52e71b7053SJung-uk Kim /********************************************************************/ 53e71b7053SJung-uk Kim 54e71b7053SJung-uk Kim /** Returns the basic GFp ec methods which provides the basis for the 55e71b7053SJung-uk Kim * optimized methods. 56e71b7053SJung-uk Kim * \return EC_METHOD object 57e71b7053SJung-uk Kim */ 58e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_simple_method(void); 59e71b7053SJung-uk Kim 60e71b7053SJung-uk Kim /** Returns GFp methods using montgomery multiplication. 61e71b7053SJung-uk Kim * \return EC_METHOD object 62e71b7053SJung-uk Kim */ 63e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_mont_method(void); 64e71b7053SJung-uk Kim 65e71b7053SJung-uk Kim /** Returns GFp methods using optimized methods for NIST recommended curves 66e71b7053SJung-uk Kim * \return EC_METHOD object 67e71b7053SJung-uk Kim */ 68e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_nist_method(void); 69e71b7053SJung-uk Kim 70e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 71e71b7053SJung-uk Kim /** Returns 64-bit optimized methods for nistp224 72e71b7053SJung-uk Kim * \return EC_METHOD object 73e71b7053SJung-uk Kim */ 74e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_nistp224_method(void); 75e71b7053SJung-uk Kim 76e71b7053SJung-uk Kim /** Returns 64-bit optimized methods for nistp256 77e71b7053SJung-uk Kim * \return EC_METHOD object 78e71b7053SJung-uk Kim */ 79e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_nistp256_method(void); 80e71b7053SJung-uk Kim 81e71b7053SJung-uk Kim /** Returns 64-bit optimized methods for nistp521 82e71b7053SJung-uk Kim * \return EC_METHOD object 83e71b7053SJung-uk Kim */ 84e71b7053SJung-uk Kim const EC_METHOD *EC_GFp_nistp521_method(void); 85e71b7053SJung-uk Kim # endif 86e71b7053SJung-uk Kim 87e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC2M 88e71b7053SJung-uk Kim /********************************************************************/ 89e71b7053SJung-uk Kim /* EC_METHOD for curves over GF(2^m) */ 90e71b7053SJung-uk Kim /********************************************************************/ 91e71b7053SJung-uk Kim 92e71b7053SJung-uk Kim /** Returns the basic GF2m ec method 93e71b7053SJung-uk Kim * \return EC_METHOD object 94e71b7053SJung-uk Kim */ 95e71b7053SJung-uk Kim const EC_METHOD *EC_GF2m_simple_method(void); 96e71b7053SJung-uk Kim 97e71b7053SJung-uk Kim # endif 98e71b7053SJung-uk Kim 99e71b7053SJung-uk Kim /********************************************************************/ 100e71b7053SJung-uk Kim /* EC_GROUP functions */ 101e71b7053SJung-uk Kim /********************************************************************/ 102e71b7053SJung-uk Kim 103e71b7053SJung-uk Kim /** Creates a new EC_GROUP object 104e71b7053SJung-uk Kim * \param meth EC_METHOD to use 105e71b7053SJung-uk Kim * \return newly created EC_GROUP object or NULL in case of an error. 106e71b7053SJung-uk Kim */ 107e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); 108e71b7053SJung-uk Kim 109e71b7053SJung-uk Kim /** Frees a EC_GROUP object 110e71b7053SJung-uk Kim * \param group EC_GROUP object to be freed. 111e71b7053SJung-uk Kim */ 112e71b7053SJung-uk Kim void EC_GROUP_free(EC_GROUP *group); 113e71b7053SJung-uk Kim 114e71b7053SJung-uk Kim /** Clears and frees a EC_GROUP object 115e71b7053SJung-uk Kim * \param group EC_GROUP object to be cleared and freed. 116e71b7053SJung-uk Kim */ 117e71b7053SJung-uk Kim void EC_GROUP_clear_free(EC_GROUP *group); 118e71b7053SJung-uk Kim 119e71b7053SJung-uk Kim /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD. 120e71b7053SJung-uk Kim * \param dst destination EC_GROUP object 121e71b7053SJung-uk Kim * \param src source EC_GROUP object 122e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 123e71b7053SJung-uk Kim */ 124e71b7053SJung-uk Kim int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); 125e71b7053SJung-uk Kim 126e71b7053SJung-uk Kim /** Creates a new EC_GROUP object and copies the copies the content 127e71b7053SJung-uk Kim * form src to the newly created EC_KEY object 128e71b7053SJung-uk Kim * \param src source EC_GROUP object 129e71b7053SJung-uk Kim * \return newly created EC_GROUP object or NULL in case of an error. 130e71b7053SJung-uk Kim */ 131e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); 132e71b7053SJung-uk Kim 133e71b7053SJung-uk Kim /** Returns the EC_METHOD of the EC_GROUP object. 134e71b7053SJung-uk Kim * \param group EC_GROUP object 135e71b7053SJung-uk Kim * \return EC_METHOD used in this EC_GROUP object. 136e71b7053SJung-uk Kim */ 137e71b7053SJung-uk Kim const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); 138e71b7053SJung-uk Kim 139e71b7053SJung-uk Kim /** Returns the field type of the EC_METHOD. 140e71b7053SJung-uk Kim * \param meth EC_METHOD object 141e71b7053SJung-uk Kim * \return NID of the underlying field type OID. 142e71b7053SJung-uk Kim */ 143e71b7053SJung-uk Kim int EC_METHOD_get_field_type(const EC_METHOD *meth); 144e71b7053SJung-uk Kim 145*da327cd2SJung-uk Kim /** Sets the generator and its order/cofactor of a EC_GROUP object. 146e71b7053SJung-uk Kim * \param group EC_GROUP object 147e71b7053SJung-uk Kim * \param generator EC_POINT object with the generator. 148e71b7053SJung-uk Kim * \param order the order of the group generated by the generator. 149e71b7053SJung-uk Kim * \param cofactor the index of the sub-group generated by the generator 150e71b7053SJung-uk Kim * in the group of all points on the elliptic curve. 151e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 152e71b7053SJung-uk Kim */ 153e71b7053SJung-uk Kim int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, 154e71b7053SJung-uk Kim const BIGNUM *order, const BIGNUM *cofactor); 155e71b7053SJung-uk Kim 156e71b7053SJung-uk Kim /** Returns the generator of a EC_GROUP object. 157e71b7053SJung-uk Kim * \param group EC_GROUP object 158e71b7053SJung-uk Kim * \return the currently used generator (possibly NULL). 159e71b7053SJung-uk Kim */ 160e71b7053SJung-uk Kim const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); 161e71b7053SJung-uk Kim 162e71b7053SJung-uk Kim /** Returns the montgomery data for order(Generator) 163e71b7053SJung-uk Kim * \param group EC_GROUP object 164e71b7053SJung-uk Kim * \return the currently used montgomery data (possibly NULL). 165e71b7053SJung-uk Kim */ 166e71b7053SJung-uk Kim BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group); 167e71b7053SJung-uk Kim 168e71b7053SJung-uk Kim /** Gets the order of a EC_GROUP 169e71b7053SJung-uk Kim * \param group EC_GROUP object 170e71b7053SJung-uk Kim * \param order BIGNUM to which the order is copied 171e71b7053SJung-uk Kim * \param ctx unused 172e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 173e71b7053SJung-uk Kim */ 174e71b7053SJung-uk Kim int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); 175e71b7053SJung-uk Kim 176e71b7053SJung-uk Kim /** Gets the order of an EC_GROUP 177e71b7053SJung-uk Kim * \param group EC_GROUP object 178e71b7053SJung-uk Kim * \return the group order 179e71b7053SJung-uk Kim */ 180e71b7053SJung-uk Kim const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); 181e71b7053SJung-uk Kim 182e71b7053SJung-uk Kim /** Gets the number of bits of the order of an EC_GROUP 183e71b7053SJung-uk Kim * \param group EC_GROUP object 184e71b7053SJung-uk Kim * \return number of bits of group order. 185e71b7053SJung-uk Kim */ 186e71b7053SJung-uk Kim int EC_GROUP_order_bits(const EC_GROUP *group); 187e71b7053SJung-uk Kim 188e71b7053SJung-uk Kim /** Gets the cofactor of a EC_GROUP 189e71b7053SJung-uk Kim * \param group EC_GROUP object 190e71b7053SJung-uk Kim * \param cofactor BIGNUM to which the cofactor is copied 191e71b7053SJung-uk Kim * \param ctx unused 192e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 193e71b7053SJung-uk Kim */ 194e71b7053SJung-uk Kim int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, 195e71b7053SJung-uk Kim BN_CTX *ctx); 196e71b7053SJung-uk Kim 197e71b7053SJung-uk Kim /** Gets the cofactor of an EC_GROUP 198e71b7053SJung-uk Kim * \param group EC_GROUP object 199e71b7053SJung-uk Kim * \return the group cofactor 200e71b7053SJung-uk Kim */ 201e71b7053SJung-uk Kim const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); 202e71b7053SJung-uk Kim 203e71b7053SJung-uk Kim /** Sets the name of a EC_GROUP object 204e71b7053SJung-uk Kim * \param group EC_GROUP object 205e71b7053SJung-uk Kim * \param nid NID of the curve name OID 206e71b7053SJung-uk Kim */ 207e71b7053SJung-uk Kim void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); 208e71b7053SJung-uk Kim 209e71b7053SJung-uk Kim /** Returns the curve name of a EC_GROUP object 210e71b7053SJung-uk Kim * \param group EC_GROUP object 211e71b7053SJung-uk Kim * \return NID of the curve name OID or 0 if not set. 212e71b7053SJung-uk Kim */ 213e71b7053SJung-uk Kim int EC_GROUP_get_curve_name(const EC_GROUP *group); 214e71b7053SJung-uk Kim 215e71b7053SJung-uk Kim void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); 216e71b7053SJung-uk Kim int EC_GROUP_get_asn1_flag(const EC_GROUP *group); 217e71b7053SJung-uk Kim 218e71b7053SJung-uk Kim void EC_GROUP_set_point_conversion_form(EC_GROUP *group, 219e71b7053SJung-uk Kim point_conversion_form_t form); 220e71b7053SJung-uk Kim point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); 221e71b7053SJung-uk Kim 222e71b7053SJung-uk Kim unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); 223e71b7053SJung-uk Kim size_t EC_GROUP_get_seed_len(const EC_GROUP *); 224e71b7053SJung-uk Kim size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); 225e71b7053SJung-uk Kim 226e71b7053SJung-uk Kim /** Sets the parameters of a ec curve defined by y^2 = x^3 + a*x + b (for GFp) 227e71b7053SJung-uk Kim * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) 228e71b7053SJung-uk Kim * \param group EC_GROUP object 229e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 230e71b7053SJung-uk Kim * defining the underlying field (GF2m) 231e71b7053SJung-uk Kim * \param a BIGNUM with parameter a of the equation 232e71b7053SJung-uk Kim * \param b BIGNUM with parameter b of the equation 233e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 234e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 235e71b7053SJung-uk Kim */ 236e71b7053SJung-uk Kim int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 237e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 238e71b7053SJung-uk Kim 239e71b7053SJung-uk Kim /** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp) 240e71b7053SJung-uk Kim * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) 241e71b7053SJung-uk Kim * \param group EC_GROUP object 242e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 243e71b7053SJung-uk Kim * defining the underlying field (GF2m) 244e71b7053SJung-uk Kim * \param a BIGNUM for parameter a of the equation 245e71b7053SJung-uk Kim * \param b BIGNUM for parameter b of the equation 246e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 247e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 248e71b7053SJung-uk Kim */ 249e71b7053SJung-uk Kim int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, 250e71b7053SJung-uk Kim BN_CTX *ctx); 251e71b7053SJung-uk Kim 252e71b7053SJung-uk Kim /** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve 253e71b7053SJung-uk Kim * \param group EC_GROUP object 254e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 255e71b7053SJung-uk Kim * defining the underlying field (GF2m) 256e71b7053SJung-uk Kim * \param a BIGNUM with parameter a of the equation 257e71b7053SJung-uk Kim * \param b BIGNUM with parameter b of the equation 258e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 259e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 260e71b7053SJung-uk Kim */ 261e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, 262e71b7053SJung-uk Kim const BIGNUM *a, const BIGNUM *b, 263e71b7053SJung-uk Kim BN_CTX *ctx)) 264e71b7053SJung-uk Kim 265e71b7053SJung-uk Kim /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve 266e71b7053SJung-uk Kim * \param group EC_GROUP object 267e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 268e71b7053SJung-uk Kim * defining the underlying field (GF2m) 269e71b7053SJung-uk Kim * \param a BIGNUM for parameter a of the equation 270e71b7053SJung-uk Kim * \param b BIGNUM for parameter b of the equation 271e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 272e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 273e71b7053SJung-uk Kim */ 274e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, 275e71b7053SJung-uk Kim BIGNUM *a, BIGNUM *b, 276e71b7053SJung-uk Kim BN_CTX *ctx)) 277e71b7053SJung-uk Kim 278e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC2M 279e71b7053SJung-uk Kim /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve 280e71b7053SJung-uk Kim * \param group EC_GROUP object 281e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 282e71b7053SJung-uk Kim * defining the underlying field (GF2m) 283e71b7053SJung-uk Kim * \param a BIGNUM with parameter a of the equation 284e71b7053SJung-uk Kim * \param b BIGNUM with parameter b of the equation 285e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 286e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 287e71b7053SJung-uk Kim */ 288e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, 289e71b7053SJung-uk Kim const BIGNUM *a, const BIGNUM *b, 290e71b7053SJung-uk Kim BN_CTX *ctx)) 291e71b7053SJung-uk Kim 292e71b7053SJung-uk Kim /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve 293e71b7053SJung-uk Kim * \param group EC_GROUP object 294e71b7053SJung-uk Kim * \param p BIGNUM with the prime number (GFp) or the polynomial 295e71b7053SJung-uk Kim * defining the underlying field (GF2m) 296e71b7053SJung-uk Kim * \param a BIGNUM for parameter a of the equation 297e71b7053SJung-uk Kim * \param b BIGNUM for parameter b of the equation 298e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 299e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 300e71b7053SJung-uk Kim */ 301e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, 302e71b7053SJung-uk Kim BIGNUM *a, BIGNUM *b, 303e71b7053SJung-uk Kim BN_CTX *ctx)) 304e71b7053SJung-uk Kim # endif 305e71b7053SJung-uk Kim /** Returns the number of bits needed to represent a field element 306e71b7053SJung-uk Kim * \param group EC_GROUP object 307e71b7053SJung-uk Kim * \return number of bits needed to represent a field element 308e71b7053SJung-uk Kim */ 309e71b7053SJung-uk Kim int EC_GROUP_get_degree(const EC_GROUP *group); 310e71b7053SJung-uk Kim 311e71b7053SJung-uk Kim /** Checks whether the parameter in the EC_GROUP define a valid ec group 312e71b7053SJung-uk Kim * \param group EC_GROUP object 313e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 314e71b7053SJung-uk Kim * \return 1 if group is a valid ec group and 0 otherwise 315e71b7053SJung-uk Kim */ 316e71b7053SJung-uk Kim int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); 317e71b7053SJung-uk Kim 318e71b7053SJung-uk Kim /** Checks whether the discriminant of the elliptic curve is zero or not 319e71b7053SJung-uk Kim * \param group EC_GROUP object 320e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 321e71b7053SJung-uk Kim * \return 1 if the discriminant is not zero and 0 otherwise 322e71b7053SJung-uk Kim */ 323e71b7053SJung-uk Kim int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); 324e71b7053SJung-uk Kim 325e71b7053SJung-uk Kim /** Compares two EC_GROUP objects 326e71b7053SJung-uk Kim * \param a first EC_GROUP object 327e71b7053SJung-uk Kim * \param b second EC_GROUP object 328e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 329e71b7053SJung-uk Kim * \return 0 if the groups are equal, 1 if not, or -1 on error 330e71b7053SJung-uk Kim */ 331e71b7053SJung-uk Kim int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); 332e71b7053SJung-uk Kim 333e71b7053SJung-uk Kim /* 334e71b7053SJung-uk Kim * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after 335e71b7053SJung-uk Kim * choosing an appropriate EC_METHOD 336e71b7053SJung-uk Kim */ 337e71b7053SJung-uk Kim 338e71b7053SJung-uk Kim /** Creates a new EC_GROUP object with the specified parameters defined 339e71b7053SJung-uk Kim * over GFp (defined by the equation y^2 = x^3 + a*x + b) 340e71b7053SJung-uk Kim * \param p BIGNUM with the prime number 341e71b7053SJung-uk Kim * \param a BIGNUM with the parameter a of the equation 342e71b7053SJung-uk Kim * \param b BIGNUM with the parameter b of the equation 343e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 344e71b7053SJung-uk Kim * \return newly created EC_GROUP object with the specified parameters 345e71b7053SJung-uk Kim */ 346e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, 347e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 348e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC2M 349e71b7053SJung-uk Kim /** Creates a new EC_GROUP object with the specified parameters defined 350e71b7053SJung-uk Kim * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b) 351e71b7053SJung-uk Kim * \param p BIGNUM with the polynomial defining the underlying field 352e71b7053SJung-uk Kim * \param a BIGNUM with the parameter a of the equation 353e71b7053SJung-uk Kim * \param b BIGNUM with the parameter b of the equation 354e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 355e71b7053SJung-uk Kim * \return newly created EC_GROUP object with the specified parameters 356e71b7053SJung-uk Kim */ 357e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, 358e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 359e71b7053SJung-uk Kim # endif 360e71b7053SJung-uk Kim 361e71b7053SJung-uk Kim /** Creates a EC_GROUP object with a curve specified by a NID 362e71b7053SJung-uk Kim * \param nid NID of the OID of the curve name 363e71b7053SJung-uk Kim * \return newly created EC_GROUP object with specified curve or NULL 364e71b7053SJung-uk Kim * if an error occurred 365e71b7053SJung-uk Kim */ 366e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_by_curve_name(int nid); 367e71b7053SJung-uk Kim 368e71b7053SJung-uk Kim /** Creates a new EC_GROUP object from an ECPARAMETERS object 369e71b7053SJung-uk Kim * \param params pointer to the ECPARAMETERS object 370e71b7053SJung-uk Kim * \return newly created EC_GROUP object with specified curve or NULL 371e71b7053SJung-uk Kim * if an error occurred 372e71b7053SJung-uk Kim */ 373e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); 374e71b7053SJung-uk Kim 375e71b7053SJung-uk Kim /** Creates an ECPARAMETERS object for the given EC_GROUP object. 376e71b7053SJung-uk Kim * \param group pointer to the EC_GROUP object 377e71b7053SJung-uk Kim * \param params pointer to an existing ECPARAMETERS object or NULL 378e71b7053SJung-uk Kim * \return pointer to the new ECPARAMETERS object or NULL 379e71b7053SJung-uk Kim * if an error occurred. 380e71b7053SJung-uk Kim */ 381e71b7053SJung-uk Kim ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, 382e71b7053SJung-uk Kim ECPARAMETERS *params); 383e71b7053SJung-uk Kim 384e71b7053SJung-uk Kim /** Creates a new EC_GROUP object from an ECPKPARAMETERS object 385e71b7053SJung-uk Kim * \param params pointer to an existing ECPKPARAMETERS object, or NULL 386e71b7053SJung-uk Kim * \return newly created EC_GROUP object with specified curve, or NULL 387e71b7053SJung-uk Kim * if an error occurred 388e71b7053SJung-uk Kim */ 389e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); 390e71b7053SJung-uk Kim 391e71b7053SJung-uk Kim /** Creates an ECPKPARAMETERS object for the given EC_GROUP object. 392e71b7053SJung-uk Kim * \param group pointer to the EC_GROUP object 393e71b7053SJung-uk Kim * \param params pointer to an existing ECPKPARAMETERS object or NULL 394e71b7053SJung-uk Kim * \return pointer to the new ECPKPARAMETERS object or NULL 395e71b7053SJung-uk Kim * if an error occurred. 396e71b7053SJung-uk Kim */ 397e71b7053SJung-uk Kim ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, 398e71b7053SJung-uk Kim ECPKPARAMETERS *params); 399e71b7053SJung-uk Kim 400e71b7053SJung-uk Kim /********************************************************************/ 401e71b7053SJung-uk Kim /* handling of internal curves */ 402e71b7053SJung-uk Kim /********************************************************************/ 403e71b7053SJung-uk Kim 404e71b7053SJung-uk Kim typedef struct { 405e71b7053SJung-uk Kim int nid; 406e71b7053SJung-uk Kim const char *comment; 407e71b7053SJung-uk Kim } EC_builtin_curve; 408e71b7053SJung-uk Kim 409e71b7053SJung-uk Kim /* 410e71b7053SJung-uk Kim * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all 411e71b7053SJung-uk Kim * available curves or zero if a error occurred. In case r is not zero, 412e71b7053SJung-uk Kim * nitems EC_builtin_curve structures are filled with the data of the first 413e71b7053SJung-uk Kim * nitems internal groups 414e71b7053SJung-uk Kim */ 415e71b7053SJung-uk Kim size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 416e71b7053SJung-uk Kim 417e71b7053SJung-uk Kim const char *EC_curve_nid2nist(int nid); 418e71b7053SJung-uk Kim int EC_curve_nist2nid(const char *name); 419e71b7053SJung-uk Kim 420e71b7053SJung-uk Kim /********************************************************************/ 421e71b7053SJung-uk Kim /* EC_POINT functions */ 422e71b7053SJung-uk Kim /********************************************************************/ 423e71b7053SJung-uk Kim 424e71b7053SJung-uk Kim /** Creates a new EC_POINT object for the specified EC_GROUP 425e71b7053SJung-uk Kim * \param group EC_GROUP the underlying EC_GROUP object 426e71b7053SJung-uk Kim * \return newly created EC_POINT object or NULL if an error occurred 427e71b7053SJung-uk Kim */ 428e71b7053SJung-uk Kim EC_POINT *EC_POINT_new(const EC_GROUP *group); 429e71b7053SJung-uk Kim 430e71b7053SJung-uk Kim /** Frees a EC_POINT object 431e71b7053SJung-uk Kim * \param point EC_POINT object to be freed 432e71b7053SJung-uk Kim */ 433e71b7053SJung-uk Kim void EC_POINT_free(EC_POINT *point); 434e71b7053SJung-uk Kim 435e71b7053SJung-uk Kim /** Clears and frees a EC_POINT object 436e71b7053SJung-uk Kim * \param point EC_POINT object to be cleared and freed 437e71b7053SJung-uk Kim */ 438e71b7053SJung-uk Kim void EC_POINT_clear_free(EC_POINT *point); 439e71b7053SJung-uk Kim 440e71b7053SJung-uk Kim /** Copies EC_POINT object 441e71b7053SJung-uk Kim * \param dst destination EC_POINT object 442e71b7053SJung-uk Kim * \param src source EC_POINT object 443e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 444e71b7053SJung-uk Kim */ 445e71b7053SJung-uk Kim int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); 446e71b7053SJung-uk Kim 447e71b7053SJung-uk Kim /** Creates a new EC_POINT object and copies the content of the supplied 448e71b7053SJung-uk Kim * EC_POINT 449e71b7053SJung-uk Kim * \param src source EC_POINT object 450e71b7053SJung-uk Kim * \param group underlying the EC_GROUP object 451e71b7053SJung-uk Kim * \return newly created EC_POINT object or NULL if an error occurred 452e71b7053SJung-uk Kim */ 453e71b7053SJung-uk Kim EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); 454e71b7053SJung-uk Kim 455e71b7053SJung-uk Kim /** Returns the EC_METHOD used in EC_POINT object 456e71b7053SJung-uk Kim * \param point EC_POINT object 457e71b7053SJung-uk Kim * \return the EC_METHOD used 458e71b7053SJung-uk Kim */ 459e71b7053SJung-uk Kim const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); 460e71b7053SJung-uk Kim 461e71b7053SJung-uk Kim /** Sets a point to infinity (neutral element) 462e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 463e71b7053SJung-uk Kim * \param point EC_POINT to set to infinity 464e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 465e71b7053SJung-uk Kim */ 466e71b7053SJung-uk Kim int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); 467e71b7053SJung-uk Kim 468e71b7053SJung-uk Kim /** Sets the jacobian projective coordinates of a EC_POINT over GFp 469e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 470e71b7053SJung-uk Kim * \param p EC_POINT object 471e71b7053SJung-uk Kim * \param x BIGNUM with the x-coordinate 472e71b7053SJung-uk Kim * \param y BIGNUM with the y-coordinate 473e71b7053SJung-uk Kim * \param z BIGNUM with the z-coordinate 474e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 475e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 476e71b7053SJung-uk Kim */ 477e71b7053SJung-uk Kim int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, 478e71b7053SJung-uk Kim EC_POINT *p, const BIGNUM *x, 479e71b7053SJung-uk Kim const BIGNUM *y, const BIGNUM *z, 480e71b7053SJung-uk Kim BN_CTX *ctx); 481e71b7053SJung-uk Kim 482e71b7053SJung-uk Kim /** Gets the jacobian projective coordinates of a EC_POINT over GFp 483e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 484e71b7053SJung-uk Kim * \param p EC_POINT object 485e71b7053SJung-uk Kim * \param x BIGNUM for the x-coordinate 486e71b7053SJung-uk Kim * \param y BIGNUM for the y-coordinate 487e71b7053SJung-uk Kim * \param z BIGNUM for the z-coordinate 488e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 489e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 490e71b7053SJung-uk Kim */ 491e71b7053SJung-uk Kim int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, 492e71b7053SJung-uk Kim const EC_POINT *p, BIGNUM *x, 493e71b7053SJung-uk Kim BIGNUM *y, BIGNUM *z, 494e71b7053SJung-uk Kim BN_CTX *ctx); 495e71b7053SJung-uk Kim 496e71b7053SJung-uk Kim /** Sets the affine coordinates of an EC_POINT 497e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 498e71b7053SJung-uk Kim * \param p EC_POINT object 499e71b7053SJung-uk Kim * \param x BIGNUM with the x-coordinate 500e71b7053SJung-uk Kim * \param y BIGNUM with the y-coordinate 501e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 502e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 503e71b7053SJung-uk Kim */ 504e71b7053SJung-uk Kim int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, 505e71b7053SJung-uk Kim const BIGNUM *x, const BIGNUM *y, 506e71b7053SJung-uk Kim BN_CTX *ctx); 507e71b7053SJung-uk Kim 508e71b7053SJung-uk Kim /** Gets the affine coordinates of an EC_POINT. 509e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 510e71b7053SJung-uk Kim * \param p EC_POINT object 511e71b7053SJung-uk Kim * \param x BIGNUM for the x-coordinate 512e71b7053SJung-uk Kim * \param y BIGNUM for the y-coordinate 513e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 514e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 515e71b7053SJung-uk Kim */ 516e71b7053SJung-uk Kim int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, 517e71b7053SJung-uk Kim BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 518e71b7053SJung-uk Kim 519e71b7053SJung-uk Kim /** Sets the affine coordinates of an EC_POINT. A synonym of 520e71b7053SJung-uk Kim * EC_POINT_set_affine_coordinates 521e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 522e71b7053SJung-uk Kim * \param p EC_POINT object 523e71b7053SJung-uk Kim * \param x BIGNUM with the x-coordinate 524e71b7053SJung-uk Kim * \param y BIGNUM with the y-coordinate 525e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 526e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 527e71b7053SJung-uk Kim */ 528e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, 529e71b7053SJung-uk Kim EC_POINT *p, 530e71b7053SJung-uk Kim const BIGNUM *x, 531e71b7053SJung-uk Kim const BIGNUM *y, 532e71b7053SJung-uk Kim BN_CTX *ctx)) 533e71b7053SJung-uk Kim 534e71b7053SJung-uk Kim /** Gets the affine coordinates of an EC_POINT. A synonym of 535e71b7053SJung-uk Kim * EC_POINT_get_affine_coordinates 536e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 537e71b7053SJung-uk Kim * \param p EC_POINT object 538e71b7053SJung-uk Kim * \param x BIGNUM for the x-coordinate 539e71b7053SJung-uk Kim * \param y BIGNUM for the y-coordinate 540e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 541e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 542e71b7053SJung-uk Kim */ 543e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, 544e71b7053SJung-uk Kim const EC_POINT *p, 545e71b7053SJung-uk Kim BIGNUM *x, 546e71b7053SJung-uk Kim BIGNUM *y, 547e71b7053SJung-uk Kim BN_CTX *ctx)) 548e71b7053SJung-uk Kim 549e71b7053SJung-uk Kim /** Sets the x9.62 compressed coordinates of a EC_POINT 550e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 551e71b7053SJung-uk Kim * \param p EC_POINT object 552e71b7053SJung-uk Kim * \param x BIGNUM with x-coordinate 553e71b7053SJung-uk Kim * \param y_bit integer with the y-Bit (either 0 or 1) 554e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 555e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 556e71b7053SJung-uk Kim */ 557e71b7053SJung-uk Kim int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, 558e71b7053SJung-uk Kim const BIGNUM *x, int y_bit, 559e71b7053SJung-uk Kim BN_CTX *ctx); 560e71b7053SJung-uk Kim 561e71b7053SJung-uk Kim /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of 562e71b7053SJung-uk Kim * EC_POINT_set_compressed_coordinates 563e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 564e71b7053SJung-uk Kim * \param p EC_POINT object 565e71b7053SJung-uk Kim * \param x BIGNUM with x-coordinate 566e71b7053SJung-uk Kim * \param y_bit integer with the y-Bit (either 0 or 1) 567e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 568e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 569e71b7053SJung-uk Kim */ 570e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, 571e71b7053SJung-uk Kim EC_POINT *p, 572e71b7053SJung-uk Kim const BIGNUM *x, 573e71b7053SJung-uk Kim int y_bit, 574e71b7053SJung-uk Kim BN_CTX *ctx)) 575e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC2M 576e71b7053SJung-uk Kim /** Sets the affine coordinates of an EC_POINT. A synonym of 577e71b7053SJung-uk Kim * EC_POINT_set_affine_coordinates 578e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 579e71b7053SJung-uk Kim * \param p EC_POINT object 580e71b7053SJung-uk Kim * \param x BIGNUM with the x-coordinate 581e71b7053SJung-uk Kim * \param y BIGNUM with the y-coordinate 582e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 583e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 584e71b7053SJung-uk Kim */ 585e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, 586e71b7053SJung-uk Kim EC_POINT *p, 587e71b7053SJung-uk Kim const BIGNUM *x, 588e71b7053SJung-uk Kim const BIGNUM *y, 589e71b7053SJung-uk Kim BN_CTX *ctx)) 590e71b7053SJung-uk Kim 591e71b7053SJung-uk Kim /** Gets the affine coordinates of an EC_POINT. A synonym of 592e71b7053SJung-uk Kim * EC_POINT_get_affine_coordinates 593e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 594e71b7053SJung-uk Kim * \param p EC_POINT object 595e71b7053SJung-uk Kim * \param x BIGNUM for the x-coordinate 596e71b7053SJung-uk Kim * \param y BIGNUM for the y-coordinate 597e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 598e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 599e71b7053SJung-uk Kim */ 600e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, 601e71b7053SJung-uk Kim const EC_POINT *p, 602e71b7053SJung-uk Kim BIGNUM *x, 603e71b7053SJung-uk Kim BIGNUM *y, 604e71b7053SJung-uk Kim BN_CTX *ctx)) 605e71b7053SJung-uk Kim 606e71b7053SJung-uk Kim /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of 607e71b7053SJung-uk Kim * EC_POINT_set_compressed_coordinates 608e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 609e71b7053SJung-uk Kim * \param p EC_POINT object 610e71b7053SJung-uk Kim * \param x BIGNUM with x-coordinate 611e71b7053SJung-uk Kim * \param y_bit integer with the y-Bit (either 0 or 1) 612e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 613e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 614e71b7053SJung-uk Kim */ 615e71b7053SJung-uk Kim DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, 616e71b7053SJung-uk Kim EC_POINT *p, 617e71b7053SJung-uk Kim const BIGNUM *x, 618e71b7053SJung-uk Kim int y_bit, 619e71b7053SJung-uk Kim BN_CTX *ctx)) 620e71b7053SJung-uk Kim # endif 621e71b7053SJung-uk Kim /** Encodes a EC_POINT object to a octet string 622e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 623e71b7053SJung-uk Kim * \param p EC_POINT object 624e71b7053SJung-uk Kim * \param form point conversion form 625e71b7053SJung-uk Kim * \param buf memory buffer for the result. If NULL the function returns 626e71b7053SJung-uk Kim * required buffer size. 627e71b7053SJung-uk Kim * \param len length of the memory buffer 628e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 629e71b7053SJung-uk Kim * \return the length of the encoded octet string or 0 if an error occurred 630e71b7053SJung-uk Kim */ 631e71b7053SJung-uk Kim size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, 632e71b7053SJung-uk Kim point_conversion_form_t form, 633e71b7053SJung-uk Kim unsigned char *buf, size_t len, BN_CTX *ctx); 634e71b7053SJung-uk Kim 635e71b7053SJung-uk Kim /** Decodes a EC_POINT from a octet string 636e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 637e71b7053SJung-uk Kim * \param p EC_POINT object 638e71b7053SJung-uk Kim * \param buf memory buffer with the encoded ec point 639e71b7053SJung-uk Kim * \param len length of the encoded ec point 640e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 641e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 642e71b7053SJung-uk Kim */ 643e71b7053SJung-uk Kim int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, 644e71b7053SJung-uk Kim const unsigned char *buf, size_t len, BN_CTX *ctx); 645e71b7053SJung-uk Kim 646e71b7053SJung-uk Kim /** Encodes an EC_POINT object to an allocated octet string 647e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 648e71b7053SJung-uk Kim * \param point EC_POINT object 649e71b7053SJung-uk Kim * \param form point conversion form 650e71b7053SJung-uk Kim * \param pbuf returns pointer to allocated buffer 651e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 652e71b7053SJung-uk Kim * \return the length of the encoded octet string or 0 if an error occurred 653e71b7053SJung-uk Kim */ 654e71b7053SJung-uk Kim size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, 655e71b7053SJung-uk Kim point_conversion_form_t form, 656e71b7053SJung-uk Kim unsigned char **pbuf, BN_CTX *ctx); 657e71b7053SJung-uk Kim 658e71b7053SJung-uk Kim /* other interfaces to point2oct/oct2point: */ 659e71b7053SJung-uk Kim BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, 660e71b7053SJung-uk Kim point_conversion_form_t form, BIGNUM *, BN_CTX *); 661e71b7053SJung-uk Kim EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, 662e71b7053SJung-uk Kim EC_POINT *, BN_CTX *); 663e71b7053SJung-uk Kim char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, 664e71b7053SJung-uk Kim point_conversion_form_t form, BN_CTX *); 665e71b7053SJung-uk Kim EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, 666e71b7053SJung-uk Kim EC_POINT *, BN_CTX *); 667e71b7053SJung-uk Kim 668e71b7053SJung-uk Kim /********************************************************************/ 669e71b7053SJung-uk Kim /* functions for doing EC_POINT arithmetic */ 670e71b7053SJung-uk Kim /********************************************************************/ 671e71b7053SJung-uk Kim 672e71b7053SJung-uk Kim /** Computes the sum of two EC_POINT 673e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 674e71b7053SJung-uk Kim * \param r EC_POINT object for the result (r = a + b) 675e71b7053SJung-uk Kim * \param a EC_POINT object with the first summand 676e71b7053SJung-uk Kim * \param b EC_POINT object with the second summand 677e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 678e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 679e71b7053SJung-uk Kim */ 680e71b7053SJung-uk Kim int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 681e71b7053SJung-uk Kim const EC_POINT *b, BN_CTX *ctx); 682e71b7053SJung-uk Kim 683e71b7053SJung-uk Kim /** Computes the double of a EC_POINT 684e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 685e71b7053SJung-uk Kim * \param r EC_POINT object for the result (r = 2 * a) 686e71b7053SJung-uk Kim * \param a EC_POINT object 687e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 688e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 689e71b7053SJung-uk Kim */ 690e71b7053SJung-uk Kim int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 691e71b7053SJung-uk Kim BN_CTX *ctx); 692e71b7053SJung-uk Kim 693e71b7053SJung-uk Kim /** Computes the inverse of a EC_POINT 694e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 695e71b7053SJung-uk Kim * \param a EC_POINT object to be inverted (it's used for the result as well) 696e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 697e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 698e71b7053SJung-uk Kim */ 699e71b7053SJung-uk Kim int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); 700e71b7053SJung-uk Kim 701e71b7053SJung-uk Kim /** Checks whether the point is the neutral element of the group 702e71b7053SJung-uk Kim * \param group the underlying EC_GROUP object 703e71b7053SJung-uk Kim * \param p EC_POINT object 704e71b7053SJung-uk Kim * \return 1 if the point is the neutral element and 0 otherwise 705e71b7053SJung-uk Kim */ 706e71b7053SJung-uk Kim int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); 707e71b7053SJung-uk Kim 708e71b7053SJung-uk Kim /** Checks whether the point is on the curve 709e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 710e71b7053SJung-uk Kim * \param point EC_POINT object to check 711e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 712e71b7053SJung-uk Kim * \return 1 if the point is on the curve, 0 if not, or -1 on error 713e71b7053SJung-uk Kim */ 714e71b7053SJung-uk Kim int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, 715e71b7053SJung-uk Kim BN_CTX *ctx); 716e71b7053SJung-uk Kim 717e71b7053SJung-uk Kim /** Compares two EC_POINTs 718e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 719e71b7053SJung-uk Kim * \param a first EC_POINT object 720e71b7053SJung-uk Kim * \param b second EC_POINT object 721e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 722e71b7053SJung-uk Kim * \return 1 if the points are not equal, 0 if they are, or -1 on error 723e71b7053SJung-uk Kim */ 724e71b7053SJung-uk Kim int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, 725e71b7053SJung-uk Kim BN_CTX *ctx); 726e71b7053SJung-uk Kim 727e71b7053SJung-uk Kim int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); 728e71b7053SJung-uk Kim int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, 729e71b7053SJung-uk Kim EC_POINT *points[], BN_CTX *ctx); 730e71b7053SJung-uk Kim 731e71b7053SJung-uk Kim /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i] 732e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 733e71b7053SJung-uk Kim * \param r EC_POINT object for the result 734e71b7053SJung-uk Kim * \param n BIGNUM with the multiplier for the group generator (optional) 735e71b7053SJung-uk Kim * \param num number further summands 736e71b7053SJung-uk Kim * \param p array of size num of EC_POINT objects 737e71b7053SJung-uk Kim * \param m array of size num of BIGNUM objects 738e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 739e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 740e71b7053SJung-uk Kim */ 741e71b7053SJung-uk Kim int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, 742e71b7053SJung-uk Kim size_t num, const EC_POINT *p[], const BIGNUM *m[], 743e71b7053SJung-uk Kim BN_CTX *ctx); 744e71b7053SJung-uk Kim 745e71b7053SJung-uk Kim /** Computes r = generator * n + q * m 746e71b7053SJung-uk Kim * \param group underlying EC_GROUP object 747e71b7053SJung-uk Kim * \param r EC_POINT object for the result 748e71b7053SJung-uk Kim * \param n BIGNUM with the multiplier for the group generator (optional) 749e71b7053SJung-uk Kim * \param q EC_POINT object with the first factor of the second summand 750e71b7053SJung-uk Kim * \param m BIGNUM with the second factor of the second summand 751e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 752e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 753e71b7053SJung-uk Kim */ 754e71b7053SJung-uk Kim int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, 755e71b7053SJung-uk Kim const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); 756e71b7053SJung-uk Kim 757e71b7053SJung-uk Kim /** Stores multiples of generator for faster point multiplication 758e71b7053SJung-uk Kim * \param group EC_GROUP object 759e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 760e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 761e71b7053SJung-uk Kim */ 762e71b7053SJung-uk Kim int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 763e71b7053SJung-uk Kim 764e71b7053SJung-uk Kim /** Reports whether a precomputation has been done 765e71b7053SJung-uk Kim * \param group EC_GROUP object 766e71b7053SJung-uk Kim * \return 1 if a pre-computation has been done and 0 otherwise 767e71b7053SJung-uk Kim */ 768e71b7053SJung-uk Kim int EC_GROUP_have_precompute_mult(const EC_GROUP *group); 769e71b7053SJung-uk Kim 770e71b7053SJung-uk Kim /********************************************************************/ 771e71b7053SJung-uk Kim /* ASN1 stuff */ 772e71b7053SJung-uk Kim /********************************************************************/ 773e71b7053SJung-uk Kim 774e71b7053SJung-uk Kim DECLARE_ASN1_ITEM(ECPKPARAMETERS) 775e71b7053SJung-uk Kim DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS) 776e71b7053SJung-uk Kim DECLARE_ASN1_ITEM(ECPARAMETERS) 777e71b7053SJung-uk Kim DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) 778e71b7053SJung-uk Kim 779e71b7053SJung-uk Kim /* 780e71b7053SJung-uk Kim * EC_GROUP_get_basis_type() returns the NID of the basis type used to 781e71b7053SJung-uk Kim * represent the field elements 782e71b7053SJung-uk Kim */ 783e71b7053SJung-uk Kim int EC_GROUP_get_basis_type(const EC_GROUP *); 784e71b7053SJung-uk Kim # ifndef OPENSSL_NO_EC2M 785e71b7053SJung-uk Kim int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); 786e71b7053SJung-uk Kim int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, 787e71b7053SJung-uk Kim unsigned int *k2, unsigned int *k3); 788e71b7053SJung-uk Kim # endif 789e71b7053SJung-uk Kim 790e71b7053SJung-uk Kim # define OPENSSL_EC_EXPLICIT_CURVE 0x000 791e71b7053SJung-uk Kim # define OPENSSL_EC_NAMED_CURVE 0x001 792e71b7053SJung-uk Kim 793e71b7053SJung-uk Kim EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); 794e71b7053SJung-uk Kim int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); 795e71b7053SJung-uk Kim 796e71b7053SJung-uk Kim # define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x) 797e71b7053SJung-uk Kim # define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x) 798e71b7053SJung-uk Kim # define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \ 799e71b7053SJung-uk Kim (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x)) 800e71b7053SJung-uk Kim # define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \ 801e71b7053SJung-uk Kim (unsigned char *)(x)) 802e71b7053SJung-uk Kim 803e71b7053SJung-uk Kim int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); 804e71b7053SJung-uk Kim # ifndef OPENSSL_NO_STDIO 805e71b7053SJung-uk Kim int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); 806e71b7053SJung-uk Kim # endif 807e71b7053SJung-uk Kim 808e71b7053SJung-uk Kim /********************************************************************/ 809e71b7053SJung-uk Kim /* EC_KEY functions */ 810e71b7053SJung-uk Kim /********************************************************************/ 811e71b7053SJung-uk Kim 812e71b7053SJung-uk Kim /* some values for the encoding_flag */ 813e71b7053SJung-uk Kim # define EC_PKEY_NO_PARAMETERS 0x001 814e71b7053SJung-uk Kim # define EC_PKEY_NO_PUBKEY 0x002 815e71b7053SJung-uk Kim 816e71b7053SJung-uk Kim /* some values for the flags field */ 817e71b7053SJung-uk Kim # define EC_FLAG_NON_FIPS_ALLOW 0x1 818e71b7053SJung-uk Kim # define EC_FLAG_FIPS_CHECKED 0x2 819e71b7053SJung-uk Kim # define EC_FLAG_COFACTOR_ECDH 0x1000 820e71b7053SJung-uk Kim 821e71b7053SJung-uk Kim /** Creates a new EC_KEY object. 822e71b7053SJung-uk Kim * \return EC_KEY object or NULL if an error occurred. 823e71b7053SJung-uk Kim */ 824e71b7053SJung-uk Kim EC_KEY *EC_KEY_new(void); 825e71b7053SJung-uk Kim 826e71b7053SJung-uk Kim int EC_KEY_get_flags(const EC_KEY *key); 827e71b7053SJung-uk Kim 828e71b7053SJung-uk Kim void EC_KEY_set_flags(EC_KEY *key, int flags); 829e71b7053SJung-uk Kim 830e71b7053SJung-uk Kim void EC_KEY_clear_flags(EC_KEY *key, int flags); 831e71b7053SJung-uk Kim 832e71b7053SJung-uk Kim /** Creates a new EC_KEY object using a named curve as underlying 833e71b7053SJung-uk Kim * EC_GROUP object. 834e71b7053SJung-uk Kim * \param nid NID of the named curve. 835e71b7053SJung-uk Kim * \return EC_KEY object or NULL if an error occurred. 836e71b7053SJung-uk Kim */ 837e71b7053SJung-uk Kim EC_KEY *EC_KEY_new_by_curve_name(int nid); 838e71b7053SJung-uk Kim 839e71b7053SJung-uk Kim /** Frees a EC_KEY object. 840e71b7053SJung-uk Kim * \param key EC_KEY object to be freed. 841e71b7053SJung-uk Kim */ 842e71b7053SJung-uk Kim void EC_KEY_free(EC_KEY *key); 843e71b7053SJung-uk Kim 844e71b7053SJung-uk Kim /** Copies a EC_KEY object. 845e71b7053SJung-uk Kim * \param dst destination EC_KEY object 846e71b7053SJung-uk Kim * \param src src EC_KEY object 847e71b7053SJung-uk Kim * \return dst or NULL if an error occurred. 848e71b7053SJung-uk Kim */ 849e71b7053SJung-uk Kim EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); 850e71b7053SJung-uk Kim 851e71b7053SJung-uk Kim /** Creates a new EC_KEY object and copies the content from src to it. 852e71b7053SJung-uk Kim * \param src the source EC_KEY object 853e71b7053SJung-uk Kim * \return newly created EC_KEY object or NULL if an error occurred. 854e71b7053SJung-uk Kim */ 855e71b7053SJung-uk Kim EC_KEY *EC_KEY_dup(const EC_KEY *src); 856e71b7053SJung-uk Kim 857e71b7053SJung-uk Kim /** Increases the internal reference count of a EC_KEY object. 858e71b7053SJung-uk Kim * \param key EC_KEY object 859e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 860e71b7053SJung-uk Kim */ 861e71b7053SJung-uk Kim int EC_KEY_up_ref(EC_KEY *key); 862e71b7053SJung-uk Kim 863e71b7053SJung-uk Kim /** Returns the ENGINE object of a EC_KEY object 864e71b7053SJung-uk Kim * \param eckey EC_KEY object 865e71b7053SJung-uk Kim * \return the ENGINE object (possibly NULL). 866e71b7053SJung-uk Kim */ 867e71b7053SJung-uk Kim ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey); 868e71b7053SJung-uk Kim 869e71b7053SJung-uk Kim /** Returns the EC_GROUP object of a EC_KEY object 870e71b7053SJung-uk Kim * \param key EC_KEY object 871e71b7053SJung-uk Kim * \return the EC_GROUP object (possibly NULL). 872e71b7053SJung-uk Kim */ 873e71b7053SJung-uk Kim const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); 874e71b7053SJung-uk Kim 875e71b7053SJung-uk Kim /** Sets the EC_GROUP of a EC_KEY object. 876e71b7053SJung-uk Kim * \param key EC_KEY object 877e71b7053SJung-uk Kim * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY 878e71b7053SJung-uk Kim * object will use an own copy of the EC_GROUP). 879e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 880e71b7053SJung-uk Kim */ 881e71b7053SJung-uk Kim int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); 882e71b7053SJung-uk Kim 883e71b7053SJung-uk Kim /** Returns the private key of a EC_KEY object. 884e71b7053SJung-uk Kim * \param key EC_KEY object 885e71b7053SJung-uk Kim * \return a BIGNUM with the private key (possibly NULL). 886e71b7053SJung-uk Kim */ 887e71b7053SJung-uk Kim const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); 888e71b7053SJung-uk Kim 889e71b7053SJung-uk Kim /** Sets the private key of a EC_KEY object. 890e71b7053SJung-uk Kim * \param key EC_KEY object 891e71b7053SJung-uk Kim * \param prv BIGNUM with the private key (note: the EC_KEY object 892e71b7053SJung-uk Kim * will use an own copy of the BIGNUM). 893e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 894e71b7053SJung-uk Kim */ 895e71b7053SJung-uk Kim int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); 896e71b7053SJung-uk Kim 897e71b7053SJung-uk Kim /** Returns the public key of a EC_KEY object. 898e71b7053SJung-uk Kim * \param key the EC_KEY object 899e71b7053SJung-uk Kim * \return a EC_POINT object with the public key (possibly NULL) 900e71b7053SJung-uk Kim */ 901e71b7053SJung-uk Kim const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); 902e71b7053SJung-uk Kim 903e71b7053SJung-uk Kim /** Sets the public key of a EC_KEY object. 904e71b7053SJung-uk Kim * \param key EC_KEY object 905e71b7053SJung-uk Kim * \param pub EC_POINT object with the public key (note: the EC_KEY object 906e71b7053SJung-uk Kim * will use an own copy of the EC_POINT object). 907e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 908e71b7053SJung-uk Kim */ 909e71b7053SJung-uk Kim int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); 910e71b7053SJung-uk Kim 911e71b7053SJung-uk Kim unsigned EC_KEY_get_enc_flags(const EC_KEY *key); 912e71b7053SJung-uk Kim void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); 913e71b7053SJung-uk Kim point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); 914e71b7053SJung-uk Kim void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); 915e71b7053SJung-uk Kim 916e71b7053SJung-uk Kim #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ 917e71b7053SJung-uk Kim CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) 918e71b7053SJung-uk Kim int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); 919e71b7053SJung-uk Kim void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); 920e71b7053SJung-uk Kim 921e71b7053SJung-uk Kim /* wrapper functions for the underlying EC_GROUP object */ 922e71b7053SJung-uk Kim void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); 923e71b7053SJung-uk Kim 924e71b7053SJung-uk Kim /** Creates a table of pre-computed multiples of the generator to 925e71b7053SJung-uk Kim * accelerate further EC_KEY operations. 926e71b7053SJung-uk Kim * \param key EC_KEY object 927e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 928e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 929e71b7053SJung-uk Kim */ 930e71b7053SJung-uk Kim int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); 931e71b7053SJung-uk Kim 932e71b7053SJung-uk Kim /** Creates a new ec private (and optional a new public) key. 933e71b7053SJung-uk Kim * \param key EC_KEY object 934e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 935e71b7053SJung-uk Kim */ 936e71b7053SJung-uk Kim int EC_KEY_generate_key(EC_KEY *key); 937e71b7053SJung-uk Kim 938e71b7053SJung-uk Kim /** Verifies that a private and/or public key is valid. 939e71b7053SJung-uk Kim * \param key the EC_KEY object 940e71b7053SJung-uk Kim * \return 1 on success and 0 otherwise. 941e71b7053SJung-uk Kim */ 942e71b7053SJung-uk Kim int EC_KEY_check_key(const EC_KEY *key); 943e71b7053SJung-uk Kim 944e71b7053SJung-uk Kim /** Indicates if an EC_KEY can be used for signing. 945e71b7053SJung-uk Kim * \param eckey the EC_KEY object 946e71b7053SJung-uk Kim * \return 1 if can can sign and 0 otherwise. 947e71b7053SJung-uk Kim */ 948e71b7053SJung-uk Kim int EC_KEY_can_sign(const EC_KEY *eckey); 949e71b7053SJung-uk Kim 950e71b7053SJung-uk Kim /** Sets a public key from affine coordinates performing 951e71b7053SJung-uk Kim * necessary NIST PKV tests. 952e71b7053SJung-uk Kim * \param key the EC_KEY object 953e71b7053SJung-uk Kim * \param x public key x coordinate 954e71b7053SJung-uk Kim * \param y public key y coordinate 955e71b7053SJung-uk Kim * \return 1 on success and 0 otherwise. 956e71b7053SJung-uk Kim */ 957e71b7053SJung-uk Kim int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, 958e71b7053SJung-uk Kim BIGNUM *y); 959e71b7053SJung-uk Kim 960e71b7053SJung-uk Kim /** Encodes an EC_KEY public key to an allocated octet string 961e71b7053SJung-uk Kim * \param key key to encode 962e71b7053SJung-uk Kim * \param form point conversion form 963e71b7053SJung-uk Kim * \param pbuf returns pointer to allocated buffer 964e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 965e71b7053SJung-uk Kim * \return the length of the encoded octet string or 0 if an error occurred 966e71b7053SJung-uk Kim */ 967e71b7053SJung-uk Kim size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form, 968e71b7053SJung-uk Kim unsigned char **pbuf, BN_CTX *ctx); 969e71b7053SJung-uk Kim 970e71b7053SJung-uk Kim /** Decodes a EC_KEY public key from a octet string 971e71b7053SJung-uk Kim * \param key key to decode 972e71b7053SJung-uk Kim * \param buf memory buffer with the encoded ec point 973e71b7053SJung-uk Kim * \param len length of the encoded ec point 974e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 975e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 976e71b7053SJung-uk Kim */ 977e71b7053SJung-uk Kim 978e71b7053SJung-uk Kim int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len, 979e71b7053SJung-uk Kim BN_CTX *ctx); 980e71b7053SJung-uk Kim 981e71b7053SJung-uk Kim /** Decodes an EC_KEY private key from an octet string 982e71b7053SJung-uk Kim * \param key key to decode 983e71b7053SJung-uk Kim * \param buf memory buffer with the encoded private key 984e71b7053SJung-uk Kim * \param len length of the encoded key 985e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 986e71b7053SJung-uk Kim */ 987e71b7053SJung-uk Kim 988e71b7053SJung-uk Kim int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len); 989e71b7053SJung-uk Kim 990e71b7053SJung-uk Kim /** Encodes a EC_KEY private key to an octet string 991e71b7053SJung-uk Kim * \param key key to encode 992e71b7053SJung-uk Kim * \param buf memory buffer for the result. If NULL the function returns 993e71b7053SJung-uk Kim * required buffer size. 994e71b7053SJung-uk Kim * \param len length of the memory buffer 995e71b7053SJung-uk Kim * \return the length of the encoded octet string or 0 if an error occurred 996e71b7053SJung-uk Kim */ 997e71b7053SJung-uk Kim 998e71b7053SJung-uk Kim size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len); 999e71b7053SJung-uk Kim 1000e71b7053SJung-uk Kim /** Encodes an EC_KEY private key to an allocated octet string 1001e71b7053SJung-uk Kim * \param eckey key to encode 1002e71b7053SJung-uk Kim * \param pbuf returns pointer to allocated buffer 1003e71b7053SJung-uk Kim * \return the length of the encoded octet string or 0 if an error occurred 1004e71b7053SJung-uk Kim */ 1005e71b7053SJung-uk Kim size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf); 1006e71b7053SJung-uk Kim 1007e71b7053SJung-uk Kim /********************************************************************/ 1008e71b7053SJung-uk Kim /* de- and encoding functions for SEC1 ECPrivateKey */ 1009e71b7053SJung-uk Kim /********************************************************************/ 1010e71b7053SJung-uk Kim 1011e71b7053SJung-uk Kim /** Decodes a private key from a memory buffer. 1012e71b7053SJung-uk Kim * \param key a pointer to a EC_KEY object which should be used (or NULL) 1013e71b7053SJung-uk Kim * \param in pointer to memory with the DER encoded private key 1014e71b7053SJung-uk Kim * \param len length of the DER encoded private key 1015e71b7053SJung-uk Kim * \return the decoded private key or NULL if an error occurred. 1016e71b7053SJung-uk Kim */ 1017e71b7053SJung-uk Kim EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); 1018e71b7053SJung-uk Kim 1019e71b7053SJung-uk Kim /** Encodes a private key object and stores the result in a buffer. 1020e71b7053SJung-uk Kim * \param key the EC_KEY object to encode 1021e71b7053SJung-uk Kim * \param out the buffer for the result (if NULL the function returns number 1022e71b7053SJung-uk Kim * of bytes needed). 1023e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 1024e71b7053SJung-uk Kim */ 1025e71b7053SJung-uk Kim int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out); 1026e71b7053SJung-uk Kim 1027e71b7053SJung-uk Kim /********************************************************************/ 1028e71b7053SJung-uk Kim /* de- and encoding functions for EC parameters */ 1029e71b7053SJung-uk Kim /********************************************************************/ 1030e71b7053SJung-uk Kim 1031e71b7053SJung-uk Kim /** Decodes ec parameter from a memory buffer. 1032e71b7053SJung-uk Kim * \param key a pointer to a EC_KEY object which should be used (or NULL) 1033e71b7053SJung-uk Kim * \param in pointer to memory with the DER encoded ec parameters 1034e71b7053SJung-uk Kim * \param len length of the DER encoded ec parameters 1035e71b7053SJung-uk Kim * \return a EC_KEY object with the decoded parameters or NULL if an error 1036e71b7053SJung-uk Kim * occurred. 1037e71b7053SJung-uk Kim */ 1038e71b7053SJung-uk Kim EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); 1039e71b7053SJung-uk Kim 1040e71b7053SJung-uk Kim /** Encodes ec parameter and stores the result in a buffer. 1041e71b7053SJung-uk Kim * \param key the EC_KEY object with ec parameters to encode 1042e71b7053SJung-uk Kim * \param out the buffer for the result (if NULL the function returns number 1043e71b7053SJung-uk Kim * of bytes needed). 1044e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred. 1045e71b7053SJung-uk Kim */ 1046e71b7053SJung-uk Kim int i2d_ECParameters(EC_KEY *key, unsigned char **out); 1047e71b7053SJung-uk Kim 1048e71b7053SJung-uk Kim /********************************************************************/ 1049e71b7053SJung-uk Kim /* de- and encoding functions for EC public key */ 1050e71b7053SJung-uk Kim /* (octet string, not DER -- hence 'o2i' and 'i2o') */ 1051e71b7053SJung-uk Kim /********************************************************************/ 1052e71b7053SJung-uk Kim 1053e71b7053SJung-uk Kim /** Decodes a ec public key from a octet string. 1054e71b7053SJung-uk Kim * \param key a pointer to a EC_KEY object which should be used 1055e71b7053SJung-uk Kim * \param in memory buffer with the encoded public key 1056e71b7053SJung-uk Kim * \param len length of the encoded public key 1057e71b7053SJung-uk Kim * \return EC_KEY object with decoded public key or NULL if an error 1058e71b7053SJung-uk Kim * occurred. 1059e71b7053SJung-uk Kim */ 1060e71b7053SJung-uk Kim EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); 1061e71b7053SJung-uk Kim 1062e71b7053SJung-uk Kim /** Encodes a ec public key in an octet string. 1063e71b7053SJung-uk Kim * \param key the EC_KEY object with the public key 1064e71b7053SJung-uk Kim * \param out the buffer for the result (if NULL the function returns number 1065e71b7053SJung-uk Kim * of bytes needed). 1066e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 1067e71b7053SJung-uk Kim */ 1068e71b7053SJung-uk Kim int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); 1069e71b7053SJung-uk Kim 1070e71b7053SJung-uk Kim /** Prints out the ec parameters on human readable form. 1071e71b7053SJung-uk Kim * \param bp BIO object to which the information is printed 1072e71b7053SJung-uk Kim * \param key EC_KEY object 1073e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 1074e71b7053SJung-uk Kim */ 1075e71b7053SJung-uk Kim int ECParameters_print(BIO *bp, const EC_KEY *key); 1076e71b7053SJung-uk Kim 1077e71b7053SJung-uk Kim /** Prints out the contents of a EC_KEY object 1078e71b7053SJung-uk Kim * \param bp BIO object to which the information is printed 1079e71b7053SJung-uk Kim * \param key EC_KEY object 1080e71b7053SJung-uk Kim * \param off line offset 1081e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 1082e71b7053SJung-uk Kim */ 1083e71b7053SJung-uk Kim int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); 1084e71b7053SJung-uk Kim 1085e71b7053SJung-uk Kim # ifndef OPENSSL_NO_STDIO 1086e71b7053SJung-uk Kim /** Prints out the ec parameters on human readable form. 1087e71b7053SJung-uk Kim * \param fp file descriptor to which the information is printed 1088e71b7053SJung-uk Kim * \param key EC_KEY object 1089e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 1090e71b7053SJung-uk Kim */ 1091e71b7053SJung-uk Kim int ECParameters_print_fp(FILE *fp, const EC_KEY *key); 1092e71b7053SJung-uk Kim 1093e71b7053SJung-uk Kim /** Prints out the contents of a EC_KEY object 1094e71b7053SJung-uk Kim * \param fp file descriptor to which the information is printed 1095e71b7053SJung-uk Kim * \param key EC_KEY object 1096e71b7053SJung-uk Kim * \param off line offset 1097e71b7053SJung-uk Kim * \return 1 on success and 0 if an error occurred 1098e71b7053SJung-uk Kim */ 1099e71b7053SJung-uk Kim int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); 1100e71b7053SJung-uk Kim 1101e71b7053SJung-uk Kim # endif 1102e71b7053SJung-uk Kim 1103e71b7053SJung-uk Kim const EC_KEY_METHOD *EC_KEY_OpenSSL(void); 1104e71b7053SJung-uk Kim const EC_KEY_METHOD *EC_KEY_get_default_method(void); 1105e71b7053SJung-uk Kim void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); 1106e71b7053SJung-uk Kim const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); 1107e71b7053SJung-uk Kim int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); 1108e71b7053SJung-uk Kim EC_KEY *EC_KEY_new_method(ENGINE *engine); 1109e71b7053SJung-uk Kim 1110c9cf7b5cSJung-uk Kim /** The old name for ecdh_KDF_X9_63 1111c9cf7b5cSJung-uk Kim * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, 1112c9cf7b5cSJung-uk Kim * it is actually specified in ANSI X9.63. 1113c9cf7b5cSJung-uk Kim * This identifier is retained for backwards compatibility 1114c9cf7b5cSJung-uk Kim */ 1115e71b7053SJung-uk Kim int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, 1116e71b7053SJung-uk Kim const unsigned char *Z, size_t Zlen, 1117e71b7053SJung-uk Kim const unsigned char *sinfo, size_t sinfolen, 1118e71b7053SJung-uk Kim const EVP_MD *md); 1119e71b7053SJung-uk Kim 1120e71b7053SJung-uk Kim int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, 1121e71b7053SJung-uk Kim const EC_KEY *ecdh, 1122e71b7053SJung-uk Kim void *(*KDF) (const void *in, size_t inlen, 1123e71b7053SJung-uk Kim void *out, size_t *outlen)); 1124e71b7053SJung-uk Kim 1125e71b7053SJung-uk Kim typedef struct ECDSA_SIG_st ECDSA_SIG; 1126e71b7053SJung-uk Kim 1127e71b7053SJung-uk Kim /** Allocates and initialize a ECDSA_SIG structure 1128e71b7053SJung-uk Kim * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1129e71b7053SJung-uk Kim */ 1130e71b7053SJung-uk Kim ECDSA_SIG *ECDSA_SIG_new(void); 1131e71b7053SJung-uk Kim 1132e71b7053SJung-uk Kim /** frees a ECDSA_SIG structure 1133e71b7053SJung-uk Kim * \param sig pointer to the ECDSA_SIG structure 1134e71b7053SJung-uk Kim */ 1135e71b7053SJung-uk Kim void ECDSA_SIG_free(ECDSA_SIG *sig); 1136e71b7053SJung-uk Kim 1137e71b7053SJung-uk Kim /** DER encode content of ECDSA_SIG object (note: this function modifies *pp 1138e71b7053SJung-uk Kim * (*pp += length of the DER encoded signature)). 1139e71b7053SJung-uk Kim * \param sig pointer to the ECDSA_SIG object 1140e71b7053SJung-uk Kim * \param pp pointer to a unsigned char pointer for the output or NULL 1141*da327cd2SJung-uk Kim * \return the length of the DER encoded ECDSA_SIG object or a negative value 1142*da327cd2SJung-uk Kim * on error 1143e71b7053SJung-uk Kim */ 1144e71b7053SJung-uk Kim int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp); 1145e71b7053SJung-uk Kim 1146e71b7053SJung-uk Kim /** Decodes a DER encoded ECDSA signature (note: this function changes *pp 1147e71b7053SJung-uk Kim * (*pp += len)). 1148e71b7053SJung-uk Kim * \param sig pointer to ECDSA_SIG pointer (may be NULL) 1149e71b7053SJung-uk Kim * \param pp memory buffer with the DER encoded signature 1150e71b7053SJung-uk Kim * \param len length of the buffer 1151e71b7053SJung-uk Kim * \return pointer to the decoded ECDSA_SIG structure (or NULL) 1152e71b7053SJung-uk Kim */ 1153e71b7053SJung-uk Kim ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len); 1154e71b7053SJung-uk Kim 1155e71b7053SJung-uk Kim /** Accessor for r and s fields of ECDSA_SIG 1156e71b7053SJung-uk Kim * \param sig pointer to ECDSA_SIG structure 1157e71b7053SJung-uk Kim * \param pr pointer to BIGNUM pointer for r (may be NULL) 1158e71b7053SJung-uk Kim * \param ps pointer to BIGNUM pointer for s (may be NULL) 1159e71b7053SJung-uk Kim */ 1160e71b7053SJung-uk Kim void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); 1161e71b7053SJung-uk Kim 1162e71b7053SJung-uk Kim /** Accessor for r field of ECDSA_SIG 1163e71b7053SJung-uk Kim * \param sig pointer to ECDSA_SIG structure 1164e71b7053SJung-uk Kim */ 1165e71b7053SJung-uk Kim const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig); 1166e71b7053SJung-uk Kim 1167e71b7053SJung-uk Kim /** Accessor for s field of ECDSA_SIG 1168e71b7053SJung-uk Kim * \param sig pointer to ECDSA_SIG structure 1169e71b7053SJung-uk Kim */ 1170e71b7053SJung-uk Kim const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig); 1171e71b7053SJung-uk Kim 1172e71b7053SJung-uk Kim /** Setter for r and s fields of ECDSA_SIG 1173e71b7053SJung-uk Kim * \param sig pointer to ECDSA_SIG structure 1174e71b7053SJung-uk Kim * \param r pointer to BIGNUM for r (may be NULL) 1175e71b7053SJung-uk Kim * \param s pointer to BIGNUM for s (may be NULL) 1176e71b7053SJung-uk Kim */ 1177e71b7053SJung-uk Kim int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); 1178e71b7053SJung-uk Kim 1179e71b7053SJung-uk Kim /** Computes the ECDSA signature of the given hash value using 1180e71b7053SJung-uk Kim * the supplied private key and returns the created signature. 1181e71b7053SJung-uk Kim * \param dgst pointer to the hash value 1182e71b7053SJung-uk Kim * \param dgst_len length of the hash value 1183e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a private EC key 1184e71b7053SJung-uk Kim * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1185e71b7053SJung-uk Kim */ 1186e71b7053SJung-uk Kim ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, 1187e71b7053SJung-uk Kim EC_KEY *eckey); 1188e71b7053SJung-uk Kim 1189e71b7053SJung-uk Kim /** Computes ECDSA signature of a given hash value using the supplied 1190e71b7053SJung-uk Kim * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1191e71b7053SJung-uk Kim * \param dgst pointer to the hash value to sign 1192e71b7053SJung-uk Kim * \param dgstlen length of the hash value 1193e71b7053SJung-uk Kim * \param kinv BIGNUM with a pre-computed inverse k (optional) 1194e71b7053SJung-uk Kim * \param rp BIGNUM with a pre-computed rp value (optional), 1195e71b7053SJung-uk Kim * see ECDSA_sign_setup 1196e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a private EC key 1197e71b7053SJung-uk Kim * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1198e71b7053SJung-uk Kim */ 1199e71b7053SJung-uk Kim ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, 1200e71b7053SJung-uk Kim const BIGNUM *kinv, const BIGNUM *rp, 1201e71b7053SJung-uk Kim EC_KEY *eckey); 1202e71b7053SJung-uk Kim 1203e71b7053SJung-uk Kim /** Verifies that the supplied signature is a valid ECDSA 1204e71b7053SJung-uk Kim * signature of the supplied hash value using the supplied public key. 1205e71b7053SJung-uk Kim * \param dgst pointer to the hash value 1206e71b7053SJung-uk Kim * \param dgst_len length of the hash value 1207e71b7053SJung-uk Kim * \param sig ECDSA_SIG structure 1208e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a public EC key 1209e71b7053SJung-uk Kim * \return 1 if the signature is valid, 0 if the signature is invalid 1210e71b7053SJung-uk Kim * and -1 on error 1211e71b7053SJung-uk Kim */ 1212e71b7053SJung-uk Kim int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, 1213e71b7053SJung-uk Kim const ECDSA_SIG *sig, EC_KEY *eckey); 1214e71b7053SJung-uk Kim 1215e71b7053SJung-uk Kim /** Precompute parts of the signing operation 1216e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a private EC key 1217e71b7053SJung-uk Kim * \param ctx BN_CTX object (optional) 1218e71b7053SJung-uk Kim * \param kinv BIGNUM pointer for the inverse of k 1219e71b7053SJung-uk Kim * \param rp BIGNUM pointer for x coordinate of k * generator 1220e71b7053SJung-uk Kim * \return 1 on success and 0 otherwise 1221e71b7053SJung-uk Kim */ 1222e71b7053SJung-uk Kim int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); 1223e71b7053SJung-uk Kim 1224e71b7053SJung-uk Kim /** Computes ECDSA signature of a given hash value using the supplied 1225e71b7053SJung-uk Kim * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1226e71b7053SJung-uk Kim * \param type this parameter is ignored 1227e71b7053SJung-uk Kim * \param dgst pointer to the hash value to sign 1228e71b7053SJung-uk Kim * \param dgstlen length of the hash value 1229e71b7053SJung-uk Kim * \param sig memory for the DER encoded created signature 1230e71b7053SJung-uk Kim * \param siglen pointer to the length of the returned signature 1231e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a private EC key 1232e71b7053SJung-uk Kim * \return 1 on success and 0 otherwise 1233e71b7053SJung-uk Kim */ 1234e71b7053SJung-uk Kim int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, 1235e71b7053SJung-uk Kim unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); 1236e71b7053SJung-uk Kim 1237e71b7053SJung-uk Kim /** Computes ECDSA signature of a given hash value using the supplied 1238e71b7053SJung-uk Kim * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1239e71b7053SJung-uk Kim * \param type this parameter is ignored 1240e71b7053SJung-uk Kim * \param dgst pointer to the hash value to sign 1241e71b7053SJung-uk Kim * \param dgstlen length of the hash value 1242e71b7053SJung-uk Kim * \param sig buffer to hold the DER encoded signature 1243e71b7053SJung-uk Kim * \param siglen pointer to the length of the returned signature 1244e71b7053SJung-uk Kim * \param kinv BIGNUM with a pre-computed inverse k (optional) 1245e71b7053SJung-uk Kim * \param rp BIGNUM with a pre-computed rp value (optional), 1246e71b7053SJung-uk Kim * see ECDSA_sign_setup 1247e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a private EC key 1248e71b7053SJung-uk Kim * \return 1 on success and 0 otherwise 1249e71b7053SJung-uk Kim */ 1250e71b7053SJung-uk Kim int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, 1251e71b7053SJung-uk Kim unsigned char *sig, unsigned int *siglen, 1252e71b7053SJung-uk Kim const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); 1253e71b7053SJung-uk Kim 1254e71b7053SJung-uk Kim /** Verifies that the given signature is valid ECDSA signature 1255e71b7053SJung-uk Kim * of the supplied hash value using the specified public key. 1256e71b7053SJung-uk Kim * \param type this parameter is ignored 1257e71b7053SJung-uk Kim * \param dgst pointer to the hash value 1258e71b7053SJung-uk Kim * \param dgstlen length of the hash value 1259e71b7053SJung-uk Kim * \param sig pointer to the DER encoded signature 1260e71b7053SJung-uk Kim * \param siglen length of the DER encoded signature 1261e71b7053SJung-uk Kim * \param eckey EC_KEY object containing a public EC key 1262e71b7053SJung-uk Kim * \return 1 if the signature is valid, 0 if the signature is invalid 1263e71b7053SJung-uk Kim * and -1 on error 1264e71b7053SJung-uk Kim */ 1265e71b7053SJung-uk Kim int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, 1266e71b7053SJung-uk Kim const unsigned char *sig, int siglen, EC_KEY *eckey); 1267e71b7053SJung-uk Kim 1268e71b7053SJung-uk Kim /** Returns the maximum length of the DER encoded signature 1269e71b7053SJung-uk Kim * \param eckey EC_KEY object 1270e71b7053SJung-uk Kim * \return numbers of bytes required for the DER encoded signature 1271e71b7053SJung-uk Kim */ 1272e71b7053SJung-uk Kim int ECDSA_size(const EC_KEY *eckey); 1273e71b7053SJung-uk Kim 1274e71b7053SJung-uk Kim /********************************************************************/ 1275e71b7053SJung-uk Kim /* EC_KEY_METHOD constructors, destructors, writers and accessors */ 1276e71b7053SJung-uk Kim /********************************************************************/ 1277e71b7053SJung-uk Kim 1278e71b7053SJung-uk Kim EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); 1279e71b7053SJung-uk Kim void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); 1280e71b7053SJung-uk Kim void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, 1281e71b7053SJung-uk Kim int (*init)(EC_KEY *key), 1282e71b7053SJung-uk Kim void (*finish)(EC_KEY *key), 1283e71b7053SJung-uk Kim int (*copy)(EC_KEY *dest, const EC_KEY *src), 1284e71b7053SJung-uk Kim int (*set_group)(EC_KEY *key, const EC_GROUP *grp), 1285e71b7053SJung-uk Kim int (*set_private)(EC_KEY *key, 1286e71b7053SJung-uk Kim const BIGNUM *priv_key), 1287e71b7053SJung-uk Kim int (*set_public)(EC_KEY *key, 1288e71b7053SJung-uk Kim const EC_POINT *pub_key)); 1289e71b7053SJung-uk Kim 1290e71b7053SJung-uk Kim void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, 1291e71b7053SJung-uk Kim int (*keygen)(EC_KEY *key)); 1292e71b7053SJung-uk Kim 1293e71b7053SJung-uk Kim void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, 1294e71b7053SJung-uk Kim int (*ckey)(unsigned char **psec, 1295e71b7053SJung-uk Kim size_t *pseclen, 1296e71b7053SJung-uk Kim const EC_POINT *pub_key, 1297e71b7053SJung-uk Kim const EC_KEY *ecdh)); 1298e71b7053SJung-uk Kim 1299e71b7053SJung-uk Kim void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, 1300e71b7053SJung-uk Kim int (*sign)(int type, const unsigned char *dgst, 1301e71b7053SJung-uk Kim int dlen, unsigned char *sig, 1302e71b7053SJung-uk Kim unsigned int *siglen, 1303e71b7053SJung-uk Kim const BIGNUM *kinv, const BIGNUM *r, 1304e71b7053SJung-uk Kim EC_KEY *eckey), 1305e71b7053SJung-uk Kim int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, 1306e71b7053SJung-uk Kim BIGNUM **kinvp, BIGNUM **rp), 1307e71b7053SJung-uk Kim ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, 1308e71b7053SJung-uk Kim int dgst_len, 1309e71b7053SJung-uk Kim const BIGNUM *in_kinv, 1310e71b7053SJung-uk Kim const BIGNUM *in_r, 1311e71b7053SJung-uk Kim EC_KEY *eckey)); 1312e71b7053SJung-uk Kim 1313e71b7053SJung-uk Kim void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, 1314e71b7053SJung-uk Kim int (*verify)(int type, const unsigned 1315e71b7053SJung-uk Kim char *dgst, int dgst_len, 1316e71b7053SJung-uk Kim const unsigned char *sigbuf, 1317e71b7053SJung-uk Kim int sig_len, EC_KEY *eckey), 1318e71b7053SJung-uk Kim int (*verify_sig)(const unsigned char *dgst, 1319e71b7053SJung-uk Kim int dgst_len, 1320e71b7053SJung-uk Kim const ECDSA_SIG *sig, 1321e71b7053SJung-uk Kim EC_KEY *eckey)); 1322e71b7053SJung-uk Kim 1323e71b7053SJung-uk Kim void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, 1324e71b7053SJung-uk Kim int (**pinit)(EC_KEY *key), 1325e71b7053SJung-uk Kim void (**pfinish)(EC_KEY *key), 1326e71b7053SJung-uk Kim int (**pcopy)(EC_KEY *dest, const EC_KEY *src), 1327e71b7053SJung-uk Kim int (**pset_group)(EC_KEY *key, 1328e71b7053SJung-uk Kim const EC_GROUP *grp), 1329e71b7053SJung-uk Kim int (**pset_private)(EC_KEY *key, 1330e71b7053SJung-uk Kim const BIGNUM *priv_key), 1331e71b7053SJung-uk Kim int (**pset_public)(EC_KEY *key, 1332e71b7053SJung-uk Kim const EC_POINT *pub_key)); 1333e71b7053SJung-uk Kim 1334e71b7053SJung-uk Kim void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, 1335e71b7053SJung-uk Kim int (**pkeygen)(EC_KEY *key)); 1336e71b7053SJung-uk Kim 1337e71b7053SJung-uk Kim void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, 1338e71b7053SJung-uk Kim int (**pck)(unsigned char **psec, 1339e71b7053SJung-uk Kim size_t *pseclen, 1340e71b7053SJung-uk Kim const EC_POINT *pub_key, 1341e71b7053SJung-uk Kim const EC_KEY *ecdh)); 1342e71b7053SJung-uk Kim 1343e71b7053SJung-uk Kim void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, 1344e71b7053SJung-uk Kim int (**psign)(int type, const unsigned char *dgst, 1345e71b7053SJung-uk Kim int dlen, unsigned char *sig, 1346e71b7053SJung-uk Kim unsigned int *siglen, 1347e71b7053SJung-uk Kim const BIGNUM *kinv, const BIGNUM *r, 1348e71b7053SJung-uk Kim EC_KEY *eckey), 1349e71b7053SJung-uk Kim int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, 1350e71b7053SJung-uk Kim BIGNUM **kinvp, BIGNUM **rp), 1351e71b7053SJung-uk Kim ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, 1352e71b7053SJung-uk Kim int dgst_len, 1353e71b7053SJung-uk Kim const BIGNUM *in_kinv, 1354e71b7053SJung-uk Kim const BIGNUM *in_r, 1355e71b7053SJung-uk Kim EC_KEY *eckey)); 1356e71b7053SJung-uk Kim 1357e71b7053SJung-uk Kim void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, 1358e71b7053SJung-uk Kim int (**pverify)(int type, const unsigned 1359e71b7053SJung-uk Kim char *dgst, int dgst_len, 1360e71b7053SJung-uk Kim const unsigned char *sigbuf, 1361e71b7053SJung-uk Kim int sig_len, EC_KEY *eckey), 1362e71b7053SJung-uk Kim int (**pverify_sig)(const unsigned char *dgst, 1363e71b7053SJung-uk Kim int dgst_len, 1364e71b7053SJung-uk Kim const ECDSA_SIG *sig, 1365e71b7053SJung-uk Kim EC_KEY *eckey)); 1366e71b7053SJung-uk Kim 1367e71b7053SJung-uk Kim # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) 1368e71b7053SJung-uk Kim 1369e71b7053SJung-uk Kim # ifndef __cplusplus 1370e71b7053SJung-uk Kim # if defined(__SUNPRO_C) 1371e71b7053SJung-uk Kim # if __SUNPRO_C >= 0x520 1372e71b7053SJung-uk Kim # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) 1373e71b7053SJung-uk Kim # endif 1374e71b7053SJung-uk Kim # endif 1375e71b7053SJung-uk Kim # endif 1376e71b7053SJung-uk Kim 1377e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ 1378e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1379e71b7053SJung-uk Kim EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ 1380e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) 1381e71b7053SJung-uk Kim 1382e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \ 1383e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1384e71b7053SJung-uk Kim EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ 1385e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL) 1386e71b7053SJung-uk Kim 1387e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \ 1388e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1389e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1390e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL) 1391e71b7053SJung-uk Kim 1392e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \ 1393e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1394e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1395e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL) 1396e71b7053SJung-uk Kim 1397e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \ 1398e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1399e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1400e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL) 1401e71b7053SJung-uk Kim 1402e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \ 1403e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1404e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1405e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL) 1406e71b7053SJung-uk Kim 1407e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \ 1408e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1409e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1410e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)(md)) 1411e71b7053SJung-uk Kim 1412e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \ 1413e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1414e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1415e71b7053SJung-uk Kim EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)(pmd)) 1416e71b7053SJung-uk Kim 1417e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \ 1418e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1419e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1420e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL) 1421e71b7053SJung-uk Kim 1422e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \ 1423e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1424e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1425e71b7053SJung-uk Kim EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, \ 1426e71b7053SJung-uk Kim (void *)(plen)) 1427e71b7053SJung-uk Kim 1428e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \ 1429e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1430e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1431e71b7053SJung-uk Kim EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)(p)) 1432e71b7053SJung-uk Kim 1433e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \ 1434e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ 1435e71b7053SJung-uk Kim EVP_PKEY_OP_DERIVE, \ 1436e71b7053SJung-uk Kim EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)(p)) 1437e71b7053SJung-uk Kim 1438e71b7053SJung-uk Kim /* SM2 will skip the operation check so no need to pass operation here */ 1439e71b7053SJung-uk Kim # define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \ 1440e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ 1441e71b7053SJung-uk Kim EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id)) 1442e71b7053SJung-uk Kim 1443e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get1_id(ctx, id) \ 1444e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ 1445e71b7053SJung-uk Kim EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id)) 1446e71b7053SJung-uk Kim 1447e71b7053SJung-uk Kim # define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \ 1448e71b7053SJung-uk Kim EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ 1449e71b7053SJung-uk Kim EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len)) 1450e71b7053SJung-uk Kim 1451e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1) 1452e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2) 1453e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3) 1454e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4) 1455e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5) 1456e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6) 1457e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7) 1458e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8) 1459e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9) 1460e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10) 1461e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_SET1_ID (EVP_PKEY_ALG_CTRL + 11) 1462e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_GET1_ID (EVP_PKEY_ALG_CTRL + 12) 1463e71b7053SJung-uk Kim # define EVP_PKEY_CTRL_GET1_ID_LEN (EVP_PKEY_ALG_CTRL + 13) 1464e71b7053SJung-uk Kim /* KDF types */ 1465e71b7053SJung-uk Kim # define EVP_PKEY_ECDH_KDF_NONE 1 1466c9cf7b5cSJung-uk Kim # define EVP_PKEY_ECDH_KDF_X9_63 2 1467c9cf7b5cSJung-uk Kim /** The old name for EVP_PKEY_ECDH_KDF_X9_63 1468c9cf7b5cSJung-uk Kim * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, 1469c9cf7b5cSJung-uk Kim * it is actually specified in ANSI X9.63. 1470c9cf7b5cSJung-uk Kim * This identifier is retained for backwards compatibility 1471c9cf7b5cSJung-uk Kim */ 1472c9cf7b5cSJung-uk Kim # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63 1473e71b7053SJung-uk Kim 1474e71b7053SJung-uk Kim 1475e71b7053SJung-uk Kim # ifdef __cplusplus 1476e71b7053SJung-uk Kim } 1477e71b7053SJung-uk Kim # endif 1478e71b7053SJung-uk Kim # endif 1479e71b7053SJung-uk Kim #endif 1480