1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimEC_GROUP_get_ecparameters, 6e71b7053SJung-uk KimEC_GROUP_get_ecpkparameters, 7*b077aed3SPierre ProncheryEC_GROUP_new_from_params, 8e71b7053SJung-uk KimEC_GROUP_new_from_ecparameters, 9e71b7053SJung-uk KimEC_GROUP_new_from_ecpkparameters, 10*b077aed3SPierre ProncheryEC_GROUP_new, 11e71b7053SJung-uk KimEC_GROUP_free, 12e71b7053SJung-uk KimEC_GROUP_clear_free, 13e71b7053SJung-uk KimEC_GROUP_new_curve_GFp, 14e71b7053SJung-uk KimEC_GROUP_new_curve_GF2m, 15*b077aed3SPierre ProncheryEC_GROUP_new_by_curve_name_ex, 16e71b7053SJung-uk KimEC_GROUP_new_by_curve_name, 17e71b7053SJung-uk KimEC_GROUP_set_curve, 18e71b7053SJung-uk KimEC_GROUP_get_curve, 19e71b7053SJung-uk KimEC_GROUP_set_curve_GFp, 20e71b7053SJung-uk KimEC_GROUP_get_curve_GFp, 21e71b7053SJung-uk KimEC_GROUP_set_curve_GF2m, 22e71b7053SJung-uk KimEC_GROUP_get_curve_GF2m, 23*b077aed3SPierre ProncheryEC_get_builtin_curves, 24*b077aed3SPierre ProncheryOSSL_EC_curve_nid2name - 25*b077aed3SPierre ProncheryFunctions for creating and destroying EC_GROUP objects 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim=head1 SYNOPSIS 28e71b7053SJung-uk Kim 29e71b7053SJung-uk Kim #include <openssl/ec.h> 30e71b7053SJung-uk Kim 31*b077aed3SPierre Pronchery EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[], 32*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq); 33*b077aed3SPierre Pronchery EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); 34*b077aed3SPierre Pronchery EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); 35e71b7053SJung-uk Kim void EC_GROUP_free(EC_GROUP *group); 36e71b7053SJung-uk Kim 37e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, 38e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 39e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, 40e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 41*b077aed3SPierre Pronchery EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq, 42*b077aed3SPierre Pronchery int nid); 43e71b7053SJung-uk Kim EC_GROUP *EC_GROUP_new_by_curve_name(int nid); 44e71b7053SJung-uk Kim 45e71b7053SJung-uk Kim int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 46e71b7053SJung-uk Kim const BIGNUM *b, BN_CTX *ctx); 47e71b7053SJung-uk Kim int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, 48e71b7053SJung-uk Kim BN_CTX *ctx); 49*b077aed3SPierre Pronchery 50*b077aed3SPierre Pronchery ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, 51*b077aed3SPierre Pronchery ECPARAMETERS *params); 52*b077aed3SPierre Pronchery ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, 53*b077aed3SPierre Pronchery ECPKPARAMETERS *params); 54*b077aed3SPierre Pronchery 55*b077aed3SPierre Pronchery size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 56*b077aed3SPierre Pronchery const char *OSSL_EC_curve_nid2name(int nid); 57*b077aed3SPierre Pronchery 58*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be 59*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 60*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>: 61*b077aed3SPierre Pronchery 62*b077aed3SPierre Pronchery EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); 63*b077aed3SPierre Pronchery void EC_GROUP_clear_free(EC_GROUP *group); 64*b077aed3SPierre Pronchery 65e71b7053SJung-uk Kim int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, 66e71b7053SJung-uk Kim const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 67e71b7053SJung-uk Kim int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, 68e71b7053SJung-uk Kim BIGNUM *a, BIGNUM *b, BN_CTX *ctx); 69e71b7053SJung-uk Kim int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, 70e71b7053SJung-uk Kim const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 71e71b7053SJung-uk Kim int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, 72e71b7053SJung-uk Kim BIGNUM *a, BIGNUM *b, BN_CTX *ctx); 73e71b7053SJung-uk Kim 74e71b7053SJung-uk Kim=head1 DESCRIPTION 75e71b7053SJung-uk Kim 7617f01e99SJung-uk KimWithin the library there are two forms of elliptic curve that are of interest. 7717f01e99SJung-uk KimThe first form is those defined over the prime field Fp. The elements of Fp are 7817f01e99SJung-uk Kimthe integers 0 to p-1, where p is a prime number. This gives us a revised 79e71b7053SJung-uk Kimelliptic curve equation as follows: 80e71b7053SJung-uk Kim 81e71b7053SJung-uk Kimy^2 mod p = x^3 +ax + b mod p 82e71b7053SJung-uk Kim 8317f01e99SJung-uk KimThe second form is those defined over a binary field F2^m where the elements of 8417f01e99SJung-uk Kimthe field are integers of length at most m bits. For this form the elliptic 8517f01e99SJung-uk Kimcurve equation is modified to: 86e71b7053SJung-uk Kim 87e71b7053SJung-uk Kimy^2 + xy = x^3 + ax^2 + b (where b != 0) 88e71b7053SJung-uk Kim 89*b077aed3SPierre ProncheryOperations in a binary field are performed relative to an 90*b077aed3SPierre ProncheryB<irreducible polynomial>. All such curves with OpenSSL use a trinomial or a 91*b077aed3SPierre Proncherypentanomial for this parameter. 92e71b7053SJung-uk Kim 93*b077aed3SPierre ProncheryAlthough deprecated since OpenSSL 3.0 and should no longer be used, 94*b077aed3SPierre Proncherya new curve can be constructed by calling EC_GROUP_new(), using the 95*b077aed3SPierre Proncheryimplementation provided by I<meth> (see L<EC_GFp_simple_method(3)>) and 96*b077aed3SPierre Proncheryassociated with the library context I<ctx> (see L<OSSL_LIB_CTX(3)>). 97*b077aed3SPierre ProncheryThe I<ctx> parameter may be NULL in which case the default library context is 98*b077aed3SPierre Proncheryused. 99*b077aed3SPierre ProncheryIt is then necessary to call EC_GROUP_set_curve() to set the curve parameters. 100*b077aed3SPierre ProncheryApplications should instead use one of the other EC_GROUP_new_* constructors. 101e71b7053SJung-uk Kim 102*b077aed3SPierre ProncheryEC_GROUP_new_from_params() creates a group with parameters specified by I<params>. 103*b077aed3SPierre ProncheryThe library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and property query string 104*b077aed3SPierre ProncheryI<propq> are used to fetch algorithms from providers. 105*b077aed3SPierre ProncheryI<params> may be either a list of explicit params or a named group, 106*b077aed3SPierre ProncheryThe values for I<ctx> and I<propq> may be NULL. 107*b077aed3SPierre ProncheryThe I<params> that can be used are described in 108*b077aed3SPierre ProncheryL<B<EVP_PKEY-EC>(7)|EVP_PKEY-EC(7)/Common EC parameters>. 109*b077aed3SPierre Pronchery 110*b077aed3SPierre ProncheryEC_GROUP_new_from_ecparameters() will create a group from the 111*b077aed3SPierre Proncheryspecified I<params> and 112*b077aed3SPierre ProncheryEC_GROUP_new_from_ecpkparameters() will create a group from the specific PK 113*b077aed3SPierre ProncheryI<params>. 114*b077aed3SPierre Pronchery 115*b077aed3SPierre ProncheryEC_GROUP_set_curve() sets the curve parameters I<p>, I<a> and I<b>. For a curve 116*b077aed3SPierre Proncheryover Fp I<p> is the prime for the field. For a curve over F2^m I<p> represents 11717f01e99SJung-uk Kimthe irreducible polynomial - each bit represents a term in the polynomial. 11858f35182SJung-uk KimTherefore, there will either be three or five bits set dependent on whether the 11917f01e99SJung-uk Kimpolynomial is a trinomial or a pentanomial. 120*b077aed3SPierre ProncheryIn either case, I<a> and I<b> represents the coefficients a and b from the 12117f01e99SJung-uk Kimrelevant equation introduced above. 122e71b7053SJung-uk Kim 123e71b7053SJung-uk KimEC_group_get_curve() obtains the previously set curve parameters. 124e71b7053SJung-uk Kim 12517f01e99SJung-uk KimEC_GROUP_set_curve_GFp() and EC_GROUP_set_curve_GF2m() are synonyms for 12617f01e99SJung-uk KimEC_GROUP_set_curve(). They are defined for backwards compatibility only and 12717f01e99SJung-uk Kimshould not be used. 128e71b7053SJung-uk Kim 12917f01e99SJung-uk KimEC_GROUP_get_curve_GFp() and EC_GROUP_get_curve_GF2m() are synonyms for 13017f01e99SJung-uk KimEC_GROUP_get_curve(). They are defined for backwards compatibility only and 13117f01e99SJung-uk Kimshould not be used. 132e71b7053SJung-uk Kim 13317f01e99SJung-uk KimThe functions EC_GROUP_new_curve_GFp() and EC_GROUP_new_curve_GF2m() are 13417f01e99SJung-uk Kimshortcuts for calling EC_GROUP_new() and then the EC_GROUP_set_curve() function. 13517f01e99SJung-uk KimAn appropriate default implementation method will be used. 136e71b7053SJung-uk Kim 13717f01e99SJung-uk KimWhilst the library can be used to create any curve using the functions described 13817f01e99SJung-uk Kimabove, there are also a number of predefined curves that are available. In order 13917f01e99SJung-uk Kimto obtain a list of all of the predefined curves, call the function 140*b077aed3SPierre ProncheryEC_get_builtin_curves(). The parameter I<r> should be an array of 141*b077aed3SPierre ProncheryEC_builtin_curve structures of size I<nitems>. The function will populate the 142*b077aed3SPierre ProncheryI<r> array with information about the built-in curves. If I<nitems> is less than 143*b077aed3SPierre Proncherythe total number of curves available, then the first I<nitems> curves will be 14417f01e99SJung-uk Kimreturned. Otherwise the total number of curves will be provided. The return 14517f01e99SJung-uk Kimvalue is the total number of curves available (whether that number has been 146*b077aed3SPierre Proncherypopulated in I<r> or not). Passing a NULL I<r>, or setting I<nitems> to 0 will 14717f01e99SJung-uk Kimdo nothing other than return the total number of curves available. 148e71b7053SJung-uk KimThe EC_builtin_curve structure is defined as follows: 149e71b7053SJung-uk Kim 150e71b7053SJung-uk Kim typedef struct { 151e71b7053SJung-uk Kim int nid; 152e71b7053SJung-uk Kim const char *comment; 153e71b7053SJung-uk Kim } EC_builtin_curve; 154e71b7053SJung-uk Kim 155*b077aed3SPierre ProncheryEach EC_builtin_curve item has a unique integer id (I<nid>), and a human 15617f01e99SJung-uk Kimreadable comment string describing the curve. 157e71b7053SJung-uk Kim 158*b077aed3SPierre ProncheryIn order to construct a built-in curve use the function 159*b077aed3SPierre ProncheryEC_GROUP_new_by_curve_name_ex() and provide the I<nid> of the curve to 160*b077aed3SPierre Proncherybe constructed, the associated library context to be used in I<ctx> (see 161*b077aed3SPierre ProncheryL<OSSL_LIB_CTX(3)>) and any property query string in I<propq>. The I<ctx> value 162*b077aed3SPierre Proncherymay be NULL in which case the default library context is used. The I<propq> 163*b077aed3SPierre Proncheryvalue may also be NULL. 164*b077aed3SPierre Pronchery 165*b077aed3SPierre ProncheryEC_GROUP_new_by_curve_name() is the same as 166*b077aed3SPierre ProncheryEC_GROUP_new_by_curve_name_ex() except that the default library context 167*b077aed3SPierre Proncheryis always used along with a NULL property query string. 168e71b7053SJung-uk Kim 16917f01e99SJung-uk KimEC_GROUP_free() frees the memory associated with the EC_GROUP. 170*b077aed3SPierre ProncheryIf I<group> is NULL nothing is done. 171e71b7053SJung-uk Kim 172*b077aed3SPierre ProncheryEC_GROUP_clear_free() is deprecated: it was meant to destroy any sensitive data 173*b077aed3SPierre Proncheryheld within the EC_GROUP and then free its memory, but since all the data stored 174*b077aed3SPierre Proncheryin the EC_GROUP is public anyway, this function is unnecessary. 175*b077aed3SPierre ProncheryIts use can be safely replaced with EC_GROUP_free(). 176*b077aed3SPierre ProncheryIf I<group> is NULL nothing is done. 177*b077aed3SPierre Pronchery 178*b077aed3SPierre ProncheryOSSL_EC_curve_nid2name() converts a curve I<nid> into the corresponding name. 179e71b7053SJung-uk Kim 180e71b7053SJung-uk Kim=head1 RETURN VALUES 181e71b7053SJung-uk Kim 18217f01e99SJung-uk KimAll EC_GROUP_new* functions return a pointer to the newly constructed group, or 18317f01e99SJung-uk KimNULL on error. 184e71b7053SJung-uk Kim 185*b077aed3SPierre ProncheryEC_get_builtin_curves() returns the number of built-in curves that are 186*b077aed3SPierre Proncheryavailable. 187e71b7053SJung-uk Kim 18817f01e99SJung-uk KimEC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), EC_GROUP_set_curve_GF2m(), 18917f01e99SJung-uk KimEC_GROUP_get_curve_GF2m() return 1 on success or 0 on error. 190e71b7053SJung-uk Kim 191*b077aed3SPierre ProncheryOSSL_EC_curve_nid2name() returns a character string constant, or NULL on error. 192*b077aed3SPierre Pronchery 193e71b7053SJung-uk Kim=head1 SEE ALSO 194e71b7053SJung-uk Kim 195e71b7053SJung-uk KimL<crypto(7)>, L<EC_GROUP_copy(3)>, 196e71b7053SJung-uk KimL<EC_POINT_new(3)>, L<EC_POINT_add(3)>, L<EC_KEY_new(3)>, 197*b077aed3SPierre ProncheryL<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)>, 198*b077aed3SPierre ProncheryL<OSSL_LIB_CTX(3)>, L<EVP_PKEY-EC(7)> 199*b077aed3SPierre Pronchery 200*b077aed3SPierre Pronchery=head1 HISTORY 201*b077aed3SPierre Pronchery 202*b077aed3SPierre Pronchery=over 2 203*b077aed3SPierre Pronchery 204*b077aed3SPierre Pronchery=item * 205*b077aed3SPierre Pronchery 206*b077aed3SPierre ProncheryEC_GROUP_new() was deprecated in OpenSSL 3.0. 207*b077aed3SPierre Pronchery 208*b077aed3SPierre ProncheryEC_GROUP_new_by_curve_name_ex() and EC_GROUP_new_from_params() were 209*b077aed3SPierre Proncheryadded in OpenSSL 3.0. 210*b077aed3SPierre Pronchery 211*b077aed3SPierre Pronchery=item * 212*b077aed3SPierre Pronchery 213*b077aed3SPierre ProncheryEC_GROUP_clear_free() was deprecated in OpenSSL 3.0; use EC_GROUP_free() 214*b077aed3SPierre Proncheryinstead. 215*b077aed3SPierre Pronchery 216*b077aed3SPierre Pronchery=item * 217*b077aed3SPierre Pronchery 218*b077aed3SPierre Pronchery EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), 219*b077aed3SPierre Pronchery EC_GROUP_set_curve_GF2m() and EC_GROUP_get_curve_GF2m() were deprecated in 220*b077aed3SPierre Pronchery OpenSSL 3.0; use EC_GROUP_set_curve() and EC_GROUP_get_curve() instead. 221*b077aed3SPierre Pronchery 222*b077aed3SPierre Pronchery=back 223e71b7053SJung-uk Kim 224e71b7053SJung-uk Kim=head1 COPYRIGHT 225e71b7053SJung-uk Kim 226*b077aed3SPierre ProncheryCopyright 2013-2021 The OpenSSL Project Authors. All Rights Reserved. 227e71b7053SJung-uk Kim 228*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 229e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 230e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 231e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 232e71b7053SJung-uk Kim 233e71b7053SJung-uk Kim=cut 234