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