xref: /freebsd/crypto/openssl/include/openssl/ec.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*
2  * Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
4  *
5  * Licensed under the Apache License 2.0 (the "License").  You may not use
6  * this file except in compliance with the License.  You can obtain a copy
7  * in the file LICENSE in the source distribution or at
8  * https://www.openssl.org/source/license.html
9  */
10 
11 #ifndef OPENSSL_EC_H
12 # define OPENSSL_EC_H
13 # pragma once
14 
15 # include <openssl/macros.h>
16 # ifndef OPENSSL_NO_DEPRECATED_3_0
17 #  define HEADER_EC_H
18 # endif
19 
20 # include <openssl/opensslconf.h>
21 # include <openssl/types.h>
22 
23 # include <string.h>
24 
25 # ifdef  __cplusplus
26 extern "C" {
27 # endif
28 
29 /* Values for EVP_PKEY_CTX_set_ec_param_enc() */
30 # define OPENSSL_EC_EXPLICIT_CURVE  0x000
31 # define OPENSSL_EC_NAMED_CURVE     0x001
32 
33 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
34 int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);
35 int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode);
36 int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx);
37 
38 int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf);
39 int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx);
40 
41 int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
42 int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
43 
44 int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len);
45 int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len);
46 
47 int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
48                                    int len);
49 # ifndef OPENSSL_NO_DEPRECATED_3_0
50 OSSL_DEPRECATEDIN_3_0
51 int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
52 # endif
53 
54 # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID    (EVP_PKEY_ALG_CTRL + 1)
55 # define EVP_PKEY_CTRL_EC_PARAM_ENC             (EVP_PKEY_ALG_CTRL + 2)
56 # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR         (EVP_PKEY_ALG_CTRL + 3)
57 # define EVP_PKEY_CTRL_EC_KDF_TYPE              (EVP_PKEY_ALG_CTRL + 4)
58 # define EVP_PKEY_CTRL_EC_KDF_MD                (EVP_PKEY_ALG_CTRL + 5)
59 # define EVP_PKEY_CTRL_GET_EC_KDF_MD            (EVP_PKEY_ALG_CTRL + 6)
60 # define EVP_PKEY_CTRL_EC_KDF_OUTLEN            (EVP_PKEY_ALG_CTRL + 7)
61 # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN        (EVP_PKEY_ALG_CTRL + 8)
62 # define EVP_PKEY_CTRL_EC_KDF_UKM               (EVP_PKEY_ALG_CTRL + 9)
63 # define EVP_PKEY_CTRL_GET_EC_KDF_UKM           (EVP_PKEY_ALG_CTRL + 10)
64 
65 /* KDF types */
66 # define EVP_PKEY_ECDH_KDF_NONE                      1
67 # define EVP_PKEY_ECDH_KDF_X9_63                     2
68 /*
69  * The old name for EVP_PKEY_ECDH_KDF_X9_63
70  *  The ECDH KDF specification has been mistakenly attributed to ANSI X9.62,
71  *  it is actually specified in ANSI X9.63.
72  *  This identifier is retained for backwards compatibility
73  */
74 # define EVP_PKEY_ECDH_KDF_X9_62   EVP_PKEY_ECDH_KDF_X9_63
75 
76 /** Enum for the point conversion form as defined in X9.62 (ECDSA)
77  *  for the encoding of a elliptic curve point (x,y) */
78 typedef enum {
79         /** the point is encoded as z||x, where the octet z specifies
80          *  which solution of the quadratic equation y is  */
81     POINT_CONVERSION_COMPRESSED = 2,
82         /** the point is encoded as z||x||y, where z is the octet 0x04  */
83     POINT_CONVERSION_UNCOMPRESSED = 4,
84         /** the point is encoded as z||x||y, where the octet z specifies
85          *  which solution of the quadratic equation y is  */
86     POINT_CONVERSION_HYBRID = 6
87 } point_conversion_form_t;
88 
89 const char *OSSL_EC_curve_nid2name(int nid);
90 
91 # ifndef OPENSSL_NO_EC
92 #  include <openssl/asn1.h>
93 #  include <openssl/symhacks.h>
94 #  ifndef OPENSSL_NO_DEPRECATED_1_1_0
95 #   include <openssl/bn.h>
96 #  endif
97 #  include <openssl/ecerr.h>
98 
99 #  ifndef OPENSSL_ECC_MAX_FIELD_BITS
100 #   define OPENSSL_ECC_MAX_FIELD_BITS 661
101 #  endif
102 
103 #  include <openssl/params.h>
104 #  ifndef OPENSSL_NO_DEPRECATED_3_0
105 typedef struct ec_method_st EC_METHOD;
106 #  endif
107 typedef struct ec_group_st EC_GROUP;
108 typedef struct ec_point_st EC_POINT;
109 typedef struct ecpk_parameters_st ECPKPARAMETERS;
110 typedef struct ec_parameters_st ECPARAMETERS;
111 
112 /********************************************************************/
113 /*               EC_METHODs for curves over GF(p)                   */
114 /********************************************************************/
115 
116 #  ifndef OPENSSL_NO_DEPRECATED_3_0
117 /** Returns the basic GFp ec methods which provides the basis for the
118  *  optimized methods.
119  *  \return  EC_METHOD object
120  */
121 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_simple_method(void);
122 
123 /** Returns GFp methods using montgomery multiplication.
124  *  \return  EC_METHOD object
125  */
126 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_mont_method(void);
127 
128 /** Returns GFp methods using optimized methods for NIST recommended curves
129  *  \return  EC_METHOD object
130  */
131 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nist_method(void);
132 
133 #   ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
134 /** Returns 64-bit optimized methods for nistp224
135  *  \return  EC_METHOD object
136  */
137 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp224_method(void);
138 
139 /** Returns 64-bit optimized methods for nistp256
140  *  \return  EC_METHOD object
141  */
142 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp256_method(void);
143 
144 /** Returns 64-bit optimized methods for nistp521
145  *  \return  EC_METHOD object
146  */
147 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp521_method(void);
148 #   endif /* OPENSSL_NO_EC_NISTP_64_GCC_128 */
149 
150 #   ifndef OPENSSL_NO_EC2M
151 /********************************************************************/
152 /*           EC_METHOD for curves over GF(2^m)                      */
153 /********************************************************************/
154 
155 /** Returns the basic GF2m ec method
156  *  \return  EC_METHOD object
157  */
158 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GF2m_simple_method(void);
159 
160 #   endif
161 
162 /********************************************************************/
163 /*                   EC_GROUP functions                             */
164 /********************************************************************/
165 
166 /**
167  *  Creates a new EC_GROUP object
168  *  \param   meth   EC_METHOD to use
169  *  \return  newly created EC_GROUP object or NULL in case of an error.
170  */
171 OSSL_DEPRECATEDIN_3_0 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
172 
173 /** Clears and frees a EC_GROUP object
174  *  \param  group  EC_GROUP object to be cleared and freed.
175  */
176 OSSL_DEPRECATEDIN_3_0 void EC_GROUP_clear_free(EC_GROUP *group);
177 
178 /** Returns the EC_METHOD of the EC_GROUP object.
179  *  \param  group  EC_GROUP object
180  *  \return EC_METHOD used in this EC_GROUP object.
181  */
182 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
183 
184 /** Returns the field type of the EC_METHOD.
185  *  \param  meth  EC_METHOD object
186  *  \return NID of the underlying field type OID.
187  */
188 OSSL_DEPRECATEDIN_3_0 int EC_METHOD_get_field_type(const EC_METHOD *meth);
189 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
190 
191 /** Frees a EC_GROUP object
192  *  \param  group  EC_GROUP object to be freed.
193  */
194 void EC_GROUP_free(EC_GROUP *group);
195 
196 /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
197  *  \param  dst  destination EC_GROUP object
198  *  \param  src  source EC_GROUP object
199  *  \return 1 on success and 0 if an error occurred.
200  */
201 int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
202 
203 /** Creates a new EC_GROUP object and copies the content
204  *  form src to the newly created EC_KEY object
205  *  \param  src  source EC_GROUP object
206  *  \return newly created EC_GROUP object or NULL in case of an error.
207  */
208 EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
209 
210 /** Sets the generator and its order/cofactor of a EC_GROUP object.
211  *  \param  group      EC_GROUP object
212  *  \param  generator  EC_POINT object with the generator.
213  *  \param  order      the order of the group generated by the generator.
214  *  \param  cofactor   the index of the sub-group generated by the generator
215  *                     in the group of all points on the elliptic curve.
216  *  \return 1 on success and 0 if an error occurred
217  */
218 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
219                            const BIGNUM *order, const BIGNUM *cofactor);
220 
221 /** Returns the generator of a EC_GROUP object.
222  *  \param  group  EC_GROUP object
223  *  \return the currently used generator (possibly NULL).
224  */
225 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
226 
227 /** Returns the montgomery data for order(Generator)
228  *  \param  group  EC_GROUP object
229  *  \return the currently used montgomery data (possibly NULL).
230 */
231 BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group);
232 
233 /** Gets the order of a EC_GROUP
234  *  \param  group  EC_GROUP object
235  *  \param  order  BIGNUM to which the order is copied
236  *  \param  ctx    unused
237  *  \return 1 on success and 0 if an error occurred
238  */
239 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
240 
241 /** Gets the order of an EC_GROUP
242  *  \param  group  EC_GROUP object
243  *  \return the group order
244  */
245 const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
246 
247 /** Gets the number of bits of the order of an EC_GROUP
248  *  \param  group  EC_GROUP object
249  *  \return number of bits of group order.
250  */
251 int EC_GROUP_order_bits(const EC_GROUP *group);
252 
253 /** Gets the cofactor of a EC_GROUP
254  *  \param  group     EC_GROUP object
255  *  \param  cofactor  BIGNUM to which the cofactor is copied
256  *  \param  ctx       unused
257  *  \return 1 on success and 0 if an error occurred
258  */
259 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
260                           BN_CTX *ctx);
261 
262 /** Gets the cofactor of an EC_GROUP
263  *  \param  group  EC_GROUP object
264  *  \return the group cofactor
265  */
266 const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
267 
268 /** Sets the name of a EC_GROUP object
269  *  \param  group  EC_GROUP object
270  *  \param  nid    NID of the curve name OID
271  */
272 void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
273 
274 /** Returns the curve name of a EC_GROUP object
275  *  \param  group  EC_GROUP object
276  *  \return NID of the curve name OID or 0 if not set.
277  */
278 int EC_GROUP_get_curve_name(const EC_GROUP *group);
279 
280 /** Gets the field of an EC_GROUP
281  *  \param  group  EC_GROUP object
282  *  \return the group field
283  */
284 const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group);
285 
286 /** Returns the field type of the EC_GROUP.
287  *  \param  group  EC_GROUP object
288  *  \return NID of the underlying field type OID.
289  */
290 int EC_GROUP_get_field_type(const EC_GROUP *group);
291 
292 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
293 int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
294 
295 void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
296                                         point_conversion_form_t form);
297 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
298 
299 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
300 size_t EC_GROUP_get_seed_len(const EC_GROUP *);
301 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
302 
303 /** Sets the parameters of an ec curve defined by y^2 = x^3 + a*x + b (for GFp)
304  *  or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)
305  *  \param  group  EC_GROUP object
306  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
307  *                 defining the underlying field (GF2m)
308  *  \param  a      BIGNUM with parameter a of the equation
309  *  \param  b      BIGNUM with parameter b of the equation
310  *  \param  ctx    BN_CTX object (optional)
311  *  \return 1 on success and 0 if an error occurred
312  */
313 int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
314                        const BIGNUM *b, BN_CTX *ctx);
315 
316 /** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp)
317  *  or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)
318  *  \param  group  EC_GROUP object
319  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
320  *                 defining the underlying field (GF2m)
321  *  \param  a      BIGNUM for parameter a of the equation
322  *  \param  b      BIGNUM for parameter b of the equation
323  *  \param  ctx    BN_CTX object (optional)
324  *  \return 1 on success and 0 if an error occurred
325  */
326 int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
327                        BN_CTX *ctx);
328 
329 #  ifndef OPENSSL_NO_DEPRECATED_3_0
330 /** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve
331  *  \param  group  EC_GROUP object
332  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
333  *                 defining the underlying field (GF2m)
334  *  \param  a      BIGNUM with parameter a of the equation
335  *  \param  b      BIGNUM with parameter b of the equation
336  *  \param  ctx    BN_CTX object (optional)
337  *  \return 1 on success and 0 if an error occurred
338  */
339 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GFp(EC_GROUP *group,
340                                                  const BIGNUM *p,
341                                                  const BIGNUM *a,
342                                                  const BIGNUM *b,
343                                                  BN_CTX *ctx);
344 
345 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
346  *  \param  group  EC_GROUP object
347  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
348  *                 defining the underlying field (GF2m)
349  *  \param  a      BIGNUM for parameter a of the equation
350  *  \param  b      BIGNUM for parameter b of the equation
351  *  \param  ctx    BN_CTX object (optional)
352  *  \return 1 on success and 0 if an error occurred
353  */
354 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GFp(const EC_GROUP *group,
355                                                  BIGNUM *p,
356                                                  BIGNUM *a, BIGNUM *b,
357                                                  BN_CTX *ctx);
358 
359 #   ifndef OPENSSL_NO_EC2M
360 /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve
361  *  \param  group  EC_GROUP object
362  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
363  *                 defining the underlying field (GF2m)
364  *  \param  a      BIGNUM with parameter a of the equation
365  *  \param  b      BIGNUM with parameter b of the equation
366  *  \param  ctx    BN_CTX object (optional)
367  *  \return 1 on success and 0 if an error occurred
368  */
369 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GF2m(EC_GROUP *group,
370                                                   const BIGNUM *p,
371                                                   const BIGNUM *a,
372                                                   const BIGNUM *b,
373                                                   BN_CTX *ctx);
374 
375 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
376  *  \param  group  EC_GROUP object
377  *  \param  p      BIGNUM with the prime number (GFp) or the polynomial
378  *                 defining the underlying field (GF2m)
379  *  \param  a      BIGNUM for parameter a of the equation
380  *  \param  b      BIGNUM for parameter b of the equation
381  *  \param  ctx    BN_CTX object (optional)
382  *  \return 1 on success and 0 if an error occurred
383  */
384 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group,
385                                                   BIGNUM *p,
386                                                   BIGNUM *a, BIGNUM *b,
387                                                   BN_CTX *ctx);
388 #   endif /* OPENSSL_NO_EC2M */
389 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
390 
391 /** Returns the number of bits needed to represent a field element
392  *  \param  group  EC_GROUP object
393  *  \return number of bits needed to represent a field element
394  */
395 int EC_GROUP_get_degree(const EC_GROUP *group);
396 
397 /** Checks whether the parameter in the EC_GROUP define a valid ec group
398  *  \param  group  EC_GROUP object
399  *  \param  ctx    BN_CTX object (optional)
400  *  \return 1 if group is a valid ec group and 0 otherwise
401  */
402 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
403 
404 /** Checks whether the discriminant of the elliptic curve is zero or not
405  *  \param  group  EC_GROUP object
406  *  \param  ctx    BN_CTX object (optional)
407  *  \return 1 if the discriminant is not zero and 0 otherwise
408  */
409 int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
410 
411 /** Compares two EC_GROUP objects
412  *  \param  a    first EC_GROUP object
413  *  \param  b    second EC_GROUP object
414  *  \param  ctx  BN_CTX object (optional)
415  *  \return 0 if the groups are equal, 1 if not, or -1 on error
416  */
417 int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
418 
419 /*
420  * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
421  * choosing an appropriate EC_METHOD
422  */
423 
424 /** Creates a new EC_GROUP object with the specified parameters defined
425  *  over GFp (defined by the equation y^2 = x^3 + a*x + b)
426  *  \param  p    BIGNUM with the prime number
427  *  \param  a    BIGNUM with the parameter a of the equation
428  *  \param  b    BIGNUM with the parameter b of the equation
429  *  \param  ctx  BN_CTX object (optional)
430  *  \return newly created EC_GROUP object with the specified parameters
431  */
432 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
433                                  const BIGNUM *b, BN_CTX *ctx);
434 #  ifndef OPENSSL_NO_EC2M
435 /** Creates a new EC_GROUP object with the specified parameters defined
436  *  over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)
437  *  \param  p    BIGNUM with the polynomial defining the underlying field
438  *  \param  a    BIGNUM with the parameter a of the equation
439  *  \param  b    BIGNUM with the parameter b of the equation
440  *  \param  ctx  BN_CTX object (optional)
441  *  \return newly created EC_GROUP object with the specified parameters
442  */
443 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
444                                   const BIGNUM *b, BN_CTX *ctx);
445 #  endif
446 
447 /**
448  * Creates a EC_GROUP object with a curve specified by parameters.
449  * The parameters may be explicit or a named curve,
450  *  \param  params A list of parameters describing the group.
451  *  \param  libctx The associated library context or NULL for the default
452  *                 context
453  *  \param  propq  A property query string
454  *  \return newly created EC_GROUP object with specified parameters or NULL
455  *          if an error occurred
456  */
457 EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
458                                    OSSL_LIB_CTX *libctx, const char *propq);
459 
460 /**
461  * Creates a EC_GROUP object with a curve specified by a NID
462  *  \param  libctx The associated library context or NULL for the default
463  *                 context
464  *  \param  propq  A property query string
465  *  \param  nid    NID of the OID of the curve name
466  *  \return newly created EC_GROUP object with specified curve or NULL
467  *          if an error occurred
468  */
469 EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq,
470                                         int nid);
471 
472 /**
473  * Creates a EC_GROUP object with a curve specified by a NID. Same as
474  * EC_GROUP_new_by_curve_name_ex but the libctx and propq are always
475  * NULL.
476  *  \param  nid    NID of the OID of the curve name
477  *  \return newly created EC_GROUP object with specified curve or NULL
478  *          if an error occurred
479  */
480 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
481 
482 /** Creates a new EC_GROUP object from an ECPARAMETERS object
483  *  \param  params  pointer to the ECPARAMETERS object
484  *  \return newly created EC_GROUP object with specified curve or NULL
485  *          if an error occurred
486  */
487 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);
488 
489 /** Creates an ECPARAMETERS object for the given EC_GROUP object.
490  *  \param  group   pointer to the EC_GROUP object
491  *  \param  params  pointer to an existing ECPARAMETERS object or NULL
492  *  \return pointer to the new ECPARAMETERS object or NULL
493  *          if an error occurred.
494  */
495 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
496                                         ECPARAMETERS *params);
497 
498 /** Creates a new EC_GROUP object from an ECPKPARAMETERS object
499  *  \param  params  pointer to an existing ECPKPARAMETERS object, or NULL
500  *  \return newly created EC_GROUP object with specified curve, or NULL
501  *          if an error occurred
502  */
503 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);
504 
505 /** Creates an ECPKPARAMETERS object for the given EC_GROUP object.
506  *  \param  group   pointer to the EC_GROUP object
507  *  \param  params  pointer to an existing ECPKPARAMETERS object or NULL
508  *  \return pointer to the new ECPKPARAMETERS object or NULL
509  *          if an error occurred.
510  */
511 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,
512                                             ECPKPARAMETERS *params);
513 
514 /********************************************************************/
515 /*               handling of internal curves                        */
516 /********************************************************************/
517 
518 typedef struct {
519     int nid;
520     const char *comment;
521 } EC_builtin_curve;
522 
523 /*
524  * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
525  * available curves or zero if a error occurred. In case r is not zero,
526  * nitems EC_builtin_curve structures are filled with the data of the first
527  * nitems internal groups
528  */
529 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
530 
531 const char *EC_curve_nid2nist(int nid);
532 int EC_curve_nist2nid(const char *name);
533 int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only,
534                                BN_CTX *ctx);
535 
536 /********************************************************************/
537 /*                    EC_POINT functions                            */
538 /********************************************************************/
539 
540 /** Creates a new EC_POINT object for the specified EC_GROUP
541  *  \param  group  EC_GROUP the underlying EC_GROUP object
542  *  \return newly created EC_POINT object or NULL if an error occurred
543  */
544 EC_POINT *EC_POINT_new(const EC_GROUP *group);
545 
546 /** Frees a EC_POINT object
547  *  \param  point  EC_POINT object to be freed
548  */
549 void EC_POINT_free(EC_POINT *point);
550 
551 /** Clears and frees a EC_POINT object
552  *  \param  point  EC_POINT object to be cleared and freed
553  */
554 void EC_POINT_clear_free(EC_POINT *point);
555 
556 /** Copies EC_POINT object
557  *  \param  dst  destination EC_POINT object
558  *  \param  src  source EC_POINT object
559  *  \return 1 on success and 0 if an error occurred
560  */
561 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
562 
563 /** Creates a new EC_POINT object and copies the content of the supplied
564  *  EC_POINT
565  *  \param  src    source EC_POINT object
566  *  \param  group  underlying the EC_GROUP object
567  *  \return newly created EC_POINT object or NULL if an error occurred
568  */
569 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
570 
571 /** Sets a point to infinity (neutral element)
572  *  \param  group  underlying EC_GROUP object
573  *  \param  point  EC_POINT to set to infinity
574  *  \return 1 on success and 0 if an error occurred
575  */
576 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
577 
578 #  ifndef OPENSSL_NO_DEPRECATED_3_0
579 /** Returns the EC_METHOD used in EC_POINT object
580  *  \param  point  EC_POINT object
581  *  \return the EC_METHOD used
582  */
583 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
584 
585 /** Sets the jacobian projective coordinates of a EC_POINT over GFp
586  *  \param  group  underlying EC_GROUP object
587  *  \param  p      EC_POINT object
588  *  \param  x      BIGNUM with the x-coordinate
589  *  \param  y      BIGNUM with the y-coordinate
590  *  \param  z      BIGNUM with the z-coordinate
591  *  \param  ctx    BN_CTX object (optional)
592  *  \return 1 on success and 0 if an error occurred
593  */
594 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_Jprojective_coordinates_GFp
595                       (const EC_GROUP *group, EC_POINT *p,
596                        const BIGNUM *x, const BIGNUM *y, const BIGNUM *z,
597                        BN_CTX *ctx);
598 
599 /** Gets the jacobian projective coordinates of a EC_POINT over GFp
600  *  \param  group  underlying EC_GROUP object
601  *  \param  p      EC_POINT object
602  *  \param  x      BIGNUM for the x-coordinate
603  *  \param  y      BIGNUM for the y-coordinate
604  *  \param  z      BIGNUM for the z-coordinate
605  *  \param  ctx    BN_CTX object (optional)
606  *  \return 1 on success and 0 if an error occurred
607  */
608 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_Jprojective_coordinates_GFp
609                       (const EC_GROUP *group, const EC_POINT *p,
610                        BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
611 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
612 
613 /** Sets the affine coordinates of an EC_POINT
614  *  \param  group  underlying EC_GROUP object
615  *  \param  p      EC_POINT object
616  *  \param  x      BIGNUM with the x-coordinate
617  *  \param  y      BIGNUM with the y-coordinate
618  *  \param  ctx    BN_CTX object (optional)
619  *  \return 1 on success and 0 if an error occurred
620  */
621 int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p,
622                                     const BIGNUM *x, const BIGNUM *y,
623                                     BN_CTX *ctx);
624 
625 /** Gets the affine coordinates of an EC_POINT.
626  *  \param  group  underlying EC_GROUP object
627  *  \param  p      EC_POINT object
628  *  \param  x      BIGNUM for the x-coordinate
629  *  \param  y      BIGNUM for the y-coordinate
630  *  \param  ctx    BN_CTX object (optional)
631  *  \return 1 on success and 0 if an error occurred
632  */
633 int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p,
634                                     BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
635 
636 #  ifndef OPENSSL_NO_DEPRECATED_3_0
637 /** Sets the affine coordinates of an EC_POINT. A synonym of
638  *  EC_POINT_set_affine_coordinates
639  *  \param  group  underlying EC_GROUP object
640  *  \param  p      EC_POINT object
641  *  \param  x      BIGNUM with the x-coordinate
642  *  \param  y      BIGNUM with the y-coordinate
643  *  \param  ctx    BN_CTX object (optional)
644  *  \return 1 on success and 0 if an error occurred
645  */
646 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GFp
647                       (const EC_GROUP *group, EC_POINT *p,
648                        const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
649 
650 /** Gets the affine coordinates of an EC_POINT. A synonym of
651  *  EC_POINT_get_affine_coordinates
652  *  \param  group  underlying EC_GROUP object
653  *  \param  p      EC_POINT object
654  *  \param  x      BIGNUM for the x-coordinate
655  *  \param  y      BIGNUM for the y-coordinate
656  *  \param  ctx    BN_CTX object (optional)
657  *  \return 1 on success and 0 if an error occurred
658  */
659 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GFp
660                       (const EC_GROUP *group, const EC_POINT *p,
661                        BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
662 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
663 
664 /** Sets the x9.62 compressed coordinates of a EC_POINT
665  *  \param  group  underlying EC_GROUP object
666  *  \param  p      EC_POINT object
667  *  \param  x      BIGNUM with x-coordinate
668  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
669  *  \param  ctx    BN_CTX object (optional)
670  *  \return 1 on success and 0 if an error occurred
671  */
672 int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p,
673                                         const BIGNUM *x, int y_bit,
674                                         BN_CTX *ctx);
675 
676 #  ifndef OPENSSL_NO_DEPRECATED_3_0
677 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
678  *  EC_POINT_set_compressed_coordinates
679  *  \param  group  underlying EC_GROUP object
680  *  \param  p      EC_POINT object
681  *  \param  x      BIGNUM with x-coordinate
682  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
683  *  \param  ctx    BN_CTX object (optional)
684  *  \return 1 on success and 0 if an error occurred
685  */
686 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GFp
687                       (const EC_GROUP *group, EC_POINT *p,
688                        const BIGNUM *x, int y_bit, BN_CTX *ctx);
689 #   ifndef OPENSSL_NO_EC2M
690 /** Sets the affine coordinates of an EC_POINT. A synonym of
691  *  EC_POINT_set_affine_coordinates
692  *  \param  group  underlying EC_GROUP object
693  *  \param  p      EC_POINT object
694  *  \param  x      BIGNUM with the x-coordinate
695  *  \param  y      BIGNUM with the y-coordinate
696  *  \param  ctx    BN_CTX object (optional)
697  *  \return 1 on success and 0 if an error occurred
698  */
699 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GF2m
700                       (const EC_GROUP *group, EC_POINT *p,
701                        const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
702 
703 /** Gets the affine coordinates of an EC_POINT. A synonym of
704  *  EC_POINT_get_affine_coordinates
705  *  \param  group  underlying EC_GROUP object
706  *  \param  p      EC_POINT object
707  *  \param  x      BIGNUM for the x-coordinate
708  *  \param  y      BIGNUM for the y-coordinate
709  *  \param  ctx    BN_CTX object (optional)
710  *  \return 1 on success and 0 if an error occurred
711  */
712 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GF2m
713                       (const EC_GROUP *group, const EC_POINT *p,
714                        BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
715 
716 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
717  *  EC_POINT_set_compressed_coordinates
718  *  \param  group  underlying EC_GROUP object
719  *  \param  p      EC_POINT object
720  *  \param  x      BIGNUM with x-coordinate
721  *  \param  y_bit  integer with the y-Bit (either 0 or 1)
722  *  \param  ctx    BN_CTX object (optional)
723  *  \return 1 on success and 0 if an error occurred
724  */
725 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GF2m
726                       (const EC_GROUP *group, EC_POINT *p,
727                        const BIGNUM *x, int y_bit, BN_CTX *ctx);
728 #   endif
729 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
730 
731 /** Encodes a EC_POINT object to a octet string
732  *  \param  group  underlying EC_GROUP object
733  *  \param  p      EC_POINT object
734  *  \param  form   point conversion form
735  *  \param  buf    memory buffer for the result. If NULL the function returns
736  *                 required buffer size.
737  *  \param  len    length of the memory buffer
738  *  \param  ctx    BN_CTX object (optional)
739  *  \return the length of the encoded octet string or 0 if an error occurred
740  */
741 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
742                           point_conversion_form_t form,
743                           unsigned char *buf, size_t len, BN_CTX *ctx);
744 
745 /** Decodes a EC_POINT from a octet string
746  *  \param  group  underlying EC_GROUP object
747  *  \param  p      EC_POINT object
748  *  \param  buf    memory buffer with the encoded ec point
749  *  \param  len    length of the encoded ec point
750  *  \param  ctx    BN_CTX object (optional)
751  *  \return 1 on success and 0 if an error occurred
752  */
753 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
754                        const unsigned char *buf, size_t len, BN_CTX *ctx);
755 
756 /** Encodes an EC_POINT object to an allocated octet string
757  *  \param  group  underlying EC_GROUP object
758  *  \param  point  EC_POINT object
759  *  \param  form   point conversion form
760  *  \param  pbuf   returns pointer to allocated buffer
761  *  \param  ctx    BN_CTX object (optional)
762  *  \return the length of the encoded octet string or 0 if an error occurred
763  */
764 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
765                           point_conversion_form_t form,
766                           unsigned char **pbuf, BN_CTX *ctx);
767 
768 /* other interfaces to point2oct/oct2point: */
769 #  ifndef OPENSSL_NO_DEPRECATED_3_0
770 OSSL_DEPRECATEDIN_3_0 BIGNUM *EC_POINT_point2bn(const EC_GROUP *,
771                                                 const EC_POINT *,
772                                                 point_conversion_form_t form,
773                                                 BIGNUM *, BN_CTX *);
774 OSSL_DEPRECATEDIN_3_0 EC_POINT *EC_POINT_bn2point(const EC_GROUP *,
775                                                   const BIGNUM *,
776                                                   EC_POINT *, BN_CTX *);
777 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
778 
779 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
780                          point_conversion_form_t form, BN_CTX *);
781 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
782                              EC_POINT *, BN_CTX *);
783 
784 /********************************************************************/
785 /*         functions for doing EC_POINT arithmetic                  */
786 /********************************************************************/
787 
788 /** Computes the sum of two EC_POINT
789  *  \param  group  underlying EC_GROUP object
790  *  \param  r      EC_POINT object for the result (r = a + b)
791  *  \param  a      EC_POINT object with the first summand
792  *  \param  b      EC_POINT object with the second summand
793  *  \param  ctx    BN_CTX object (optional)
794  *  \return 1 on success and 0 if an error occurred
795  */
796 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
797                  const EC_POINT *b, BN_CTX *ctx);
798 
799 /** Computes the double of a EC_POINT
800  *  \param  group  underlying EC_GROUP object
801  *  \param  r      EC_POINT object for the result (r = 2 * a)
802  *  \param  a      EC_POINT object
803  *  \param  ctx    BN_CTX object (optional)
804  *  \return 1 on success and 0 if an error occurred
805  */
806 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
807                  BN_CTX *ctx);
808 
809 /** Computes the inverse of a EC_POINT
810  *  \param  group  underlying EC_GROUP object
811  *  \param  a      EC_POINT object to be inverted (it's used for the result as well)
812  *  \param  ctx    BN_CTX object (optional)
813  *  \return 1 on success and 0 if an error occurred
814  */
815 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
816 
817 /** Checks whether the point is the neutral element of the group
818  *  \param  group  the underlying EC_GROUP object
819  *  \param  p      EC_POINT object
820  *  \return 1 if the point is the neutral element and 0 otherwise
821  */
822 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
823 
824 /** Checks whether the point is on the curve
825  *  \param  group  underlying EC_GROUP object
826  *  \param  point  EC_POINT object to check
827  *  \param  ctx    BN_CTX object (optional)
828  *  \return 1 if the point is on the curve, 0 if not, or -1 on error
829  */
830 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
831                          BN_CTX *ctx);
832 
833 /** Compares two EC_POINTs
834  *  \param  group  underlying EC_GROUP object
835  *  \param  a      first EC_POINT object
836  *  \param  b      second EC_POINT object
837  *  \param  ctx    BN_CTX object (optional)
838  *  \return 1 if the points are not equal, 0 if they are, or -1 on error
839  */
840 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
841                  BN_CTX *ctx);
842 
843 #  ifndef OPENSSL_NO_DEPRECATED_3_0
844 OSSL_DEPRECATEDIN_3_0 int EC_POINT_make_affine(const EC_GROUP *group,
845                                                EC_POINT *point, BN_CTX *ctx);
846 OSSL_DEPRECATEDIN_3_0 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
847                                                 EC_POINT *points[], BN_CTX *ctx);
848 
849 /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i]
850  *  \param  group  underlying EC_GROUP object
851  *  \param  r      EC_POINT object for the result
852  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
853  *  \param  num    number further summands
854  *  \param  p      array of size num of EC_POINT objects
855  *  \param  m      array of size num of BIGNUM objects
856  *  \param  ctx    BN_CTX object (optional)
857  *  \return 1 on success and 0 if an error occurred
858  */
859 OSSL_DEPRECATEDIN_3_0 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r,
860                                         const BIGNUM *n, size_t num,
861                                         const EC_POINT *p[], const BIGNUM *m[],
862                                         BN_CTX *ctx);
863 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
864 
865 /** Computes r = generator * n + q * m
866  *  \param  group  underlying EC_GROUP object
867  *  \param  r      EC_POINT object for the result
868  *  \param  n      BIGNUM with the multiplier for the group generator (optional)
869  *  \param  q      EC_POINT object with the first factor of the second summand
870  *  \param  m      BIGNUM with the second factor of the second summand
871  *  \param  ctx    BN_CTX object (optional)
872  *  \return 1 on success and 0 if an error occurred
873  */
874 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
875                  const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
876 
877 #  ifndef OPENSSL_NO_DEPRECATED_3_0
878 /** Stores multiples of generator for faster point multiplication
879  *  \param  group  EC_GROUP object
880  *  \param  ctx    BN_CTX object (optional)
881  *  \return 1 on success and 0 if an error occurred
882  */
883 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
884 
885 /** Reports whether a precomputation has been done
886  *  \param  group  EC_GROUP object
887  *  \return 1 if a pre-computation has been done and 0 otherwise
888  */
889 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
890 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
891 
892 /********************************************************************/
893 /*                       ASN1 stuff                                 */
894 /********************************************************************/
895 
896 DECLARE_ASN1_ITEM(ECPKPARAMETERS)
897 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS)
898 DECLARE_ASN1_ITEM(ECPARAMETERS)
899 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS)
900 
901 /*
902  * EC_GROUP_get_basis_type() returns the NID of the basis type used to
903  * represent the field elements
904  */
905 int EC_GROUP_get_basis_type(const EC_GROUP *);
906 #  ifndef OPENSSL_NO_EC2M
907 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
908 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
909                                    unsigned int *k2, unsigned int *k3);
910 #  endif
911 
912 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
913 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
914 
915 #  define d2i_ECPKParameters_bio(bp,x) \
916     ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x)
917 #  define i2d_ECPKParameters_bio(bp,x) \
918     ASN1_i2d_bio_of(EC_GROUP, i2d_ECPKParameters, bp, x)
919 #  define d2i_ECPKParameters_fp(fp,x) \
920     (EC_GROUP *)ASN1_d2i_fp(NULL, (d2i_of_void *)d2i_ECPKParameters, (fp), \
921                             (void **)(x))
922 #  define i2d_ECPKParameters_fp(fp,x) \
923     ASN1_i2d_fp((i2d_of_void *)i2d_ECPKParameters, (fp), (void *)(x))
924 
925 #  ifndef OPENSSL_NO_DEPRECATED_3_0
926 OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print(BIO *bp, const EC_GROUP *x,
927                                                int off);
928 #   ifndef OPENSSL_NO_STDIO
929 OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x,
930                                                   int off);
931 #   endif
932 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
933 
934 /********************************************************************/
935 /*                      EC_KEY functions                            */
936 /********************************************************************/
937 
938 /* some values for the encoding_flag */
939 #  define EC_PKEY_NO_PARAMETERS   0x001
940 #  define EC_PKEY_NO_PUBKEY       0x002
941 
942 /* some values for the flags field */
943 #  define EC_FLAG_SM2_RANGE              0x0004
944 #  define EC_FLAG_COFACTOR_ECDH          0x1000
945 #  define EC_FLAG_CHECK_NAMED_GROUP      0x2000
946 #  define EC_FLAG_CHECK_NAMED_GROUP_NIST 0x4000
947 #  define EC_FLAG_CHECK_NAMED_GROUP_MASK \
948     (EC_FLAG_CHECK_NAMED_GROUP | EC_FLAG_CHECK_NAMED_GROUP_NIST)
949 
950 /* Deprecated flags -  it was using 0x01..0x02 */
951 #  define EC_FLAG_NON_FIPS_ALLOW         0x0000
952 #  define EC_FLAG_FIPS_CHECKED           0x0000
953 
954 #  ifndef OPENSSL_NO_DEPRECATED_3_0
955 /**
956  *  Creates a new EC_KEY object.
957  *  \param  ctx  The library context for to use for this EC_KEY. May be NULL in
958  *               which case the default library context is used.
959  *  \return EC_KEY object or NULL if an error occurred.
960  */
961 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_ex(OSSL_LIB_CTX *ctx, const char *propq);
962 
963 /**
964  *  Creates a new EC_KEY object. Same as calling EC_KEY_new_ex with a
965  *  NULL library context
966  *  \return EC_KEY object or NULL if an error occurred.
967  */
968 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new(void);
969 
970 OSSL_DEPRECATEDIN_3_0 int EC_KEY_get_flags(const EC_KEY *key);
971 
972 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_flags(EC_KEY *key, int flags);
973 
974 OSSL_DEPRECATEDIN_3_0 void EC_KEY_clear_flags(EC_KEY *key, int flags);
975 
976 OSSL_DEPRECATEDIN_3_0 int EC_KEY_decoded_from_explicit_params(const EC_KEY *key);
977 
978 /**
979  *  Creates a new EC_KEY object using a named curve as underlying
980  *  EC_GROUP object.
981  *  \param  ctx   The library context for to use for this EC_KEY. May be NULL in
982  *                which case the default library context is used.
983  *  \param  propq Any property query string
984  *  \param  nid   NID of the named curve.
985  *  \return EC_KEY object or NULL if an error occurred.
986  */
987 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name_ex(OSSL_LIB_CTX *ctx,
988                                                           const char *propq,
989                                                           int nid);
990 
991 /**
992  *  Creates a new EC_KEY object using a named curve as underlying
993  *  EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL
994  *  library context and property query string.
995  *  \param  nid  NID of the named curve.
996  *  \return EC_KEY object or NULL if an error occurred.
997  */
998 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name(int nid);
999 
1000 /** Frees a EC_KEY object.
1001  *  \param  key  EC_KEY object to be freed.
1002  */
1003 OSSL_DEPRECATEDIN_3_0 void EC_KEY_free(EC_KEY *key);
1004 
1005 /** Copies a EC_KEY object.
1006  *  \param  dst  destination EC_KEY object
1007  *  \param  src  src EC_KEY object
1008  *  \return dst or NULL if an error occurred.
1009  */
1010 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
1011 
1012 /** Creates a new EC_KEY object and copies the content from src to it.
1013  *  \param  src  the source EC_KEY object
1014  *  \return newly created EC_KEY object or NULL if an error occurred.
1015  */
1016 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_dup(const EC_KEY *src);
1017 
1018 /** Increases the internal reference count of a EC_KEY object.
1019  *  \param  key  EC_KEY object
1020  *  \return 1 on success and 0 if an error occurred.
1021  */
1022 OSSL_DEPRECATEDIN_3_0 int EC_KEY_up_ref(EC_KEY *key);
1023 
1024 /** Returns the ENGINE object of a EC_KEY object
1025  *  \param  eckey  EC_KEY object
1026  *  \return the ENGINE object (possibly NULL).
1027  */
1028 OSSL_DEPRECATEDIN_3_0 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey);
1029 
1030 /** Returns the EC_GROUP object of a EC_KEY object
1031  *  \param  key  EC_KEY object
1032  *  \return the EC_GROUP object (possibly NULL).
1033  */
1034 OSSL_DEPRECATEDIN_3_0 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
1035 
1036 /** Sets the EC_GROUP of a EC_KEY object.
1037  *  \param  key    EC_KEY object
1038  *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY
1039  *                 object will use an own copy of the EC_GROUP).
1040  *  \return 1 on success and 0 if an error occurred.
1041  */
1042 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
1043 
1044 /** Returns the private key of a EC_KEY object.
1045  *  \param  key  EC_KEY object
1046  *  \return a BIGNUM with the private key (possibly NULL).
1047  */
1048 OSSL_DEPRECATEDIN_3_0 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
1049 
1050 /** Sets the private key of a EC_KEY object.
1051  *  \param  key  EC_KEY object
1052  *  \param  prv  BIGNUM with the private key (note: the EC_KEY object
1053  *               will use an own copy of the BIGNUM).
1054  *  \return 1 on success and 0 if an error occurred.
1055  */
1056 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
1057 
1058 /** Returns the public key of a EC_KEY object.
1059  *  \param  key  the EC_KEY object
1060  *  \return a EC_POINT object with the public key (possibly NULL)
1061  */
1062 OSSL_DEPRECATEDIN_3_0 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
1063 
1064 /** Sets the public key of a EC_KEY object.
1065  *  \param  key  EC_KEY object
1066  *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object
1067  *               will use an own copy of the EC_POINT object).
1068  *  \return 1 on success and 0 if an error occurred.
1069  */
1070 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
1071 
1072 OSSL_DEPRECATEDIN_3_0 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
1073 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
1074 OSSL_DEPRECATEDIN_3_0 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
1075 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_conv_form(EC_KEY *eckey,
1076                                                 point_conversion_form_t cform);
1077 #  endif /*OPENSSL_NO_DEPRECATED_3_0 */
1078 
1079 #  define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
1080     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
1081 
1082 #  ifndef OPENSSL_NO_DEPRECATED_3_0
1083 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);
1084 OSSL_DEPRECATEDIN_3_0 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);
1085 
1086 /* wrapper functions for the underlying EC_GROUP object */
1087 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
1088 
1089 /** Creates a table of pre-computed multiples of the generator to
1090  *  accelerate further EC_KEY operations.
1091  *  \param  key  EC_KEY object
1092  *  \param  ctx  BN_CTX object (optional)
1093  *  \return 1 on success and 0 if an error occurred.
1094  */
1095 OSSL_DEPRECATEDIN_3_0 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
1096 
1097 /** Creates a new ec private (and optional a new public) key.
1098  *  \param  key  EC_KEY object
1099  *  \return 1 on success and 0 if an error occurred.
1100  */
1101 OSSL_DEPRECATEDIN_3_0 int EC_KEY_generate_key(EC_KEY *key);
1102 
1103 /** Verifies that a private and/or public key is valid.
1104  *  \param  key  the EC_KEY object
1105  *  \return 1 on success and 0 otherwise.
1106  */
1107 OSSL_DEPRECATEDIN_3_0 int EC_KEY_check_key(const EC_KEY *key);
1108 
1109 /** Indicates if an EC_KEY can be used for signing.
1110  *  \param  eckey  the EC_KEY object
1111  *  \return 1 if can can sign and 0 otherwise.
1112  */
1113 OSSL_DEPRECATEDIN_3_0 int EC_KEY_can_sign(const EC_KEY *eckey);
1114 
1115 /** Sets a public key from affine coordinates performing
1116  *  necessary NIST PKV tests.
1117  *  \param  key  the EC_KEY object
1118  *  \param  x    public key x coordinate
1119  *  \param  y    public key y coordinate
1120  *  \return 1 on success and 0 otherwise.
1121  */
1122 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key,
1123                                                                    BIGNUM *x,
1124                                                                    BIGNUM *y);
1125 
1126 /** Encodes an EC_KEY public key to an allocated octet string
1127  *  \param  key    key to encode
1128  *  \param  form   point conversion form
1129  *  \param  pbuf   returns pointer to allocated buffer
1130  *  \param  ctx    BN_CTX object (optional)
1131  *  \return the length of the encoded octet string or 0 if an error occurred
1132  */
1133 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_key2buf(const EC_KEY *key,
1134                                             point_conversion_form_t form,
1135                                             unsigned char **pbuf, BN_CTX *ctx);
1136 
1137 /** Decodes a EC_KEY public key from a octet string
1138  *  \param  key    key to decode
1139  *  \param  buf    memory buffer with the encoded ec point
1140  *  \param  len    length of the encoded ec point
1141  *  \param  ctx    BN_CTX object (optional)
1142  *  \return 1 on success and 0 if an error occurred
1143  */
1144 
1145 OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf,
1146                                          size_t len, BN_CTX *ctx);
1147 
1148 /** Decodes an EC_KEY private key from an octet string
1149  *  \param  key    key to decode
1150  *  \param  buf    memory buffer with the encoded private key
1151  *  \param  len    length of the encoded key
1152  *  \return 1 on success and 0 if an error occurred
1153  */
1154 
1155 OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf,
1156                                           size_t len);
1157 
1158 /** Encodes a EC_KEY private key to an octet string
1159  *  \param  key    key to encode
1160  *  \param  buf    memory buffer for the result. If NULL the function returns
1161  *                 required buffer size.
1162  *  \param  len    length of the memory buffer
1163  *  \return the length of the encoded octet string or 0 if an error occurred
1164  */
1165 
1166 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2oct(const EC_KEY *key,
1167                                              unsigned char *buf, size_t len);
1168 
1169 /** Encodes an EC_KEY private key to an allocated octet string
1170  *  \param  eckey  key to encode
1171  *  \param  pbuf   returns pointer to allocated buffer
1172  *  \return the length of the encoded octet string or 0 if an error occurred
1173  */
1174 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2buf(const EC_KEY *eckey,
1175                                              unsigned char **pbuf);
1176 
1177 /********************************************************************/
1178 /*        de- and encoding functions for SEC1 ECPrivateKey          */
1179 /********************************************************************/
1180 
1181 /** Decodes a private key from a memory buffer.
1182  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1183  *  \param  in   pointer to memory with the DER encoded private key
1184  *  \param  len  length of the DER encoded private key
1185  *  \return the decoded private key or NULL if an error occurred.
1186  */
1187 OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECPrivateKey(EC_KEY **key,
1188                                                const unsigned char **in,
1189                                                long len);
1190 
1191 /** Encodes a private key object and stores the result in a buffer.
1192  *  \param  key  the EC_KEY object to encode
1193  *  \param  out  the buffer for the result (if NULL the function returns number
1194  *               of bytes needed).
1195  *  \return 1 on success and 0 if an error occurred.
1196  */
1197 OSSL_DEPRECATEDIN_3_0 int i2d_ECPrivateKey(const EC_KEY *key,
1198                                            unsigned char **out);
1199 
1200 /********************************************************************/
1201 /*        de- and encoding functions for EC parameters              */
1202 /********************************************************************/
1203 
1204 /** Decodes ec parameter from a memory buffer.
1205  *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)
1206  *  \param  in   pointer to memory with the DER encoded ec parameters
1207  *  \param  len  length of the DER encoded ec parameters
1208  *  \return a EC_KEY object with the decoded parameters or NULL if an error
1209  *          occurred.
1210  */
1211 OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECParameters(EC_KEY **key,
1212                                                const unsigned char **in,
1213                                                long len);
1214 
1215 /** Encodes ec parameter and stores the result in a buffer.
1216  *  \param  key  the EC_KEY object with ec parameters to encode
1217  *  \param  out  the buffer for the result (if NULL the function returns number
1218  *               of bytes needed).
1219  *  \return 1 on success and 0 if an error occurred.
1220  */
1221 OSSL_DEPRECATEDIN_3_0 int i2d_ECParameters(const EC_KEY *key,
1222                                            unsigned char **out);
1223 
1224 /********************************************************************/
1225 /*         de- and encoding functions for EC public key             */
1226 /*         (octet string, not DER -- hence 'o2i' and 'i2o')         */
1227 /********************************************************************/
1228 
1229 /** Decodes an ec public key from a octet string.
1230  *  \param  key  a pointer to a EC_KEY object which should be used
1231  *  \param  in   memory buffer with the encoded public key
1232  *  \param  len  length of the encoded public key
1233  *  \return EC_KEY object with decoded public key or NULL if an error
1234  *          occurred.
1235  */
1236 OSSL_DEPRECATEDIN_3_0 EC_KEY *o2i_ECPublicKey(EC_KEY **key,
1237                                               const unsigned char **in, long len);
1238 
1239 /** Encodes an ec public key in an octet string.
1240  *  \param  key  the EC_KEY object with the public key
1241  *  \param  out  the buffer for the result (if NULL the function returns number
1242  *               of bytes needed).
1243  *  \return 1 on success and 0 if an error occurred
1244  */
1245 OSSL_DEPRECATEDIN_3_0 int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out);
1246 
1247 /** Prints out the ec parameters on human readable form.
1248  *  \param  bp   BIO object to which the information is printed
1249  *  \param  key  EC_KEY object
1250  *  \return 1 on success and 0 if an error occurred
1251  */
1252 OSSL_DEPRECATEDIN_3_0 int ECParameters_print(BIO *bp, const EC_KEY *key);
1253 
1254 /** Prints out the contents of a EC_KEY object
1255  *  \param  bp   BIO object to which the information is printed
1256  *  \param  key  EC_KEY object
1257  *  \param  off  line offset
1258  *  \return 1 on success and 0 if an error occurred
1259  */
1260 OSSL_DEPRECATEDIN_3_0 int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
1261 
1262 #   ifndef OPENSSL_NO_STDIO
1263 /** Prints out the ec parameters on human readable form.
1264  *  \param  fp   file descriptor to which the information is printed
1265  *  \param  key  EC_KEY object
1266  *  \return 1 on success and 0 if an error occurred
1267  */
1268 OSSL_DEPRECATEDIN_3_0 int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
1269 
1270 /** Prints out the contents of a EC_KEY object
1271  *  \param  fp   file descriptor to which the information is printed
1272  *  \param  key  EC_KEY object
1273  *  \param  off  line offset
1274  *  \return 1 on success and 0 if an error occurred
1275  */
1276 OSSL_DEPRECATEDIN_3_0 int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
1277 #   endif /* OPENSSL_NO_STDIO */
1278 
1279 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_OpenSSL(void);
1280 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_get_default_method(void);
1281 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
1282 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
1283 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
1284 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_method(ENGINE *engine);
1285 
1286 /** The old name for ecdh_KDF_X9_63
1287  *  The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
1288  *  it is actually specified in ANSI X9.63.
1289  *  This identifier is retained for backwards compatibility
1290  */
1291 OSSL_DEPRECATEDIN_3_0 int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
1292                                          const unsigned char *Z, size_t Zlen,
1293                                          const unsigned char *sinfo,
1294                                          size_t sinfolen, const EVP_MD *md);
1295 
1296 OSSL_DEPRECATEDIN_3_0 int ECDH_compute_key(void *out, size_t outlen,
1297                                            const EC_POINT *pub_key,
1298                                            const EC_KEY *ecdh,
1299                                            void *(*KDF)(const void *in,
1300                                                         size_t inlen, void *out,
1301                                                         size_t *outlen));
1302 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
1303 
1304 typedef struct ECDSA_SIG_st ECDSA_SIG;
1305 
1306 /** Allocates and initialize a ECDSA_SIG structure
1307  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1308  */
1309 ECDSA_SIG *ECDSA_SIG_new(void);
1310 
1311 /** frees a ECDSA_SIG structure
1312  *  \param  sig  pointer to the ECDSA_SIG structure
1313  */
1314 void ECDSA_SIG_free(ECDSA_SIG *sig);
1315 
1316 /** i2d_ECDSA_SIG encodes content of ECDSA_SIG (note: this function modifies *pp
1317  *  (*pp += length of the DER encoded signature)).
1318  *  \param  sig  pointer to the ECDSA_SIG object
1319  *  \param  pp   pointer to a unsigned char pointer for the output or NULL
1320  *  \return the length of the DER encoded ECDSA_SIG object or a negative value
1321  *          on error
1322  */
1323 DECLARE_ASN1_ENCODE_FUNCTIONS_only(ECDSA_SIG, ECDSA_SIG)
1324 
1325 /** d2i_ECDSA_SIG decodes an ECDSA signature (note: this function modifies *pp
1326  *  (*pp += len)).
1327  *  \param  sig  pointer to ECDSA_SIG pointer (may be NULL)
1328  *  \param  pp   memory buffer with the DER encoded signature
1329  *  \param  len  length of the buffer
1330  *  \return pointer to the decoded ECDSA_SIG structure (or NULL)
1331  */
1332 
1333 /** Accessor for r and s fields of ECDSA_SIG
1334  *  \param  sig  pointer to ECDSA_SIG structure
1335  *  \param  pr   pointer to BIGNUM pointer for r (may be NULL)
1336  *  \param  ps   pointer to BIGNUM pointer for s (may be NULL)
1337  */
1338 void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
1339 
1340 /** Accessor for r field of ECDSA_SIG
1341  *  \param  sig  pointer to ECDSA_SIG structure
1342  */
1343 const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
1344 
1345 /** Accessor for s field of ECDSA_SIG
1346  *  \param  sig  pointer to ECDSA_SIG structure
1347  */
1348 const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
1349 
1350 /** Setter for r and s fields of ECDSA_SIG
1351  *  \param  sig  pointer to ECDSA_SIG structure
1352  *  \param  r    pointer to BIGNUM for r
1353  *  \param  s    pointer to BIGNUM for s
1354  */
1355 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
1356 
1357 #  ifndef OPENSSL_NO_DEPRECATED_3_0
1358 /** Computes the ECDSA signature of the given hash value using
1359  *  the supplied private key and returns the created signature.
1360  *  \param  dgst      pointer to the hash value
1361  *  \param  dgst_len  length of the hash value
1362  *  \param  eckey     EC_KEY object containing a private EC key
1363  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1364  */
1365 OSSL_DEPRECATEDIN_3_0 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,
1366                                                int dgst_len, EC_KEY *eckey);
1367 
1368 /** Computes ECDSA signature of a given hash value using the supplied
1369  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1370  *  \param  dgst     pointer to the hash value to sign
1371  *  \param  dgstlen  length of the hash value
1372  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1373  *  \param  rp       BIGNUM with a pre-computed rp value (optional),
1374  *                   see ECDSA_sign_setup
1375  *  \param  eckey    EC_KEY object containing a private EC key
1376  *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1377  */
1378 OSSL_DEPRECATEDIN_3_0 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst,
1379                                                   int dgstlen, const BIGNUM *kinv,
1380                                                   const BIGNUM *rp, EC_KEY *eckey);
1381 
1382 /** Verifies that the supplied signature is a valid ECDSA
1383  *  signature of the supplied hash value using the supplied public key.
1384  *  \param  dgst      pointer to the hash value
1385  *  \param  dgst_len  length of the hash value
1386  *  \param  sig       ECDSA_SIG structure
1387  *  \param  eckey     EC_KEY object containing a public EC key
1388  *  \return 1 if the signature is valid, 0 if the signature is invalid
1389  *          and -1 on error
1390  */
1391 OSSL_DEPRECATEDIN_3_0 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
1392                                           const ECDSA_SIG *sig, EC_KEY *eckey);
1393 
1394 /** Precompute parts of the signing operation
1395  *  \param  eckey  EC_KEY object containing a private EC key
1396  *  \param  ctx    BN_CTX object (optional)
1397  *  \param  kinv   BIGNUM pointer for the inverse of k
1398  *  \param  rp     BIGNUM pointer for x coordinate of k * generator
1399  *  \return 1 on success and 0 otherwise
1400  */
1401 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
1402                                            BIGNUM **kinv, BIGNUM **rp);
1403 
1404 /** Computes ECDSA signature of a given hash value using the supplied
1405  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1406  *  \param  type     this parameter is ignored
1407  *  \param  dgst     pointer to the hash value to sign
1408  *  \param  dgstlen  length of the hash value
1409  *  \param  sig      memory for the DER encoded created signature
1410  *  \param  siglen   pointer to the length of the returned signature
1411  *  \param  eckey    EC_KEY object containing a private EC key
1412  *  \return 1 on success and 0 otherwise
1413  */
1414 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign(int type, const unsigned char *dgst,
1415                                      int dgstlen, unsigned char *sig,
1416                                      unsigned int *siglen, EC_KEY *eckey);
1417 
1418 /** Computes ECDSA signature of a given hash value using the supplied
1419  *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1420  *  \param  type     this parameter is ignored
1421  *  \param  dgst     pointer to the hash value to sign
1422  *  \param  dgstlen  length of the hash value
1423  *  \param  sig      buffer to hold the DER encoded signature
1424  *  \param  siglen   pointer to the length of the returned signature
1425  *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
1426  *  \param  rp       BIGNUM with a pre-computed rp value (optional),
1427  *                   see ECDSA_sign_setup
1428  *  \param  eckey    EC_KEY object containing a private EC key
1429  *  \return 1 on success and 0 otherwise
1430  */
1431 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign_ex(int type, const unsigned char *dgst,
1432                                         int dgstlen, unsigned char *sig,
1433                                         unsigned int *siglen, const BIGNUM *kinv,
1434                                         const BIGNUM *rp, EC_KEY *eckey);
1435 
1436 /** Verifies that the given signature is valid ECDSA signature
1437  *  of the supplied hash value using the specified public key.
1438  *  \param  type     this parameter is ignored
1439  *  \param  dgst     pointer to the hash value
1440  *  \param  dgstlen  length of the hash value
1441  *  \param  sig      pointer to the DER encoded signature
1442  *  \param  siglen   length of the DER encoded signature
1443  *  \param  eckey    EC_KEY object containing a public EC key
1444  *  \return 1 if the signature is valid, 0 if the signature is invalid
1445  *          and -1 on error
1446  */
1447 OSSL_DEPRECATEDIN_3_0 int ECDSA_verify(int type, const unsigned char *dgst,
1448                                        int dgstlen, const unsigned char *sig,
1449                                        int siglen, EC_KEY *eckey);
1450 
1451 /** Returns the maximum length of the DER encoded signature
1452  *  \param  eckey  EC_KEY object
1453  *  \return numbers of bytes required for the DER encoded signature
1454  */
1455 OSSL_DEPRECATEDIN_3_0 int ECDSA_size(const EC_KEY *eckey);
1456 
1457 /********************************************************************/
1458 /*  EC_KEY_METHOD constructors, destructors, writers and accessors  */
1459 /********************************************************************/
1460 
1461 OSSL_DEPRECATEDIN_3_0 EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
1462 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
1463 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_init
1464                       (EC_KEY_METHOD *meth,
1465                        int (*init)(EC_KEY *key),
1466                        void (*finish)(EC_KEY *key),
1467                        int (*copy)(EC_KEY *dest, const EC_KEY *src),
1468                        int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
1469                        int (*set_private)(EC_KEY *key, const BIGNUM *priv_key),
1470                        int (*set_public)(EC_KEY *key, const EC_POINT *pub_key));
1471 
1472 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
1473                                                     int (*keygen)(EC_KEY *key));
1474 
1475 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_compute_key
1476                       (EC_KEY_METHOD *meth,
1477                        int (*ckey)(unsigned char **psec, size_t *pseclen,
1478                                    const EC_POINT *pub_key, const EC_KEY *ecdh));
1479 
1480 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_sign
1481                       (EC_KEY_METHOD *meth,
1482                        int (*sign)(int type, const unsigned char *dgst,
1483                                    int dlen, unsigned char *sig,
1484                                    unsigned int *siglen,
1485                                    const BIGNUM *kinv, const BIGNUM *r,
1486                                    EC_KEY *eckey),
1487                        int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1488                                          BIGNUM **kinvp, BIGNUM **rp),
1489                        ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
1490                                               int dgst_len,
1491                                               const BIGNUM *in_kinv,
1492                                               const BIGNUM *in_r,
1493                                               EC_KEY *eckey));
1494 
1495 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_verify
1496                       (EC_KEY_METHOD *meth,
1497                        int (*verify)(int type, const unsigned
1498                                      char *dgst, int dgst_len,
1499                                      const unsigned char *sigbuf,
1500                                      int sig_len, EC_KEY *eckey),
1501                        int (*verify_sig)(const unsigned char *dgst,
1502                                          int dgst_len, const ECDSA_SIG *sig,
1503                                          EC_KEY *eckey));
1504 
1505 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_init
1506                       (const EC_KEY_METHOD *meth,
1507                        int (**pinit)(EC_KEY *key),
1508                        void (**pfinish)(EC_KEY *key),
1509                        int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
1510                        int (**pset_group)(EC_KEY *key, const EC_GROUP *grp),
1511                        int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key),
1512                        int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key));
1513 
1514 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_keygen
1515                       (const EC_KEY_METHOD *meth, int (**pkeygen)(EC_KEY *key));
1516 
1517 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_compute_key
1518                       (const EC_KEY_METHOD *meth,
1519                        int (**pck)(unsigned char **psec,
1520                        size_t *pseclen,
1521                        const EC_POINT *pub_key,
1522                        const EC_KEY *ecdh));
1523 
1524 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_sign
1525                       (const EC_KEY_METHOD *meth,
1526                        int (**psign)(int type, const unsigned char *dgst,
1527                                      int dlen, unsigned char *sig,
1528                                      unsigned int *siglen,
1529                                      const BIGNUM *kinv, const BIGNUM *r,
1530                                      EC_KEY *eckey),
1531                        int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
1532                                            BIGNUM **kinvp, BIGNUM **rp),
1533                        ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
1534                                                 int dgst_len,
1535                                                 const BIGNUM *in_kinv,
1536                                                 const BIGNUM *in_r,
1537                                                 EC_KEY *eckey));
1538 
1539 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_verify
1540                       (const EC_KEY_METHOD *meth,
1541                        int (**pverify)(int type, const unsigned
1542                                        char *dgst, int dgst_len,
1543                                        const unsigned char *sigbuf,
1544                                        int sig_len, EC_KEY *eckey),
1545                        int (**pverify_sig)(const unsigned char *dgst,
1546                                            int dgst_len,
1547                                            const ECDSA_SIG *sig,
1548                                            EC_KEY *eckey));
1549 #  endif /* OPENSSL_NO_DEPRECATED_3_0 */
1550 
1551 #  define EVP_EC_gen(curve) \
1552     EVP_PKEY_Q_keygen(NULL, NULL, "EC", (char *)(strstr(curve, "")))
1553     /* strstr is used to enable type checking for the variadic string arg */
1554 #  define ECParameters_dup(x) ASN1_dup_of(EC_KEY, i2d_ECParameters, \
1555                                           d2i_ECParameters, x)
1556 
1557 #  ifndef __cplusplus
1558 #   if defined(__SUNPRO_C)
1559 #    if __SUNPRO_C >= 0x520
1560 #     pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
1561 #    endif
1562 #   endif
1563 #  endif
1564 
1565 # endif
1566 # ifdef  __cplusplus
1567 }
1568 # endif
1569 #endif
1570