1=pod 2 3=head1 NAME 4 5EC_GROUP_get_ecparameters, 6EC_GROUP_get_ecpkparameters, 7EC_GROUP_new_from_params, 8EC_GROUP_to_params, 9EC_GROUP_new_from_ecparameters, 10EC_GROUP_new_from_ecpkparameters, 11EC_GROUP_new, 12EC_GROUP_free, 13EC_GROUP_clear_free, 14EC_GROUP_new_curve_GFp, 15EC_GROUP_new_curve_GF2m, 16EC_GROUP_new_by_curve_name_ex, 17EC_GROUP_new_by_curve_name, 18EC_GROUP_set_curve, 19EC_GROUP_get_curve, 20EC_GROUP_set_curve_GFp, 21EC_GROUP_get_curve_GFp, 22EC_GROUP_set_curve_GF2m, 23EC_GROUP_get_curve_GF2m, 24EC_get_builtin_curves, 25OSSL_EC_curve_nid2name - 26Functions for creating and destroying EC_GROUP objects 27 28=head1 SYNOPSIS 29 30 #include <openssl/ec.h> 31 32 EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[], 33 OSSL_LIB_CTX *libctx, const char *propq); 34 OSSL_PARAM *EC_GROUP_to_params(const EC_GROUP *group, OSSL_LIB_CTX *libctx, 35 const char *propq, BN_CTX *bnctx); 36 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); 37 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); 38 void EC_GROUP_free(EC_GROUP *group); 39 40 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, 41 const BIGNUM *b, BN_CTX *ctx); 42 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, 43 const BIGNUM *b, BN_CTX *ctx); 44 EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq, 45 int nid); 46 EC_GROUP *EC_GROUP_new_by_curve_name(int nid); 47 48 int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 49 const BIGNUM *b, BN_CTX *ctx); 50 int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, 51 BN_CTX *ctx); 52 53 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, 54 ECPARAMETERS *params); 55 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, 56 ECPKPARAMETERS *params); 57 58 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 59 const char *OSSL_EC_curve_nid2name(int nid); 60 61The following functions have been deprecated since OpenSSL 3.0, and can be 62hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 63see L<openssl_user_macros(7)>: 64 65 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); 66 void EC_GROUP_clear_free(EC_GROUP *group); 67 68 int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, 69 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 70 int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, 71 BIGNUM *a, BIGNUM *b, BN_CTX *ctx); 72 int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, 73 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 74 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, 75 BIGNUM *a, BIGNUM *b, BN_CTX *ctx); 76 77=head1 DESCRIPTION 78 79Within the library there are two forms of elliptic curve that are of interest. 80The first form is those defined over the prime field Fp. The elements of Fp are 81the integers 0 to p-1, where p is a prime number. This gives us a revised 82elliptic curve equation as follows: 83 84y^2 mod p = x^3 +ax + b mod p 85 86The second form is those defined over a binary field F2^m where the elements of 87the field are integers of length at most m bits. For this form the elliptic 88curve equation is modified to: 89 90y^2 + xy = x^3 + ax^2 + b (where b != 0) 91 92Operations in a binary field are performed relative to an 93B<irreducible polynomial>. All such curves with OpenSSL use a trinomial or a 94pentanomial for this parameter. 95 96Although deprecated since OpenSSL 3.0 and should no longer be used, 97a new curve can be constructed by calling EC_GROUP_new(), using the 98implementation provided by I<meth> (see L<EC_GFp_simple_method(3)>) and 99associated with the library context I<ctx> (see L<OSSL_LIB_CTX(3)>). 100The I<ctx> parameter may be NULL in which case the default library context is 101used. 102It is then necessary to call EC_GROUP_set_curve() to set the curve parameters. 103Applications should instead use one of the other EC_GROUP_new_* constructors. 104 105EC_GROUP_new_from_params() creates a group with parameters specified by I<params>. 106The library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and property query string 107I<propq> are used to fetch algorithms from providers. 108I<params> may be either a list of explicit params or a named group, 109The values for I<ctx> and I<propq> may be NULL. 110The I<params> that can be used are described in 111L<B<EVP_PKEY-EC>(7)|EVP_PKEY-EC(7)/Common EC parameters>. 112 113EC_GROUP_to_params creates an OSSL_PARAM array with the corresponding parameters 114describing the given EC_GROUP. The resulting parameters may contain parameters 115describing a named or explicit curve depending on the EC_GROUP. 116The library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and property query string 117I<propq> are used to fetch algorithms from providers. 118I<bnctx> is an optional preallocated BN_CTX (to save the overhead of allocating 119and freeing the structure in a loop). 120The values for I<libctx>, I<propq> and I<bnctx> may be NULL. 121The caller is responsible for freeing the OSSL_PARAM pointer returned. 122 123EC_GROUP_new_from_ecparameters() will create a group from the 124specified I<params> and 125EC_GROUP_new_from_ecpkparameters() will create a group from the specific PK 126I<params>. 127 128EC_GROUP_set_curve() sets the curve parameters I<p>, I<a> and I<b>. For a curve 129over Fp I<p> is the prime for the field. For a curve over F2^m I<p> represents 130the irreducible polynomial - each bit represents a term in the polynomial. 131Therefore, there will either be three or five bits set dependent on whether the 132polynomial is a trinomial or a pentanomial. 133In either case, I<a> and I<b> represents the coefficients a and b from the 134relevant equation introduced above. 135 136EC_group_get_curve() obtains the previously set curve parameters. 137 138EC_GROUP_set_curve_GFp() and EC_GROUP_set_curve_GF2m() are synonyms for 139EC_GROUP_set_curve(). They are defined for backwards compatibility only and 140should not be used. 141 142EC_GROUP_get_curve_GFp() and EC_GROUP_get_curve_GF2m() are synonyms for 143EC_GROUP_get_curve(). They are defined for backwards compatibility only and 144should not be used. 145 146The functions EC_GROUP_new_curve_GFp() and EC_GROUP_new_curve_GF2m() are 147shortcuts for calling EC_GROUP_new() and then the EC_GROUP_set_curve() function. 148An appropriate default implementation method will be used. 149 150Whilst the library can be used to create any curve using the functions described 151above, there are also a number of predefined curves that are available. In order 152to obtain a list of all of the predefined curves, call the function 153EC_get_builtin_curves(). The parameter I<r> should be an array of 154EC_builtin_curve structures of size I<nitems>. The function will populate the 155I<r> array with information about the built-in curves. If I<nitems> is less than 156the total number of curves available, then the first I<nitems> curves will be 157returned. Otherwise the total number of curves will be provided. The return 158value is the total number of curves available (whether that number has been 159populated in I<r> or not). Passing a NULL I<r>, or setting I<nitems> to 0 will 160do nothing other than return the total number of curves available. 161The EC_builtin_curve structure is defined as follows: 162 163 typedef struct { 164 int nid; 165 const char *comment; 166 } EC_builtin_curve; 167 168Each EC_builtin_curve item has a unique integer id (I<nid>), and a human 169readable comment string describing the curve. 170 171In order to construct a built-in curve use the function 172EC_GROUP_new_by_curve_name_ex() and provide the I<nid> of the curve to 173be constructed, the associated library context to be used in I<ctx> (see 174L<OSSL_LIB_CTX(3)>) and any property query string in I<propq>. The I<ctx> value 175may be NULL in which case the default library context is used. The I<propq> 176value may also be NULL. 177 178EC_GROUP_new_by_curve_name() is the same as 179EC_GROUP_new_by_curve_name_ex() except that the default library context 180is always used along with a NULL property query string. 181 182EC_GROUP_free() frees the memory associated with the EC_GROUP. 183If I<group> is NULL nothing is done. 184 185EC_GROUP_clear_free() is deprecated: it was meant to destroy any sensitive data 186held within the EC_GROUP and then free its memory, but since all the data stored 187in the EC_GROUP is public anyway, this function is unnecessary. 188Its use can be safely replaced with EC_GROUP_free(). 189If I<group> is NULL nothing is done. 190 191OSSL_EC_curve_nid2name() converts a curve I<nid> into the corresponding name. 192 193=head1 RETURN VALUES 194 195All EC_GROUP_new* functions return a pointer to the newly constructed group, or 196NULL on error. 197 198EC_get_builtin_curves() returns the number of built-in curves that are 199available. 200 201EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), EC_GROUP_set_curve_GF2m(), 202EC_GROUP_get_curve_GF2m() return 1 on success or 0 on error. 203 204OSSL_EC_curve_nid2name() returns a character string constant, or NULL on error. 205 206=head1 SEE ALSO 207 208L<crypto(7)>, L<EC_GROUP_copy(3)>, 209L<EC_POINT_new(3)>, L<EC_POINT_add(3)>, L<EC_KEY_new(3)>, 210L<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)>, 211L<OSSL_LIB_CTX(3)>, L<EVP_PKEY-EC(7)> 212 213=head1 HISTORY 214 215EC_GROUP_to_params() was added in OpenSSL 3.2. 216 217=over 2 218 219=item * 220 221EC_GROUP_new() was deprecated in OpenSSL 3.0. 222 223EC_GROUP_new_by_curve_name_ex() and EC_GROUP_new_from_params() were 224added in OpenSSL 3.0. 225 226=item * 227 228EC_GROUP_clear_free() was deprecated in OpenSSL 3.0; use EC_GROUP_free() 229instead. 230 231=item * 232 233 EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), 234 EC_GROUP_set_curve_GF2m() and EC_GROUP_get_curve_GF2m() were deprecated in 235 OpenSSL 3.0; use EC_GROUP_set_curve() and EC_GROUP_get_curve() instead. 236 237=back 238 239=head1 COPYRIGHT 240 241Copyright 2013-2024 The OpenSSL Project Authors. All Rights Reserved. 242 243Licensed under the Apache License 2.0 (the "License"). You may not use 244this file except in compliance with the License. You can obtain a copy 245in the file LICENSE in the source distribution or at 246L<https://www.openssl.org/source/license.html>. 247 248=cut 249