ec.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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 0x04 */
  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. # ifndef OPENSSL_NO_EC2M
  151. /********************************************************************/
  152. /* EC_METHOD for curves over GF(2^m) */
  153. /********************************************************************/
  154. /** Returns the basic GF2m ec method
  155. * \return EC_METHOD object
  156. */
  157. const EC_METHOD *EC_GF2m_simple_method(void);
  158. # endif
  159. /********************************************************************/
  160. /* EC_GROUP functions */
  161. /********************************************************************/
  162. /** Creates a new EC_GROUP object
  163. * \param meth EC_METHOD to use
  164. * \return newly created EC_GROUP object or NULL in case of an error.
  165. */
  166. EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
  167. /** Frees a EC_GROUP object
  168. * \param group EC_GROUP object to be freed.
  169. */
  170. void EC_GROUP_free(EC_GROUP *group);
  171. /** Clears and frees a EC_GROUP object
  172. * \param group EC_GROUP object to be cleared and freed.
  173. */
  174. void EC_GROUP_clear_free(EC_GROUP *group);
  175. /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
  176. * \param dst destination EC_GROUP object
  177. * \param src source EC_GROUP object
  178. * \return 1 on success and 0 if an error occurred.
  179. */
  180. int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
  181. /** Creates a new EC_GROUP object and copies the copies the content
  182. * form src to the newly created EC_KEY object
  183. * \param src source EC_GROUP object
  184. * \return newly created EC_GROUP object or NULL in case of an error.
  185. */
  186. EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
  187. /** Returns the EC_METHOD of the EC_GROUP object.
  188. * \param group EC_GROUP object
  189. * \return EC_METHOD used in this EC_GROUP object.
  190. */
  191. const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
  192. /** Returns the field type of the EC_METHOD.
  193. * \param meth EC_METHOD object
  194. * \return NID of the underlying field type OID.
  195. */
  196. int EC_METHOD_get_field_type(const EC_METHOD *meth);
  197. /** Sets the generator and it's order/cofactor of a EC_GROUP object.
  198. * \param group EC_GROUP object
  199. * \param generator EC_POINT object with the generator.
  200. * \param order the order of the group generated by the generator.
  201. * \param cofactor the index of the sub-group generated by the generator
  202. * in the group of all points on the elliptic curve.
  203. * \return 1 on success and 0 if an error occured
  204. */
  205. int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
  206. const BIGNUM *order, const BIGNUM *cofactor);
  207. /** Returns the generator of a EC_GROUP object.
  208. * \param group EC_GROUP object
  209. * \return the currently used generator (possibly NULL).
  210. */
  211. const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
  212. /** Gets the order of a EC_GROUP
  213. * \param group EC_GROUP object
  214. * \param order BIGNUM to which the order is copied
  215. * \param ctx BN_CTX object (optional)
  216. * \return 1 on success and 0 if an error occured
  217. */
  218. int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
  219. /** Gets the cofactor of a EC_GROUP
  220. * \param group EC_GROUP object
  221. * \param cofactor BIGNUM to which the cofactor is copied
  222. * \param ctx BN_CTX object (optional)
  223. * \return 1 on success and 0 if an error occured
  224. */
  225. int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
  226. BN_CTX *ctx);
  227. /** Sets the name of a EC_GROUP object
  228. * \param group EC_GROUP object
  229. * \param nid NID of the curve name OID
  230. */
  231. void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
  232. /** Returns the curve name of a EC_GROUP object
  233. * \param group EC_GROUP object
  234. * \return NID of the curve name OID or 0 if not set.
  235. */
  236. int EC_GROUP_get_curve_name(const EC_GROUP *group);
  237. void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
  238. int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
  239. void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
  240. point_conversion_form_t form);
  241. point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
  242. unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
  243. size_t EC_GROUP_get_seed_len(const EC_GROUP *);
  244. size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
  245. /** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b
  246. * \param group EC_GROUP object
  247. * \param p BIGNUM with the prime number
  248. * \param a BIGNUM with parameter a of the equation
  249. * \param b BIGNUM with parameter b of the equation
  250. * \param ctx BN_CTX object (optional)
  251. * \return 1 on success and 0 if an error occured
  252. */
  253. int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
  254. const BIGNUM *b, BN_CTX *ctx);
  255. /** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b
  256. * \param group EC_GROUP object
  257. * \param p BIGNUM for the prime number
  258. * \param a BIGNUM for parameter a of the equation
  259. * \param b BIGNUM for parameter b of the equation
  260. * \param ctx BN_CTX object (optional)
  261. * \return 1 on success and 0 if an error occured
  262. */
  263. int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
  264. BIGNUM *b, BN_CTX *ctx);
  265. # ifndef OPENSSL_NO_EC2M
  266. /** Sets the parameter of a ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
  267. * \param group EC_GROUP object
  268. * \param p BIGNUM with the polynomial defining the underlying field
  269. * \param a BIGNUM with parameter a of the equation
  270. * \param b BIGNUM with parameter b of the equation
  271. * \param ctx BN_CTX object (optional)
  272. * \return 1 on success and 0 if an error occured
  273. */
  274. int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
  275. const BIGNUM *b, BN_CTX *ctx);
  276. /** Gets the parameter of the ec over GF2m defined by y^2 + x*y = x^3 + a*x^2 + b
  277. * \param group EC_GROUP object
  278. * \param p BIGNUM for the polynomial defining the underlying field
  279. * \param a BIGNUM for parameter a of the equation
  280. * \param b BIGNUM for parameter b of the equation
  281. * \param ctx BN_CTX object (optional)
  282. * \return 1 on success and 0 if an error occured
  283. */
  284. int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
  285. BIGNUM *b, BN_CTX *ctx);
  286. # endif
  287. /** Returns the number of bits needed to represent a field element
  288. * \param group EC_GROUP object
  289. * \return number of bits needed to represent a field element
  290. */
  291. int EC_GROUP_get_degree(const EC_GROUP *group);
  292. /** Checks whether the parameter in the EC_GROUP define a valid ec group
  293. * \param group EC_GROUP object
  294. * \param ctx BN_CTX object (optional)
  295. * \return 1 if group is a valid ec group and 0 otherwise
  296. */
  297. int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
  298. /** Checks whether the discriminant of the elliptic curve is zero or not
  299. * \param group EC_GROUP object
  300. * \param ctx BN_CTX object (optional)
  301. * \return 1 if the discriminant is not zero and 0 otherwise
  302. */
  303. int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
  304. /** Compares two EC_GROUP objects
  305. * \param a first EC_GROUP object
  306. * \param b second EC_GROUP object
  307. * \param ctx BN_CTX object (optional)
  308. * \return 0 if both groups are equal and 1 otherwise
  309. */
  310. int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
  311. /*
  312. * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
  313. * choosing an appropriate EC_METHOD
  314. */
  315. /** Creates a new EC_GROUP object with the specified parameters defined
  316. * over GFp (defined by the equation y^2 = x^3 + a*x + b)
  317. * \param p BIGNUM with the prime number
  318. * \param a BIGNUM with the parameter a of the equation
  319. * \param b BIGNUM with the parameter b of the equation
  320. * \param ctx BN_CTX object (optional)
  321. * \return newly created EC_GROUP object with the specified parameters
  322. */
  323. EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
  324. const BIGNUM *b, BN_CTX *ctx);
  325. # ifndef OPENSSL_NO_EC2M
  326. /** Creates a new EC_GROUP object with the specified parameters defined
  327. * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)
  328. * \param p BIGNUM with the polynomial defining the underlying field
  329. * \param a BIGNUM with the parameter a of the equation
  330. * \param b BIGNUM with the parameter b of the equation
  331. * \param ctx BN_CTX object (optional)
  332. * \return newly created EC_GROUP object with the specified parameters
  333. */
  334. EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
  335. const BIGNUM *b, BN_CTX *ctx);
  336. # endif
  337. /** Creates a EC_GROUP object with a curve specified by a NID
  338. * \param nid NID of the OID of the curve name
  339. * \return newly created EC_GROUP object with specified curve or NULL
  340. * if an error occurred
  341. */
  342. EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
  343. /********************************************************************/
  344. /* handling of internal curves */
  345. /********************************************************************/
  346. typedef struct {
  347. int nid;
  348. const char *comment;
  349. } EC_builtin_curve;
  350. /*
  351. * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
  352. * available curves or zero if a error occurred. In case r ist not zero
  353. * nitems EC_builtin_curve structures are filled with the data of the first
  354. * nitems internal groups
  355. */
  356. size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
  357. /********************************************************************/
  358. /* EC_POINT functions */
  359. /********************************************************************/
  360. /** Creates a new EC_POINT object for the specified EC_GROUP
  361. * \param group EC_GROUP the underlying EC_GROUP object
  362. * \return newly created EC_POINT object or NULL if an error occurred
  363. */
  364. EC_POINT *EC_POINT_new(const EC_GROUP *group);
  365. /** Frees a EC_POINT object
  366. * \param point EC_POINT object to be freed
  367. */
  368. void EC_POINT_free(EC_POINT *point);
  369. /** Clears and frees a EC_POINT object
  370. * \param point EC_POINT object to be cleared and freed
  371. */
  372. void EC_POINT_clear_free(EC_POINT *point);
  373. /** Copies EC_POINT object
  374. * \param dst destination EC_POINT object
  375. * \param src source EC_POINT object
  376. * \return 1 on success and 0 if an error occured
  377. */
  378. int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
  379. /** Creates a new EC_POINT object and copies the content of the supplied
  380. * EC_POINT
  381. * \param src source EC_POINT object
  382. * \param group underlying the EC_GROUP object
  383. * \return newly created EC_POINT object or NULL if an error occurred
  384. */
  385. EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
  386. /** Returns the EC_METHOD used in EC_POINT object
  387. * \param point EC_POINT object
  388. * \return the EC_METHOD used
  389. */
  390. const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
  391. /** Sets a point to infinity (neutral element)
  392. * \param group underlying EC_GROUP object
  393. * \param point EC_POINT to set to infinity
  394. * \return 1 on success and 0 if an error occured
  395. */
  396. int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
  397. /** Sets the jacobian projective coordinates of a EC_POINT over GFp
  398. * \param group underlying EC_GROUP object
  399. * \param p EC_POINT object
  400. * \param x BIGNUM with the x-coordinate
  401. * \param y BIGNUM with the y-coordinate
  402. * \param z BIGNUM with the z-coordinate
  403. * \param ctx BN_CTX object (optional)
  404. * \return 1 on success and 0 if an error occured
  405. */
  406. int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
  407. EC_POINT *p, const BIGNUM *x,
  408. const BIGNUM *y, const BIGNUM *z,
  409. BN_CTX *ctx);
  410. /** Gets the jacobian projective coordinates of a EC_POINT over GFp
  411. * \param group underlying EC_GROUP object
  412. * \param p EC_POINT object
  413. * \param x BIGNUM for the x-coordinate
  414. * \param y BIGNUM for the y-coordinate
  415. * \param z BIGNUM for the z-coordinate
  416. * \param ctx BN_CTX object (optional)
  417. * \return 1 on success and 0 if an error occured
  418. */
  419. int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
  420. const EC_POINT *p, BIGNUM *x,
  421. BIGNUM *y, BIGNUM *z,
  422. BN_CTX *ctx);
  423. /** Sets the affine coordinates of a EC_POINT over GFp
  424. * \param group underlying EC_GROUP object
  425. * \param p EC_POINT object
  426. * \param x BIGNUM with the x-coordinate
  427. * \param y BIGNUM with the y-coordinate
  428. * \param ctx BN_CTX object (optional)
  429. * \return 1 on success and 0 if an error occured
  430. */
  431. int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  432. const BIGNUM *x, const BIGNUM *y,
  433. BN_CTX *ctx);
  434. /** Gets the affine coordinates of a EC_POINT over GFp
  435. * \param group underlying EC_GROUP object
  436. * \param p EC_POINT object
  437. * \param x BIGNUM for the x-coordinate
  438. * \param y BIGNUM for the y-coordinate
  439. * \param ctx BN_CTX object (optional)
  440. * \return 1 on success and 0 if an error occured
  441. */
  442. int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
  443. const EC_POINT *p, BIGNUM *x,
  444. BIGNUM *y, BN_CTX *ctx);
  445. /** Sets the x9.62 compressed coordinates of a EC_POINT over GFp
  446. * \param group underlying EC_GROUP object
  447. * \param p EC_POINT object
  448. * \param x BIGNUM with x-coordinate
  449. * \param y_bit integer with the y-Bit (either 0 or 1)
  450. * \param ctx BN_CTX object (optional)
  451. * \return 1 on success and 0 if an error occured
  452. */
  453. int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
  454. EC_POINT *p, const BIGNUM *x,
  455. int y_bit, BN_CTX *ctx);
  456. # ifndef OPENSSL_NO_EC2M
  457. /** Sets the affine coordinates of a EC_POINT over GF2m
  458. * \param group underlying EC_GROUP object
  459. * \param p EC_POINT object
  460. * \param x BIGNUM with the x-coordinate
  461. * \param y BIGNUM with the y-coordinate
  462. * \param ctx BN_CTX object (optional)
  463. * \return 1 on success and 0 if an error occured
  464. */
  465. int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
  466. const BIGNUM *x, const BIGNUM *y,
  467. BN_CTX *ctx);
  468. /** Gets the affine coordinates of a EC_POINT over GF2m
  469. * \param group underlying EC_GROUP object
  470. * \param p EC_POINT object
  471. * \param x BIGNUM for the x-coordinate
  472. * \param y BIGNUM for the y-coordinate
  473. * \param ctx BN_CTX object (optional)
  474. * \return 1 on success and 0 if an error occured
  475. */
  476. int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
  477. const EC_POINT *p, BIGNUM *x,
  478. BIGNUM *y, BN_CTX *ctx);
  479. /** Sets the x9.62 compressed coordinates of a EC_POINT over GF2m
  480. * \param group underlying EC_GROUP object
  481. * \param p EC_POINT object
  482. * \param x BIGNUM with x-coordinate
  483. * \param y_bit integer with the y-Bit (either 0 or 1)
  484. * \param ctx BN_CTX object (optional)
  485. * \return 1 on success and 0 if an error occured
  486. */
  487. int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
  488. EC_POINT *p, const BIGNUM *x,
  489. int y_bit, BN_CTX *ctx);
  490. # endif
  491. /** Encodes a EC_POINT object to a octet string
  492. * \param group underlying EC_GROUP object
  493. * \param p EC_POINT object
  494. * \param form point conversion form
  495. * \param buf memory buffer for the result. If NULL the function returns
  496. * required buffer size.
  497. * \param len length of the memory buffer
  498. * \param ctx BN_CTX object (optional)
  499. * \return the length of the encoded octet string or 0 if an error occurred
  500. */
  501. size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
  502. point_conversion_form_t form,
  503. unsigned char *buf, size_t len, BN_CTX *ctx);
  504. /** Decodes a EC_POINT from a octet string
  505. * \param group underlying EC_GROUP object
  506. * \param p EC_POINT object
  507. * \param buf memory buffer with the encoded ec point
  508. * \param len length of the encoded ec point
  509. * \param ctx BN_CTX object (optional)
  510. * \return 1 on success and 0 if an error occured
  511. */
  512. int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
  513. const unsigned char *buf, size_t len, BN_CTX *ctx);
  514. /* other interfaces to point2oct/oct2point: */
  515. BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
  516. point_conversion_form_t form, BIGNUM *, BN_CTX *);
  517. EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
  518. EC_POINT *, BN_CTX *);
  519. char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
  520. point_conversion_form_t form, BN_CTX *);
  521. EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
  522. EC_POINT *, BN_CTX *);
  523. /********************************************************************/
  524. /* functions for doing EC_POINT arithmetic */
  525. /********************************************************************/
  526. /** Computes the sum of two EC_POINT
  527. * \param group underlying EC_GROUP object
  528. * \param r EC_POINT object for the result (r = a + b)
  529. * \param a EC_POINT object with the first summand
  530. * \param b EC_POINT object with the second summand
  531. * \param ctx BN_CTX object (optional)
  532. * \return 1 on success and 0 if an error occured
  533. */
  534. int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
  535. const EC_POINT *b, BN_CTX *ctx);
  536. /** Computes the double of a EC_POINT
  537. * \param group underlying EC_GROUP object
  538. * \param r EC_POINT object for the result (r = 2 * a)
  539. * \param a EC_POINT object
  540. * \param ctx BN_CTX object (optional)
  541. * \return 1 on success and 0 if an error occured
  542. */
  543. int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
  544. BN_CTX *ctx);
  545. /** Computes the inverse of a EC_POINT
  546. * \param group underlying EC_GROUP object
  547. * \param a EC_POINT object to be inverted (it's used for the result as well)
  548. * \param ctx BN_CTX object (optional)
  549. * \return 1 on success and 0 if an error occured
  550. */
  551. int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
  552. /** Checks whether the point is the neutral element of the group
  553. * \param group the underlying EC_GROUP object
  554. * \param p EC_POINT object
  555. * \return 1 if the point is the neutral element and 0 otherwise
  556. */
  557. int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
  558. /** Checks whether the point is on the curve
  559. * \param group underlying EC_GROUP object
  560. * \param point EC_POINT object to check
  561. * \param ctx BN_CTX object (optional)
  562. * \return 1 if point if on the curve and 0 otherwise
  563. */
  564. int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
  565. BN_CTX *ctx);
  566. /** Compares two EC_POINTs
  567. * \param group underlying EC_GROUP object
  568. * \param a first EC_POINT object
  569. * \param b second EC_POINT object
  570. * \param ctx BN_CTX object (optional)
  571. * \return 0 if both points are equal and a value != 0 otherwise
  572. */
  573. int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
  574. BN_CTX *ctx);
  575. int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
  576. int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
  577. EC_POINT *points[], BN_CTX *ctx);
  578. /** Computes r = generator * n sum_{i=0}^{num-1} p[i] * m[i]
  579. * \param group underlying EC_GROUP object
  580. * \param r EC_POINT object for the result
  581. * \param n BIGNUM with the multiplier for the group generator (optional)
  582. * \param num number futher summands
  583. * \param p array of size num of EC_POINT objects
  584. * \param m array of size num of BIGNUM objects
  585. * \param ctx BN_CTX object (optional)
  586. * \return 1 on success and 0 if an error occured
  587. */
  588. int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
  589. size_t num, const EC_POINT *p[], const BIGNUM *m[],
  590. BN_CTX *ctx);
  591. /** Computes r = generator * n + q * m
  592. * \param group underlying EC_GROUP object
  593. * \param r EC_POINT object for the result
  594. * \param n BIGNUM with the multiplier for the group generator (optional)
  595. * \param q EC_POINT object with the first factor of the second summand
  596. * \param m BIGNUM with the second factor of the second summand
  597. * \param ctx BN_CTX object (optional)
  598. * \return 1 on success and 0 if an error occured
  599. */
  600. int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
  601. const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
  602. /** Stores multiples of generator for faster point multiplication
  603. * \param group EC_GROUP object
  604. * \param ctx BN_CTX object (optional)
  605. * \return 1 on success and 0 if an error occured
  606. */
  607. int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
  608. /** Reports whether a precomputation has been done
  609. * \param group EC_GROUP object
  610. * \return 1 if a pre-computation has been done and 0 otherwise
  611. */
  612. int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
  613. /********************************************************************/
  614. /* ASN1 stuff */
  615. /********************************************************************/
  616. /*
  617. * EC_GROUP_get_basis_type() returns the NID of the basis type used to
  618. * represent the field elements
  619. */
  620. int EC_GROUP_get_basis_type(const EC_GROUP *);
  621. # ifndef OPENSSL_NO_EC2M
  622. int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
  623. int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
  624. unsigned int *k2, unsigned int *k3);
  625. # endif
  626. # define OPENSSL_EC_NAMED_CURVE 0x001
  627. typedef struct ecpk_parameters_st ECPKPARAMETERS;
  628. EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
  629. int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
  630. # define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
  631. # define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
  632. # define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
  633. (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
  634. # define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
  635. (unsigned char *)(x))
  636. # ifndef OPENSSL_NO_BIO
  637. int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
  638. # endif
  639. # ifndef OPENSSL_NO_FP_API
  640. int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
  641. # endif
  642. /********************************************************************/
  643. /* EC_KEY functions */
  644. /********************************************************************/
  645. typedef struct ec_key_st EC_KEY;
  646. /* some values for the encoding_flag */
  647. # define EC_PKEY_NO_PARAMETERS 0x001
  648. # define EC_PKEY_NO_PUBKEY 0x002
  649. /* some values for the flags field */
  650. # define EC_FLAG_NON_FIPS_ALLOW 0x1
  651. # define EC_FLAG_FIPS_CHECKED 0x2
  652. /** Creates a new EC_KEY object.
  653. * \return EC_KEY object or NULL if an error occurred.
  654. */
  655. EC_KEY *EC_KEY_new(void);
  656. int EC_KEY_get_flags(const EC_KEY *key);
  657. void EC_KEY_set_flags(EC_KEY *key, int flags);
  658. void EC_KEY_clear_flags(EC_KEY *key, int flags);
  659. /** Creates a new EC_KEY object using a named curve as underlying
  660. * EC_GROUP object.
  661. * \param nid NID of the named curve.
  662. * \return EC_KEY object or NULL if an error occurred.
  663. */
  664. EC_KEY *EC_KEY_new_by_curve_name(int nid);
  665. /** Frees a EC_KEY object.
  666. * \param key EC_KEY object to be freed.
  667. */
  668. void EC_KEY_free(EC_KEY *key);
  669. /** Copies a EC_KEY object.
  670. * \param dst destination EC_KEY object
  671. * \param src src EC_KEY object
  672. * \return dst or NULL if an error occurred.
  673. */
  674. EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
  675. /** Creates a new EC_KEY object and copies the content from src to it.
  676. * \param src the source EC_KEY object
  677. * \return newly created EC_KEY object or NULL if an error occurred.
  678. */
  679. EC_KEY *EC_KEY_dup(const EC_KEY *src);
  680. /** Increases the internal reference count of a EC_KEY object.
  681. * \param key EC_KEY object
  682. * \return 1 on success and 0 if an error occurred.
  683. */
  684. int EC_KEY_up_ref(EC_KEY *key);
  685. /** Returns the EC_GROUP object of a EC_KEY object
  686. * \param key EC_KEY object
  687. * \return the EC_GROUP object (possibly NULL).
  688. */
  689. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
  690. /** Sets the EC_GROUP of a EC_KEY object.
  691. * \param key EC_KEY object
  692. * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY
  693. * object will use an own copy of the EC_GROUP).
  694. * \return 1 on success and 0 if an error occurred.
  695. */
  696. int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
  697. /** Returns the private key of a EC_KEY object.
  698. * \param key EC_KEY object
  699. * \return a BIGNUM with the private key (possibly NULL).
  700. */
  701. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
  702. /** Sets the private key of a EC_KEY object.
  703. * \param key EC_KEY object
  704. * \param prv BIGNUM with the private key (note: the EC_KEY object
  705. * will use an own copy of the BIGNUM).
  706. * \return 1 on success and 0 if an error occurred.
  707. */
  708. int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
  709. /** Returns the public key of a EC_KEY object.
  710. * \param key the EC_KEY object
  711. * \return a EC_POINT object with the public key (possibly NULL)
  712. */
  713. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
  714. /** Sets the public key of a EC_KEY object.
  715. * \param key EC_KEY object
  716. * \param pub EC_POINT object with the public key (note: the EC_KEY object
  717. * will use an own copy of the EC_POINT object).
  718. * \return 1 on success and 0 if an error occurred.
  719. */
  720. int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
  721. unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
  722. void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
  723. point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
  724. void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
  725. /* functions to set/get method specific data */
  726. void *EC_KEY_get_key_method_data(EC_KEY *key,
  727. void *(*dup_func) (void *),
  728. void (*free_func) (void *),
  729. void (*clear_free_func) (void *));
  730. /** Sets the key method data of an EC_KEY object, if none has yet been set.
  731. * \param key EC_KEY object
  732. * \param data opaque data to install.
  733. * \param dup_func a function that duplicates |data|.
  734. * \param free_func a function that frees |data|.
  735. * \param clear_free_func a function that wipes and frees |data|.
  736. * \return the previously set data pointer, or NULL if |data| was inserted.
  737. */
  738. void *EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
  739. void *(*dup_func) (void *),
  740. void (*free_func) (void *),
  741. void (*clear_free_func) (void *));
  742. /* wrapper functions for the underlying EC_GROUP object */
  743. void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
  744. /** Creates a table of pre-computed multiples of the generator to
  745. * accelerate further EC_KEY operations.
  746. * \param key EC_KEY object
  747. * \param ctx BN_CTX object (optional)
  748. * \return 1 on success and 0 if an error occurred.
  749. */
  750. int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
  751. /** Creates a new ec private (and optional a new public) key.
  752. * \param key EC_KEY object
  753. * \return 1 on success and 0 if an error occurred.
  754. */
  755. int EC_KEY_generate_key(EC_KEY *key);
  756. /** Verifies that a private and/or public key is valid.
  757. * \param key the EC_KEY object
  758. * \return 1 on success and 0 otherwise.
  759. */
  760. int EC_KEY_check_key(const EC_KEY *key);
  761. /** Sets a public key from affine coordindates performing
  762. * neccessary NIST PKV tests.
  763. * \param key the EC_KEY object
  764. * \param x public key x coordinate
  765. * \param y public key y coordinate
  766. * \return 1 on success and 0 otherwise.
  767. */
  768. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
  769. BIGNUM *y);
  770. /********************************************************************/
  771. /* de- and encoding functions for SEC1 ECPrivateKey */
  772. /********************************************************************/
  773. /** Decodes a private key from a memory buffer.
  774. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  775. * \param in pointer to memory with the DER encoded private key
  776. * \param len length of the DER encoded private key
  777. * \return the decoded private key or NULL if an error occurred.
  778. */
  779. EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
  780. /** Encodes a private key object and stores the result in a buffer.
  781. * \param key the EC_KEY object to encode
  782. * \param out the buffer for the result (if NULL the function returns number
  783. * of bytes needed).
  784. * \return 1 on success and 0 if an error occurred.
  785. */
  786. int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
  787. /********************************************************************/
  788. /* de- and encoding functions for EC parameters */
  789. /********************************************************************/
  790. /** Decodes ec parameter from a memory buffer.
  791. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  792. * \param in pointer to memory with the DER encoded ec parameters
  793. * \param len length of the DER encoded ec parameters
  794. * \return a EC_KEY object with the decoded parameters or NULL if an error
  795. * occurred.
  796. */
  797. EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
  798. /** Encodes ec parameter and stores the result in a buffer.
  799. * \param key the EC_KEY object with ec paramters to encode
  800. * \param out the buffer for the result (if NULL the function returns number
  801. * of bytes needed).
  802. * \return 1 on success and 0 if an error occurred.
  803. */
  804. int i2d_ECParameters(EC_KEY *key, unsigned char **out);
  805. /********************************************************************/
  806. /* de- and encoding functions for EC public key */
  807. /* (octet string, not DER -- hence 'o2i' and 'i2o') */
  808. /********************************************************************/
  809. /** Decodes a ec public key from a octet string.
  810. * \param key a pointer to a EC_KEY object which should be used
  811. * \param in memory buffer with the encoded public key
  812. * \param len length of the encoded public key
  813. * \return EC_KEY object with decoded public key or NULL if an error
  814. * occurred.
  815. */
  816. EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
  817. /** Encodes a ec public key in an octet string.
  818. * \param key the EC_KEY object with the public key
  819. * \param out the buffer for the result (if NULL the function returns number
  820. * of bytes needed).
  821. * \return 1 on success and 0 if an error occurred
  822. */
  823. int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
  824. # ifndef OPENSSL_NO_BIO
  825. /** Prints out the ec parameters on human readable form.
  826. * \param bp BIO object to which the information is printed
  827. * \param key EC_KEY object
  828. * \return 1 on success and 0 if an error occurred
  829. */
  830. int ECParameters_print(BIO *bp, const EC_KEY *key);
  831. /** Prints out the contents of a EC_KEY object
  832. * \param bp BIO object to which the information is printed
  833. * \param key EC_KEY object
  834. * \param off line offset
  835. * \return 1 on success and 0 if an error occurred
  836. */
  837. int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
  838. # endif
  839. # ifndef OPENSSL_NO_FP_API
  840. /** Prints out the ec parameters on human readable form.
  841. * \param fp file descriptor to which the information is printed
  842. * \param key EC_KEY object
  843. * \return 1 on success and 0 if an error occurred
  844. */
  845. int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
  846. /** Prints out the contents of a EC_KEY object
  847. * \param fp file descriptor to which the information is printed
  848. * \param key EC_KEY object
  849. * \param off line offset
  850. * \return 1 on success and 0 if an error occurred
  851. */
  852. int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
  853. # endif
  854. # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
  855. # ifndef __cplusplus
  856. # if defined(__SUNPRO_C)
  857. # if __SUNPRO_C >= 0x520
  858. # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
  859. # endif
  860. # endif
  861. # endif
  862. # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
  863. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \
  864. EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
  865. # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
  866. /* BEGIN ERROR CODES */
  867. /*
  868. * The following lines are auto generated by the script mkerr.pl. Any changes
  869. * made after this point may be overwritten when the script is next run.
  870. */
  871. void ERR_load_EC_strings(void);
  872. /* Error codes for the EC functions. */
  873. /* Function codes. */
  874. # define EC_F_BN_TO_FELEM 224
  875. # define EC_F_COMPUTE_WNAF 143
  876. # define EC_F_D2I_ECPARAMETERS 144
  877. # define EC_F_D2I_ECPKPARAMETERS 145
  878. # define EC_F_D2I_ECPRIVATEKEY 146
  879. # define EC_F_DO_EC_KEY_PRINT 221
  880. # define EC_F_ECKEY_PARAM2TYPE 223
  881. # define EC_F_ECKEY_PARAM_DECODE 212
  882. # define EC_F_ECKEY_PRIV_DECODE 213
  883. # define EC_F_ECKEY_PRIV_ENCODE 214
  884. # define EC_F_ECKEY_PUB_DECODE 215
  885. # define EC_F_ECKEY_PUB_ENCODE 216
  886. # define EC_F_ECKEY_TYPE2PARAM 220
  887. # define EC_F_ECPARAMETERS_PRINT 147
  888. # define EC_F_ECPARAMETERS_PRINT_FP 148
  889. # define EC_F_ECPKPARAMETERS_PRINT 149
  890. # define EC_F_ECPKPARAMETERS_PRINT_FP 150
  891. # define EC_F_ECP_NIST_MOD_192 203
  892. # define EC_F_ECP_NIST_MOD_224 204
  893. # define EC_F_ECP_NIST_MOD_256 205
  894. # define EC_F_ECP_NIST_MOD_521 206
  895. # define EC_F_EC_ASN1_GROUP2CURVE 153
  896. # define EC_F_EC_ASN1_GROUP2FIELDID 154
  897. # define EC_F_EC_ASN1_GROUP2PARAMETERS 155
  898. # define EC_F_EC_ASN1_GROUP2PKPARAMETERS 156
  899. # define EC_F_EC_ASN1_PARAMETERS2GROUP 157
  900. # define EC_F_EC_ASN1_PKPARAMETERS2GROUP 158
  901. # define EC_F_EC_EX_DATA_SET_DATA 211
  902. # define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208
  903. # define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159
  904. # define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195
  905. # define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160
  906. # define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161
  907. # define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
  908. # define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
  909. # define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164
  910. # define EC_F_EC_GFP_MONT_FIELD_DECODE 133
  911. # define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
  912. # define EC_F_EC_GFP_MONT_FIELD_MUL 131
  913. # define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209
  914. # define EC_F_EC_GFP_MONT_FIELD_SQR 132
  915. # define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189
  916. # define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP 135
  917. # define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE 225
  918. # define EC_F_EC_GFP_NISTP224_POINTS_MUL 228
  919. # define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226
  920. # define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE 230
  921. # define EC_F_EC_GFP_NISTP256_POINTS_MUL 231
  922. # define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232
  923. # define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE 233
  924. # define EC_F_EC_GFP_NISTP521_POINTS_MUL 234
  925. # define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235
  926. # define EC_F_EC_GFP_NIST_FIELD_MUL 200
  927. # define EC_F_EC_GFP_NIST_FIELD_SQR 201
  928. # define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202
  929. # define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165
  930. # define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166
  931. # define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
  932. # define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
  933. # define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
  934. # define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
  935. # define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
  936. # define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
  937. # define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167
  938. # define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
  939. # define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168
  940. # define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
  941. # define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169
  942. # define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
  943. # define EC_F_EC_GROUP_CHECK 170
  944. # define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171
  945. # define EC_F_EC_GROUP_COPY 106
  946. # define EC_F_EC_GROUP_GET0_GENERATOR 139
  947. # define EC_F_EC_GROUP_GET_COFACTOR 140
  948. # define EC_F_EC_GROUP_GET_CURVE_GF2M 172
  949. # define EC_F_EC_GROUP_GET_CURVE_GFP 130
  950. # define EC_F_EC_GROUP_GET_DEGREE 173
  951. # define EC_F_EC_GROUP_GET_ORDER 141
  952. # define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193
  953. # define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194
  954. # define EC_F_EC_GROUP_NEW 108
  955. # define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174
  956. # define EC_F_EC_GROUP_NEW_FROM_DATA 175
  957. # define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
  958. # define EC_F_EC_GROUP_SET_CURVE_GF2M 176
  959. # define EC_F_EC_GROUP_SET_CURVE_GFP 109
  960. # define EC_F_EC_GROUP_SET_EXTRA_DATA 110
  961. # define EC_F_EC_GROUP_SET_GENERATOR 111
  962. # define EC_F_EC_KEY_CHECK_KEY 177
  963. # define EC_F_EC_KEY_COPY 178
  964. # define EC_F_EC_KEY_GENERATE_KEY 179
  965. # define EC_F_EC_KEY_NEW 182
  966. # define EC_F_EC_KEY_PRINT 180
  967. # define EC_F_EC_KEY_PRINT_FP 181
  968. # define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 229
  969. # define EC_F_EC_POINTS_MAKE_AFFINE 136
  970. # define EC_F_EC_POINT_ADD 112
  971. # define EC_F_EC_POINT_CMP 113
  972. # define EC_F_EC_POINT_COPY 114
  973. # define EC_F_EC_POINT_DBL 115
  974. # define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183
  975. # define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
  976. # define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
  977. # define EC_F_EC_POINT_INVERT 210
  978. # define EC_F_EC_POINT_IS_AT_INFINITY 118
  979. # define EC_F_EC_POINT_IS_ON_CURVE 119
  980. # define EC_F_EC_POINT_MAKE_AFFINE 120
  981. # define EC_F_EC_POINT_MUL 184
  982. # define EC_F_EC_POINT_NEW 121
  983. # define EC_F_EC_POINT_OCT2POINT 122
  984. # define EC_F_EC_POINT_POINT2OCT 123
  985. # define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185
  986. # define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
  987. # define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186
  988. # define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
  989. # define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
  990. # define EC_F_EC_POINT_SET_TO_INFINITY 127
  991. # define EC_F_EC_PRE_COMP_DUP 207
  992. # define EC_F_EC_PRE_COMP_NEW 196
  993. # define EC_F_EC_WNAF_MUL 187
  994. # define EC_F_EC_WNAF_PRECOMPUTE_MULT 188
  995. # define EC_F_I2D_ECPARAMETERS 190
  996. # define EC_F_I2D_ECPKPARAMETERS 191
  997. # define EC_F_I2D_ECPRIVATEKEY 192
  998. # define EC_F_I2O_ECPUBLICKEY 151
  999. # define EC_F_NISTP224_PRE_COMP_NEW 227
  1000. # define EC_F_NISTP256_PRE_COMP_NEW 236
  1001. # define EC_F_NISTP521_PRE_COMP_NEW 237
  1002. # define EC_F_O2I_ECPUBLICKEY 152
  1003. # define EC_F_OLD_EC_PRIV_DECODE 222
  1004. # define EC_F_PKEY_EC_CTRL 197
  1005. # define EC_F_PKEY_EC_CTRL_STR 198
  1006. # define EC_F_PKEY_EC_DERIVE 217
  1007. # define EC_F_PKEY_EC_KEYGEN 199
  1008. # define EC_F_PKEY_EC_PARAMGEN 219
  1009. # define EC_F_PKEY_EC_SIGN 218
  1010. /* Reason codes. */
  1011. # define EC_R_ASN1_ERROR 115
  1012. # define EC_R_ASN1_UNKNOWN_FIELD 116
  1013. # define EC_R_BIGNUM_OUT_OF_RANGE 144
  1014. # define EC_R_BUFFER_TOO_SMALL 100
  1015. # define EC_R_COORDINATES_OUT_OF_RANGE 146
  1016. # define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
  1017. # define EC_R_DECODE_ERROR 142
  1018. # define EC_R_DISCRIMINANT_IS_ZERO 118
  1019. # define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
  1020. # define EC_R_FIELD_TOO_LARGE 143
  1021. # define EC_R_GF2M_NOT_SUPPORTED 147
  1022. # define EC_R_GROUP2PKPARAMETERS_FAILURE 120
  1023. # define EC_R_I2D_ECPKPARAMETERS_FAILURE 121
  1024. # define EC_R_INCOMPATIBLE_OBJECTS 101
  1025. # define EC_R_INVALID_ARGUMENT 112
  1026. # define EC_R_INVALID_COMPRESSED_POINT 110
  1027. # define EC_R_INVALID_COMPRESSION_BIT 109
  1028. # define EC_R_INVALID_CURVE 141
  1029. # define EC_R_INVALID_DIGEST_TYPE 138
  1030. # define EC_R_INVALID_ENCODING 102
  1031. # define EC_R_INVALID_FIELD 103
  1032. # define EC_R_INVALID_FORM 104
  1033. # define EC_R_INVALID_GROUP_ORDER 122
  1034. # define EC_R_INVALID_PENTANOMIAL_BASIS 132
  1035. # define EC_R_INVALID_PRIVATE_KEY 123
  1036. # define EC_R_INVALID_TRINOMIAL_BASIS 137
  1037. # define EC_R_KEYS_NOT_SET 140
  1038. # define EC_R_MISSING_PARAMETERS 124
  1039. # define EC_R_MISSING_PRIVATE_KEY 125
  1040. # define EC_R_NOT_A_NIST_PRIME 135
  1041. # define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136
  1042. # define EC_R_NOT_IMPLEMENTED 126
  1043. # define EC_R_NOT_INITIALIZED 111
  1044. # define EC_R_NO_FIELD_MOD 133
  1045. # define EC_R_NO_PARAMETERS_SET 139
  1046. # define EC_R_PASSED_NULL_PARAMETER 134
  1047. # define EC_R_PKPARAMETERS2GROUP_FAILURE 127
  1048. # define EC_R_POINT_AT_INFINITY 106
  1049. # define EC_R_POINT_IS_NOT_ON_CURVE 107
  1050. # define EC_R_SLOT_FULL 108
  1051. # define EC_R_UNDEFINED_GENERATOR 113
  1052. # define EC_R_UNDEFINED_ORDER 128
  1053. # define EC_R_UNKNOWN_GROUP 129
  1054. # define EC_R_UNKNOWN_ORDER 114
  1055. # define EC_R_UNSUPPORTED_FIELD 131
  1056. # define EC_R_WRONG_CURVE_PARAMETERS 145
  1057. # define EC_R_WRONG_ORDER 130
  1058. #ifdef __cplusplus
  1059. }
  1060. #endif
  1061. #endif