2 * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
15 # include <openssl/macros.h>
16 # ifndef OPENSSL_NO_DEPRECATED_3_0
20 # include <openssl/opensslconf.h>
22 # ifndef OPENSSL_NO_EC
23 # include <openssl/asn1.h>
24 # include <openssl/symhacks.h>
25 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
26 # include <openssl/bn.h>
28 # include <openssl/ecerr.h>
33 # ifndef OPENSSL_ECC_MAX_FIELD_BITS
34 # define OPENSSL_ECC_MAX_FIELD_BITS 661
37 /** Enum for the point conversion form as defined in X9.62 (ECDSA)
38 * for the encoding of a elliptic curve point (x,y) */
40 /** the point is encoded as z||x, where the octet z specifies
41 * which solution of the quadratic equation y is */
42 POINT_CONVERSION_COMPRESSED
= 2,
43 /** the point is encoded as z||x||y, where z is the octet 0x04 */
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
48 } point_conversion_form_t
;
50 # include <openssl/params.h>
51 # ifndef OPENSSL_NO_DEPRECATED_3_0
52 typedef struct ec_method_st EC_METHOD
;
54 typedef struct ec_group_st EC_GROUP
;
55 typedef struct ec_point_st EC_POINT
;
56 typedef struct ecpk_parameters_st ECPKPARAMETERS
;
57 typedef struct ec_parameters_st ECPARAMETERS
;
59 /********************************************************************/
60 /* EC_METHODs for curves over GF(p) */
61 /********************************************************************/
63 /** Returns the basic GFp ec methods which provides the basis for the
65 * \return EC_METHOD object
67 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_simple_method(void))
69 /** Returns GFp methods using montgomery multiplication.
70 * \return EC_METHOD object
72 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_mont_method(void))
74 /** Returns GFp methods using optimized methods for NIST recommended curves
75 * \return EC_METHOD object
77 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_nist_method(void))
79 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
80 /** Returns 64-bit optimized methods for nistp224
81 * \return EC_METHOD object
83 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_nistp224_method(void))
85 /** Returns 64-bit optimized methods for nistp256
86 * \return EC_METHOD object
88 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_nistp256_method(void))
90 /** Returns 64-bit optimized methods for nistp521
91 * \return EC_METHOD object
93 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GFp_nistp521_method(void))
96 # ifndef OPENSSL_NO_EC2M
97 /********************************************************************/
98 /* EC_METHOD for curves over GF(2^m) */
99 /********************************************************************/
101 /** Returns the basic GF2m ec method
102 * \return EC_METHOD object
104 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GF2m_simple_method(void))
108 /********************************************************************/
109 /* EC_GROUP functions */
110 /********************************************************************/
113 * Creates a new EC_GROUP object
114 * \param meth EC_METHOD to use
115 * \return newly created EC_GROUP object or NULL in case of an error.
117 DEPRECATEDIN_3_0(EC_GROUP
*EC_GROUP_new(const EC_METHOD
*meth
))
119 /** Frees a EC_GROUP object
120 * \param group EC_GROUP object to be freed.
122 void EC_GROUP_free(EC_GROUP
*group
);
124 /** Clears and frees a EC_GROUP object
125 * \param group EC_GROUP object to be cleared and freed.
127 DEPRECATEDIN_3_0(void EC_GROUP_clear_free(EC_GROUP
*group
))
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.
134 int EC_GROUP_copy(EC_GROUP
*dst
, const EC_GROUP
*src
);
136 /** Creates a new EC_GROUP object and copies the content
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.
141 EC_GROUP
*EC_GROUP_dup(const EC_GROUP
*src
);
143 /** Returns the EC_METHOD of the EC_GROUP object.
144 * \param group EC_GROUP object
145 * \return EC_METHOD used in this EC_GROUP object.
147 DEPRECATEDIN_3_0(const EC_METHOD
*EC_GROUP_method_of(const EC_GROUP
*group
))
149 /** Returns the field type of the EC_METHOD.
150 * \param meth EC_METHOD object
151 * \return NID of the underlying field type OID.
153 DEPRECATEDIN_3_0(int EC_METHOD_get_field_type(const EC_METHOD
*meth
))
155 /** Sets the generator and its order/cofactor of a EC_GROUP object.
156 * \param group EC_GROUP object
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.
161 * \return 1 on success and 0 if an error occurred
163 int EC_GROUP_set_generator(EC_GROUP
*group
, const EC_POINT
*generator
,
164 const BIGNUM
*order
, const BIGNUM
*cofactor
);
166 /** Returns the generator of a EC_GROUP object.
167 * \param group EC_GROUP object
168 * \return the currently used generator (possibly NULL).
170 const EC_POINT
*EC_GROUP_get0_generator(const EC_GROUP
*group
);
172 /** Returns the montgomery data for order(Generator)
173 * \param group EC_GROUP object
174 * \return the currently used montgomery data (possibly NULL).
176 BN_MONT_CTX
*EC_GROUP_get_mont_data(const EC_GROUP
*group
);
178 /** Gets the order of a EC_GROUP
179 * \param group EC_GROUP object
180 * \param order BIGNUM to which the order is copied
182 * \return 1 on success and 0 if an error occurred
184 int EC_GROUP_get_order(const EC_GROUP
*group
, BIGNUM
*order
, BN_CTX
*ctx
);
186 /** Gets the order of an EC_GROUP
187 * \param group EC_GROUP object
188 * \return the group order
190 const BIGNUM
*EC_GROUP_get0_order(const EC_GROUP
*group
);
192 /** Gets the number of bits of the order of an EC_GROUP
193 * \param group EC_GROUP object
194 * \return number of bits of group order.
196 int EC_GROUP_order_bits(const EC_GROUP
*group
);
198 /** Gets the cofactor of a EC_GROUP
199 * \param group EC_GROUP object
200 * \param cofactor BIGNUM to which the cofactor is copied
202 * \return 1 on success and 0 if an error occurred
204 int EC_GROUP_get_cofactor(const EC_GROUP
*group
, BIGNUM
*cofactor
,
207 /** Gets the cofactor of an EC_GROUP
208 * \param group EC_GROUP object
209 * \return the group cofactor
211 const BIGNUM
*EC_GROUP_get0_cofactor(const EC_GROUP
*group
);
213 /** Sets the name of a EC_GROUP object
214 * \param group EC_GROUP object
215 * \param nid NID of the curve name OID
217 void EC_GROUP_set_curve_name(EC_GROUP
*group
, int nid
);
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.
223 int EC_GROUP_get_curve_name(const EC_GROUP
*group
);
225 /** Gets the field of an EC_GROUP
226 * \param group EC_GROUP object
227 * \return the group field
229 const BIGNUM
*EC_GROUP_get0_field(const EC_GROUP
*group
);
231 /** Returns the field type of the EC_GROUP.
232 * \param group EC_GROUP object
233 * \return NID of the underlying field type OID.
235 int EC_GROUP_get_field_type(const EC_GROUP
*group
);
237 void EC_GROUP_set_asn1_flag(EC_GROUP
*group
, int flag
);
238 int EC_GROUP_get_asn1_flag(const EC_GROUP
*group
);
240 void EC_GROUP_set_point_conversion_form(EC_GROUP
*group
,
241 point_conversion_form_t form
);
242 point_conversion_form_t
EC_GROUP_get_point_conversion_form(const EC_GROUP
*);
244 unsigned char *EC_GROUP_get0_seed(const EC_GROUP
*x
);
245 size_t EC_GROUP_get_seed_len(const EC_GROUP
*);
246 size_t EC_GROUP_set_seed(EC_GROUP
*, const unsigned char *, size_t len
);
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)
250 * \param group EC_GROUP object
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
258 int EC_GROUP_set_curve(EC_GROUP
*group
, const BIGNUM
*p
, const BIGNUM
*a
,
259 const BIGNUM
*b
, BN_CTX
*ctx
);
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
271 int EC_GROUP_get_curve(const EC_GROUP
*group
, BIGNUM
*p
, BIGNUM
*a
, BIGNUM
*b
,
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)
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)
281 * \return 1 on success and 0 if an error occurred
283 DEPRECATEDIN_3_0(int EC_GROUP_set_curve_GFp(EC_GROUP
*group
, const BIGNUM
*p
,
284 const BIGNUM
*a
, const BIGNUM
*b
,
287 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
288 * \param group EC_GROUP object
289 * \param p BIGNUM with the prime number (GFp) or the polynomial
290 * defining the underlying field (GF2m)
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)
294 * \return 1 on success and 0 if an error occurred
296 DEPRECATEDIN_3_0(int EC_GROUP_get_curve_GFp(const EC_GROUP
*group
, BIGNUM
*p
,
297 BIGNUM
*a
, BIGNUM
*b
,
300 # ifndef OPENSSL_NO_EC2M
301 /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve
302 * \param group EC_GROUP object
303 * \param p BIGNUM with the prime number (GFp) or the polynomial
304 * defining the underlying field (GF2m)
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)
308 * \return 1 on success and 0 if an error occurred
310 DEPRECATEDIN_3_0(int EC_GROUP_set_curve_GF2m(EC_GROUP
*group
, const BIGNUM
*p
,
311 const BIGNUM
*a
, const BIGNUM
*b
,
314 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
315 * \param group EC_GROUP object
316 * \param p BIGNUM with the prime number (GFp) or the polynomial
317 * defining the underlying field (GF2m)
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)
321 * \return 1 on success and 0 if an error occurred
323 DEPRECATEDIN_3_0(int EC_GROUP_get_curve_GF2m(const EC_GROUP
*group
, BIGNUM
*p
,
324 BIGNUM
*a
, BIGNUM
*b
,
327 /** Returns the number of bits needed to represent a field element
328 * \param group EC_GROUP object
329 * \return number of bits needed to represent a field element
331 int EC_GROUP_get_degree(const EC_GROUP
*group
);
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
338 int EC_GROUP_check(const EC_GROUP
*group
, BN_CTX
*ctx
);
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
345 int EC_GROUP_check_discriminant(const EC_GROUP
*group
, BN_CTX
*ctx
);
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)
351 * \return 0 if the groups are equal, 1 if not, or -1 on error
353 int EC_GROUP_cmp(const EC_GROUP
*a
, const EC_GROUP
*b
, BN_CTX
*ctx
);
356 * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
357 * choosing an appropriate EC_METHOD
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
368 EC_GROUP
*EC_GROUP_new_curve_GFp(const BIGNUM
*p
, const BIGNUM
*a
,
369 const BIGNUM
*b
, BN_CTX
*ctx
);
370 # ifndef OPENSSL_NO_EC2M
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
379 EC_GROUP
*EC_GROUP_new_curve_GF2m(const BIGNUM
*p
, const BIGNUM
*a
,
380 const BIGNUM
*b
, BN_CTX
*ctx
);
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
389 * \param propq A property query string
390 * \return newly created EC_GROUP object with specified parameters or NULL
391 * if an error occurred
393 EC_GROUP
*EC_GROUP_new_from_params(const OSSL_PARAM params
[],
394 OSSL_LIB_CTX
*libctx
, const char *propq
);
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
400 * \param propq A property query string
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
405 EC_GROUP
*EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX
*libctx
, const char *propq
,
409 * Creates a EC_GROUP object with a curve specified by a NID. Same as
410 * EC_GROUP_new_by_curve_name_ex but the libctx and propq are always
412 * \param nid NID of the OID of the curve name
413 * \return newly created EC_GROUP object with specified curve or NULL
414 * if an error occurred
416 EC_GROUP
*EC_GROUP_new_by_curve_name(int nid
);
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
423 EC_GROUP
*EC_GROUP_new_from_ecparameters(const ECPARAMETERS
*params
);
425 /** Creates an ECPARAMETERS object for the given EC_GROUP object.
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.
431 ECPARAMETERS
*EC_GROUP_get_ecparameters(const EC_GROUP
*group
,
432 ECPARAMETERS
*params
);
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
439 EC_GROUP
*EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS
*params
);
441 /** Creates an ECPKPARAMETERS object for the given EC_GROUP object.
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.
447 ECPKPARAMETERS
*EC_GROUP_get_ecpkparameters(const EC_GROUP
*group
,
448 ECPKPARAMETERS
*params
);
450 /********************************************************************/
451 /* handling of internal curves */
452 /********************************************************************/
460 * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
461 * available curves or zero if a error occurred. In case r is not zero,
462 * nitems EC_builtin_curve structures are filled with the data of the first
463 * nitems internal groups
465 size_t EC_get_builtin_curves(EC_builtin_curve
*r
, size_t nitems
);
467 const char *EC_curve_nid2nist(int nid
);
468 int EC_curve_nist2nid(const char *name
);
469 int EC_GROUP_check_named_curve(const EC_GROUP
*group
, int nist_only
,
472 /********************************************************************/
473 /* EC_POINT functions */
474 /********************************************************************/
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
480 EC_POINT
*EC_POINT_new(const EC_GROUP
*group
);
482 /** Frees a EC_POINT object
483 * \param point EC_POINT object to be freed
485 void EC_POINT_free(EC_POINT
*point
);
487 /** Clears and frees a EC_POINT object
488 * \param point EC_POINT object to be cleared and freed
490 void EC_POINT_clear_free(EC_POINT
*point
);
492 /** Copies EC_POINT object
493 * \param dst destination EC_POINT object
494 * \param src source EC_POINT object
495 * \return 1 on success and 0 if an error occurred
497 int EC_POINT_copy(EC_POINT
*dst
, const EC_POINT
*src
);
499 /** Creates a new EC_POINT object and copies the content of the supplied
501 * \param src source EC_POINT object
502 * \param group underlying the EC_GROUP object
503 * \return newly created EC_POINT object or NULL if an error occurred
505 EC_POINT
*EC_POINT_dup(const EC_POINT
*src
, const EC_GROUP
*group
);
507 /** Returns the EC_METHOD used in EC_POINT object
508 * \param point EC_POINT object
509 * \return the EC_METHOD used
511 DEPRECATEDIN_3_0(const EC_METHOD
*EC_POINT_method_of(const EC_POINT
*point
))
513 /** Sets a point to infinity (neutral element)
514 * \param group underlying EC_GROUP object
515 * \param point EC_POINT to set to infinity
516 * \return 1 on success and 0 if an error occurred
518 int EC_POINT_set_to_infinity(const EC_GROUP
*group
, EC_POINT
*point
);
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)
527 * \return 1 on success and 0 if an error occurred
529 DEPRECATEDIN_3_0(int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP
*group
,
530 EC_POINT
*p
, const BIGNUM
*x
,
531 const BIGNUM
*y
, const BIGNUM
*z
,
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)
541 * \return 1 on success and 0 if an error occurred
543 DEPRECATEDIN_3_0(int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP
*group
,
544 const EC_POINT
*p
, BIGNUM
*x
,
545 BIGNUM
*y
, BIGNUM
*z
,
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
556 int EC_POINT_set_affine_coordinates(const EC_GROUP
*group
, EC_POINT
*p
,
557 const BIGNUM
*x
, const BIGNUM
*y
,
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
568 int EC_POINT_get_affine_coordinates(const EC_GROUP
*group
, const EC_POINT
*p
,
569 BIGNUM
*x
, BIGNUM
*y
, BN_CTX
*ctx
);
571 /** Sets the affine coordinates of an EC_POINT. A synonym of
572 * EC_POINT_set_affine_coordinates
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)
578 * \return 1 on success and 0 if an error occurred
580 DEPRECATEDIN_3_0(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP
*group
,
586 /** Gets the affine coordinates of an EC_POINT. A synonym of
587 * EC_POINT_get_affine_coordinates
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)
593 * \return 1 on success and 0 if an error occurred
595 DEPRECATEDIN_3_0(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP
*group
,
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
609 int EC_POINT_set_compressed_coordinates(const EC_GROUP
*group
, EC_POINT
*p
,
610 const BIGNUM
*x
, int y_bit
,
613 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
614 * EC_POINT_set_compressed_coordinates
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)
620 * \return 1 on success and 0 if an error occurred
622 DEPRECATEDIN_3_0(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP
*group
,
627 # ifndef OPENSSL_NO_EC2M
628 /** Sets the affine coordinates of an EC_POINT. A synonym of
629 * EC_POINT_set_affine_coordinates
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)
635 * \return 1 on success and 0 if an error occurred
637 DEPRECATEDIN_3_0(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP
*group
,
643 /** Gets the affine coordinates of an EC_POINT. A synonym of
644 * EC_POINT_get_affine_coordinates
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)
650 * \return 1 on success and 0 if an error occurred
652 DEPRECATEDIN_3_0(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP
*group
,
658 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
659 * EC_POINT_set_compressed_coordinates
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)
665 * \return 1 on success and 0 if an error occurred
667 DEPRECATEDIN_3_0(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP
*group
,
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
683 size_t EC_POINT_point2oct(const EC_GROUP
*group
, const EC_POINT
*p
,
684 point_conversion_form_t form
,
685 unsigned char *buf
, size_t len
, BN_CTX
*ctx
);
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)
693 * \return 1 on success and 0 if an error occurred
695 int EC_POINT_oct2point(const EC_GROUP
*group
, EC_POINT
*p
,
696 const unsigned char *buf
, size_t len
, BN_CTX
*ctx
);
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
703 * \param ctx BN_CTX object (optional)
704 * \return the length of the encoded octet string or 0 if an error occurred
706 size_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
);
710 /* other interfaces to point2oct/oct2point: */
711 # ifndef OPENSSL_NO_DEPRECATED_3_0
712 OSSL_DEPRECATEDIN_3_0 BIGNUM
*EC_POINT_point2bn(const EC_GROUP
*,
714 point_conversion_form_t form
,
716 OSSL_DEPRECATEDIN_3_0 EC_POINT
*EC_POINT_bn2point(const EC_GROUP
*,
718 EC_POINT
*, BN_CTX
*);
719 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
721 char *EC_POINT_point2hex(const EC_GROUP
*, const EC_POINT
*,
722 point_conversion_form_t form
, BN_CTX
*);
723 EC_POINT
*EC_POINT_hex2point(const EC_GROUP
*, const char *,
724 EC_POINT
*, BN_CTX
*);
726 /********************************************************************/
727 /* functions for doing EC_POINT arithmetic */
728 /********************************************************************/
730 /** Computes the sum of two EC_POINT
731 * \param group underlying EC_GROUP object
732 * \param r EC_POINT object for the result (r = a + b)
733 * \param a EC_POINT object with the first summand
734 * \param b EC_POINT object with the second summand
735 * \param ctx BN_CTX object (optional)
736 * \return 1 on success and 0 if an error occurred
738 int EC_POINT_add(const EC_GROUP
*group
, EC_POINT
*r
, const EC_POINT
*a
,
739 const EC_POINT
*b
, BN_CTX
*ctx
);
741 /** Computes the double of a EC_POINT
742 * \param group underlying EC_GROUP object
743 * \param r EC_POINT object for the result (r = 2 * a)
744 * \param a EC_POINT object
745 * \param ctx BN_CTX object (optional)
746 * \return 1 on success and 0 if an error occurred
748 int EC_POINT_dbl(const EC_GROUP
*group
, EC_POINT
*r
, const EC_POINT
*a
,
751 /** Computes the inverse of a EC_POINT
752 * \param group underlying EC_GROUP object
753 * \param a EC_POINT object to be inverted (it's used for the result as well)
754 * \param ctx BN_CTX object (optional)
755 * \return 1 on success and 0 if an error occurred
757 int EC_POINT_invert(const EC_GROUP
*group
, EC_POINT
*a
, BN_CTX
*ctx
);
759 /** Checks whether the point is the neutral element of the group
760 * \param group the underlying EC_GROUP object
761 * \param p EC_POINT object
762 * \return 1 if the point is the neutral element and 0 otherwise
764 int EC_POINT_is_at_infinity(const EC_GROUP
*group
, const EC_POINT
*p
);
766 /** Checks whether the point is on the curve
767 * \param group underlying EC_GROUP object
768 * \param point EC_POINT object to check
769 * \param ctx BN_CTX object (optional)
770 * \return 1 if the point is on the curve, 0 if not, or -1 on error
772 int EC_POINT_is_on_curve(const EC_GROUP
*group
, const EC_POINT
*point
,
775 /** Compares two EC_POINTs
776 * \param group underlying EC_GROUP object
777 * \param a first EC_POINT object
778 * \param b second EC_POINT object
779 * \param ctx BN_CTX object (optional)
780 * \return 1 if the points are not equal, 0 if they are, or -1 on error
782 int EC_POINT_cmp(const EC_GROUP
*group
, const EC_POINT
*a
, const EC_POINT
*b
,
785 DEPRECATEDIN_3_0(int EC_POINT_make_affine(const EC_GROUP
*group
,
786 EC_POINT
*point
, BN_CTX
*ctx
))
787 DEPRECATEDIN_3_0(int EC_POINTs_make_affine(const EC_GROUP
*group
, size_t num
,
788 EC_POINT
*points
[], BN_CTX
*ctx
))
790 /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i]
791 * \param group underlying EC_GROUP object
792 * \param r EC_POINT object for the result
793 * \param n BIGNUM with the multiplier for the group generator (optional)
794 * \param num number further summands
795 * \param p array of size num of EC_POINT objects
796 * \param m array of size num of BIGNUM objects
797 * \param ctx BN_CTX object (optional)
798 * \return 1 on success and 0 if an error occurred
800 DEPRECATEDIN_3_0(int EC_POINTs_mul(const EC_GROUP
*group
, EC_POINT
*r
,
801 const BIGNUM
*n
, size_t num
,
802 const EC_POINT
*p
[], const BIGNUM
*m
[],
805 /** Computes r = generator * n + q * m
806 * \param group underlying EC_GROUP object
807 * \param r EC_POINT object for the result
808 * \param n BIGNUM with the multiplier for the group generator (optional)
809 * \param q EC_POINT object with the first factor of the second summand
810 * \param m BIGNUM with the second factor of the second summand
811 * \param ctx BN_CTX object (optional)
812 * \return 1 on success and 0 if an error occurred
814 int EC_POINT_mul(const EC_GROUP
*group
, EC_POINT
*r
, const BIGNUM
*n
,
815 const EC_POINT
*q
, const BIGNUM
*m
, BN_CTX
*ctx
);
817 /** Stores multiples of generator for faster point multiplication
818 * \param group EC_GROUP object
819 * \param ctx BN_CTX object (optional)
820 * \return 1 on success and 0 if an error occurred
822 DEPRECATEDIN_3_0(int EC_GROUP_precompute_mult(EC_GROUP
*group
, BN_CTX
*ctx
))
824 /** Reports whether a precomputation has been done
825 * \param group EC_GROUP object
826 * \return 1 if a pre-computation has been done and 0 otherwise
828 DEPRECATEDIN_3_0(int EC_GROUP_have_precompute_mult(const EC_GROUP
*group
))
830 /********************************************************************/
832 /********************************************************************/
834 DECLARE_ASN1_ITEM(ECPKPARAMETERS
)
835 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS
)
836 DECLARE_ASN1_ITEM(ECPARAMETERS
)
837 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS
)
840 * EC_GROUP_get_basis_type() returns the NID of the basis type used to
841 * represent the field elements
843 int EC_GROUP_get_basis_type(const EC_GROUP
*);
844 # ifndef OPENSSL_NO_EC2M
845 int EC_GROUP_get_trinomial_basis(const EC_GROUP
*, unsigned int *k
);
846 int EC_GROUP_get_pentanomial_basis(const EC_GROUP
*, unsigned int *k1
,
847 unsigned int *k2
, unsigned int *k3
);
850 # define OPENSSL_EC_EXPLICIT_CURVE 0x000
851 # define OPENSSL_EC_NAMED_CURVE 0x001
853 EC_GROUP
*d2i_ECPKParameters(EC_GROUP
**, const unsigned char **in
, long len
);
854 int i2d_ECPKParameters(const EC_GROUP
*, unsigned char **out
);
856 # define d2i_ECPKParameters_bio(bp,x) \
857 ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x)
858 # define i2d_ECPKParameters_bio(bp,x) \
859 ASN1_i2d_bio_of(EC_GROUP, i2d_ECPKParameters, bp, x)
860 # define d2i_ECPKParameters_fp(fp,x) \
861 (EC_GROUP *)ASN1_d2i_fp(NULL, (char *(*)())d2i_ECPKParameters, (fp), \
862 (unsigned char **)(x))
863 # define i2d_ECPKParameters_fp(fp,x) \
864 ASN1_i2d_fp(i2d_ECPKParameters,(fp), (unsigned char *)(x))
866 int ECPKParameters_print(BIO
*bp
, const EC_GROUP
*x
, int off
);
867 # ifndef OPENSSL_NO_STDIO
868 int ECPKParameters_print_fp(FILE *fp
, const EC_GROUP
*x
, int off
);
871 /********************************************************************/
872 /* EC_KEY functions */
873 /********************************************************************/
875 /* some values for the encoding_flag */
876 # define EC_PKEY_NO_PARAMETERS 0x001
877 # define EC_PKEY_NO_PUBKEY 0x002
879 /* some values for the flags field */
880 # define EC_FLAG_NON_FIPS_ALLOW 0x1
881 # define EC_FLAG_FIPS_CHECKED 0x2
882 # define EC_FLAG_COFACTOR_ECDH 0x1000
883 # define EC_FLAG_SM2_RANGE 0x4
886 * Creates a new EC_KEY object.
887 * \param ctx The library context for to use for this EC_KEY. May be NULL in
888 * which case the default library context is used.
889 * \return EC_KEY object or NULL if an error occurred.
891 EC_KEY
*EC_KEY_new_ex(OSSL_LIB_CTX
*ctx
, const char *propq
);
894 * Creates a new EC_KEY object. Same as calling EC_KEY_new_ex with a
895 * NULL library context
896 * \return EC_KEY object or NULL if an error occurred.
898 EC_KEY
*EC_KEY_new(void);
900 int EC_KEY_get_flags(const EC_KEY
*key
);
902 void EC_KEY_set_flags(EC_KEY
*key
, int flags
);
904 void EC_KEY_clear_flags(EC_KEY
*key
, int flags
);
906 int EC_KEY_decoded_from_explicit_params(const EC_KEY
*key
);
909 * Creates a new EC_KEY object using a named curve as underlying
911 * \param ctx The library context for to use for this EC_KEY. May be NULL in
912 * which case the default library context is used.
913 * \param propq Any property query string
914 * \param nid NID of the named curve.
915 * \return EC_KEY object or NULL if an error occurred.
917 EC_KEY
*EC_KEY_new_by_curve_name_ex(OSSL_LIB_CTX
*ctx
, const char *propq
,
921 * Creates a new EC_KEY object using a named curve as underlying
922 * EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL
923 * library context and property query string.
924 * \param nid NID of the named curve.
925 * \return EC_KEY object or NULL if an error occurred.
927 EC_KEY
*EC_KEY_new_by_curve_name(int nid
);
930 /** Frees a EC_KEY object.
931 * \param key EC_KEY object to be freed.
933 void EC_KEY_free(EC_KEY
*key
);
935 /** Copies a EC_KEY object.
936 * \param dst destination EC_KEY object
937 * \param src src EC_KEY object
938 * \return dst or NULL if an error occurred.
940 EC_KEY
*EC_KEY_copy(EC_KEY
*dst
, const EC_KEY
*src
);
942 /** Creates a new EC_KEY object and copies the content from src to it.
943 * \param src the source EC_KEY object
944 * \return newly created EC_KEY object or NULL if an error occurred.
946 EC_KEY
*EC_KEY_dup(const EC_KEY
*src
);
948 /** Increases the internal reference count of a EC_KEY object.
949 * \param key EC_KEY object
950 * \return 1 on success and 0 if an error occurred.
952 int EC_KEY_up_ref(EC_KEY
*key
);
954 /** Returns the ENGINE object of a EC_KEY object
955 * \param eckey EC_KEY object
956 * \return the ENGINE object (possibly NULL).
958 ENGINE
*EC_KEY_get0_engine(const EC_KEY
*eckey
);
960 /** Returns the EC_GROUP object of a EC_KEY object
961 * \param key EC_KEY object
962 * \return the EC_GROUP object (possibly NULL).
964 const EC_GROUP
*EC_KEY_get0_group(const EC_KEY
*key
);
966 /** Sets the EC_GROUP of a EC_KEY object.
967 * \param key EC_KEY object
968 * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY
969 * object will use an own copy of the EC_GROUP).
970 * \return 1 on success and 0 if an error occurred.
972 int EC_KEY_set_group(EC_KEY
*key
, const EC_GROUP
*group
);
974 /** Returns the private key of a EC_KEY object.
975 * \param key EC_KEY object
976 * \return a BIGNUM with the private key (possibly NULL).
978 const BIGNUM
*EC_KEY_get0_private_key(const EC_KEY
*key
);
980 /** Sets the private key of a EC_KEY object.
981 * \param key EC_KEY object
982 * \param prv BIGNUM with the private key (note: the EC_KEY object
983 * will use an own copy of the BIGNUM).
984 * \return 1 on success and 0 if an error occurred.
986 int EC_KEY_set_private_key(EC_KEY
*key
, const BIGNUM
*prv
);
988 /** Returns the public key of a EC_KEY object.
989 * \param key the EC_KEY object
990 * \return a EC_POINT object with the public key (possibly NULL)
992 const EC_POINT
*EC_KEY_get0_public_key(const EC_KEY
*key
);
994 /** Sets the public key of a EC_KEY object.
995 * \param key EC_KEY object
996 * \param pub EC_POINT object with the public key (note: the EC_KEY object
997 * will use an own copy of the EC_POINT object).
998 * \return 1 on success and 0 if an error occurred.
1000 int EC_KEY_set_public_key(EC_KEY
*key
, const EC_POINT
*pub
);
1002 unsigned EC_KEY_get_enc_flags(const EC_KEY
*key
);
1003 void EC_KEY_set_enc_flags(EC_KEY
*eckey
, unsigned int flags
);
1004 point_conversion_form_t
EC_KEY_get_conv_form(const EC_KEY
*key
);
1005 void EC_KEY_set_conv_form(EC_KEY
*eckey
, point_conversion_form_t cform
);
1007 # define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
1008 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
1009 int EC_KEY_set_ex_data(EC_KEY
*key
, int idx
, void *arg
);
1010 void *EC_KEY_get_ex_data(const EC_KEY
*key
, int idx
);
1012 /* wrapper functions for the underlying EC_GROUP object */
1013 void EC_KEY_set_asn1_flag(EC_KEY
*eckey
, int asn1_flag
);
1015 /** Creates a table of pre-computed multiples of the generator to
1016 * accelerate further EC_KEY operations.
1017 * \param key EC_KEY object
1018 * \param ctx BN_CTX object (optional)
1019 * \return 1 on success and 0 if an error occurred.
1021 DEPRECATEDIN_3_0(int EC_KEY_precompute_mult(EC_KEY
*key
, BN_CTX
*ctx
))
1023 /** Creates a new ec private (and optional a new public) key.
1024 * \param key EC_KEY object
1025 * \return 1 on success and 0 if an error occurred.
1027 int EC_KEY_generate_key(EC_KEY
*key
);
1029 /** Verifies that a private and/or public key is valid.
1030 * \param key the EC_KEY object
1031 * \return 1 on success and 0 otherwise.
1033 int EC_KEY_check_key(const EC_KEY
*key
);
1035 /** Indicates if an EC_KEY can be used for signing.
1036 * \param eckey the EC_KEY object
1037 * \return 1 if can can sign and 0 otherwise.
1039 int EC_KEY_can_sign(const EC_KEY
*eckey
);
1041 /** Sets a public key from affine coordinates performing
1042 * necessary NIST PKV tests.
1043 * \param key the EC_KEY object
1044 * \param x public key x coordinate
1045 * \param y public key y coordinate
1046 * \return 1 on success and 0 otherwise.
1048 int EC_KEY_set_public_key_affine_coordinates(EC_KEY
*key
, BIGNUM
*x
,
1051 /** Encodes an EC_KEY public key to an allocated octet string
1052 * \param key key to encode
1053 * \param form point conversion form
1054 * \param pbuf returns pointer to allocated buffer
1055 * \param ctx BN_CTX object (optional)
1056 * \return the length of the encoded octet string or 0 if an error occurred
1058 size_t EC_KEY_key2buf(const EC_KEY
*key
, point_conversion_form_t form
,
1059 unsigned char **pbuf
, BN_CTX
*ctx
);
1061 /** Decodes a EC_KEY public key from a octet string
1062 * \param key key to decode
1063 * \param buf memory buffer with the encoded ec point
1064 * \param len length of the encoded ec point
1065 * \param ctx BN_CTX object (optional)
1066 * \return 1 on success and 0 if an error occurred
1069 int EC_KEY_oct2key(EC_KEY
*key
, const unsigned char *buf
, size_t len
,
1072 /** Decodes an EC_KEY private key from an octet string
1073 * \param key key to decode
1074 * \param buf memory buffer with the encoded private key
1075 * \param len length of the encoded key
1076 * \return 1 on success and 0 if an error occurred
1079 int EC_KEY_oct2priv(EC_KEY
*key
, const unsigned char *buf
, size_t len
);
1081 /** Encodes a EC_KEY private key to an octet string
1082 * \param key key to encode
1083 * \param buf memory buffer for the result. If NULL the function returns
1084 * required buffer size.
1085 * \param len length of the memory buffer
1086 * \return the length of the encoded octet string or 0 if an error occurred
1089 size_t EC_KEY_priv2oct(const EC_KEY
*key
, unsigned char *buf
, size_t len
);
1091 /** Encodes an EC_KEY private key to an allocated octet string
1092 * \param eckey key to encode
1093 * \param pbuf returns pointer to allocated buffer
1094 * \return the length of the encoded octet string or 0 if an error occurred
1096 size_t EC_KEY_priv2buf(const EC_KEY
*eckey
, unsigned char **pbuf
);
1098 /********************************************************************/
1099 /* de- and encoding functions for SEC1 ECPrivateKey */
1100 /********************************************************************/
1102 /** Decodes a private key from a memory buffer.
1103 * \param key a pointer to a EC_KEY object which should be used (or NULL)
1104 * \param in pointer to memory with the DER encoded private key
1105 * \param len length of the DER encoded private key
1106 * \return the decoded private key or NULL if an error occurred.
1108 EC_KEY
*d2i_ECPrivateKey(EC_KEY
**key
, const unsigned char **in
, long len
);
1110 /** Encodes a private key object and stores the result in a buffer.
1111 * \param key the EC_KEY object to encode
1112 * \param out the buffer for the result (if NULL the function returns number
1114 * \return 1 on success and 0 if an error occurred.
1116 int i2d_ECPrivateKey(const EC_KEY
*key
, unsigned char **out
);
1118 /********************************************************************/
1119 /* de- and encoding functions for EC parameters */
1120 /********************************************************************/
1122 /** Decodes ec parameter from a memory buffer.
1123 * \param key a pointer to a EC_KEY object which should be used (or NULL)
1124 * \param in pointer to memory with the DER encoded ec parameters
1125 * \param len length of the DER encoded ec parameters
1126 * \return a EC_KEY object with the decoded parameters or NULL if an error
1129 EC_KEY
*d2i_ECParameters(EC_KEY
**key
, const unsigned char **in
, long len
);
1131 /** Encodes ec parameter and stores the result in a buffer.
1132 * \param key the EC_KEY object with ec parameters to encode
1133 * \param out the buffer for the result (if NULL the function returns number
1135 * \return 1 on success and 0 if an error occurred.
1137 int i2d_ECParameters(const EC_KEY
*key
, unsigned char **out
);
1139 /********************************************************************/
1140 /* de- and encoding functions for EC public key */
1141 /* (octet string, not DER -- hence 'o2i' and 'i2o') */
1142 /********************************************************************/
1144 /** Decodes a ec public key from a octet string.
1145 * \param key a pointer to a EC_KEY object which should be used
1146 * \param in memory buffer with the encoded public key
1147 * \param len length of the encoded public key
1148 * \return EC_KEY object with decoded public key or NULL if an error
1151 EC_KEY
*o2i_ECPublicKey(EC_KEY
**key
, const unsigned char **in
, long len
);
1153 /** Encodes a ec public key in an octet string.
1154 * \param key the EC_KEY object with the public key
1155 * \param out the buffer for the result (if NULL the function returns number
1157 * \return 1 on success and 0 if an error occurred
1159 int i2o_ECPublicKey(const EC_KEY
*key
, unsigned char **out
);
1161 /** Prints out the ec parameters on human readable form.
1162 * \param bp BIO object to which the information is printed
1163 * \param key EC_KEY object
1164 * \return 1 on success and 0 if an error occurred
1166 int ECParameters_print(BIO
*bp
, const EC_KEY
*key
);
1168 /** Prints out the contents of a EC_KEY object
1169 * \param bp BIO object to which the information is printed
1170 * \param key EC_KEY object
1171 * \param off line offset
1172 * \return 1 on success and 0 if an error occurred
1174 int EC_KEY_print(BIO
*bp
, const EC_KEY
*key
, int off
);
1176 # ifndef OPENSSL_NO_STDIO
1177 /** Prints out the ec parameters on human readable form.
1178 * \param fp file descriptor to which the information is printed
1179 * \param key EC_KEY object
1180 * \return 1 on success and 0 if an error occurred
1182 int ECParameters_print_fp(FILE *fp
, const EC_KEY
*key
);
1184 /** Prints out the contents of a EC_KEY object
1185 * \param fp file descriptor to which the information is printed
1186 * \param key EC_KEY object
1187 * \param off line offset
1188 * \return 1 on success and 0 if an error occurred
1190 int EC_KEY_print_fp(FILE *fp
, const EC_KEY
*key
, int off
);
1194 const EC_KEY_METHOD
*EC_KEY_OpenSSL(void);
1195 const EC_KEY_METHOD
*EC_KEY_get_default_method(void);
1196 void EC_KEY_set_default_method(const EC_KEY_METHOD
*meth
);
1197 const EC_KEY_METHOD
*EC_KEY_get_method(const EC_KEY
*key
);
1198 int EC_KEY_set_method(EC_KEY
*key
, const EC_KEY_METHOD
*meth
);
1199 EC_KEY
*EC_KEY_new_method(ENGINE
*engine
);
1201 /** The old name for ecdh_KDF_X9_63
1202 * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
1203 * it is actually specified in ANSI X9.63.
1204 * This identifier is retained for backwards compatibility
1206 DEPRECATEDIN_3_0(int ECDH_KDF_X9_62(unsigned char *out
, size_t outlen
,
1207 const unsigned char *Z
, size_t Zlen
,
1208 const unsigned char *sinfo
, size_t sinfolen
,
1211 DEPRECATEDIN_3_0(int ECDH_compute_key(void *out
, size_t outlen
,
1212 const EC_POINT
*pub_key
,
1214 void *(*KDF
)(const void *in
, size_t inlen
,
1215 void *out
, size_t *outlen
)))
1217 typedef struct ECDSA_SIG_st ECDSA_SIG
;
1219 /** Allocates and initialize a ECDSA_SIG structure
1220 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1222 ECDSA_SIG
*ECDSA_SIG_new(void);
1224 /** frees a ECDSA_SIG structure
1225 * \param sig pointer to the ECDSA_SIG structure
1227 void ECDSA_SIG_free(ECDSA_SIG
*sig
);
1229 /** i2d_ECDSA_SIG encodes content of ECDSA_SIG (note: this function modifies *pp
1230 * (*pp += length of the DER encoded signature)).
1231 * \param sig pointer to the ECDSA_SIG object
1232 * \param pp pointer to a unsigned char pointer for the output or NULL
1233 * \return the length of the DER encoded ECDSA_SIG object or a negative value
1236 DECLARE_ASN1_ENCODE_FUNCTIONS_only(ECDSA_SIG
, ECDSA_SIG
)
1238 /** d2i_ECDSA_SIG decodes an ECDSA signature (note: this function modifies *pp
1240 * \param sig pointer to ECDSA_SIG pointer (may be NULL)
1241 * \param pp memory buffer with the DER encoded signature
1242 * \param len length of the buffer
1243 * \return pointer to the decoded ECDSA_SIG structure (or NULL)
1246 /** Accessor for r and s fields of ECDSA_SIG
1247 * \param sig pointer to ECDSA_SIG structure
1248 * \param pr pointer to BIGNUM pointer for r (may be NULL)
1249 * \param ps pointer to BIGNUM pointer for s (may be NULL)
1251 void ECDSA_SIG_get0(const ECDSA_SIG
*sig
, const BIGNUM
**pr
, const BIGNUM
**ps
);
1253 /** Accessor for r field of ECDSA_SIG
1254 * \param sig pointer to ECDSA_SIG structure
1256 const BIGNUM
*ECDSA_SIG_get0_r(const ECDSA_SIG
*sig
);
1258 /** Accessor for s field of ECDSA_SIG
1259 * \param sig pointer to ECDSA_SIG structure
1261 const BIGNUM
*ECDSA_SIG_get0_s(const ECDSA_SIG
*sig
);
1263 /** Setter for r and s fields of ECDSA_SIG
1264 * \param sig pointer to ECDSA_SIG structure
1265 * \param r pointer to BIGNUM for r (may be NULL)
1266 * \param s pointer to BIGNUM for s (may be NULL)
1268 int ECDSA_SIG_set0(ECDSA_SIG
*sig
, BIGNUM
*r
, BIGNUM
*s
);
1270 /** Computes the ECDSA signature of the given hash value using
1271 * the supplied private key and returns the created signature.
1272 * \param dgst pointer to the hash value
1273 * \param dgst_len length of the hash value
1274 * \param eckey EC_KEY object containing a private EC key
1275 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1277 DEPRECATEDIN_3_0(ECDSA_SIG
*ECDSA_do_sign(const unsigned char *dgst
,
1278 int dgst_len
, EC_KEY
*eckey
))
1280 /** Computes ECDSA signature of a given hash value using the supplied
1281 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1282 * \param dgst pointer to the hash value to sign
1283 * \param dgstlen length of the hash value
1284 * \param kinv BIGNUM with a pre-computed inverse k (optional)
1285 * \param rp BIGNUM with a pre-computed rp value (optional),
1286 * see ECDSA_sign_setup
1287 * \param eckey EC_KEY object containing a private EC key
1288 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
1290 DEPRECATEDIN_3_0(ECDSA_SIG
*ECDSA_do_sign_ex(const unsigned char *dgst
,
1291 int dgstlen
, const BIGNUM
*kinv
,
1292 const BIGNUM
*rp
, EC_KEY
*eckey
))
1294 /** Verifies that the supplied signature is a valid ECDSA
1295 * signature of the supplied hash value using the supplied public key.
1296 * \param dgst pointer to the hash value
1297 * \param dgst_len length of the hash value
1298 * \param sig ECDSA_SIG structure
1299 * \param eckey EC_KEY object containing a public EC key
1300 * \return 1 if the signature is valid, 0 if the signature is invalid
1303 DEPRECATEDIN_3_0(int ECDSA_do_verify(const unsigned char *dgst
, int dgst_len
,
1304 const ECDSA_SIG
*sig
, EC_KEY
*eckey
))
1306 /** Precompute parts of the signing operation
1307 * \param eckey EC_KEY object containing a private EC key
1308 * \param ctx BN_CTX object (optional)
1309 * \param kinv BIGNUM pointer for the inverse of k
1310 * \param rp BIGNUM pointer for x coordinate of k * generator
1311 * \return 1 on success and 0 otherwise
1313 DEPRECATEDIN_3_0(int ECDSA_sign_setup(EC_KEY
*eckey
, BN_CTX
*ctx
,
1314 BIGNUM
**kinv
, BIGNUM
**rp
))
1316 /** Computes ECDSA signature of a given hash value using the supplied
1317 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1318 * \param type this parameter is ignored
1319 * \param dgst pointer to the hash value to sign
1320 * \param dgstlen length of the hash value
1321 * \param sig memory for the DER encoded created signature
1322 * \param siglen pointer to the length of the returned signature
1323 * \param eckey EC_KEY object containing a private EC key
1324 * \return 1 on success and 0 otherwise
1326 DEPRECATEDIN_3_0(int ECDSA_sign(int type
, const unsigned char *dgst
,
1327 int dgstlen
, unsigned char *sig
,
1328 unsigned int *siglen
, EC_KEY
*eckey
))
1330 /** Computes ECDSA signature of a given hash value using the supplied
1331 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
1332 * \param type this parameter is ignored
1333 * \param dgst pointer to the hash value to sign
1334 * \param dgstlen length of the hash value
1335 * \param sig buffer to hold the DER encoded signature
1336 * \param siglen pointer to the length of the returned signature
1337 * \param kinv BIGNUM with a pre-computed inverse k (optional)
1338 * \param rp BIGNUM with a pre-computed rp value (optional),
1339 * see ECDSA_sign_setup
1340 * \param eckey EC_KEY object containing a private EC key
1341 * \return 1 on success and 0 otherwise
1343 DEPRECATEDIN_3_0(int ECDSA_sign_ex(int type
, const unsigned char *dgst
,
1344 int dgstlen
, unsigned char *sig
,
1345 unsigned int *siglen
, const BIGNUM
*kinv
,
1346 const BIGNUM
*rp
, EC_KEY
*eckey
))
1348 /** Verifies that the given signature is valid ECDSA signature
1349 * of the supplied hash value using the specified public key.
1350 * \param type this parameter is ignored
1351 * \param dgst pointer to the hash value
1352 * \param dgstlen length of the hash value
1353 * \param sig pointer to the DER encoded signature
1354 * \param siglen length of the DER encoded signature
1355 * \param eckey EC_KEY object containing a public EC key
1356 * \return 1 if the signature is valid, 0 if the signature is invalid
1359 DEPRECATEDIN_3_0(int ECDSA_verify(int type
, const unsigned char *dgst
,
1360 int dgstlen
, const unsigned char *sig
,
1361 int siglen
, EC_KEY
*eckey
))
1363 /** Returns the maximum length of the DER encoded signature
1364 * \param eckey EC_KEY object
1365 * \return numbers of bytes required for the DER encoded signature
1367 DEPRECATEDIN_3_0(int ECDSA_size(const EC_KEY
*eckey
))
1369 /********************************************************************/
1370 /* EC_KEY_METHOD constructors, destructors, writers and accessors */
1371 /********************************************************************/
1373 DEPRECATEDIN_3_0(EC_KEY_METHOD
*EC_KEY_METHOD_new(const EC_KEY_METHOD
*meth
))
1374 DEPRECATEDIN_3_0(void EC_KEY_METHOD_free(EC_KEY_METHOD
*meth
))
1375 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_init
1376 (EC_KEY_METHOD
*meth
,
1377 int (*init
)(EC_KEY
*key
),
1378 void (*finish
)(EC_KEY
*key
),
1379 int (*copy
)(EC_KEY
*dest
, const EC_KEY
*src
),
1380 int (*set_group
)(EC_KEY
*key
, const EC_GROUP
*grp
),
1381 int (*set_private
)(EC_KEY
*key
,
1382 const BIGNUM
*priv_key
),
1383 int (*set_public
)(EC_KEY
*key
,
1384 const EC_POINT
*pub_key
)))
1386 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD
*meth
,
1387 int (*keygen
)(EC_KEY
*key
)))
1389 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_compute_key
1390 (EC_KEY_METHOD
*meth
,
1391 int (*ckey
)(unsigned char **psec
,
1393 const EC_POINT
*pub_key
,
1394 const EC_KEY
*ecdh
)))
1396 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_sign
1397 (EC_KEY_METHOD
*meth
,
1398 int (*sign
)(int type
, const unsigned char *dgst
,
1399 int dlen
, unsigned char *sig
,
1400 unsigned int *siglen
,
1401 const BIGNUM
*kinv
, const BIGNUM
*r
,
1403 int (*sign_setup
)(EC_KEY
*eckey
, BN_CTX
*ctx_in
,
1404 BIGNUM
**kinvp
, BIGNUM
**rp
),
1405 ECDSA_SIG
*(*sign_sig
)(const unsigned char *dgst
,
1407 const BIGNUM
*in_kinv
,
1411 DEPRECATEDIN_3_0(void EC_KEY_METHOD_set_verify
1412 (EC_KEY_METHOD
*meth
,
1413 int (*verify
)(int type
, const unsigned
1414 char *dgst
, int dgst_len
,
1415 const unsigned char *sigbuf
,
1416 int sig_len
, EC_KEY
*eckey
),
1417 int (*verify_sig
)(const unsigned char *dgst
,
1419 const ECDSA_SIG
*sig
,
1422 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_init
1423 (const EC_KEY_METHOD
*meth
,
1424 int (**pinit
)(EC_KEY
*key
),
1425 void (**pfinish
)(EC_KEY
*key
),
1426 int (**pcopy
)(EC_KEY
*dest
, const EC_KEY
*src
),
1427 int (**pset_group
)(EC_KEY
*key
,
1428 const EC_GROUP
*grp
),
1429 int (**pset_private
)(EC_KEY
*key
,
1430 const BIGNUM
*priv_key
),
1431 int (**pset_public
)(EC_KEY
*key
,
1432 const EC_POINT
*pub_key
)))
1434 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD
*meth
,
1435 int (**pkeygen
)(EC_KEY
*key
)))
1437 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_compute_key
1438 (const EC_KEY_METHOD
*meth
,
1439 int (**pck
)(unsigned char **psec
,
1441 const EC_POINT
*pub_key
,
1442 const EC_KEY
*ecdh
)))
1444 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_sign
1445 (const EC_KEY_METHOD
*meth
,
1446 int (**psign
)(int type
, const unsigned char *dgst
,
1447 int dlen
, unsigned char *sig
,
1448 unsigned int *siglen
,
1449 const BIGNUM
*kinv
, const BIGNUM
*r
,
1451 int (**psign_setup
)(EC_KEY
*eckey
, BN_CTX
*ctx_in
,
1452 BIGNUM
**kinvp
, BIGNUM
**rp
),
1453 ECDSA_SIG
*(**psign_sig
)(const unsigned char *dgst
,
1455 const BIGNUM
*in_kinv
,
1459 DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_verify
1460 (const EC_KEY_METHOD
*meth
,
1461 int (**pverify
)(int type
, const unsigned
1462 char *dgst
, int dgst_len
,
1463 const unsigned char *sigbuf
,
1464 int sig_len
, EC_KEY
*eckey
),
1465 int (**pverify_sig
)(const unsigned char *dgst
,
1467 const ECDSA_SIG
*sig
,
1470 # define ECParameters_dup(x) ASN1_dup_of(EC_KEY, i2d_ECParameters, \
1471 d2i_ECParameters, x)
1473 # ifndef __cplusplus
1474 # if defined(__SUNPRO_C)
1475 # if __SUNPRO_C >= 0x520
1476 # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
1481 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX
*ctx
, int nid
);
1482 int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX
*ctx
, int param_enc
);
1483 int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX
*ctx
, int cofactor_mode
);
1484 int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX
*ctx
);
1486 int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX
*ctx
, int kdf
);
1487 int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX
*ctx
);
1489 int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
*md
);
1490 int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX
*ctx
, const EVP_MD
**md
);
1492 int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX
*ctx
, int len
);
1493 int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX
*ctx
, int *len
);
1495 int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX
*ctx
, unsigned char *ukm
,
1497 int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX
*ctx
, unsigned char **ukm
);
1499 # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
1500 # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2)
1501 # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3)
1502 # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4)
1503 # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5)
1504 # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6)
1505 # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7)
1506 # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8)
1507 # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9)
1508 # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10)
1511 # define EVP_PKEY_ECDH_KDF_NONE 1
1512 # define EVP_PKEY_ECDH_KDF_X9_63 2
1513 /** The old name for EVP_PKEY_ECDH_KDF_X9_63
1514 * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
1515 * it is actually specified in ANSI X9.63.
1516 * This identifier is retained for backwards compatibility
1518 # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63