Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/include/openssl/ec.h

raw
1 // Originally written by Bodo Moeller for the OpenSSL project.
2 // Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
3 // Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 //
5 // The elliptic curve binary polynomial software is originally written by
6 // Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
7 // Laboratories.
8 //
9 // SPDX-License-Identifier: Apache-2.0
10
11 #ifndef OPENSSL_HEADER_EC_H
12 #define OPENSSL_HEADER_EC_H
13
14 #include <openssl/base.h>
15
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
19
20
21 // Low-level operations on elliptic curves.
22
23
24 // point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for
25 // the encoding of a elliptic curve point (x,y)
26 typedef enum {
27 // POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x,
28 // where the octet z specifies which solution of the quadratic equation y
29 // is.
30 POINT_CONVERSION_COMPRESSED = 2,
31
32 // POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as
33 // z||x||y, where z is the octet 0x04.
34 POINT_CONVERSION_UNCOMPRESSED = 4,
35
36 // POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y,
37 // where z specifies which solution of the quadratic equation y is.
38 POINT_CONVERSION_HYBRID = 6
39 } point_conversion_form_t;
40
41
42 // Elliptic curve groups.
43 //
44 // Elliptic curve groups are represented by |EC_GROUP| objects. Unlike OpenSSL,
45 // if limited to the APIs in this section, callers may treat |EC_GROUP|s as
46 // static, immutable objects which do not need to be copied or released. In
47 // BoringSSL, only custom |EC_GROUP|s created by |EC_GROUP_new_curve_GFp|
48 // (deprecated) are dynamic.
49 //
50 // Callers may cast away |const| and use |EC_GROUP_dup| and |EC_GROUP_free| with
51 // static groups, for compatibility with OpenSSL or dynamic groups, but it is
52 // otherwise unnecessary.
53
54 // EC_group_p224 returns an |EC_GROUP| for P-224, also known as secp224r1.
55 OPENSSL_EXPORT const EC_GROUP *EC_group_p224(void);
56
57 // EC_group_p256 returns an |EC_GROUP| for P-256, also known as secp256r1 or
58 // prime256v1.
59 OPENSSL_EXPORT const EC_GROUP *EC_group_p256(void);
60
61 // EC_group_p384 returns an |EC_GROUP| for P-384, also known as secp384r1.
62 OPENSSL_EXPORT const EC_GROUP *EC_group_p384(void);
63
64 // EC_group_p521 returns an |EC_GROUP| for P-521, also known as secp521r1.
65 OPENSSL_EXPORT const EC_GROUP *EC_group_p521(void);
66
67 // EC_group_secp256k1 returns an |EC_GROUP| for secp256k1.
68 OPENSSL_EXPORT const EC_GROUP *EC_group_secp256k1(void);
69
70 // EC_GROUP_new_by_curve_name returns the |EC_GROUP| object for the elliptic
71 // curve specified by |nid|, or NULL on unsupported NID. For OpenSSL
72 // compatibility, this function returns a non-const pointer which may be passed
73 // to |EC_GROUP_free|. However, the resulting object is actually static and
74 // calling |EC_GROUP_free| is optional.
75 //
76 // The supported NIDs are (see crypto/fipsmodule/ec/ec.c):
77 // - |NID_secp224r1| (NIST P-224)
78 // - |NID_X9_62_prime256v1| (NIST P-256)
79 // - |NID_secp384r1| (NIST P-384)
80 // - |NID_secp521r1| (NIST P-521)
81 // - |NID_secp256k1| (SEC/ANSI P-256 K1)
82 //
83 // Calling this function causes all four curves to be linked into the binary.
84 // Prefer calling |EC_group_*| to allow the static linker to drop unused curves.
85 //
86 // If in doubt, use |NID_X9_62_prime256v1|, or see the curve25519.h header for
87 // more modern primitives.
88 OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
89
90 // EC_GROUP_new_by_curve_name_mutable is like |EC_GROUP_new_by_curve_name|, but
91 // dynamically allocates a mutable |EC_GROUP| pointer for more OpenSSL
92 // compatibility. Although |EC_GROUP_new_by_curve_name| returns a const pointer
93 // under the hood, resulting objects returned by this function MUST be freed
94 // by |EC_GROUP_free|.
95 //
96 // Note: Users should use |EC_GROUP_new_by_curve_name| when possible.
97 OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name_mutable(int nid);
98
99 // EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero
100 // otherwise.
101 OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b,
102 BN_CTX *ignored);
103
104 // EC_GROUP_get0_generator returns a pointer to the internal |EC_POINT| object
105 // in |group| that specifies the generator for the group.
106 OPENSSL_EXPORT const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
107
108 // EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in
109 // |group| that specifies the order of the group.
110 OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
111
112 // EC_GROUP_order_bits returns the number of bits of the order of |group|.
113 OPENSSL_EXPORT int EC_GROUP_order_bits(const EC_GROUP *group);
114
115 // EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using
116 // |ctx|, if it's not NULL. It returns one on success and zero otherwise.
117 OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group,
118 BIGNUM *cofactor, BN_CTX *ctx);
119
120 // EC_GROUP_get_curve_GFp gets various parameters about a group. It sets
121 // |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to
122 // the parameters of the curve when expressed as y² = x³ + ax + b. Any of the
123 // output parameters can be NULL. It returns one on success and zero on
124 // error.
125 OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p,
126 BIGNUM *out_a, BIGNUM *out_b,
127 BN_CTX *ctx);
128
129 // EC_GROUP_get_curve_name returns a NID that identifies |group|.
130 OPENSSL_EXPORT int EC_GROUP_get_curve_name(const EC_GROUP *group);
131
132 // EC_GROUP_get_degree returns the number of bits needed to represent an
133 // element of the field underlying |group|.
134 OPENSSL_EXPORT unsigned EC_GROUP_get_degree(const EC_GROUP *group);
135
136 // EC_curve_nid2nist returns the NIST name of the elliptic curve specified by
137 // |nid|, or NULL if |nid| is not a NIST curve. For example, it returns "P-256"
138 // for |NID_X9_62_prime256v1|.
139 OPENSSL_EXPORT const char *EC_curve_nid2nist(int nid);
140
141 // EC_curve_nist2nid returns the NID of the elliptic curve specified by the NIST
142 // name |name|, or |NID_undef| if |name| is not a recognized name. For example,
143 // it returns |NID_X9_62_prime256v1| for "P-256".
144 OPENSSL_EXPORT int EC_curve_nist2nid(const char *name);
145
146 // Points on elliptic curves.
147
148 // EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL
149 // on error.
150 OPENSSL_EXPORT EC_POINT *EC_POINT_new(const EC_GROUP *group);
151
152 // EC_POINT_free frees |point| and the data that it points to.
153 OPENSSL_EXPORT void EC_POINT_free(EC_POINT *point);
154
155 // EC_POINT_copy sets |*dest| equal to |*src|. It returns one on success and
156 // zero otherwise.
157 OPENSSL_EXPORT int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src);
158
159 // EC_POINT_dup returns a fresh |EC_POINT| that contains the same values as
160 // |src|, or NULL on error.
161 OPENSSL_EXPORT EC_POINT *EC_POINT_dup(const EC_POINT *src,
162 const EC_GROUP *group);
163
164 // EC_POINT_set_to_infinity sets |point| to be the "point at infinity" for the
165 // given group.
166 OPENSSL_EXPORT int EC_POINT_set_to_infinity(const EC_GROUP *group,
167 EC_POINT *point);
168
169 // EC_POINT_is_at_infinity returns one iff |point| is the point at infinity and
170 // zero otherwise.
171 OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group,
172 const EC_POINT *point);
173
174 // EC_POINT_is_on_curve returns one if |point| is an element of |group| and
175 // and zero otherwise or when an error occurs. This is different from OpenSSL,
176 // which returns -1 on error. If |ctx| is non-NULL, it may be used.
177 OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group,
178 const EC_POINT *point, BN_CTX *ctx);
179
180 // EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if
181 // not equal and -1 on error. If |ctx| is not NULL, it may be used.
182 OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a,
183 const EC_POINT *b, BN_CTX *ctx);
184
185
186 // Point conversion.
187
188 // EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of
189 // |point| using |ctx|, if it's not NULL. It returns one on success and zero
190 // otherwise.
191 //
192 // Either |x| or |y| may be NULL to skip computing that coordinate. This is
193 // slightly faster in the common case where only the x-coordinate is needed.
194 OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
195 const EC_POINT *point,
196 BIGNUM *x, BIGNUM *y,
197 BN_CTX *ctx);
198
199 // EC_POINT_get_affine_coordinates is an alias of
200 // |EC_POINT_get_affine_coordinates_GFp|.
201 OPENSSL_EXPORT int EC_POINT_get_affine_coordinates(const EC_GROUP *group,
202 const EC_POINT *point,
203 BIGNUM *x, BIGNUM *y,
204 BN_CTX *ctx);
205
206 // EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
207 // (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
208 // on success or zero on error. It's considered an error if the point is not on
209 // the curve.
210 //
211 // Note that the corresponding function in OpenSSL versions prior to 1.0.2s does
212 // not check if the point is on the curve. This is a security-critical check, so
213 // code additionally supporting OpenSSL should repeat the check with
214 // |EC_POINT_is_on_curve| or check for older OpenSSL versions with
215 // |OPENSSL_VERSION_NUMBER|.
216 OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
217 EC_POINT *point,
218 const BIGNUM *x,
219 const BIGNUM *y,
220 BN_CTX *ctx);
221
222 // EC_POINT_set_affine_coordinates is an alias of
223 // |EC_POINT_set_affine_coordinates_GFp|.
224 OPENSSL_EXPORT int EC_POINT_set_affine_coordinates(const EC_GROUP *group,
225 EC_POINT *point,
226 const BIGNUM *x,
227 const BIGNUM *y,
228 BN_CTX *ctx);
229
230 // EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
231 // into, at most, |len| bytes at |buf|. It returns the number of bytes written
232 // or zero on error if |buf| is non-NULL, else the number of bytes needed. The
233 // |ctx| argument may be used if not NULL.
234 OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
235 const EC_POINT *point,
236 point_conversion_form_t form,
237 uint8_t *buf, size_t len, BN_CTX *ctx);
238
239 // EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the
240 // serialised point to |cbb|. It returns one on success and zero on error.
241 OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group,
242 const EC_POINT *point,
243 point_conversion_form_t form,
244 BN_CTX *ctx);
245
246 // EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format
247 // serialisation in |buf|. It returns one on success and zero on error. The
248 // |ctx| argument may be used if not NULL. It's considered an error if |buf|
249 // does not represent a point on the curve.
250 OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
251 const uint8_t *buf, size_t len,
252 BN_CTX *ctx);
253
254 // EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with
255 // the given |x| coordinate and the y coordinate specified by |y_bit| (see
256 // X9.62). It returns one on success and zero otherwise.
257 OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
258 const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit,
259 BN_CTX *ctx);
260
261
262 // Group operations.
263
264 // EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and
265 // zero otherwise. If |ctx| is not NULL, it may be used.
266 OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r,
267 const EC_POINT *a, const EC_POINT *b,
268 BN_CTX *ctx);
269
270 // EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and
271 // zero otherwise. If |ctx| is not NULL, it may be used.
272 OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r,
273 const EC_POINT *a, BN_CTX *ctx);
274
275 // EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and
276 // zero otherwise. If |ctx| is not NULL, it may be used.
277 OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a,
278 BN_CTX *ctx);
279
280 // EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero
281 // otherwise. If |ctx| is not NULL, it may be used.
282 OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
283 const BIGNUM *n, const EC_POINT *q,
284 const BIGNUM *m, BN_CTX *ctx);
285
286
287 // Hash-to-curve.
288 //
289 // The following functions implement primitives from RFC 9380. The |dst|
290 // parameter in each function is the domain separation tag and must be unique
291 // for each protocol and between the |hash_to_curve| and |hash_to_scalar|
292 // variants. See section 3.1 of the spec for additional guidance on this
293 // parameter.
294
295 // EC_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
296 // writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
297 // from RFC 9380. It returns one on success and zero on error.
298 OPENSSL_EXPORT int EC_hash_to_curve_p256_xmd_sha256_sswu(
299 const EC_GROUP *group, EC_POINT *out, const uint8_t *dst, size_t dst_len,
300 const uint8_t *msg, size_t msg_len);
301
302 // EC_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
303 // writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
304 // from RFC 9380. It returns one on success and zero on error.
305 OPENSSL_EXPORT int EC_hash_to_curve_p384_xmd_sha384_sswu(
306 const EC_GROUP *group, EC_POINT *out, const uint8_t *dst, size_t dst_len,
307 const uint8_t *msg, size_t msg_len);
308
309 // EC_GROUP_free releases a reference to |group|, if |group| was created by
310 // |EC_GROUP_new_by_curve_name_mutable| or |EC_GROUP_new_curve_GFp|. If
311 // |group| is static, it does nothing.
312 //
313 // This function exists for OpenSSL compatibility, and to manage dynamic
314 // |EC_GROUP|s constructed by |EC_GROUP_new_by_curve_name_mutable| and
315 // |EC_GROUP_new_curve_GFp|. Callers that do not need either may ignore this
316 // function.
317 OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group);
318
319 // EC_GROUP_dup increments |group|'s reference count and returns it, if |group|
320 // was created by |EC_GROUP_new_curve_GFp|. If |group| was created by
321 // |EC_GROUP_new_by_curve_name_mutable|, it does a deep copy of |group|. If
322 // |group| is static, it simply returns |group|.
323 //
324 // This function exists for OpenSSL compatibility, and to manage dynamic
325 // |EC_GROUP|s constructed by |EC_GROUP_new_by_curve_name_mutable| and
326 // |EC_GROUP_new_curve_GFp|. Callers that do not need either may ignore this
327 // function.
328 OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *group);
329
330
331 // Deprecated functions.
332
333 // EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based
334 // on the equation y² = x³ + a·x + b. It returns the new group or NULL on
335 // error. The lifetime of the resulting object must be managed with
336 // |EC_GROUP_dup| and |EC_GROUP_free|.
337 //
338 // This new group has no generator. It is an error to use a generator-less group
339 // with any functions except for |EC_GROUP_free|, |EC_POINT_new|,
340 // |EC_POINT_set_affine_coordinates_GFp|, and |EC_GROUP_set_generator|.
341 //
342 // |EC_GROUP|s returned by this function will always compare as unequal via
343 // |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always
344 // return |NID_undef|.
345 //
346 // This function is provided for compatibility with some legacy applications
347 // only. Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name|
348 // instead. This ensures the result meets preconditions necessary for
349 // elliptic curve algorithms to function correctly and securely.
350 //
351 // Given invalid parameters, this function may fail or it may return an
352 // |EC_GROUP| which breaks these preconditions. Subsequent operations may then
353 // return arbitrary, incorrect values. Callers should not pass
354 // attacker-controlled values to this function.
355 OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p,
356 const BIGNUM *a,
357 const BIGNUM *b, BN_CTX *ctx);
358
359 // EC_GROUP_set_generator sets the generator for |group| to |generator|, which
360 // must have the given order and cofactor. It may only be used with |EC_GROUP|
361 // objects returned by |EC_GROUP_new_curve_GFp| and may only be used once on
362 // each group. |generator| must have been created using |group|.
363 OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group,
364 const EC_POINT *generator,
365 const BIGNUM *order,
366 const BIGNUM *cofactor);
367
368
369 // EC_POINT_point2bn calls |EC_POINT_point2oct| to serialize |point| into the
370 // X9.62 form given by |form| and returns the serialized output as a |BIGNUM|.
371 // The returned |BIGNUM| is a representation of serialized bytes. On success, it
372 // returns the |BIGNUM| pointer supplied or, if |ret| is NULL, allocates and
373 // returns a fresh |BIGNUM|. On error, it returns NULL. The |ctx| argument may
374 // be used if not NULL.
375 //
376 // Note: |EC_POINT|s are not individual |BIGNUM| integers, so these aren't
377 // particularly useful. Use |EC_POINT_point2oct| directly instead.
378 OPENSSL_EXPORT OPENSSL_DEPRECATED BIGNUM *EC_POINT_point2bn(
379 const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
380 BIGNUM *ret, BN_CTX *ctx);
381
382 // EC_POINT_bn2point is like |EC_POINT_point2bn|, but calls |EC_POINT_oct2point|
383 // to de-serialize the |BIGNUM| representation of bytes back to an |EC_POINT|.
384 // On success, it returns the |EC_POINT| pointer supplied or, if |ret| is NULL,
385 // allocates and returns a fresh |EC_POINT|. On error, it returns NULL. The
386 // |ctx| argument may be used if not NULL.
387 //
388 // Note: |EC_POINT|s are not individual |BIGNUM| integers, so these aren't
389 // particularly useful. Use |EC_POINT_oct2point| directly instead.
390 OPENSSL_EXPORT OPENSSL_DEPRECATED EC_POINT *EC_POINT_bn2point(
391 const EC_GROUP *group, const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx);
392
393 // EC_GROUP_get_order sets |*order| to the order of |group|, if it's not
394 // NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use
395 // |EC_GROUP_get0_order| instead.
396 OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order,
397 BN_CTX *ctx);
398
399 // EC_builtin_curve describes a supported elliptic curve.
400 typedef struct {
401 int nid;
402 const char *comment;
403 } EC_builtin_curve;
404
405 // EC_get_builtin_curves writes at most |max_num_curves| elements to
406 // |out_curves| and returns the total number that it would have written, had
407 // |max_num_curves| been large enough.
408 //
409 // The |EC_builtin_curve| items describe the supported elliptic curves.
410 OPENSSL_EXPORT size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
411 size_t max_num_curves);
412
413 // EC_POINT_clear_free calls |EC_POINT_free|.
414 OPENSSL_EXPORT void EC_POINT_clear_free(EC_POINT *point);
415
416
417 // General No-op Functions [Deprecated].
418
419 // EC_GROUP_set_seed does nothing and returns 0.
420 //
421 // Like OpenSSL's EC documentations indicates, the value of the seed is not used
422 // in any cryptographic methods. It is only used to indicate the original seed
423 // used to generate the curve's parameters and is preserved during ASN.1
424 // communications. Please refrain from creating your own custom curves.
425 OPENSSL_EXPORT OPENSSL_DEPRECATED size_t
426 EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len);
427
428 // EC_GROUP_get0_seed returns NULL.
429 OPENSSL_EXPORT OPENSSL_DEPRECATED unsigned char *EC_GROUP_get0_seed(
430 const EC_GROUP *group);
431
432 // EC_GROUP_get_seed_len returns 0.
433 OPENSSL_EXPORT OPENSSL_DEPRECATED size_t
434 EC_GROUP_get_seed_len(const EC_GROUP *group);
435
436 // ECPKParameters_print prints nothing and returns 1.
437 OPENSSL_EXPORT OPENSSL_DEPRECATED int ECPKParameters_print(
438 BIO *bio, const EC_GROUP *group, int offset);
439
440
441 // |EC_GROUP| No-op Functions [Deprecated].
442 //
443 // Unlike OpenSSL's |EC_GROUP| implementation, our |EC_GROUP|s for named
444 // curves are static and immutable. The following functions pertain to
445 // the mutable aspects of OpenSSL's |EC_GROUP| structure. Using these
446 // functions undermines the assumption that our curves are static. Consider
447 // using the listed alternatives.
448
449 // OPENSSL_EC_EXPLICIT_CURVE lets OpenSSL encode the curve as explicitly
450 // encoded curve parameters. AWS-LC does not support this.
451 //
452 // Note: Sadly, this was the default prior to OpenSSL 1.1.0.
453 #define OPENSSL_EC_EXPLICIT_CURVE 0
454
455 // OPENSSL_EC_NAMED_CURVE lets OpenSSL encode a named curve form with its
456 // corresponding NID. This is the only ASN1 encoding method for |EC_GROUP| that
457 // AWS-LC supports.
458 #define OPENSSL_EC_NAMED_CURVE 1
459
460 // EC_GROUP_set_asn1_flag does nothing. In OpenSSL, |flag| is used to determine
461 // whether the curve encoding uses explicit parameters or a named curve using an
462 // ASN1 OID. AWS-LC does not support serialization of explicit curve parameters.
463 // This behavior is only intended for custom curves. We encourage the use of
464 // named curves instead.
465 OPENSSL_EXPORT OPENSSL_DEPRECATED void EC_GROUP_set_asn1_flag(EC_GROUP *group,
466 int flag);
467
468 // EC_GROUP_get_asn1_flag returns |OPENSSL_EC_NAMED_CURVE|.
469 OPENSSL_EXPORT OPENSSL_DEPRECATED int EC_GROUP_get_asn1_flag(
470 const EC_GROUP *group);
471
472 // EC_GROUP_set_point_conversion_form aborts the process if |form| is not
473 // |POINT_CONVERSION_UNCOMPRESSED| or |POINT_CONVERSION_COMPRESSED|, and
474 // otherwise does nothing. This DOES NOT change the encoding format for
475 // |EC_GROUP| by default. |group| must be allocated by
476 // |EC_GROUP_new_by_curve_name_mutable| for the encoding format to change.
477 //
478 // Note: Use |EC_KEY_set_conv_form| / |EC_KEY_get_conv_form| to set and return
479 // the desired compression format.
480 OPENSSL_EXPORT OPENSSL_DEPRECATED void EC_GROUP_set_point_conversion_form(
481 EC_GROUP *group, point_conversion_form_t form);
482
483 // EC_GROUP_get_point_conversion_form returns |POINT_CONVERSION_UNCOMPRESSED|
484 // (the default compression format).
485 //
486 // Note: Use |EC_KEY_set_conv_form| / |EC_KEY_get_conv_form| to set and return
487 // the desired compression format.
488 OPENSSL_EXPORT OPENSSL_DEPRECATED point_conversion_form_t
489 EC_GROUP_get_point_conversion_form(const EC_GROUP *group);
490
491 // EC_KEY_decoded_from_explicit_params returns 1 if the |EC_KEY| was constructed
492 // from explicitly encoded parameters to determine the |EC_GROUP|, otherwise
493 // returns 0.
494 OPENSSL_EXPORT OPENSSL_DEPRECATED int EC_KEY_decoded_from_explicit_params(const EC_KEY *key);
495
496
497 // EC_METHOD No-ops [Deprecated].
498 //
499 // |EC_METHOD| is a low level implementation detail of the EC module, but
500 // it’s exposed in traditionally public API. This should be an internal only
501 // concept. Users should switch to a different suitable constructor like
502 // |EC_GROUP_new_curve_GFp|, |EC_GROUP_new_curve_GF2m|, or
503 // |EC_GROUP_new_by_curve_name|. The |EC_METHOD| APIs have also been
504 // deprecated in OpenSSL 3.0.
505
506 typedef struct ec_method_st EC_METHOD;
507
508 // EC_GROUP_method_of returns a dummy non-NULL pointer.
509 OPENSSL_EXPORT OPENSSL_DEPRECATED const EC_METHOD *EC_GROUP_method_of(
510 const EC_GROUP *group);
511
512 // EC_METHOD_get_field_type returns NID_X9_62_prime_field.
513 OPENSSL_EXPORT OPENSSL_DEPRECATED int EC_METHOD_get_field_type(
514 const EC_METHOD *meth);
515
516
517 #if defined(__cplusplus)
518 } // extern C
519 #endif
520
521 // Old code expects to get EC_KEY from ec.h.
522 #include <openssl/ec_key.h>
523
524 #if defined(__cplusplus)
525 extern "C++" {
526
527 BSSL_NAMESPACE_BEGIN
528
529 BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free)
530 BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free)
531
532 BSSL_NAMESPACE_END
533
534 } // extern C++
535
536 #endif
537
538 #define EC_R_BUFFER_TOO_SMALL 100
539 #define EC_R_COORDINATES_OUT_OF_RANGE 101
540 #define EC_R_D2I_ECPKPARAMETERS_FAILURE 102
541 #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 103
542 #define EC_R_GROUP2PKPARAMETERS_FAILURE 104
543 #define EC_R_I2D_ECPKPARAMETERS_FAILURE 105
544 #define EC_R_INCOMPATIBLE_OBJECTS 106
545 #define EC_R_INVALID_COMPRESSED_POINT 107
546 #define EC_R_INVALID_COMPRESSION_BIT 108
547 #define EC_R_INVALID_ENCODING 109
548 #define EC_R_INVALID_FIELD 110
549 #define EC_R_INVALID_FORM 111
550 #define EC_R_INVALID_GROUP_ORDER 112
551 #define EC_R_INVALID_PRIVATE_KEY 113
552 #define EC_R_MISSING_PARAMETERS 114
553 #define EC_R_MISSING_PRIVATE_KEY 115
554 #define EC_R_NON_NAMED_CURVE 116
555 #define EC_R_NOT_INITIALIZED 117
556 #define EC_R_PKPARAMETERS2GROUP_FAILURE 118
557 #define EC_R_POINT_AT_INFINITY 119
558 #define EC_R_POINT_IS_NOT_ON_CURVE 120
559 #define EC_R_SLOT_FULL 121
560 #define EC_R_UNDEFINED_GENERATOR 122
561 #define EC_R_UNKNOWN_GROUP 123
562 #define EC_R_UNKNOWN_ORDER 124
563 #define EC_R_WRONG_ORDER 125
564 #define EC_R_BIGNUM_OUT_OF_RANGE 126
565 #define EC_R_WRONG_CURVE_PARAMETERS 127
566 #define EC_R_DECODE_ERROR 128
567 #define EC_R_ENCODE_ERROR 129
568 #define EC_R_GROUP_MISMATCH 130
569 #define EC_R_INVALID_COFACTOR 131
570 #define EC_R_PUBLIC_KEY_VALIDATION_FAILED 132
571 #define EC_R_INVALID_SCALAR 133
572
573 #endif // OPENSSL_HEADER_EC_H