ec.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /* crypto/ec/ec.h */
  2. /*
  3. * Originally written by Bodo Moeller for the OpenSSL project.
  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. /* ====================================================================
  10. * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * 3. All advertising materials mentioning features or use of this
  25. * software must display the following acknowledgment:
  26. * "This product includes software developed by the OpenSSL Project
  27. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  28. *
  29. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  30. * endorse or promote products derived from this software without
  31. * prior written permission. For written permission, please contact
  32. * openssl-core@openssl.org.
  33. *
  34. * 5. Products derived from this software may not be called "OpenSSL"
  35. * nor may "OpenSSL" appear in their names without prior written
  36. * permission of the OpenSSL Project.
  37. *
  38. * 6. Redistributions of any form whatsoever must retain the following
  39. * acknowledgment:
  40. * "This product includes software developed by the OpenSSL Project
  41. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  44. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  46. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  47. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  49. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  50. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  52. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  53. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  54. * OF THE POSSIBILITY OF SUCH DAMAGE.
  55. * ====================================================================
  56. *
  57. * This product includes cryptographic software written by Eric Young
  58. * (eay@cryptsoft.com). This product includes software written by Tim
  59. * Hudson (tjh@cryptsoft.com).
  60. *
  61. */
  62. /* ====================================================================
  63. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  64. *
  65. * Portions of the attached software ("Contribution") are developed by
  66. * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
  67. *
  68. * The Contribution is licensed pursuant to the OpenSSL open source
  69. * license provided above.
  70. *
  71. * The elliptic curve binary polynomial software is originally written by
  72. * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
  73. *
  74. */
  75. #ifndef HEADER_EC_H
  76. #define HEADER_EC_H
  77. #include <openssl/opensslconf.h>
  78. #ifdef OPENSSL_NO_EC
  79. #error EC is disabled.
  80. #endif
  81. #include <openssl/asn1.h>
  82. #include <openssl/symhacks.h>
  83. #ifndef OPENSSL_NO_DEPRECATED
  84. #include <openssl/bn.h>
  85. #endif
  86. #ifdef __cplusplus
  87. extern "C" {
  88. #elif defined(__SUNPRO_C)
  89. # if __SUNPRO_C >= 0x520
  90. # pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
  91. # endif
  92. #endif
  93. #ifndef OPENSSL_ECC_MAX_FIELD_BITS
  94. # define OPENSSL_ECC_MAX_FIELD_BITS 661
  95. #endif
  96. /** Enum for the point conversion form as defined in X9.62 (ECDSA)
  97. * for the encoding of a elliptic curve point (x,y) */
  98. typedef enum {
  99. /** the point is encoded as z||x, where the octet z specifies
  100. * which solution of the quadratic equation y is */
  101. POINT_CONVERSION_COMPRESSED = 2,
  102. /** the point is encoded as z||x||y, where z is the octet 0x02 */
  103. POINT_CONVERSION_UNCOMPRESSED = 4,
  104. /** the point is encoded as z||x||y, where the octet z specifies
  105. * which solution of the quadratic equation y is */
  106. POINT_CONVERSION_HYBRID = 6
  107. } point_conversion_form_t;
  108. typedef struct ec_method_st EC_METHOD;
  109. typedef struct ec_group_st
  110. /*
  111. EC_METHOD *meth;
  112. -- field definition
  113. -- curve coefficients
  114. -- optional generator with associated information (order, cofactor)
  115. -- optional extra data (precomputed table for fast computation of multiples of generator)
  116. -- ASN1 stuff
  117. */
  118. EC_GROUP;
  119. typedef struct ec_point_st EC_POINT;
  120. /********************************************************************/
  121. /* EC_METHODs for curves over GF(p) */
  122. /********************************************************************/
  123. /** Returns the basic GFp ec methods which provides the basis for the
  124. * optimized methods.
  125. * \return EC_METHOD object
  126. */
  127. const EC_METHOD *EC_GFp_simple_method(void);
  128. /** Returns GFp methods using montgomery multiplication.
  129. * \return EC_METHOD object
  130. */
  131. const EC_METHOD *EC_GFp_mont_method(void);
  132. /** Returns GFp methods using optimized methods for NIST recommended curves
  133. * \return EC_METHOD object
  134. */
  135. const EC_METHOD *EC_GFp_nist_method(void);
  136. #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
  137. /** Returns 64-bit optimized methods for nistp224
  138. * \return EC_METHOD object
  139. */
  140. const EC_METHOD *EC_GFp_nistp224_method(void);
  141. /** Returns 64-bit optimized methods for nistp256
  142. * \return EC_METHOD object
  143. */
  144. const EC_METHOD *EC_GFp_nistp256_method(void);
  145. /** Returns 64-bit optimized methods for nistp521
  146. * \return EC_METHOD object
  147. */
  148. const EC_METHOD *EC_GFp_nistp521_method(void);
  149. #endif
  150. /********************************************************************/
  151. /* EC_GROUP functions */
  152. /********************************************************************/
  153. /** Creates a new EC_GROUP object
  154. * \param meth EC_METHOD to use
  155. * \return newly created EC_GROUP object or NULL in case of an error.
  156. */
  157. EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
  158. /** Frees a EC_GROUP object
  159. * \param group EC_GROUP object to be freed.
  160. */
  161. void EC_GROUP_free(EC_GROUP *group);
  162. /** Clears and frees a EC_GROUP object
  163. * \param group EC_GROUP object to be cleared and freed.
  164. */
  165. void EC_GROUP_clear_free(EC_GROUP *group);
  166. /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
  167. * \param dst destination EC_GROUP object
  168. * \param src source EC_GROUP object
  169. * \return 1 on success and 0 if an error occurred.
  170. */
  171. int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
  172. /** Creates a new EC_GROUP object and copies the copies the content
  173. * form src to the newly created EC_KEY object
  174. * \param src source EC_GROUP object
  175. * \return newly created EC_GROUP object or NULL in case of an error.
  176. */
  177. EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
  178. /** Returns the EC_METHOD of the EC_GROUP object.
  179. * \param group EC_GROUP object
  180. * \return EC_METHOD used in this EC_GROUP object.
  181. */
  182. const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
  183. /** Returns the field type of the EC_METHOD.
  184. * \param meth EC_METHOD object
  185. * \return NID of the underlying field type OID.
  186. */
  187. int EC_METHOD_get_field_type(const EC_METHOD *meth);
  188. /** Sets the generator and it's order/cofactor of a EC_GROUP object.
  189. * \param group EC_GROUP object
  190. * \param generator EC_POINT object with the generator.
  191. * \param order the order of the group generated by the generator.
  192. * \param cofactor the index of the sub-group generated by the generator
  193. * in the group of all points on the elliptic curve.
  194. * \return 1 on success and 0 if an error occured
  195. */
  196. int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
  197. /** Returns the generator of a EC_GROUP object.
  198. * \param group EC_GROUP object
  199. * \return the currently used generator (possibly NULL).
  200. */
  201. const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
  202. /** Gets the order of a EC_GROUP
  203. * \param group EC_GROUP object
  204. * \param order BIGNUM to which the order is copied
  205. * \param ctx BN_CTX object (optional)
  206. * \return 1 on success and 0 if an error occured
  207. */
  208. int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
  209. /** Gets the cofactor of a EC_GROUP
  210. * \param group EC_GROUP object
  211. * \param cofactor BIGNUM to which the cofactor is copied
  212. * \param ctx BN_CTX object (optional)
  213. * \return 1 on success and 0 if an error occured
  214. */
  215. int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
  216. /** Sets the name of a EC_GROUP object
  217. * \param group EC_GROUP object
  218. * \param nid NID of the curve name OID
  219. */
  220. void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
  221. /** Returns the curve name of a EC_GROUP object
  222. * \param group EC_GROUP object
  223. * \return NID of the curve name OID or 0 if not set.
  224. */
  225. int EC_GROUP_get_curve_name(const EC_GROUP *group);
  226. void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
  227. int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
  228. void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form);
  229. point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
  230. unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
  231. size_t EC_GROUP_get_seed_len(const EC_GROUP *);
  232. size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
  233. /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b
  234. * \param group EC_GROUP object
  235. * \param p BIGNUM with the prime number
  236. * \param a BIGNUM with parameter a of the equation
  237. * \param b BIGNUM with parameter b of the equation
  238. * \param ctx BN_CTX object (optional)
  239. * \return 1 on success and 0 if an error occured
  240. */
  241. int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  242. /** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b
  243. * \param group EC_GROUP object
  244. * \param p BIGNUM for the prime number
  245. * \param a BIGNUM for parameter a of the equation
  246. * \param b BIGNUM for parameter b of the equation
  247. * \param ctx BN_CTX object (optional)
  248. * \return 1 on success and 0 if an error occured
  249. */
  250. int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  251. /** Returns the number of bits needed to represent a field element
  252. * \param group EC_GROUP object
  253. * \return number of bits needed to represent a field element
  254. */
  255. int EC_GROUP_get_degree(const EC_GROUP *group);
  256. /** Checks whether the parameter in the EC_GROUP define a valid ec group
  257. * \param group EC_GROUP object
  258. * \param ctx BN_CTX object (optional)
  259. * \return 1 if group is a valid ec group and 0 otherwise
  260. */
  261. int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
  262. /** Checks whether the discriminant of the elliptic curve is zero or not
  263. * \param group EC_GROUP object
  264. * \param ctx BN_CTX object (optional)
  265. * \return 1 if the discriminant is not zero and 0 otherwise
  266. */
  267. int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
  268. /** Compares two EC_GROUP objects
  269. * \param a first EC_GROUP object
  270. * \param b second EC_GROUP object
  271. * \param ctx BN_CTX object (optional)
  272. * \return 0 if both groups are equal and 1 otherwise
  273. */
  274. int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
  275. /* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
  276. * after choosing an appropriate EC_METHOD */
  277. /** Creates a new EC_GROUP object with the specified parameters defined
  278. * over GFp (defined by the equation y^2 = x^3 + a*x + b)
  279. * \param p BIGNUM with the prime number
  280. * \param a BIGNUM with the parameter a of the equation
  281. * \param b BIGNUM with the parameter b of the equation
  282. * \param ctx BN_CTX object (optional)
  283. * \return newly created EC_GROUP object with the specified parameters
  284. */
  285. EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  286. /** Creates a EC_GROUP object with a curve specified by a NID
  287. * \param nid NID of the OID of the curve name
  288. * \return newly created EC_GROUP object with specified curve or NULL
  289. * if an error occurred
  290. */
  291. EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
  292. /********************************************************************/
  293. /* handling of internal curves */
  294. /********************************************************************/
  295. typedef struct {
  296. int nid;
  297. const char *comment;
  298. } EC_builtin_curve;
  299. /* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
  300. * of all available curves or zero if a error occurred.
  301. * In case r ist not zero nitems EC_builtin_curve structures
  302. * are filled with the data of the first nitems internal groups */
  303. size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
  304. /********************************************************************/
  305. /* EC_POINT functions */
  306. /********************************************************************/
  307. /** Creates a new EC_POINT object for the specified EC_GROUP
  308. * \param group EC_GROUP the underlying EC_GROUP object
  309. * \return newly created EC_POINT object or NULL if an error occurred
  310. */
  311. EC_POINT *EC_POINT_new(const EC_GROUP *group);
  312. /** Frees a EC_POINT object
  313. * \param point EC_POINT object to be freed
  314. */
  315. void EC_POINT_free(EC_POINT *point);
  316. /** Clears and frees a EC_POINT object
  317. * \param point EC_POINT object to be cleared and freed
  318. */
  319. void EC_POINT_clear_free(EC_POINT *point);
  320. /** Copies EC_POINT object
  321. * \param dst destination EC_POINT object
  322. * \param src source EC_POINT object
  323. * \return 1 on success and 0 if an error occured
  324. */
  325. int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
  326. /** Creates a new EC_POINT object and copies the content of the supplied
  327. * EC_POINT
  328. * \param src source EC_POINT object
  329. * \param group underlying the EC_GROUP object
  330. * \return newly created EC_POINT object or NULL if an error occurred
  331. */
  332. EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
  333. /** Returns the EC_METHOD used in EC_POINT object
  334. * \param point EC_POINT object
  335. * \return the EC_METHOD used
  336. */
  337. const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
  338. /** Sets a point to infinity (neutral element)
  339. * \param group underlying EC_GROUP object
  340. * \param point EC_POINT to set to infinity
  341. * \return 1 on success and 0 if an error occured
  342. */
  343. int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
  344. /** Sets the jacobian projective coordinates of a EC_POINT over GFp
  345. * \param group underlying EC_GROUP object
  346. * \param p EC_POINT object
  347. * \param x BIGNUM with the x-coordinate
  348. * \param y BIGNUM with the y-coordinate
  349. * \param z BIGNUM with the z-coordinate
  350. * \param ctx BN_CTX object (optional)
  351. * \return 1 on success and 0 if an error occured
  352. */
  353. int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  354. const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx);
  355. /** Gets the jacobian projective coordinates of a EC_POINT over GFp
  356. * \param group underlying EC_GROUP object
  357. * \param p EC_POINT object
  358. * \param x BIGNUM for the x-coordinate
  359. * \param y BIGNUM for the y-coordinate
  360. * \param z BIGNUM for the z-coordinate
  361. * \param ctx BN_CTX object (optional)
  362. * \return 1 on success and 0 if an error occured
  363. */
  364. int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
  365. const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
  366. /** Sets the affine coordinates of a EC_POINT over GFp
  367. * \param group underlying EC_GROUP object
  368. * \param p EC_POINT object
  369. * \param x BIGNUM with the x-coordinate
  370. * \param y BIGNUM with the y-coordinate
  371. * \param ctx BN_CTX object (optional)
  372. * \return 1 on success and 0 if an error occured
  373. */
  374. int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  375. const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
  376. /** Gets the affine coordinates of a EC_POINT over GFp
  377. * \param group underlying EC_GROUP object
  378. * \param p EC_POINT object
  379. * \param x BIGNUM for the x-coordinate
  380. * \param y BIGNUM for the y-coordinate
  381. * \param ctx BN_CTX object (optional)
  382. * \return 1 on success and 0 if an error occured
  383. */
  384. int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
  385. const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
  386. /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp
  387. * \param group underlying EC_GROUP object
  388. * \param p EC_POINT object
  389. * \param x BIGNUM with x-coordinate
  390. * \param y_bit integer with the y-Bit (either 0 or 1)
  391. * \param ctx BN_CTX object (optional)
  392. * \return 1 on success and 0 if an error occured
  393. */
  394. int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  395. const BIGNUM *x, int y_bit, BN_CTX *ctx);
  396. /** Encodes a EC_POINT object to a octet string
  397. * \param group underlying EC_GROUP object
  398. * \param p EC_POINT object
  399. * \param form point conversion form
  400. * \param buf memory buffer for the result. If NULL the function returns
  401. * required buffer size.
  402. * \param len length of the memory buffer
  403. * \param ctx BN_CTX object (optional)
  404. * \return the length of the encoded octet string or 0 if an error occurred
  405. */
  406. size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
  407. point_conversion_form_t form,
  408. unsigned char *buf, size_t len, BN_CTX *ctx);
  409. /** Decodes a EC_POINT from a octet string
  410. * \param group underlying EC_GROUP object
  411. * \param p EC_POINT object
  412. * \param buf memory buffer with the encoded ec point
  413. * \param len length of the encoded ec point
  414. * \param ctx BN_CTX object (optional)
  415. * \return 1 on success and 0 if an error occured
  416. */
  417. int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
  418. const unsigned char *buf, size_t len, BN_CTX *ctx);
  419. /* other interfaces to point2oct/oct2point: */
  420. BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
  421. point_conversion_form_t form, BIGNUM *, BN_CTX *);
  422. EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
  423. EC_POINT *, BN_CTX *);
  424. char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
  425. point_conversion_form_t form, BN_CTX *);
  426. EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
  427. EC_POINT *, BN_CTX *);
  428. /********************************************************************/
  429. /* functions for doing EC_POINT arithmetic */
  430. /********************************************************************/
  431. /** Computes the sum of two EC_POINT
  432. * \param group underlying EC_GROUP object
  433. * \param r EC_POINT object for the result (r = a + b)
  434. * \param a EC_POINT object with the first summand
  435. * \param b EC_POINT object with the second summand
  436. * \param ctx BN_CTX object (optional)
  437. * \return 1 on success and 0 if an error occured
  438. */
  439. int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
  440. /** Computes the double of a EC_POINT
  441. * \param group underlying EC_GROUP object
  442. * \param r EC_POINT object for the result (r = 2 * a)
  443. * \param a EC_POINT object
  444. * \param ctx BN_CTX object (optional)
  445. * \return 1 on success and 0 if an error occured
  446. */
  447. int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx);
  448. /** Computes the inverse of a EC_POINT
  449. * \param group underlying EC_GROUP object
  450. * \param a EC_POINT object to be inverted (it's used for the result as well)
  451. * \param ctx BN_CTX object (optional)
  452. * \return 1 on success and 0 if an error occured
  453. */
  454. int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
  455. /** Checks whether the point is the neutral element of the group
  456. * \param group the underlying EC_GROUP object
  457. * \param p EC_POINT object
  458. * \return 1 if the point is the neutral element and 0 otherwise
  459. */
  460. int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
  461. /** Checks whether the point is on the curve
  462. * \param group underlying EC_GROUP object
  463. * \param point EC_POINT object to check
  464. * \param ctx BN_CTX object (optional)
  465. * \return 1 if point if on the curve and 0 otherwise
  466. */
  467. int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);
  468. /** Compares two EC_POINTs
  469. * \param group underlying EC_GROUP object
  470. * \param a first EC_POINT object
  471. * \param b second EC_POINT object
  472. * \param ctx BN_CTX object (optional)
  473. * \return 0 if both points are equal and a value != 0 otherwise
  474. */
  475. int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
  476. int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
  477. int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx);
  478. /** Computes r = generator * n sum_{i=0}^num p[i] * m[i]
  479. * \param group underlying EC_GROUP object
  480. * \param r EC_POINT object for the result
  481. * \param n BIGNUM with the multiplier for the group generator (optional)
  482. * \param num number futher summands
  483. * \param p array of size num of EC_POINT objects
  484. * \param m array of size num of BIGNUM objects
  485. * \param ctx BN_CTX object (optional)
  486. * \return 1 on success and 0 if an error occured
  487. */
  488. 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);
  489. /** Computes r = generator * n + q * m
  490. * \param group underlying EC_GROUP object
  491. * \param r EC_POINT object for the result
  492. * \param n BIGNUM with the multiplier for the group generator (optional)
  493. * \param q EC_POINT object with the first factor of the second summand
  494. * \param m BIGNUM with the second factor of the second summand
  495. * \param ctx BN_CTX object (optional)
  496. * \return 1 on success and 0 if an error occured
  497. */
  498. int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
  499. /** Stores multiples of generator for faster point multiplication
  500. * \param group EC_GROUP object
  501. * \param ctx BN_CTX object (optional)
  502. * \return 1 on success and 0 if an error occured
  503. */
  504. int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
  505. /** Reports whether a precomputation has been done
  506. * \param group EC_GROUP object
  507. * \return 1 if a pre-computation has been done and 0 otherwise
  508. */
  509. int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
  510. /********************************************************************/
  511. /* ASN1 stuff */
  512. /********************************************************************/
  513. /* EC_GROUP_get_basis_type() returns the NID of the basis type
  514. * used to represent the field elements */
  515. int EC_GROUP_get_basis_type(const EC_GROUP *);
  516. #define OPENSSL_EC_NAMED_CURVE 0x001
  517. typedef struct ecpk_parameters_st ECPKPARAMETERS;
  518. EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
  519. int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
  520. #define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
  521. #define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
  522. #define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
  523. (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
  524. #define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
  525. (unsigned char *)(x))
  526. #ifndef OPENSSL_NO_BIO
  527. int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
  528. #endif
  529. #ifndef OPENSSL_NO_FP_API
  530. int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
  531. #endif
  532. /********************************************************************/
  533. /* EC_KEY functions */
  534. /********************************************************************/
  535. typedef struct ec_key_st EC_KEY;
  536. /* some values for the encoding_flag */
  537. #define EC_PKEY_NO_PARAMETERS 0x001
  538. #define EC_PKEY_NO_PUBKEY 0x002
  539. /* some values for the flags field */
  540. #define EC_FLAG_NON_FIPS_ALLOW 0x1
  541. #define EC_FLAG_FIPS_CHECKED 0x2
  542. /** Creates a new EC_KEY object.
  543. * \return EC_KEY object or NULL if an error occurred.
  544. */
  545. EC_KEY *EC_KEY_new(void);
  546. int EC_KEY_get_flags(const EC_KEY *key);
  547. void EC_KEY_set_flags(EC_KEY *key, int flags);
  548. void EC_KEY_clear_flags(EC_KEY *key, int flags);
  549. /** Creates a new EC_KEY object using a named curve as underlying
  550. * EC_GROUP object.
  551. * \param nid NID of the named curve.
  552. * \return EC_KEY object or NULL if an error occurred.
  553. */
  554. EC_KEY *EC_KEY_new_by_curve_name(int nid);
  555. /** Frees a EC_KEY object.
  556. * \param key EC_KEY object to be freed.
  557. */
  558. void EC_KEY_free(EC_KEY *key);
  559. /** Copies a EC_KEY object.
  560. * \param dst destination EC_KEY object
  561. * \param src src EC_KEY object
  562. * \return dst or NULL if an error occurred.
  563. */
  564. EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
  565. /** Creates a new EC_KEY object and copies the content from src to it.
  566. * \param src the source EC_KEY object
  567. * \return newly created EC_KEY object or NULL if an error occurred.
  568. */
  569. EC_KEY *EC_KEY_dup(const EC_KEY *src);
  570. /** Increases the internal reference count of a EC_KEY object.
  571. * \param key EC_KEY object
  572. * \return 1 on success and 0 if an error occurred.
  573. */
  574. int EC_KEY_up_ref(EC_KEY *key);
  575. /** Returns the EC_GROUP object of a EC_KEY object
  576. * \param key EC_KEY object
  577. * \return the EC_GROUP object (possibly NULL).
  578. */
  579. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
  580. /** Sets the EC_GROUP of a EC_KEY object.
  581. * \param key EC_KEY object
  582. * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY
  583. * object will use an own copy of the EC_GROUP).
  584. * \return 1 on success and 0 if an error occurred.
  585. */
  586. int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
  587. /** Returns the private key of a EC_KEY object.
  588. * \param key EC_KEY object
  589. * \return a BIGNUM with the private key (possibly NULL).
  590. */
  591. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
  592. /** Sets the private key of a EC_KEY object.
  593. * \param key EC_KEY object
  594. * \param prv BIGNUM with the private key (note: the EC_KEY object
  595. * will use an own copy of the BIGNUM).
  596. * \return 1 on success and 0 if an error occurred.
  597. */
  598. int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
  599. /** Returns the public key of a EC_KEY object.
  600. * \param key the EC_KEY object
  601. * \return a EC_POINT object with the public key (possibly NULL)
  602. */
  603. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
  604. /** Sets the public key of a EC_KEY object.
  605. * \param key EC_KEY object
  606. * \param pub EC_POINT object with the public key (note: the EC_KEY object
  607. * will use an own copy of the EC_POINT object).
  608. * \return 1 on success and 0 if an error occurred.
  609. */
  610. int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
  611. unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
  612. void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
  613. point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
  614. void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
  615. /* functions to set/get method specific data */
  616. void *EC_KEY_get_key_method_data(EC_KEY *key,
  617. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
  618. /** Sets the key method data of an EC_KEY object, if none has yet been set.
  619. * \param key EC_KEY object
  620. * \param data opaque data to install.
  621. * \param dup_func a function that duplicates |data|.
  622. * \param free_func a function that frees |data|.
  623. * \param clear_free_func a function that wipes and frees |data|.
  624. * \return the previously set data pointer, or NULL if |data| was inserted.
  625. */
  626. void *EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
  627. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
  628. /* wrapper functions for the underlying EC_GROUP object */
  629. void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
  630. /** Creates a table of pre-computed multiples of the generator to
  631. * accelerate further EC_KEY operations.
  632. * \param key EC_KEY object
  633. * \param ctx BN_CTX object (optional)
  634. * \return 1 on success and 0 if an error occurred.
  635. */
  636. int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
  637. /** Creates a new ec private (and optional a new public) key.
  638. * \param key EC_KEY object
  639. * \return 1 on success and 0 if an error occurred.
  640. */
  641. int EC_KEY_generate_key(EC_KEY *key);
  642. /** Verifies that a private and/or public key is valid.
  643. * \param key the EC_KEY object
  644. * \return 1 on success and 0 otherwise.
  645. */
  646. int EC_KEY_check_key(const EC_KEY *key);
  647. /** Sets a public key from affine coordindates performing
  648. * neccessary NIST PKV tests.
  649. * \param key the EC_KEY object
  650. * \param x public key x coordinate
  651. * \param y public key y coordinate
  652. * \return 1 on success and 0 otherwise.
  653. */
  654. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y);
  655. /********************************************************************/
  656. /* de- and encoding functions for SEC1 ECPrivateKey */
  657. /********************************************************************/
  658. /** Decodes a private key from a memory buffer.
  659. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  660. * \param in pointer to memory with the DER encoded private key
  661. * \param len length of the DER encoded private key
  662. * \return the decoded private key or NULL if an error occurred.
  663. */
  664. EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
  665. /** Encodes a private key object and stores the result in a buffer.
  666. * \param key the EC_KEY object to encode
  667. * \param out the buffer for the result (if NULL the function returns number
  668. * of bytes needed).
  669. * \return 1 on success and 0 if an error occurred.
  670. */
  671. int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
  672. /********************************************************************/
  673. /* de- and encoding functions for EC parameters */
  674. /********************************************************************/
  675. /** Decodes ec parameter from a memory buffer.
  676. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  677. * \param in pointer to memory with the DER encoded ec parameters
  678. * \param len length of the DER encoded ec parameters
  679. * \return a EC_KEY object with the decoded parameters or NULL if an error
  680. * occurred.
  681. */
  682. EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
  683. /** Encodes ec parameter and stores the result in a buffer.
  684. * \param key the EC_KEY object with ec paramters to encode
  685. * \param out the buffer for the result (if NULL the function returns number
  686. * of bytes needed).
  687. * \return 1 on success and 0 if an error occurred.
  688. */
  689. int i2d_ECParameters(EC_KEY *key, unsigned char **out);
  690. /********************************************************************/
  691. /* de- and encoding functions for EC public key */
  692. /* (octet string, not DER -- hence 'o2i' and 'i2o') */
  693. /********************************************************************/
  694. /** Decodes a ec public key from a octet string.
  695. * \param key a pointer to a EC_KEY object which should be used
  696. * \param in memory buffer with the encoded public key
  697. * \param len length of the encoded public key
  698. * \return EC_KEY object with decoded public key or NULL if an error
  699. * occurred.
  700. */
  701. EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
  702. /** Encodes a ec public key in an octet string.
  703. * \param key the EC_KEY object with the public key
  704. * \param out the buffer for the result (if NULL the function returns number
  705. * of bytes needed).
  706. * \return 1 on success and 0 if an error occurred
  707. */
  708. int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
  709. #ifndef OPENSSL_NO_BIO
  710. /** Prints out the ec parameters on human readable form.
  711. * \param bp BIO object to which the information is printed
  712. * \param key EC_KEY object
  713. * \return 1 on success and 0 if an error occurred
  714. */
  715. int ECParameters_print(BIO *bp, const EC_KEY *key);
  716. /** Prints out the contents of a EC_KEY object
  717. * \param bp BIO object to which the information is printed
  718. * \param key EC_KEY object
  719. * \param off line offset
  720. * \return 1 on success and 0 if an error occurred
  721. */
  722. int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
  723. #endif
  724. #ifndef OPENSSL_NO_FP_API
  725. /** Prints out the ec parameters on human readable form.
  726. * \param fp file descriptor to which the information is printed
  727. * \param key EC_KEY object
  728. * \return 1 on success and 0 if an error occurred
  729. */
  730. int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
  731. /** Prints out the contents of a EC_KEY object
  732. * \param fp file descriptor to which the information is printed
  733. * \param key EC_KEY object
  734. * \param off line offset
  735. * \return 1 on success and 0 if an error occurred
  736. */
  737. int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
  738. #endif
  739. #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
  740. #ifndef __cplusplus
  741. #if defined(__SUNPRO_C)
  742. # if __SUNPRO_C >= 0x520
  743. # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
  744. # endif
  745. # endif
  746. #endif
  747. #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
  748. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \
  749. EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
  750. #define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
  751. /* BEGIN ERROR CODES */
  752. /* The following lines are auto generated by the script mkerr.pl. Any changes
  753. * made after this point may be overwritten when the script is next run.
  754. */
  755. void ERR_load_EC_strings(void);
  756. /* Error codes for the EC functions. */
  757. /* Function codes. */
  758. #define EC_F_BN_TO_FELEM 224
  759. #define EC_F_COMPUTE_WNAF 143
  760. #define EC_F_D2I_ECPARAMETERS 144
  761. #define EC_F_D2I_ECPKPARAMETERS 145
  762. #define EC_F_D2I_ECPRIVATEKEY 146
  763. #define EC_F_DO_EC_KEY_PRINT 221
  764. #define EC_F_ECKEY_PARAM2TYPE 223
  765. #define EC_F_ECKEY_PARAM_DECODE 212
  766. #define EC_F_ECKEY_PRIV_DECODE 213
  767. #define EC_F_ECKEY_PRIV_ENCODE 214
  768. #define EC_F_ECKEY_PUB_DECODE 215
  769. #define EC_F_ECKEY_PUB_ENCODE 216
  770. #define EC_F_ECKEY_TYPE2PARAM 220
  771. #define EC_F_ECPARAMETERS_PRINT 147
  772. #define EC_F_ECPARAMETERS_PRINT_FP 148
  773. #define EC_F_ECPKPARAMETERS_PRINT 149
  774. #define EC_F_ECPKPARAMETERS_PRINT_FP 150
  775. #define EC_F_ECP_NIST_MOD_192 203
  776. #define EC_F_ECP_NIST_MOD_224 204
  777. #define EC_F_ECP_NIST_MOD_256 205
  778. #define EC_F_ECP_NIST_MOD_521 206
  779. #define EC_F_EC_ASN1_GROUP2CURVE 153
  780. #define EC_F_EC_ASN1_GROUP2FIELDID 154
  781. #define EC_F_EC_ASN1_GROUP2PARAMETERS 155
  782. #define EC_F_EC_ASN1_GROUP2PKPARAMETERS 156
  783. #define EC_F_EC_ASN1_PARAMETERS2GROUP 157
  784. #define EC_F_EC_ASN1_PKPARAMETERS2GROUP 158
  785. #define EC_F_EC_EX_DATA_SET_DATA 211
  786. #define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208
  787. #define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159
  788. #define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195
  789. #define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160
  790. #define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161
  791. #define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
  792. #define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
  793. #define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164
  794. #define EC_F_EC_GFP_MONT_FIELD_DECODE 133
  795. #define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
  796. #define EC_F_EC_GFP_MONT_FIELD_MUL 131
  797. #define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209
  798. #define EC_F_EC_GFP_MONT_FIELD_SQR 132
  799. #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189
  800. #define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP 135
  801. #define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE 225
  802. #define EC_F_EC_GFP_NISTP224_POINTS_MUL 228
  803. #define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226
  804. #define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE 230
  805. #define EC_F_EC_GFP_NISTP256_POINTS_MUL 231
  806. #define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232
  807. #define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE 233
  808. #define EC_F_EC_GFP_NISTP521_POINTS_MUL 234
  809. #define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235
  810. #define EC_F_EC_GFP_NIST_FIELD_MUL 200
  811. #define EC_F_EC_GFP_NIST_FIELD_SQR 201
  812. #define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202
  813. #define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165
  814. #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166
  815. #define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
  816. #define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
  817. #define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
  818. #define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
  819. #define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
  820. #define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
  821. #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167
  822. #define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
  823. #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168
  824. #define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
  825. #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169
  826. #define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
  827. #define EC_F_EC_GROUP_CHECK 170
  828. #define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171
  829. #define EC_F_EC_GROUP_COPY 106
  830. #define EC_F_EC_GROUP_GET0_GENERATOR 139
  831. #define EC_F_EC_GROUP_GET_COFACTOR 140
  832. #define EC_F_EC_GROUP_GET_CURVE_GF2M 172
  833. #define EC_F_EC_GROUP_GET_CURVE_GFP 130
  834. #define EC_F_EC_GROUP_GET_DEGREE 173
  835. #define EC_F_EC_GROUP_GET_ORDER 141
  836. #define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193
  837. #define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194
  838. #define EC_F_EC_GROUP_NEW 108
  839. #define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174
  840. #define EC_F_EC_GROUP_NEW_FROM_DATA 175
  841. #define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
  842. #define EC_F_EC_GROUP_SET_CURVE_GF2M 176
  843. #define EC_F_EC_GROUP_SET_CURVE_GFP 109
  844. #define EC_F_EC_GROUP_SET_EXTRA_DATA 110
  845. #define EC_F_EC_GROUP_SET_GENERATOR 111
  846. #define EC_F_EC_KEY_CHECK_KEY 177
  847. #define EC_F_EC_KEY_COPY 178
  848. #define EC_F_EC_KEY_GENERATE_KEY 179
  849. #define EC_F_EC_KEY_NEW 182
  850. #define EC_F_EC_KEY_PRINT 180
  851. #define EC_F_EC_KEY_PRINT_FP 181
  852. #define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 229
  853. #define EC_F_EC_POINTS_MAKE_AFFINE 136
  854. #define EC_F_EC_POINT_ADD 112
  855. #define EC_F_EC_POINT_CMP 113
  856. #define EC_F_EC_POINT_COPY 114
  857. #define EC_F_EC_POINT_DBL 115
  858. #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183
  859. #define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
  860. #define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
  861. #define EC_F_EC_POINT_INVERT 210
  862. #define EC_F_EC_POINT_IS_AT_INFINITY 118
  863. #define EC_F_EC_POINT_IS_ON_CURVE 119
  864. #define EC_F_EC_POINT_MAKE_AFFINE 120
  865. #define EC_F_EC_POINT_MUL 184
  866. #define EC_F_EC_POINT_NEW 121
  867. #define EC_F_EC_POINT_OCT2POINT 122
  868. #define EC_F_EC_POINT_POINT2OCT 123
  869. #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185
  870. #define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
  871. #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186
  872. #define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
  873. #define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
  874. #define EC_F_EC_POINT_SET_TO_INFINITY 127
  875. #define EC_F_EC_PRE_COMP_DUP 207
  876. #define EC_F_EC_PRE_COMP_NEW 196
  877. #define EC_F_EC_WNAF_MUL 187
  878. #define EC_F_EC_WNAF_PRECOMPUTE_MULT 188
  879. #define EC_F_I2D_ECPARAMETERS 190
  880. #define EC_F_I2D_ECPKPARAMETERS 191
  881. #define EC_F_I2D_ECPRIVATEKEY 192
  882. #define EC_F_I2O_ECPUBLICKEY 151
  883. #define EC_F_NISTP224_PRE_COMP_NEW 227
  884. #define EC_F_NISTP256_PRE_COMP_NEW 236
  885. #define EC_F_NISTP521_PRE_COMP_NEW 237
  886. #define EC_F_O2I_ECPUBLICKEY 152
  887. #define EC_F_OLD_EC_PRIV_DECODE 222
  888. #define EC_F_PKEY_EC_CTRL 197
  889. #define EC_F_PKEY_EC_CTRL_STR 198
  890. #define EC_F_PKEY_EC_DERIVE 217
  891. #define EC_F_PKEY_EC_KEYGEN 199
  892. #define EC_F_PKEY_EC_PARAMGEN 219
  893. #define EC_F_PKEY_EC_SIGN 218
  894. /* Reason codes. */
  895. #define EC_R_ASN1_ERROR 115
  896. #define EC_R_ASN1_UNKNOWN_FIELD 116
  897. #define EC_R_BIGNUM_OUT_OF_RANGE 144
  898. #define EC_R_BUFFER_TOO_SMALL 100
  899. #define EC_R_COORDINATES_OUT_OF_RANGE 146
  900. #define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
  901. #define EC_R_DECODE_ERROR 142
  902. #define EC_R_DISCRIMINANT_IS_ZERO 118
  903. #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
  904. #define EC_R_FIELD_TOO_LARGE 143
  905. #define EC_R_GF2M_NOT_SUPPORTED 147
  906. #define EC_R_GROUP2PKPARAMETERS_FAILURE 120
  907. #define EC_R_I2D_ECPKPARAMETERS_FAILURE 121
  908. #define EC_R_INCOMPATIBLE_OBJECTS 101
  909. #define EC_R_INVALID_ARGUMENT 112
  910. #define EC_R_INVALID_COMPRESSED_POINT 110
  911. #define EC_R_INVALID_COMPRESSION_BIT 109
  912. #define EC_R_INVALID_CURVE 141
  913. #define EC_R_INVALID_DIGEST_TYPE 138
  914. #define EC_R_INVALID_ENCODING 102
  915. #define EC_R_INVALID_FIELD 103
  916. #define EC_R_INVALID_FORM 104
  917. #define EC_R_INVALID_GROUP_ORDER 122
  918. #define EC_R_INVALID_PENTANOMIAL_BASIS 132
  919. #define EC_R_INVALID_PRIVATE_KEY 123
  920. #define EC_R_INVALID_TRINOMIAL_BASIS 137
  921. #define EC_R_KEYS_NOT_SET 140
  922. #define EC_R_MISSING_PARAMETERS 124
  923. #define EC_R_MISSING_PRIVATE_KEY 125
  924. #define EC_R_NOT_A_NIST_PRIME 135
  925. #define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136
  926. #define EC_R_NOT_IMPLEMENTED 126
  927. #define EC_R_NOT_INITIALIZED 111
  928. #define EC_R_NO_FIELD_MOD 133
  929. #define EC_R_NO_PARAMETERS_SET 139
  930. #define EC_R_PASSED_NULL_PARAMETER 134
  931. #define EC_R_PKPARAMETERS2GROUP_FAILURE 127
  932. #define EC_R_POINT_AT_INFINITY 106
  933. #define EC_R_POINT_IS_NOT_ON_CURVE 107
  934. #define EC_R_SLOT_FULL 108
  935. #define EC_R_UNDEFINED_GENERATOR 113
  936. #define EC_R_UNDEFINED_ORDER 128
  937. #define EC_R_UNKNOWN_GROUP 129
  938. #define EC_R_UNKNOWN_ORDER 114
  939. #define EC_R_UNSUPPORTED_FIELD 131
  940. #define EC_R_WRONG_CURVE_PARAMETERS 145
  941. #define EC_R_WRONG_ORDER 130
  942. #ifdef __cplusplus
  943. }
  944. #endif
  945. #endif