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