Turn audio into a shareable video. forked from nypublicradio/audiogram

ec.h 62KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  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