diff options
author | tb <> | 2023-04-27 07:04:23 +0000 |
---|---|---|
committer | tb <> | 2023-04-27 07:04:23 +0000 |
commit | adbe201ecbd761e38994ee2089dd4b89a8087289 (patch) | |
tree | fb530fe4e2cefc14d992b01795a4b270510305de /src | |
parent | 0acb08679ba1725041a8633560d06583bcb04b8d (diff) | |
download | openbsd-adbe201ecbd761e38994ee2089dd4b89a8087289.tar.gz openbsd-adbe201ecbd761e38994ee2089dd4b89a8087289.tar.bz2 openbsd-adbe201ecbd761e38994ee2089dd4b89a8087289.zip |
Nuke doxygen noise
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec.h | 458 |
1 files changed, 37 insertions, 421 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h index 0589e36d98..519e192bda 100644 --- a/src/lib/libcrypto/ec/ec.h +++ b/src/lib/libcrypto/ec/ec.h | |||
@@ -1,11 +1,7 @@ | |||
1 | /* $OpenBSD: ec.h,v 1.39 2023/04/26 13:12:51 tb Exp $ */ | 1 | /* $OpenBSD: ec.h,v 1.40 2023/04/27 07:04:23 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
5 | /** | ||
6 | * \file crypto/ec/ec.h Include file for the OpenSSL EC functions | ||
7 | * \author Originally written by Bodo Moeller for the OpenSSL project | ||
8 | */ | ||
9 | /* ==================================================================== | 5 | /* ==================================================================== |
10 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | 6 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. |
11 | * | 7 | * |
@@ -136,7 +132,8 @@ int EC_GROUP_get_curve_name(const EC_GROUP *group); | |||
136 | void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); | 132 | void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); |
137 | int EC_GROUP_get_asn1_flag(const EC_GROUP *group); | 133 | int EC_GROUP_get_asn1_flag(const EC_GROUP *group); |
138 | 134 | ||
139 | void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form); | 135 | void EC_GROUP_set_point_conversion_form(EC_GROUP *group, |
136 | point_conversion_form_t form); | ||
140 | point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); | 137 | point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); |
141 | 138 | ||
142 | unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); | 139 | unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); |
@@ -167,72 +164,26 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, | |||
167 | const BIGNUM *b, BN_CTX *ctx); | 164 | const BIGNUM *b, BN_CTX *ctx); |
168 | EC_GROUP *EC_GROUP_new_by_curve_name(int nid); | 165 | EC_GROUP *EC_GROUP_new_by_curve_name(int nid); |
169 | 166 | ||
170 | /********************************************************************/ | ||
171 | /* handling of internal curves */ | ||
172 | /********************************************************************/ | ||
173 | |||
174 | typedef struct { | 167 | typedef struct { |
175 | int nid; | 168 | int nid; |
176 | const char *comment; | 169 | const char *comment; |
177 | } EC_builtin_curve; | 170 | } EC_builtin_curve; |
178 | 171 | ||
179 | /* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number | ||
180 | * of all available curves or zero if a error occurred. | ||
181 | * In case r ist not zero nitems EC_builtin_curve structures | ||
182 | * are filled with the data of the first nitems internal groups */ | ||
183 | size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); | 172 | size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); |
184 | 173 | ||
185 | const char *EC_curve_nid2nist(int nid); | 174 | const char *EC_curve_nid2nist(int nid); |
186 | int EC_curve_nist2nid(const char *name); | 175 | int EC_curve_nist2nid(const char *name); |
187 | 176 | ||
188 | /********************************************************************/ | ||
189 | /* EC_POINT functions */ | ||
190 | /********************************************************************/ | ||
191 | |||
192 | /** Creates a new EC_POINT object for the specified EC_GROUP | ||
193 | * \param group EC_GROUP the underlying EC_GROUP object | ||
194 | * \return newly created EC_POINT object or NULL if an error occurred | ||
195 | */ | ||
196 | EC_POINT *EC_POINT_new(const EC_GROUP *group); | 177 | EC_POINT *EC_POINT_new(const EC_GROUP *group); |
197 | |||
198 | /** Frees a EC_POINT object | ||
199 | * \param point EC_POINT object to be freed | ||
200 | */ | ||
201 | void EC_POINT_free(EC_POINT *point); | 178 | void EC_POINT_free(EC_POINT *point); |
202 | |||
203 | /** Clears and frees a EC_POINT object | ||
204 | * \param point EC_POINT object to be cleared and freed | ||
205 | */ | ||
206 | #ifndef LIBRESSL_INTERNAL | 179 | #ifndef LIBRESSL_INTERNAL |
207 | void EC_POINT_clear_free(EC_POINT *point); | 180 | void EC_POINT_clear_free(EC_POINT *point); |
208 | #endif | 181 | #endif |
209 | |||
210 | /** Copies EC_POINT object | ||
211 | * \param dst destination EC_POINT object | ||
212 | * \param src source EC_POINT object | ||
213 | * \return 1 on success and 0 if an error occurred | ||
214 | */ | ||
215 | int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); | 182 | int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); |
216 | |||
217 | /** Creates a new EC_POINT object and copies the content of the supplied | ||
218 | * EC_POINT | ||
219 | * \param src source EC_POINT object | ||
220 | * \param group underlying the EC_GROUP object | ||
221 | * \return newly created EC_POINT object or NULL if an error occurred | ||
222 | */ | ||
223 | EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); | 183 | EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); |
224 | 184 | ||
225 | /** Returns the EC_METHOD used in EC_POINT object | ||
226 | * \param point EC_POINT object | ||
227 | * \return the EC_METHOD used | ||
228 | */ | ||
229 | const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); | 185 | const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); |
230 | 186 | ||
231 | /** Sets a point to infinity (neutral element) | ||
232 | * \param group underlying EC_GROUP object | ||
233 | * \param point EC_POINT to set to infinity | ||
234 | * \return 1 on success and 0 if an error occurred | ||
235 | */ | ||
236 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); | 187 | int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); |
237 | 188 | ||
238 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, | 189 | int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, |
@@ -243,209 +194,57 @@ int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, | |||
243 | const BIGNUM *x, int y_bit, BN_CTX *ctx); | 194 | const BIGNUM *x, int y_bit, BN_CTX *ctx); |
244 | 195 | ||
245 | #if defined(LIBRESSL_INTERNAL) | 196 | #if defined(LIBRESSL_INTERNAL) |
246 | |||
247 | int EC_POINT_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *p, | 197 | int EC_POINT_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *p, |
248 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); | 198 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); |
249 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, | 199 | int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group, |
250 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); | 200 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); |
251 | |||
252 | #else | 201 | #else |
253 | |||
254 | /** Sets the jacobian projective coordinates of a EC_POINT over GFp | ||
255 | * \param group underlying EC_GROUP object | ||
256 | * \param p EC_POINT object | ||
257 | * \param x BIGNUM with the x-coordinate | ||
258 | * \param y BIGNUM with the y-coordinate | ||
259 | * \param z BIGNUM with the z-coordinate | ||
260 | * \param ctx BN_CTX object (optional) | ||
261 | * \return 1 on success and 0 if an error occurred | ||
262 | */ | ||
263 | int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | 202 | int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, |
264 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); | 203 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx); |
265 | |||
266 | /** Gets the jacobian projective coordinates of a EC_POINT over GFp | ||
267 | * \param group underlying EC_GROUP object | ||
268 | * \param p EC_POINT object | ||
269 | * \param x BIGNUM for the x-coordinate | ||
270 | * \param y BIGNUM for the y-coordinate | ||
271 | * \param z BIGNUM for the z-coordinate | ||
272 | * \param ctx BN_CTX object (optional) | ||
273 | * \return 1 on success and 0 if an error occurred | ||
274 | */ | ||
275 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, | 204 | int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, |
276 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); | 205 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); |
277 | |||
278 | /** Sets the affine coordinates of a EC_POINT over GFp | ||
279 | * \param group underlying EC_GROUP object | ||
280 | * \param p EC_POINT object | ||
281 | * \param x BIGNUM with the x-coordinate | ||
282 | * \param y BIGNUM with the y-coordinate | ||
283 | * \param ctx BN_CTX object (optional) | ||
284 | * \return 1 on success and 0 if an error occurred | ||
285 | */ | ||
286 | int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | 206 | int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, |
287 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); | 207 | const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); |
288 | |||
289 | /** Gets the affine coordinates of a EC_POINT over GFp | ||
290 | * \param group underlying EC_GROUP object | ||
291 | * \param p EC_POINT object | ||
292 | * \param x BIGNUM for the x-coordinate | ||
293 | * \param y BIGNUM for the y-coordinate | ||
294 | * \param ctx BN_CTX object (optional) | ||
295 | * \return 1 on success and 0 if an error occurred | ||
296 | */ | ||
297 | int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, | 208 | int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, |
298 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); | 209 | const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx); |
299 | |||
300 | /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp | ||
301 | * \param group underlying EC_GROUP object | ||
302 | * \param p EC_POINT object | ||
303 | * \param x BIGNUM with x-coordinate | ||
304 | * \param y_bit integer with the y-Bit (either 0 or 1) | ||
305 | * \param ctx BN_CTX object (optional) | ||
306 | * \return 1 on success and 0 if an error occurred | ||
307 | */ | ||
308 | int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, | 210 | int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, |
309 | const BIGNUM *x, int y_bit, BN_CTX *ctx); | 211 | const BIGNUM *x, int y_bit, BN_CTX *ctx); |
310 | #endif /* !LIBRESSL_INTERNAL */ | 212 | #endif /* !LIBRESSL_INTERNAL */ |
311 | |||
312 | /** Encodes a EC_POINT object to a octet string | ||
313 | * \param group underlying EC_GROUP object | ||
314 | * \param p EC_POINT object | ||
315 | * \param form point conversion form | ||
316 | * \param buf memory buffer for the result. If NULL the function returns | ||
317 | * required buffer size. | ||
318 | * \param len length of the memory buffer | ||
319 | * \param ctx BN_CTX object (optional) | ||
320 | * \return the length of the encoded octet string or 0 if an error occurred | ||
321 | */ | ||
322 | size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, | 213 | size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, |
323 | point_conversion_form_t form, | 214 | point_conversion_form_t form, unsigned char *buf, size_t len, BN_CTX *ctx); |
324 | unsigned char *buf, size_t len, BN_CTX *ctx); | ||
325 | |||
326 | /** Decodes a EC_POINT from a octet string | ||
327 | * \param group underlying EC_GROUP object | ||
328 | * \param p EC_POINT object | ||
329 | * \param buf memory buffer with the encoded ec point | ||
330 | * \param len length of the encoded ec point | ||
331 | * \param ctx BN_CTX object (optional) | ||
332 | * \return 1 on success and 0 if an error occurred | ||
333 | */ | ||
334 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, | 215 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, |
335 | const unsigned char *buf, size_t len, BN_CTX *ctx); | 216 | const unsigned char *buf, size_t len, BN_CTX *ctx); |
336 | 217 | ||
337 | /* other interfaces to point2oct/oct2point: */ | ||
338 | BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, | 218 | BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, |
339 | point_conversion_form_t form, BIGNUM *, BN_CTX *); | 219 | point_conversion_form_t form, BIGNUM *, BN_CTX *); |
340 | EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, | 220 | EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, EC_POINT *, |
341 | EC_POINT *, BN_CTX *); | 221 | BN_CTX *); |
342 | char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, | 222 | char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, |
343 | point_conversion_form_t form, BN_CTX *); | 223 | point_conversion_form_t form, BN_CTX *); |
344 | EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, | 224 | EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, EC_POINT *, |
345 | EC_POINT *, BN_CTX *); | 225 | BN_CTX *); |
346 | |||
347 | |||
348 | /********************************************************************/ | ||
349 | /* functions for doing EC_POINT arithmetic */ | ||
350 | /********************************************************************/ | ||
351 | |||
352 | /** Computes the sum of two EC_POINT | ||
353 | * \param group underlying EC_GROUP object | ||
354 | * \param r EC_POINT object for the result (r = a + b) | ||
355 | * \param a EC_POINT object with the first summand | ||
356 | * \param b EC_POINT object with the second summand | ||
357 | * \param ctx BN_CTX object (optional) | ||
358 | * \return 1 on success and 0 if an error occurred | ||
359 | */ | ||
360 | int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx); | ||
361 | |||
362 | /** Computes the double of a EC_POINT | ||
363 | * \param group underlying EC_GROUP object | ||
364 | * \param r EC_POINT object for the result (r = 2 * a) | ||
365 | * \param a EC_POINT object | ||
366 | * \param ctx BN_CTX object (optional) | ||
367 | * \return 1 on success and 0 if an error occurred | ||
368 | */ | ||
369 | int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx); | ||
370 | 226 | ||
371 | /** Computes the inverse of a EC_POINT | 227 | int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
372 | * \param group underlying EC_GROUP object | 228 | const EC_POINT *b, BN_CTX *ctx); |
373 | * \param a EC_POINT object to be inverted (it's used for the result as well) | 229 | int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, |
374 | * \param ctx BN_CTX object (optional) | 230 | BN_CTX *ctx); |
375 | * \return 1 on success and 0 if an error occurred | ||
376 | */ | ||
377 | int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); | 231 | int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); |
378 | |||
379 | /** Checks whether the point is the neutral element of the group | ||
380 | * \param group the underlying EC_GROUP object | ||
381 | * \param p EC_POINT object | ||
382 | * \return 1 if the point is the neutral element and 0 otherwise | ||
383 | */ | ||
384 | int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); | 232 | int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); |
385 | 233 | int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, | |
386 | /** Checks whether the point is on the curve | 234 | BN_CTX *ctx); |
387 | * \param group underlying EC_GROUP object | 235 | int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, |
388 | * \param point EC_POINT object to check | 236 | BN_CTX *ctx); |
389 | * \param ctx BN_CTX object (optional) | ||
390 | * \return 1 if point if on the curve and 0 otherwise | ||
391 | */ | ||
392 | int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx); | ||
393 | |||
394 | /** Compares two EC_POINTs | ||
395 | * \param group underlying EC_GROUP object | ||
396 | * \param a first EC_POINT object | ||
397 | * \param b second EC_POINT object | ||
398 | * \param ctx BN_CTX object (optional) | ||
399 | * \return 0 if both points are equal and a value != 0 otherwise | ||
400 | */ | ||
401 | int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx); | ||
402 | 237 | ||
403 | int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); | 238 | int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); |
404 | int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx); | 239 | int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], |
405 | 240 | BN_CTX *ctx); | |
406 | /** Computes r = generator * n sum_{i=0}^num p[i] * m[i] | 241 | int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, |
407 | * \param group underlying EC_GROUP object | 242 | size_t num, const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx); |
408 | * \param r EC_POINT object for the result | 243 | int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, |
409 | * \param n BIGNUM with the multiplier for the group generator (optional) | 244 | const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); |
410 | * \param num number further summands | ||
411 | * \param p array of size num of EC_POINT objects | ||
412 | * \param m array of size num of BIGNUM objects | ||
413 | * \param ctx BN_CTX object (optional) | ||
414 | * \return 1 on success and 0 if an error occurred | ||
415 | */ | ||
416 | int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx); | ||
417 | |||
418 | /** Computes r = generator * n + q * m | ||
419 | * \param group underlying EC_GROUP object | ||
420 | * \param r EC_POINT object for the result | ||
421 | * \param n BIGNUM with the multiplier for the group generator (optional) | ||
422 | * \param q EC_POINT object with the first factor of the second summand | ||
423 | * \param m BIGNUM with the second factor of the second summand | ||
424 | * \param ctx BN_CTX object (optional) | ||
425 | * \return 1 on success and 0 if an error occurred | ||
426 | */ | ||
427 | int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); | ||
428 | |||
429 | /** Stores multiples of generator for faster point multiplication | ||
430 | * \param group EC_GROUP object | ||
431 | * \param ctx BN_CTX object (optional) | ||
432 | * \return 1 on success and 0 if an error occurred | ||
433 | */ | ||
434 | int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | 245 | int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
435 | |||
436 | /** Reports whether a precomputation has been done | ||
437 | * \param group EC_GROUP object | ||
438 | * \return 1 if a pre-computation has been done and 0 otherwise | ||
439 | */ | ||
440 | int EC_GROUP_have_precompute_mult(const EC_GROUP *group); | 246 | int EC_GROUP_have_precompute_mult(const EC_GROUP *group); |
441 | 247 | ||
442 | |||
443 | /********************************************************************/ | ||
444 | /* ASN1 stuff */ | ||
445 | /********************************************************************/ | ||
446 | |||
447 | /* EC_GROUP_get_basis_type() returns the NID of the basis type | ||
448 | * used to represent the field elements */ | ||
449 | int EC_GROUP_get_basis_type(const EC_GROUP *); | 248 | int EC_GROUP_get_basis_type(const EC_GROUP *); |
450 | 249 | ||
451 | #define OPENSSL_EC_EXPLICIT_CURVE 0x000 | 250 | #define OPENSSL_EC_EXPLICIT_CURVE 0x000 |
@@ -464,109 +263,35 @@ int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); | |||
464 | (unsigned char *)(x)) | 263 | (unsigned char *)(x)) |
465 | 264 | ||
466 | #ifndef OPENSSL_NO_BIO | 265 | #ifndef OPENSSL_NO_BIO |
467 | int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); | 266 | int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); |
468 | #endif | 267 | #endif |
469 | int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); | 268 | int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); |
470 | |||
471 | |||
472 | /********************************************************************/ | ||
473 | /* EC_KEY functions */ | ||
474 | /********************************************************************/ | ||
475 | 269 | ||
476 | typedef struct ec_key_st EC_KEY; | 270 | typedef struct ec_key_st EC_KEY; |
477 | typedef struct ec_key_method_st EC_KEY_METHOD; | 271 | typedef struct ec_key_method_st EC_KEY_METHOD; |
478 | 272 | ||
479 | /* some values for the encoding_flag */ | ||
480 | #define EC_PKEY_NO_PARAMETERS 0x001 | 273 | #define EC_PKEY_NO_PARAMETERS 0x001 |
481 | #define EC_PKEY_NO_PUBKEY 0x002 | 274 | #define EC_PKEY_NO_PUBKEY 0x002 |
482 | 275 | ||
483 | /* some values for the flags field */ | ||
484 | #define EC_FLAG_NON_FIPS_ALLOW 0x1 | 276 | #define EC_FLAG_NON_FIPS_ALLOW 0x1 |
485 | #define EC_FLAG_FIPS_CHECKED 0x2 | 277 | #define EC_FLAG_FIPS_CHECKED 0x2 |
486 | #define EC_FLAG_COFACTOR_ECDH 0x1000 | 278 | #define EC_FLAG_COFACTOR_ECDH 0x1000 |
487 | 279 | ||
488 | /** Creates a new EC_KEY object. | ||
489 | * \return EC_KEY object or NULL if an error occurred. | ||
490 | */ | ||
491 | EC_KEY *EC_KEY_new(void); | 280 | EC_KEY *EC_KEY_new(void); |
492 | |||
493 | int EC_KEY_get_flags(const EC_KEY *key); | 281 | int EC_KEY_get_flags(const EC_KEY *key); |
494 | |||
495 | void EC_KEY_set_flags(EC_KEY *key, int flags); | 282 | void EC_KEY_set_flags(EC_KEY *key, int flags); |
496 | |||
497 | void EC_KEY_clear_flags(EC_KEY *key, int flags); | 283 | void EC_KEY_clear_flags(EC_KEY *key, int flags); |
498 | |||
499 | /** Creates a new EC_KEY object using a named curve as underlying | ||
500 | * EC_GROUP object. | ||
501 | * \param nid NID of the named curve. | ||
502 | * \return EC_KEY object or NULL if an error occurred. | ||
503 | */ | ||
504 | EC_KEY *EC_KEY_new_by_curve_name(int nid); | 284 | EC_KEY *EC_KEY_new_by_curve_name(int nid); |
505 | |||
506 | /** Frees a EC_KEY object. | ||
507 | * \param key EC_KEY object to be freed. | ||
508 | */ | ||
509 | void EC_KEY_free(EC_KEY *key); | 285 | void EC_KEY_free(EC_KEY *key); |
510 | |||
511 | /** Copies a EC_KEY object. | ||
512 | * \param dst destination EC_KEY object | ||
513 | * \param src src EC_KEY object | ||
514 | * \return dst or NULL if an error occurred. | ||
515 | */ | ||
516 | EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); | 286 | EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); |
517 | |||
518 | /** Creates a new EC_KEY object and copies the content from src to it. | ||
519 | * \param src the source EC_KEY object | ||
520 | * \return newly created EC_KEY object or NULL if an error occurred. | ||
521 | */ | ||
522 | EC_KEY *EC_KEY_dup(const EC_KEY *src); | 287 | EC_KEY *EC_KEY_dup(const EC_KEY *src); |
523 | |||
524 | /** Increases the internal reference count of a EC_KEY object. | ||
525 | * \param key EC_KEY object | ||
526 | * \return 1 on success and 0 if an error occurred. | ||
527 | */ | ||
528 | int EC_KEY_up_ref(EC_KEY *key); | 288 | int EC_KEY_up_ref(EC_KEY *key); |
529 | 289 | ||
530 | /** Returns the EC_GROUP object of a EC_KEY object | ||
531 | * \param key EC_KEY object | ||
532 | * \return the EC_GROUP object (possibly NULL). | ||
533 | */ | ||
534 | const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); | 290 | const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); |
535 | |||
536 | /** Sets the EC_GROUP of a EC_KEY object. | ||
537 | * \param key EC_KEY object | ||
538 | * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY | ||
539 | * object will use an own copy of the EC_GROUP). | ||
540 | * \return 1 on success and 0 if an error occurred. | ||
541 | */ | ||
542 | int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); | 291 | int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); |
543 | |||
544 | /** Returns the private key of a EC_KEY object. | ||
545 | * \param key EC_KEY object | ||
546 | * \return a BIGNUM with the private key (possibly NULL). | ||
547 | */ | ||
548 | const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); | 292 | const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); |
549 | |||
550 | /** Sets the private key of a EC_KEY object. | ||
551 | * \param key EC_KEY object | ||
552 | * \param prv BIGNUM with the private key (note: the EC_KEY object | ||
553 | * will use an own copy of the BIGNUM). | ||
554 | * \return 1 on success and 0 if an error occurred. | ||
555 | */ | ||
556 | int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); | 293 | int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); |
557 | |||
558 | /** Returns the public key of a EC_KEY object. | ||
559 | * \param key the EC_KEY object | ||
560 | * \return a EC_POINT object with the public key (possibly NULL) | ||
561 | */ | ||
562 | const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); | 294 | const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); |
563 | |||
564 | /** Sets the public key of a EC_KEY object. | ||
565 | * \param key EC_KEY object | ||
566 | * \param pub EC_POINT object with the public key (note: the EC_KEY object | ||
567 | * will use an own copy of the EC_POINT object). | ||
568 | * \return 1 on success and 0 if an error occurred. | ||
569 | */ | ||
570 | int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); | 295 | int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); |
571 | 296 | ||
572 | unsigned EC_KEY_get_enc_flags(const EC_KEY *key); | 297 | unsigned EC_KEY_get_enc_flags(const EC_KEY *key); |
@@ -574,135 +299,26 @@ void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); | |||
574 | point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); | 299 | point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); |
575 | void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); | 300 | void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); |
576 | 301 | ||
577 | /* wrapper functions for the underlying EC_GROUP object */ | ||
578 | void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); | 302 | void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); |
579 | |||
580 | /** Creates a table of pre-computed multiples of the generator to | ||
581 | * accelerate further EC_KEY operations. | ||
582 | * \param key EC_KEY object | ||
583 | * \param ctx BN_CTX object (optional) | ||
584 | * \return 1 on success and 0 if an error occurred. | ||
585 | */ | ||
586 | int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); | 303 | int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); |
587 | |||
588 | /** Creates a new ec private (and optional a new public) key. | ||
589 | * \param key EC_KEY object | ||
590 | * \return 1 on success and 0 if an error occurred. | ||
591 | */ | ||
592 | int EC_KEY_generate_key(EC_KEY *key); | 304 | int EC_KEY_generate_key(EC_KEY *key); |
593 | |||
594 | /** Verifies that a private and/or public key is valid. | ||
595 | * \param key the EC_KEY object | ||
596 | * \return 1 on success and 0 otherwise. | ||
597 | */ | ||
598 | int EC_KEY_check_key(const EC_KEY *key); | 305 | int EC_KEY_check_key(const EC_KEY *key); |
599 | |||
600 | /** Sets a public key from affine coordinates performing | ||
601 | * necessary NIST PKV tests. | ||
602 | * \param key the EC_KEY object | ||
603 | * \param x public key x coordinate | ||
604 | * \param y public key y coordinate | ||
605 | * \return 1 on success and 0 otherwise. | ||
606 | */ | ||
607 | int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y); | 306 | int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y); |
608 | 307 | ||
609 | |||
610 | /********************************************************************/ | ||
611 | /* de- and encoding functions for SEC1 ECPrivateKey */ | ||
612 | /********************************************************************/ | ||
613 | |||
614 | /** Decodes a private key from a memory buffer. | ||
615 | * \param key a pointer to a EC_KEY object which should be used (or NULL) | ||
616 | * \param in pointer to memory with the DER encoded private key | ||
617 | * \param len length of the DER encoded private key | ||
618 | * \return the decoded private key or NULL if an error occurred. | ||
619 | */ | ||
620 | EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); | 308 | EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); |
621 | |||
622 | /** Encodes a private key object and stores the result in a buffer. | ||
623 | * \param key the EC_KEY object to encode | ||
624 | * \param out the buffer for the result (if NULL the function returns number | ||
625 | * of bytes needed). | ||
626 | * \return 1 on success and 0 if an error occurred. | ||
627 | */ | ||
628 | int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out); | 309 | int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out); |
629 | |||
630 | |||
631 | /********************************************************************/ | ||
632 | /* de- and encoding functions for EC parameters */ | ||
633 | /********************************************************************/ | ||
634 | |||
635 | /** Decodes ec parameter from a memory buffer. | ||
636 | * \param key a pointer to a EC_KEY object which should be used (or NULL) | ||
637 | * \param in pointer to memory with the DER encoded ec parameters | ||
638 | * \param len length of the DER encoded ec parameters | ||
639 | * \return a EC_KEY object with the decoded parameters or NULL if an error | ||
640 | * occurred. | ||
641 | */ | ||
642 | EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); | 310 | EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); |
643 | |||
644 | /** Encodes ec parameter and stores the result in a buffer. | ||
645 | * \param key the EC_KEY object with ec parameters to encode | ||
646 | * \param out the buffer for the result (if NULL the function returns number | ||
647 | * of bytes needed). | ||
648 | * \return 1 on success and 0 if an error occurred. | ||
649 | */ | ||
650 | int i2d_ECParameters(EC_KEY *key, unsigned char **out); | 311 | int i2d_ECParameters(EC_KEY *key, unsigned char **out); |
651 | 312 | ||
652 | |||
653 | /********************************************************************/ | ||
654 | /* de- and encoding functions for EC public key */ | ||
655 | /* (octet string, not DER -- hence 'o2i' and 'i2o') */ | ||
656 | /********************************************************************/ | ||
657 | |||
658 | /** Decodes a ec public key from a octet string. | ||
659 | * \param key a pointer to a EC_KEY object which should be used | ||
660 | * \param in memory buffer with the encoded public key | ||
661 | * \param len length of the encoded public key | ||
662 | * \return EC_KEY object with decoded public key or NULL if an error | ||
663 | * occurred. | ||
664 | */ | ||
665 | EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); | 313 | EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); |
666 | |||
667 | /** Encodes a ec public key in an octet string. | ||
668 | * \param key the EC_KEY object with the public key | ||
669 | * \param out the buffer for the result (if NULL the function returns number | ||
670 | * of bytes needed). | ||
671 | * \return 1 on success and 0 if an error occurred | ||
672 | */ | ||
673 | int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); | 314 | int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); |
674 | 315 | ||
675 | #ifndef OPENSSL_NO_BIO | 316 | #ifndef OPENSSL_NO_BIO |
676 | /** Prints out the ec parameters on human readable form. | 317 | int ECParameters_print(BIO *bp, const EC_KEY *key); |
677 | * \param bp BIO object to which the information is printed | 318 | int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); |
678 | * \param key EC_KEY object | ||
679 | * \return 1 on success and 0 if an error occurred | ||
680 | */ | ||
681 | int ECParameters_print(BIO *bp, const EC_KEY *key); | ||
682 | |||
683 | /** Prints out the contents of a EC_KEY object | ||
684 | * \param bp BIO object to which the information is printed | ||
685 | * \param key EC_KEY object | ||
686 | * \param off line offset | ||
687 | * \return 1 on success and 0 if an error occurred | ||
688 | */ | ||
689 | int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); | ||
690 | |||
691 | #endif | 319 | #endif |
692 | /** Prints out the ec parameters on human readable form. | 320 | int ECParameters_print_fp(FILE *fp, const EC_KEY *key); |
693 | * \param fp file descriptor to which the information is printed | 321 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); |
694 | * \param key EC_KEY object | ||
695 | * \return 1 on success and 0 if an error occurred | ||
696 | */ | ||
697 | int ECParameters_print_fp(FILE *fp, const EC_KEY *key); | ||
698 | |||
699 | /** Prints out the contents of a EC_KEY object | ||
700 | * \param fp file descriptor to which the information is printed | ||
701 | * \param key EC_KEY object | ||
702 | * \param off line offset | ||
703 | * \return 1 on success and 0 if an error occurred | ||
704 | */ | ||
705 | int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); | ||
706 | 322 | ||
707 | #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ | 323 | #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ |
708 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) | 324 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) |