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