ec.h 62 KB

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