xref: /aosp_15_r20/external/cronet/third_party/boringssl/src/include/openssl/ec.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 /* Originally written by Bodo Moeller for the OpenSSL project.
2  * ====================================================================
3  * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. All advertising materials mentioning features or use of this
18  *    software must display the following acknowledgment:
19  *    "This product includes software developed by the OpenSSL Project
20  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21  *
22  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23  *    endorse or promote products derived from this software without
24  *    prior written permission. For written permission, please contact
25  *    [email protected].
26  *
27  * 5. Products derived from this software may not be called "OpenSSL"
28  *    nor may "OpenSSL" appear in their names without prior written
29  *    permission of the OpenSSL Project.
30  *
31  * 6. Redistributions of any form whatsoever must retain the following
32  *    acknowledgment:
33  *    "This product includes software developed by the OpenSSL Project
34  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47  * OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This product includes cryptographic software written by Eric Young
51  * ([email protected]).  This product includes software written by Tim
52  * Hudson ([email protected]).
53  *
54  */
55 /* ====================================================================
56  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57  *
58  * Portions of the attached software ("Contribution") are developed by
59  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
60  *
61  * The Contribution is licensed pursuant to the OpenSSL open source
62  * license provided above.
63  *
64  * The elliptic curve binary polynomial software is originally written by
65  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
66  * Laboratories. */
67 
68 #ifndef OPENSSL_HEADER_EC_H
69 #define OPENSSL_HEADER_EC_H
70 
71 #include <openssl/base.h>
72 
73 #if defined(__cplusplus)
74 extern "C" {
75 #endif
76 
77 
78 // Low-level operations on elliptic curves.
79 
80 
81 // point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for
82 // the encoding of a elliptic curve point (x,y)
83 typedef enum {
84   // POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x,
85   // where the octet z specifies which solution of the quadratic equation y
86   // is.
87   POINT_CONVERSION_COMPRESSED = 2,
88 
89   // POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as
90   // z||x||y, where z is the octet 0x04.
91   POINT_CONVERSION_UNCOMPRESSED = 4,
92 
93   // POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y,
94   // where z specifies which solution of the quadratic equation y is. This is
95   // not supported by the code and has never been observed in use.
96   //
97   // TODO(agl): remove once node.js no longer references this.
98   POINT_CONVERSION_HYBRID = 6,
99 } point_conversion_form_t;
100 
101 
102 // Elliptic curve groups.
103 //
104 // Elliptic curve groups are represented by |EC_GROUP| objects. Unlike OpenSSL,
105 // if limited to the APIs in this section, callers may treat |EC_GROUP|s as
106 // static, immutable objects which do not need to be copied or released. In
107 // BoringSSL, only custom |EC_GROUP|s created by |EC_GROUP_new_curve_GFp|
108 // (deprecated) are dynamic.
109 //
110 // Callers may cast away |const| and use |EC_GROUP_dup| and |EC_GROUP_free| with
111 // static groups, for compatibility with OpenSSL or dynamic groups, but it is
112 // otherwise unnecessary.
113 
114 // EC_group_p224 returns an |EC_GROUP| for P-224, also known as secp224r1.
115 OPENSSL_EXPORT const EC_GROUP *EC_group_p224(void);
116 
117 // EC_group_p256 returns an |EC_GROUP| for P-256, also known as secp256r1 or
118 // prime256v1.
119 OPENSSL_EXPORT const EC_GROUP *EC_group_p256(void);
120 
121 // EC_group_p384 returns an |EC_GROUP| for P-384, also known as secp384r1.
122 OPENSSL_EXPORT const EC_GROUP *EC_group_p384(void);
123 
124 // EC_group_p521 returns an |EC_GROUP| for P-521, also known as secp521r1.
125 OPENSSL_EXPORT const EC_GROUP *EC_group_p521(void);
126 
127 // EC_GROUP_new_by_curve_name returns the |EC_GROUP| object for the elliptic
128 // curve specified by |nid|, or NULL on unsupported NID.  For OpenSSL
129 // compatibility, this function returns a non-const pointer which may be passed
130 // to |EC_GROUP_free|. However, the resulting object is actually static and
131 // calling |EC_GROUP_free| is optional.
132 //
133 // The supported NIDs are:
134 // - |NID_secp224r1| (P-224)
135 // - |NID_X9_62_prime256v1| (P-256)
136 // - |NID_secp384r1| (P-384)
137 // - |NID_secp521r1| (P-521)
138 //
139 // Calling this function causes all four curves to be linked into the binary.
140 // Prefer calling |EC_group_*| to allow the static linker to drop unused curves.
141 //
142 // If in doubt, use |NID_X9_62_prime256v1|, or see the curve25519.h header for
143 // more modern primitives.
144 OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
145 
146 // EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero
147 // otherwise.
148 OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b,
149                                 BN_CTX *ignored);
150 
151 // EC_GROUP_get0_generator returns a pointer to the internal |EC_POINT| object
152 // in |group| that specifies the generator for the group.
153 OPENSSL_EXPORT const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
154 
155 // EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in
156 // |group| that specifies the order of the group.
157 OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
158 
159 // EC_GROUP_order_bits returns the number of bits of the order of |group|.
160 OPENSSL_EXPORT int EC_GROUP_order_bits(const EC_GROUP *group);
161 
162 // EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using
163 // |ctx|, if it's not NULL. It returns one on success and zero otherwise.
164 OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group,
165                                          BIGNUM *cofactor, BN_CTX *ctx);
166 
167 // EC_GROUP_get_curve_GFp gets various parameters about a group. It sets
168 // |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to
169 // the parameters of the curve when expressed as y² = x³ + ax + b. Any of the
170 // output parameters can be NULL. It returns one on success and zero on
171 // error.
172 OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p,
173                                           BIGNUM *out_a, BIGNUM *out_b,
174                                           BN_CTX *ctx);
175 
176 // EC_GROUP_get_curve_name returns a NID that identifies |group|.
177 OPENSSL_EXPORT int EC_GROUP_get_curve_name(const EC_GROUP *group);
178 
179 // EC_GROUP_get_degree returns the number of bits needed to represent an
180 // element of the field underlying |group|.
181 OPENSSL_EXPORT unsigned EC_GROUP_get_degree(const EC_GROUP *group);
182 
183 // EC_curve_nid2nist returns the NIST name of the elliptic curve specified by
184 // |nid|, or NULL if |nid| is not a NIST curve. For example, it returns "P-256"
185 // for |NID_X9_62_prime256v1|.
186 OPENSSL_EXPORT const char *EC_curve_nid2nist(int nid);
187 
188 // EC_curve_nist2nid returns the NID of the elliptic curve specified by the NIST
189 // name |name|, or |NID_undef| if |name| is not a recognized name. For example,
190 // it returns |NID_X9_62_prime256v1| for "P-256".
191 OPENSSL_EXPORT int EC_curve_nist2nid(const char *name);
192 
193 
194 // Points on elliptic curves.
195 
196 // EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL
197 // on error.
198 OPENSSL_EXPORT EC_POINT *EC_POINT_new(const EC_GROUP *group);
199 
200 // EC_POINT_free frees |point| and the data that it points to.
201 OPENSSL_EXPORT void EC_POINT_free(EC_POINT *point);
202 
203 // EC_POINT_copy sets |*dest| equal to |*src|. It returns one on success and
204 // zero otherwise.
205 OPENSSL_EXPORT int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src);
206 
207 // EC_POINT_dup returns a fresh |EC_POINT| that contains the same values as
208 // |src|, or NULL on error.
209 OPENSSL_EXPORT EC_POINT *EC_POINT_dup(const EC_POINT *src,
210                                       const EC_GROUP *group);
211 
212 // EC_POINT_set_to_infinity sets |point| to be the "point at infinity" for the
213 // given group.
214 OPENSSL_EXPORT int EC_POINT_set_to_infinity(const EC_GROUP *group,
215                                             EC_POINT *point);
216 
217 // EC_POINT_is_at_infinity returns one iff |point| is the point at infinity and
218 // zero otherwise.
219 OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group,
220                                            const EC_POINT *point);
221 
222 // EC_POINT_is_on_curve returns one if |point| is an element of |group| and
223 // and zero otherwise or when an error occurs. This is different from OpenSSL,
224 // which returns -1 on error. If |ctx| is non-NULL, it may be used.
225 OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group,
226                                         const EC_POINT *point, BN_CTX *ctx);
227 
228 // EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if
229 // not equal and -1 on error. If |ctx| is not NULL, it may be used.
230 OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a,
231                                 const EC_POINT *b, BN_CTX *ctx);
232 
233 
234 // Point conversion.
235 
236 // EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of
237 // |point| using |ctx|, if it's not NULL. It returns one on success and zero
238 // otherwise.
239 //
240 // Either |x| or |y| may be NULL to skip computing that coordinate. This is
241 // slightly faster in the common case where only the x-coordinate is needed.
242 OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
243                                                        const EC_POINT *point,
244                                                        BIGNUM *x, BIGNUM *y,
245                                                        BN_CTX *ctx);
246 
247 // EC_POINT_get_affine_coordinates is an alias of
248 // |EC_POINT_get_affine_coordinates_GFp|.
249 OPENSSL_EXPORT int EC_POINT_get_affine_coordinates(const EC_GROUP *group,
250                                                    const EC_POINT *point,
251                                                    BIGNUM *x, BIGNUM *y,
252                                                    BN_CTX *ctx);
253 
254 // EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
255 // (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
256 // on success or zero on error. It's considered an error if the point is not on
257 // the curve.
258 //
259 // Note that the corresponding function in OpenSSL versions prior to 1.0.2s does
260 // not check if the point is on the curve. This is a security-critical check, so
261 // code additionally supporting OpenSSL should repeat the check with
262 // |EC_POINT_is_on_curve| or check for older OpenSSL versions with
263 // |OPENSSL_VERSION_NUMBER|.
264 OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
265                                                        EC_POINT *point,
266                                                        const BIGNUM *x,
267                                                        const BIGNUM *y,
268                                                        BN_CTX *ctx);
269 
270 // EC_POINT_set_affine_coordinates is an alias of
271 // |EC_POINT_set_affine_coordinates_GFp|.
272 OPENSSL_EXPORT int EC_POINT_set_affine_coordinates(const EC_GROUP *group,
273                                                    EC_POINT *point,
274                                                    const BIGNUM *x,
275                                                    const BIGNUM *y,
276                                                    BN_CTX *ctx);
277 
278 // EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
279 // into, at most, |max_out| bytes at |buf|. It returns the number of bytes
280 // written or zero on error if |buf| is non-NULL, else the number of bytes
281 // needed. The |ctx| argument may be used if not NULL.
282 OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
283                                          const EC_POINT *point,
284                                          point_conversion_form_t form,
285                                          uint8_t *buf, size_t max_out,
286                                          BN_CTX *ctx);
287 
288 // EC_POINT_point2buf serialises |point| into the X9.62 form given by |form| to
289 // a newly-allocated buffer and sets |*out_buf| to point to it. It returns the
290 // length of the result on success or zero on error. The caller must release
291 // |*out_buf| with |OPENSSL_free| when done.
292 OPENSSL_EXPORT size_t EC_POINT_point2buf(const EC_GROUP *group,
293                                          const EC_POINT *point,
294                                          point_conversion_form_t form,
295                                          uint8_t **out_buf, BN_CTX *ctx);
296 
297 // EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the
298 // serialised point to |cbb|. It returns one on success and zero on error.
299 OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group,
300                                       const EC_POINT *point,
301                                       point_conversion_form_t form,
302                                       BN_CTX *ctx);
303 
304 // EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format
305 // serialisation in |buf|. It returns one on success and zero on error. The
306 // |ctx| argument may be used if not NULL. It's considered an error if |buf|
307 // does not represent a point on the curve.
308 OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
309                                       const uint8_t *buf, size_t len,
310                                       BN_CTX *ctx);
311 
312 // EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with
313 // the given |x| coordinate and the y coordinate specified by |y_bit| (see
314 // X9.62). It returns one on success and zero otherwise.
315 OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
316     const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit,
317     BN_CTX *ctx);
318 
319 
320 // Group operations.
321 
322 // EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and
323 // zero otherwise. If |ctx| is not NULL, it may be used.
324 OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r,
325                                 const EC_POINT *a, const EC_POINT *b,
326                                 BN_CTX *ctx);
327 
328 // EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and
329 // zero otherwise. If |ctx| is not NULL, it may be used.
330 OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r,
331                                 const EC_POINT *a, BN_CTX *ctx);
332 
333 // EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and
334 // zero otherwise. If |ctx| is not NULL, it may be used.
335 OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a,
336                                    BN_CTX *ctx);
337 
338 // EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero
339 // otherwise. If |ctx| is not NULL, it may be used.
340 OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
341                                 const BIGNUM *n, const EC_POINT *q,
342                                 const BIGNUM *m, BN_CTX *ctx);
343 
344 
345 // Hash-to-curve.
346 //
347 // The following functions implement primitives from RFC 9380. The |dst|
348 // parameter in each function is the domain separation tag and must be unique
349 // for each protocol and between the |hash_to_curve| and |hash_to_scalar|
350 // variants. See section 3.1 of the spec for additional guidance on this
351 // parameter.
352 
353 // EC_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
354 // writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
355 // from RFC 9380. It returns one on success and zero on error.
356 OPENSSL_EXPORT int EC_hash_to_curve_p256_xmd_sha256_sswu(
357     const EC_GROUP *group, EC_POINT *out, const uint8_t *dst, size_t dst_len,
358     const uint8_t *msg, size_t msg_len);
359 
360 // EC_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
361 // writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
362 // from RFC 9380. It returns one on success and zero on error.
363 OPENSSL_EXPORT int EC_hash_to_curve_p384_xmd_sha384_sswu(
364     const EC_GROUP *group, EC_POINT *out, const uint8_t *dst, size_t dst_len,
365     const uint8_t *msg, size_t msg_len);
366 
367 
368 // Deprecated functions.
369 
370 // EC_GROUP_free releases a reference to |group|, if |group| was created by
371 // |EC_GROUP_new_curve_GFp|. If |group| is static, it does nothing.
372 //
373 // This function exists for OpenSSL compatibilty, and to manage dynamic
374 // |EC_GROUP|s constructed by |EC_GROUP_new_curve_GFp|. Callers that do not need
375 // either may ignore this function.
376 OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group);
377 
378 // EC_GROUP_dup increments |group|'s reference count and returns it, if |group|
379 // was created by |EC_GROUP_new_curve_GFp|. If |group| is static, it simply
380 // returns |group|.
381 //
382 // This function exists for OpenSSL compatibilty, and to manage dynamic
383 // |EC_GROUP|s constructed by |EC_GROUP_new_curve_GFp|. Callers that do not need
384 // either may ignore this function.
385 OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *group);
386 
387 // EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based
388 // on the equation y² = x³ + a·x + b. It returns the new group or NULL on
389 // error. The lifetime of the resulting object must be managed with
390 // |EC_GROUP_dup| and |EC_GROUP_free|.
391 //
392 // This new group has no generator. It is an error to use a generator-less group
393 // with any functions except for |EC_GROUP_free|, |EC_POINT_new|,
394 // |EC_POINT_set_affine_coordinates_GFp|, and |EC_GROUP_set_generator|.
395 //
396 // |EC_GROUP|s returned by this function will always compare as unequal via
397 // |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always
398 // return |NID_undef|.
399 //
400 // This function is provided for compatibility with some legacy applications
401 // only. Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name|
402 // instead. This ensures the result meets preconditions necessary for
403 // elliptic curve algorithms to function correctly and securely.
404 //
405 // Given invalid parameters, this function may fail or it may return an
406 // |EC_GROUP| which breaks these preconditions. Subsequent operations may then
407 // return arbitrary, incorrect values. Callers should not pass
408 // attacker-controlled values to this function.
409 OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p,
410                                                 const BIGNUM *a,
411                                                 const BIGNUM *b, BN_CTX *ctx);
412 
413 // EC_GROUP_set_generator sets the generator for |group| to |generator|, which
414 // must have the given order and cofactor. It may only be used with |EC_GROUP|
415 // objects returned by |EC_GROUP_new_curve_GFp| and may only be used once on
416 // each group. |generator| must have been created using |group|.
417 OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group,
418                                           const EC_POINT *generator,
419                                           const BIGNUM *order,
420                                           const BIGNUM *cofactor);
421 
422 // EC_GROUP_get_order sets |*order| to the order of |group|, if it's not
423 // NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use
424 // |EC_GROUP_get0_order| instead.
425 OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order,
426                                       BN_CTX *ctx);
427 
428 #define OPENSSL_EC_EXPLICIT_CURVE 0
429 #define OPENSSL_EC_NAMED_CURVE 1
430 
431 // EC_GROUP_set_asn1_flag does nothing.
432 OPENSSL_EXPORT void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
433 
434 // EC_GROUP_get_asn1_flag returns |OPENSSL_EC_NAMED_CURVE|.
435 OPENSSL_EXPORT int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
436 
437 typedef struct ec_method_st EC_METHOD;
438 
439 // EC_GROUP_method_of returns a dummy non-NULL pointer.
440 OPENSSL_EXPORT const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
441 
442 // EC_METHOD_get_field_type returns NID_X9_62_prime_field.
443 OPENSSL_EXPORT int EC_METHOD_get_field_type(const EC_METHOD *meth);
444 
445 // EC_GROUP_set_point_conversion_form aborts the process if |form| is not
446 // |POINT_CONVERSION_UNCOMPRESSED| and otherwise does nothing.
447 OPENSSL_EXPORT void EC_GROUP_set_point_conversion_form(
448     EC_GROUP *group, point_conversion_form_t form);
449 
450 // EC_builtin_curve describes a supported elliptic curve.
451 typedef struct {
452   int nid;
453   const char *comment;
454 } EC_builtin_curve;
455 
456 // EC_get_builtin_curves writes at most |max_num_curves| elements to
457 // |out_curves| and returns the total number that it would have written, had
458 // |max_num_curves| been large enough.
459 //
460 // The |EC_builtin_curve| items describe the supported elliptic curves.
461 OPENSSL_EXPORT size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
462                                             size_t max_num_curves);
463 
464 // EC_POINT_clear_free calls |EC_POINT_free|.
465 OPENSSL_EXPORT void EC_POINT_clear_free(EC_POINT *point);
466 
467 
468 #if defined(__cplusplus)
469 }  // extern C
470 #endif
471 
472 // Old code expects to get EC_KEY from ec.h.
473 #include <openssl/ec_key.h>
474 
475 #if defined(__cplusplus)
476 extern "C++" {
477 
478 BSSL_NAMESPACE_BEGIN
479 
480 BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free)
481 BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free)
482 
483 BSSL_NAMESPACE_END
484 
485 }  // extern C++
486 
487 #endif
488 
489 #define EC_R_BUFFER_TOO_SMALL 100
490 #define EC_R_COORDINATES_OUT_OF_RANGE 101
491 #define EC_R_D2I_ECPKPARAMETERS_FAILURE 102
492 #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 103
493 #define EC_R_GROUP2PKPARAMETERS_FAILURE 104
494 #define EC_R_I2D_ECPKPARAMETERS_FAILURE 105
495 #define EC_R_INCOMPATIBLE_OBJECTS 106
496 #define EC_R_INVALID_COMPRESSED_POINT 107
497 #define EC_R_INVALID_COMPRESSION_BIT 108
498 #define EC_R_INVALID_ENCODING 109
499 #define EC_R_INVALID_FIELD 110
500 #define EC_R_INVALID_FORM 111
501 #define EC_R_INVALID_GROUP_ORDER 112
502 #define EC_R_INVALID_PRIVATE_KEY 113
503 #define EC_R_MISSING_PARAMETERS 114
504 #define EC_R_MISSING_PRIVATE_KEY 115
505 #define EC_R_NON_NAMED_CURVE 116
506 #define EC_R_NOT_INITIALIZED 117
507 #define EC_R_PKPARAMETERS2GROUP_FAILURE 118
508 #define EC_R_POINT_AT_INFINITY 119
509 #define EC_R_POINT_IS_NOT_ON_CURVE 120
510 #define EC_R_SLOT_FULL 121
511 #define EC_R_UNDEFINED_GENERATOR 122
512 #define EC_R_UNKNOWN_GROUP 123
513 #define EC_R_UNKNOWN_ORDER 124
514 #define EC_R_WRONG_ORDER 125
515 #define EC_R_BIGNUM_OUT_OF_RANGE 126
516 #define EC_R_WRONG_CURVE_PARAMETERS 127
517 #define EC_R_DECODE_ERROR 128
518 #define EC_R_ENCODE_ERROR 129
519 #define EC_R_GROUP_MISMATCH 130
520 #define EC_R_INVALID_COFACTOR 131
521 #define EC_R_PUBLIC_KEY_VALIDATION_FAILED 132
522 #define EC_R_INVALID_SCALAR 133
523 
524 #endif  // OPENSSL_HEADER_EC_H
525