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