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