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