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