blob: 4a08a9b1f1c7d5b4ce730c968beec840ad6f2eb6 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/* Originally written by Bodo Moeller for the OpenSSL project.
2 * ====================================================================
3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* ====================================================================
56 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57 *
58 * Portions of the attached software ("Contribution") are developed by
59 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
60 *
61 * The Contribution is licensed pursuant to the OpenSSL open source
62 * license provided above.
63 *
64 * The elliptic curve binary polynomial software is originally written by
65 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
66 * Laboratories. */
67
68#ifndef OPENSSL_HEADER_EC_H
69#define OPENSSL_HEADER_EC_H
70
71#include <openssl/base.h>
72
73#if defined(__cplusplus)
74extern "C" {
75#endif
76
77
David Benjamin4512b792017-08-18 19:21:50 -040078// Low-level operations on elliptic curves.
David Benjamin5b082e82014-12-26 00:54:52 -050079
80
David Benjamin4512b792017-08-18 19:21:50 -040081// point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for
82// the encoding of a elliptic curve point (x,y)
Adam Langley95c29f32014-06-20 12:00:00 -070083typedef enum {
David Benjamin4512b792017-08-18 19:21:50 -040084 // POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x,
85 // where the octet z specifies which solution of the quadratic equation y
86 // is.
Adam Langleyce9d85e2016-01-24 15:58:39 -080087 POINT_CONVERSION_COMPRESSED = 2,
88
David Benjamin4512b792017-08-18 19:21:50 -040089 // POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as
90 // z||x||y, where z is the octet 0x04.
Adam Langleyce9d85e2016-01-24 15:58:39 -080091 POINT_CONVERSION_UNCOMPRESSED = 4,
92
David Benjamin4512b792017-08-18 19:21:50 -040093 // POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y,
94 // where z specifies which solution of the quadratic equation y is. This is
95 // not supported by the code and has never been observed in use.
96 //
97 // TODO(agl): remove once node.js no longer references this.
Adam Langleyce9d85e2016-01-24 15:58:39 -080098 POINT_CONVERSION_HYBRID = 6,
Adam Langley95c29f32014-06-20 12:00:00 -070099} point_conversion_form_t;
100
101
David Benjamin4512b792017-08-18 19:21:50 -0400102// Elliptic curve groups.
Adam Langley95c29f32014-06-20 12:00:00 -0700103
David Benjamin4512b792017-08-18 19:21:50 -0400104// EC_GROUP_new_by_curve_name returns a fresh EC_GROUP object for the elliptic
105// curve specified by |nid|, or NULL on error.
106//
107// The supported NIDs are:
108// NID_secp224r1,
109// NID_X9_62_prime256v1,
110// NID_secp384r1,
111// NID_secp521r1
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700112OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
Adam Langley95c29f32014-06-20 12:00:00 -0700113
David Benjamin4512b792017-08-18 19:21:50 -0400114// EC_GROUP_free frees |group| and the data that it points to.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700115OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700116
David Benjamin4512b792017-08-18 19:21:50 -0400117// EC_GROUP_dup returns a fresh |EC_GROUP| which is equal to |a| or NULL on
118// error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700119OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *a);
Adam Langley95c29f32014-06-20 12:00:00 -0700120
David Benjamin4512b792017-08-18 19:21:50 -0400121// EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero
122// otherwise.
Adam Langley93531bd2015-02-13 10:47:56 -0800123OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b,
124 BN_CTX *ignored);
Adam Langley95c29f32014-06-20 12:00:00 -0700125
David Benjamin4512b792017-08-18 19:21:50 -0400126// EC_GROUP_get0_generator returns a pointer to the internal |EC_POINT| object
127// in |group| that specifies the generator for the group.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700128OPENSSL_EXPORT const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700129
David Benjamin4512b792017-08-18 19:21:50 -0400130// EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in
131// |group| that specifies the order of the group.
Brian Smitha3d9de02015-11-18 17:07:14 -1000132OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700133
David Benjamin4512b792017-08-18 19:21:50 -0400134// EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using
135// |ctx|, if it's not NULL. It returns one on success and zero otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700136OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group,
137 BIGNUM *cofactor, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700138
David Benjamin4512b792017-08-18 19:21:50 -0400139// EC_GROUP_get_curve_GFp gets various parameters about a group. It sets
140// |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to
141// the parameters of the curve when expressed as y² = x³ + ax + b. Any of the
142// output parameters can be NULL. It returns one on success and zero on
143// error.
Adam Langley0eb1aae2014-08-22 12:24:16 -0700144OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p,
145 BIGNUM *out_a, BIGNUM *out_b,
146 BN_CTX *ctx);
147
David Benjamin4512b792017-08-18 19:21:50 -0400148// EC_GROUP_get_curve_name returns a NID that identifies |group|.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700149OPENSSL_EXPORT int EC_GROUP_get_curve_name(const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700150
David Benjamin4512b792017-08-18 19:21:50 -0400151// EC_GROUP_get_degree returns the number of bits needed to represent an
152// element of the field underlying |group|.
Brian Smith274341d2015-10-08 17:10:15 -1000153OPENSSL_EXPORT unsigned EC_GROUP_get_degree(const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700154
Adam Langley95c29f32014-06-20 12:00:00 -0700155
David Benjamin4512b792017-08-18 19:21:50 -0400156// Points on elliptic curves.
Adam Langley95c29f32014-06-20 12:00:00 -0700157
David Benjamin4512b792017-08-18 19:21:50 -0400158// EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL
159// on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700160OPENSSL_EXPORT EC_POINT *EC_POINT_new(const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700161
David Benjamin4512b792017-08-18 19:21:50 -0400162// EC_POINT_free frees |point| and the data that it points to.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700163OPENSSL_EXPORT void EC_POINT_free(EC_POINT *point);
Adam Langley95c29f32014-06-20 12:00:00 -0700164
David Benjamin4512b792017-08-18 19:21:50 -0400165// EC_POINT_clear_free clears the data that |point| points to, frees it and
166// then frees |point| itself.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700167OPENSSL_EXPORT void EC_POINT_clear_free(EC_POINT *point);
Adam Langley95c29f32014-06-20 12:00:00 -0700168
David Benjamin4512b792017-08-18 19:21:50 -0400169// EC_POINT_copy sets |*dest| equal to |*src|. It returns one on success and
170// zero otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700171OPENSSL_EXPORT int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src);
Adam Langley95c29f32014-06-20 12:00:00 -0700172
David Benjamin4512b792017-08-18 19:21:50 -0400173// EC_POINT_dup returns a fresh |EC_POINT| that contains the same values as
174// |src|, or NULL on error.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700175OPENSSL_EXPORT EC_POINT *EC_POINT_dup(const EC_POINT *src,
176 const EC_GROUP *group);
Adam Langley95c29f32014-06-20 12:00:00 -0700177
David Benjamin4512b792017-08-18 19:21:50 -0400178// EC_POINT_set_to_infinity sets |point| to be the "point at infinity" for the
179// given group.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700180OPENSSL_EXPORT int EC_POINT_set_to_infinity(const EC_GROUP *group,
181 EC_POINT *point);
Adam Langley95c29f32014-06-20 12:00:00 -0700182
David Benjamin4512b792017-08-18 19:21:50 -0400183// EC_POINT_is_at_infinity returns one iff |point| is the point at infinity and
184// zero otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700185OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group,
186 const EC_POINT *point);
Adam Langley95c29f32014-06-20 12:00:00 -0700187
David Benjamin4512b792017-08-18 19:21:50 -0400188// EC_POINT_is_on_curve returns one if |point| is an element of |group| and
189// and zero otherwise or when an error occurs. This is different from OpenSSL,
190// which returns -1 on error. If |ctx| is non-NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700191OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group,
192 const EC_POINT *point, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700193
David Benjamin4512b792017-08-18 19:21:50 -0400194// EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if
195// not equal and -1 on error. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700196OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a,
197 const EC_POINT *b, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700198
David Benjamin4512b792017-08-18 19:21:50 -0400199// EC_POINT_make_affine converts |point| to affine form, internally. It returns
200// one on success and zero otherwise. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700201OPENSSL_EXPORT int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point,
202 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700203
David Benjamin4512b792017-08-18 19:21:50 -0400204// EC_POINTs_make_affine converts |num| points from |points| to affine form,
205// internally. It returns one on success and zero otherwise. If |ctx| is not
206// NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700207OPENSSL_EXPORT int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
208 EC_POINT *points[], BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700209
210
David Benjamin4512b792017-08-18 19:21:50 -0400211// Point conversion.
Adam Langley95c29f32014-06-20 12:00:00 -0700212
David Benjamin4512b792017-08-18 19:21:50 -0400213// EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of
214// |point| using |ctx|, if it's not NULL. It returns one on success and zero
215// otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700216OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
217 const EC_POINT *point,
218 BIGNUM *x, BIGNUM *y,
219 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700220
David Benjamin4512b792017-08-18 19:21:50 -0400221// EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
222// (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
223// on success or zero on error. Note that, unlike with OpenSSL, it's
224// considered an error if the point is not on the curve.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700225OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
226 EC_POINT *point,
227 const BIGNUM *x,
228 const BIGNUM *y,
229 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700230
David Benjamin4512b792017-08-18 19:21:50 -0400231// EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
232// into, at most, |len| bytes at |buf|. It returns the number of bytes written
233// or zero on error if |buf| is non-NULL, else the number of bytes needed. The
234// |ctx| argument may be used if not NULL.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700235OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
236 const EC_POINT *point,
237 point_conversion_form_t form,
238 uint8_t *buf, size_t len, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700239
David Benjamin4512b792017-08-18 19:21:50 -0400240// EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the
241// serialised point to |cbb|. It returns one on success and zero on error.
David Benjamin6014ea62015-12-30 21:39:34 -0500242OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group,
243 const EC_POINT *point,
244 point_conversion_form_t form,
245 BN_CTX *ctx);
246
David Benjamin4512b792017-08-18 19:21:50 -0400247// EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format
248// serialisation in |buf|. It returns one on success and zero otherwise. The
249// |ctx| argument may be used if not NULL.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700250OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
251 const uint8_t *buf, size_t len,
252 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700253
David Benjamin4512b792017-08-18 19:21:50 -0400254// EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with
255// the given |x| coordinate and the y coordinate specified by |y_bit| (see
256// X9.62). It returns one on success and zero otherwise.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700257OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
258 const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit,
259 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700260
261
David Benjamin4512b792017-08-18 19:21:50 -0400262// Group operations.
Adam Langley95c29f32014-06-20 12:00:00 -0700263
David Benjamin4512b792017-08-18 19:21:50 -0400264// EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and
265// zero otherwise. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700266OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r,
267 const EC_POINT *a, const EC_POINT *b,
268 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700269
David Benjamin4512b792017-08-18 19:21:50 -0400270// EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and
271// zero otherwise. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700272OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r,
273 const EC_POINT *a, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700274
David Benjamin4512b792017-08-18 19:21:50 -0400275// EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and
276// zero otherwise. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700277OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a,
278 BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700279
David Benjamin4512b792017-08-18 19:21:50 -0400280// EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero
281// otherwise. If |ctx| is not NULL, it may be used.
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700282OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
283 const BIGNUM *n, const EC_POINT *q,
284 const BIGNUM *m, BN_CTX *ctx);
Adam Langley95c29f32014-06-20 12:00:00 -0700285
Adam Langley95c29f32014-06-20 12:00:00 -0700286
David Benjamin4512b792017-08-18 19:21:50 -0400287// Deprecated functions.
Adam Langleyc3ef76f2015-04-13 14:34:17 -0700288
David Benjamin4512b792017-08-18 19:21:50 -0400289// EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based
290// on the equation y² = x³ + a·x + b. It returns the new group or NULL on
291// error.
292//
293// This new group has no generator. It is an error to use a generator-less group
294// with any functions except for |EC_GROUP_free|, |EC_POINT_new|,
295// |EC_POINT_set_affine_coordinates_GFp|, and |EC_GROUP_set_generator|.
296//
297// |EC_GROUP|s returned by this function will always compare as unequal via
298// |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always
299// return |NID_undef|.
300//
301// Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name| instead.
David Benjamin6f7374b2016-03-11 16:08:39 -0500302OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p,
303 const BIGNUM *a,
304 const BIGNUM *b, BN_CTX *ctx);
305
David Benjamin4512b792017-08-18 19:21:50 -0400306// EC_GROUP_set_generator sets the generator for |group| to |generator|, which
307// must have the given order and cofactor. It may only be used with |EC_GROUP|
308// objects returned by |EC_GROUP_new_curve_GFp| and may only be used once on
309// each group.
David Benjamin6f7374b2016-03-11 16:08:39 -0500310OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group,
311 const EC_POINT *generator,
312 const BIGNUM *order,
313 const BIGNUM *cofactor);
314
David Benjamin4512b792017-08-18 19:21:50 -0400315// EC_GROUP_get_order sets |*order| to the order of |group|, if it's not
316// NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use
317// |EC_GROUP_get0_order| instead.
Brian Smitha3d9de02015-11-18 17:07:14 -1000318OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order,
319 BN_CTX *ctx);
320
David Benjamin4512b792017-08-18 19:21:50 -0400321// EC_GROUP_set_asn1_flag does nothing.
Adam Langleyc3ef76f2015-04-13 14:34:17 -0700322OPENSSL_EXPORT void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
323
324#define OPENSSL_EC_NAMED_CURVE 0
325
326typedef struct ec_method_st EC_METHOD;
327
David Benjamin4512b792017-08-18 19:21:50 -0400328// EC_GROUP_method_of returns NULL.
Adam Langleyc3ef76f2015-04-13 14:34:17 -0700329OPENSSL_EXPORT const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
330
David Benjamin4512b792017-08-18 19:21:50 -0400331// EC_METHOD_get_field_type returns NID_X9_62_prime_field.
Adam Langleyc3ef76f2015-04-13 14:34:17 -0700332OPENSSL_EXPORT int EC_METHOD_get_field_type(const EC_METHOD *meth);
333
David Benjamin4512b792017-08-18 19:21:50 -0400334// EC_GROUP_set_point_conversion_form aborts the process if |form| is not
335// |POINT_CONVERSION_UNCOMPRESSED| and otherwise does nothing.
Adam Langley126320c2015-05-04 17:43:00 -0700336OPENSSL_EXPORT void EC_GROUP_set_point_conversion_form(
337 EC_GROUP *group, point_conversion_form_t form);
338
David Benjamin4512b792017-08-18 19:21:50 -0400339// EC_builtin_curve describes a supported elliptic curve.
Adam Langleyce9d85e2016-01-24 15:58:39 -0800340typedef struct {
341 int nid;
342 const char *comment;
343} EC_builtin_curve;
344
David Benjamin4512b792017-08-18 19:21:50 -0400345// EC_get_builtin_curves writes at most |max_num_curves| elements to
346// |out_curves| and returns the total number that it would have written, had
347// |max_num_curves| been large enough.
348//
349// The |EC_builtin_curve| items describe the supported elliptic curves.
Adam Langleyce9d85e2016-01-24 15:58:39 -0800350OPENSSL_EXPORT size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
351 size_t max_num_curves);
Adam Langleyc3ef76f2015-04-13 14:34:17 -0700352
David Benjamin4512b792017-08-18 19:21:50 -0400353// Old code expects to get EC_KEY from ec.h.
Adam Langleyd2b5af52016-07-12 08:03:59 -0700354#include <openssl/ec_key.h>
355
Adam Langley95c29f32014-06-20 12:00:00 -0700356
357#if defined(__cplusplus)
David Benjamin4512b792017-08-18 19:21:50 -0400358} // extern C
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700359
360extern "C++" {
361
362namespace bssl {
363
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700364BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free)
365BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free)
366
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700367} // namespace bssl
368
David Benjamin4512b792017-08-18 19:21:50 -0400369} // extern C++
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700370
Adam Langley8c3c3132016-07-11 15:22:19 -0700371#endif
372
David Benjamin689be0f2015-02-11 15:55:26 -0500373#define EC_R_BUFFER_TOO_SMALL 100
374#define EC_R_COORDINATES_OUT_OF_RANGE 101
375#define EC_R_D2I_ECPKPARAMETERS_FAILURE 102
376#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 103
377#define EC_R_GROUP2PKPARAMETERS_FAILURE 104
378#define EC_R_I2D_ECPKPARAMETERS_FAILURE 105
379#define EC_R_INCOMPATIBLE_OBJECTS 106
380#define EC_R_INVALID_COMPRESSED_POINT 107
381#define EC_R_INVALID_COMPRESSION_BIT 108
382#define EC_R_INVALID_ENCODING 109
383#define EC_R_INVALID_FIELD 110
384#define EC_R_INVALID_FORM 111
385#define EC_R_INVALID_GROUP_ORDER 112
386#define EC_R_INVALID_PRIVATE_KEY 113
387#define EC_R_MISSING_PARAMETERS 114
388#define EC_R_MISSING_PRIVATE_KEY 115
389#define EC_R_NON_NAMED_CURVE 116
390#define EC_R_NOT_INITIALIZED 117
391#define EC_R_PKPARAMETERS2GROUP_FAILURE 118
392#define EC_R_POINT_AT_INFINITY 119
393#define EC_R_POINT_IS_NOT_ON_CURVE 120
394#define EC_R_SLOT_FULL 121
395#define EC_R_UNDEFINED_GENERATOR 122
396#define EC_R_UNKNOWN_GROUP 123
397#define EC_R_UNKNOWN_ORDER 124
398#define EC_R_WRONG_ORDER 125
Adam Langleyad6b28e2015-04-14 12:07:44 -0700399#define EC_R_BIGNUM_OUT_OF_RANGE 126
400#define EC_R_WRONG_CURVE_PARAMETERS 127
David Benjamin2f6410b2016-01-03 00:57:37 -0800401#define EC_R_DECODE_ERROR 128
402#define EC_R_ENCODE_ERROR 129
403#define EC_R_GROUP_MISMATCH 130
David Benjamin8cf79af2016-06-16 14:58:36 -0400404#define EC_R_INVALID_COFACTOR 131
Steven Valdezb15143f2017-04-13 13:14:12 -0400405#define EC_R_PUBLIC_KEY_VALIDATION_FAILED 132
Adam Langley95c29f32014-06-20 12:00:00 -0700406
David Benjamin4512b792017-08-18 19:21:50 -0400407#endif // OPENSSL_HEADER_EC_H