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