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