ec.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  1. /*
  2. * Copyright 2002-2020 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. int EC_KEY_decoded_from_explicit_params(const EC_KEY *key);
  728. /** Creates a new EC_KEY object using a named curve as underlying
  729. * EC_GROUP object.
  730. * \param nid NID of the named curve.
  731. * \return EC_KEY object or NULL if an error occurred.
  732. */
  733. EC_KEY *EC_KEY_new_by_curve_name(int nid);
  734. /** Frees a EC_KEY object.
  735. * \param key EC_KEY object to be freed.
  736. */
  737. void EC_KEY_free(EC_KEY *key);
  738. /** Copies a EC_KEY object.
  739. * \param dst destination EC_KEY object
  740. * \param src src EC_KEY object
  741. * \return dst or NULL if an error occurred.
  742. */
  743. EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
  744. /** Creates a new EC_KEY object and copies the content from src to it.
  745. * \param src the source EC_KEY object
  746. * \return newly created EC_KEY object or NULL if an error occurred.
  747. */
  748. EC_KEY *EC_KEY_dup(const EC_KEY *src);
  749. /** Increases the internal reference count of a EC_KEY object.
  750. * \param key EC_KEY object
  751. * \return 1 on success and 0 if an error occurred.
  752. */
  753. int EC_KEY_up_ref(EC_KEY *key);
  754. /** Returns the ENGINE object of a EC_KEY object
  755. * \param eckey EC_KEY object
  756. * \return the ENGINE object (possibly NULL).
  757. */
  758. ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey);
  759. /** Returns the EC_GROUP object of a EC_KEY object
  760. * \param key EC_KEY object
  761. * \return the EC_GROUP object (possibly NULL).
  762. */
  763. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
  764. /** Sets the EC_GROUP of a EC_KEY object.
  765. * \param key EC_KEY object
  766. * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY
  767. * object will use an own copy of the EC_GROUP).
  768. * \return 1 on success and 0 if an error occurred.
  769. */
  770. int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
  771. /** Returns the private key of a EC_KEY object.
  772. * \param key EC_KEY object
  773. * \return a BIGNUM with the private key (possibly NULL).
  774. */
  775. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
  776. /** Sets the private key of a EC_KEY object.
  777. * \param key EC_KEY object
  778. * \param prv BIGNUM with the private key (note: the EC_KEY object
  779. * will use an own copy of the BIGNUM).
  780. * \return 1 on success and 0 if an error occurred.
  781. */
  782. int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
  783. /** Returns the public key of a EC_KEY object.
  784. * \param key the EC_KEY object
  785. * \return a EC_POINT object with the public key (possibly NULL)
  786. */
  787. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
  788. /** Sets the public key of a EC_KEY object.
  789. * \param key EC_KEY object
  790. * \param pub EC_POINT object with the public key (note: the EC_KEY object
  791. * will use an own copy of the EC_POINT object).
  792. * \return 1 on success and 0 if an error occurred.
  793. */
  794. int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
  795. unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
  796. void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
  797. point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
  798. void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
  799. #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
  800. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
  801. int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);
  802. void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);
  803. /* wrapper functions for the underlying EC_GROUP object */
  804. void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
  805. /** Creates a table of pre-computed multiples of the generator to
  806. * accelerate further EC_KEY operations.
  807. * \param key EC_KEY object
  808. * \param ctx BN_CTX object (optional)
  809. * \return 1 on success and 0 if an error occurred.
  810. */
  811. int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
  812. /** Creates a new ec private (and optional a new public) key.
  813. * \param key EC_KEY object
  814. * \return 1 on success and 0 if an error occurred.
  815. */
  816. int EC_KEY_generate_key(EC_KEY *key);
  817. /** Verifies that a private and/or public key is valid.
  818. * \param key the EC_KEY object
  819. * \return 1 on success and 0 otherwise.
  820. */
  821. int EC_KEY_check_key(const EC_KEY *key);
  822. /** Indicates if an EC_KEY can be used for signing.
  823. * \param eckey the EC_KEY object
  824. * \return 1 if can can sign and 0 otherwise.
  825. */
  826. int EC_KEY_can_sign(const EC_KEY *eckey);
  827. /** Sets a public key from affine coordinates performing
  828. * necessary NIST PKV tests.
  829. * \param key the EC_KEY object
  830. * \param x public key x coordinate
  831. * \param y public key y coordinate
  832. * \return 1 on success and 0 otherwise.
  833. */
  834. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
  835. BIGNUM *y);
  836. /** Encodes an EC_KEY public key to an allocated octet string
  837. * \param key key to encode
  838. * \param form point conversion form
  839. * \param pbuf returns pointer to allocated buffer
  840. * \param ctx BN_CTX object (optional)
  841. * \return the length of the encoded octet string or 0 if an error occurred
  842. */
  843. size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form,
  844. unsigned char **pbuf, BN_CTX *ctx);
  845. /** Decodes a EC_KEY public key from a octet string
  846. * \param key key to decode
  847. * \param buf memory buffer with the encoded ec point
  848. * \param len length of the encoded ec point
  849. * \param ctx BN_CTX object (optional)
  850. * \return 1 on success and 0 if an error occurred
  851. */
  852. int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
  853. BN_CTX *ctx);
  854. /** Decodes an EC_KEY private key from an octet string
  855. * \param key key to decode
  856. * \param buf memory buffer with the encoded private key
  857. * \param len length of the encoded key
  858. * \return 1 on success and 0 if an error occurred
  859. */
  860. int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len);
  861. /** Encodes a EC_KEY private key to an octet string
  862. * \param key key to encode
  863. * \param buf memory buffer for the result. If NULL the function returns
  864. * required buffer size.
  865. * \param len length of the memory buffer
  866. * \return the length of the encoded octet string or 0 if an error occurred
  867. */
  868. size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len);
  869. /** Encodes an EC_KEY private key to an allocated octet string
  870. * \param eckey key to encode
  871. * \param pbuf returns pointer to allocated buffer
  872. * \return the length of the encoded octet string or 0 if an error occurred
  873. */
  874. size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf);
  875. /********************************************************************/
  876. /* de- and encoding functions for SEC1 ECPrivateKey */
  877. /********************************************************************/
  878. /** Decodes a private key from a memory buffer.
  879. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  880. * \param in pointer to memory with the DER encoded private key
  881. * \param len length of the DER encoded private key
  882. * \return the decoded private key or NULL if an error occurred.
  883. */
  884. EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
  885. /** Encodes a private key object and stores the result in a buffer.
  886. * \param key the EC_KEY object to encode
  887. * \param out the buffer for the result (if NULL the function returns number
  888. * of bytes needed).
  889. * \return 1 on success and 0 if an error occurred.
  890. */
  891. int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
  892. /********************************************************************/
  893. /* de- and encoding functions for EC parameters */
  894. /********************************************************************/
  895. /** Decodes ec parameter from a memory buffer.
  896. * \param key a pointer to a EC_KEY object which should be used (or NULL)
  897. * \param in pointer to memory with the DER encoded ec parameters
  898. * \param len length of the DER encoded ec parameters
  899. * \return a EC_KEY object with the decoded parameters or NULL if an error
  900. * occurred.
  901. */
  902. EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
  903. /** Encodes ec parameter and stores the result in a buffer.
  904. * \param key the EC_KEY object with ec parameters to encode
  905. * \param out the buffer for the result (if NULL the function returns number
  906. * of bytes needed).
  907. * \return 1 on success and 0 if an error occurred.
  908. */
  909. int i2d_ECParameters(EC_KEY *key, unsigned char **out);
  910. /********************************************************************/
  911. /* de- and encoding functions for EC public key */
  912. /* (octet string, not DER -- hence 'o2i' and 'i2o') */
  913. /********************************************************************/
  914. /** Decodes a ec public key from a octet string.
  915. * \param key a pointer to a EC_KEY object which should be used
  916. * \param in memory buffer with the encoded public key
  917. * \param len length of the encoded public key
  918. * \return EC_KEY object with decoded public key or NULL if an error
  919. * occurred.
  920. */
  921. EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
  922. /** Encodes a ec public key in an octet string.
  923. * \param key the EC_KEY object with the public key
  924. * \param out the buffer for the result (if NULL the function returns number
  925. * of bytes needed).
  926. * \return 1 on success and 0 if an error occurred
  927. */
  928. int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out);
  929. /** Prints out the ec parameters on human readable form.
  930. * \param bp BIO object to which the information is printed
  931. * \param key EC_KEY object
  932. * \return 1 on success and 0 if an error occurred
  933. */
  934. int ECParameters_print(BIO *bp, const EC_KEY *key);
  935. /** Prints out the contents of a EC_KEY object
  936. * \param bp BIO object to which the information is printed
  937. * \param key EC_KEY object
  938. * \param off line offset
  939. * \return 1 on success and 0 if an error occurred
  940. */
  941. int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
  942. # ifndef OPENSSL_NO_STDIO
  943. /** Prints out the ec parameters on human readable form.
  944. * \param fp file descriptor to which the information is printed
  945. * \param key EC_KEY object
  946. * \return 1 on success and 0 if an error occurred
  947. */
  948. int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
  949. /** Prints out the contents of a EC_KEY object
  950. * \param fp file descriptor to which the information is printed
  951. * \param key EC_KEY object
  952. * \param off line offset
  953. * \return 1 on success and 0 if an error occurred
  954. */
  955. int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
  956. # endif
  957. const EC_KEY_METHOD *EC_KEY_OpenSSL(void);
  958. const EC_KEY_METHOD *EC_KEY_get_default_method(void);
  959. void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
  960. const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
  961. int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
  962. EC_KEY *EC_KEY_new_method(ENGINE *engine);
  963. /** The old name for ecdh_KDF_X9_63
  964. * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
  965. * it is actually specified in ANSI X9.63.
  966. * This identifier is retained for backwards compatibility
  967. */
  968. int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
  969. const unsigned char *Z, size_t Zlen,
  970. const unsigned char *sinfo, size_t sinfolen,
  971. const EVP_MD *md);
  972. int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
  973. const EC_KEY *ecdh,
  974. void *(*KDF) (const void *in, size_t inlen,
  975. void *out, size_t *outlen));
  976. typedef struct ECDSA_SIG_st ECDSA_SIG;
  977. /** Allocates and initialize a ECDSA_SIG structure
  978. * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  979. */
  980. ECDSA_SIG *ECDSA_SIG_new(void);
  981. /** frees a ECDSA_SIG structure
  982. * \param sig pointer to the ECDSA_SIG structure
  983. */
  984. void ECDSA_SIG_free(ECDSA_SIG *sig);
  985. /** DER encode content of ECDSA_SIG object (note: this function modifies *pp
  986. * (*pp += length of the DER encoded signature)).
  987. * \param sig pointer to the ECDSA_SIG object
  988. * \param pp pointer to a unsigned char pointer for the output or NULL
  989. * \return the length of the DER encoded ECDSA_SIG object or a negative value
  990. * on error
  991. */
  992. int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
  993. /** Decodes a DER encoded ECDSA signature (note: this function changes *pp
  994. * (*pp += len)).
  995. * \param sig pointer to ECDSA_SIG pointer (may be NULL)
  996. * \param pp memory buffer with the DER encoded signature
  997. * \param len length of the buffer
  998. * \return pointer to the decoded ECDSA_SIG structure (or NULL)
  999. */
  1000. ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
  1001. /** Accessor for r and s fields of ECDSA_SIG
  1002. * \param sig pointer to ECDSA_SIG structure
  1003. * \param pr pointer to BIGNUM pointer for r (may be NULL)
  1004. * \param ps pointer to BIGNUM pointer for s (may be NULL)
  1005. */
  1006. void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
  1007. /** Accessor for r field of ECDSA_SIG
  1008. * \param sig pointer to ECDSA_SIG structure
  1009. */
  1010. const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
  1011. /** Accessor for s field of ECDSA_SIG
  1012. * \param sig pointer to ECDSA_SIG structure
  1013. */
  1014. const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
  1015. /** Setter for r and s fields of ECDSA_SIG
  1016. * \param sig pointer to ECDSA_SIG structure
  1017. * \param r pointer to BIGNUM for r (may be NULL)
  1018. * \param s pointer to BIGNUM for s (may be NULL)
  1019. */
  1020. int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
  1021. /** Computes the ECDSA signature of the given hash value using
  1022. * the supplied private key and returns the created signature.
  1023. * \param dgst pointer to the hash value
  1024. * \param dgst_len length of the hash value
  1025. * \param eckey EC_KEY object containing a private EC key
  1026. * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  1027. */
  1028. ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
  1029. EC_KEY *eckey);
  1030. /** Computes ECDSA signature of a given hash value using the supplied
  1031. * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
  1032. * \param dgst pointer to the hash value to sign
  1033. * \param dgstlen length of the hash value
  1034. * \param kinv BIGNUM with a pre-computed inverse k (optional)
  1035. * \param rp BIGNUM with a pre-computed rp value (optional),
  1036. * see ECDSA_sign_setup
  1037. * \param eckey EC_KEY object containing a private EC key
  1038. * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
  1039. */
  1040. ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
  1041. const BIGNUM *kinv, const BIGNUM *rp,
  1042. EC_KEY *eckey);
  1043. /** Verifies that the supplied signature is a valid ECDSA
  1044. * signature of the supplied hash value using the supplied public key.
  1045. * \param dgst pointer to the hash value
  1046. * \param dgst_len length of the hash value
  1047. * \param sig ECDSA_SIG structure
  1048. * \param eckey EC_KEY object containing a public EC key
  1049. * \return 1 if the signature is valid, 0 if the signature is invalid
  1050. * and -1 on error
  1051. */
  1052. int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
  1053. const ECDSA_SIG *sig, EC_KEY *eckey);
  1054. /** Precompute parts of the signing operation
  1055. * \param eckey EC_KEY object containing a private EC key
  1056. * \param ctx BN_CTX object (optional)
  1057. * \param kinv BIGNUM pointer for the inverse of k
  1058. * \param rp BIGNUM pointer for x coordinate of k * generator
  1059. * \return 1 on success and 0 otherwise
  1060. */
  1061. int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
  1062. /** Computes ECDSA signature of a given hash value using the supplied
  1063. * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
  1064. * \param type this parameter is ignored
  1065. * \param dgst pointer to the hash value to sign
  1066. * \param dgstlen length of the hash value
  1067. * \param sig memory for the DER encoded created signature
  1068. * \param siglen pointer to the length of the returned signature
  1069. * \param eckey EC_KEY object containing a private EC key
  1070. * \return 1 on success and 0 otherwise
  1071. */
  1072. int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
  1073. unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
  1074. /** Computes ECDSA signature of a given hash value using the supplied
  1075. * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
  1076. * \param type this parameter is ignored
  1077. * \param dgst pointer to the hash value to sign
  1078. * \param dgstlen length of the hash value
  1079. * \param sig buffer to hold the DER encoded signature
  1080. * \param siglen pointer to the length of the returned signature
  1081. * \param kinv BIGNUM with a pre-computed inverse k (optional)
  1082. * \param rp BIGNUM with a pre-computed rp value (optional),
  1083. * see ECDSA_sign_setup
  1084. * \param eckey EC_KEY object containing a private EC key
  1085. * \return 1 on success and 0 otherwise
  1086. */
  1087. int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
  1088. unsigned char *sig, unsigned int *siglen,
  1089. const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
  1090. /** Verifies that the given signature is valid ECDSA signature
  1091. * of the supplied hash value using the specified public key.
  1092. * \param type this parameter is ignored
  1093. * \param dgst pointer to the hash value
  1094. * \param dgstlen length of the hash value
  1095. * \param sig pointer to the DER encoded signature
  1096. * \param siglen length of the DER encoded signature
  1097. * \param eckey EC_KEY object containing a public EC key
  1098. * \return 1 if the signature is valid, 0 if the signature is invalid
  1099. * and -1 on error
  1100. */
  1101. int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
  1102. const unsigned char *sig, int siglen, EC_KEY *eckey);
  1103. /** Returns the maximum length of the DER encoded signature
  1104. * \param eckey EC_KEY object
  1105. * \return numbers of bytes required for the DER encoded signature
  1106. */
  1107. int ECDSA_size(const EC_KEY *eckey);
  1108. /********************************************************************/
  1109. /* EC_KEY_METHOD constructors, destructors, writers and accessors */
  1110. /********************************************************************/
  1111. EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
  1112. void EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
  1113. void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
  1114. int (*init)(EC_KEY *key),
  1115. void (*finish)(EC_KEY *key),
  1116. int (*copy)(EC_KEY *dest, const EC_KEY *src),
  1117. int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
  1118. int (*set_private)(EC_KEY *key,
  1119. const BIGNUM *priv_key),
  1120. int (*set_public)(EC_KEY *key,
  1121. const EC_POINT *pub_key));
  1122. void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
  1123. int (*keygen)(EC_KEY *key));
  1124. void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
  1125. int (*ckey)(unsigned char **psec,
  1126. size_t *pseclen,
  1127. const EC_POINT *pub_key,
  1128. const EC_KEY *ecdh));
  1129. void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
  1130. int (*sign)(int type, const unsigned char *dgst,
  1131. int dlen, unsigned char *sig,
  1132. unsigned int *siglen,
  1133. const BIGNUM *kinv, const BIGNUM *r,
  1134. EC_KEY *eckey),
  1135. int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
  1136. BIGNUM **kinvp, BIGNUM **rp),
  1137. ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
  1138. int dgst_len,
  1139. const BIGNUM *in_kinv,
  1140. const BIGNUM *in_r,
  1141. EC_KEY *eckey));
  1142. void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
  1143. int (*verify)(int type, const unsigned
  1144. char *dgst, int dgst_len,
  1145. const unsigned char *sigbuf,
  1146. int sig_len, EC_KEY *eckey),
  1147. int (*verify_sig)(const unsigned char *dgst,
  1148. int dgst_len,
  1149. const ECDSA_SIG *sig,
  1150. EC_KEY *eckey));
  1151. void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
  1152. int (**pinit)(EC_KEY *key),
  1153. void (**pfinish)(EC_KEY *key),
  1154. int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
  1155. int (**pset_group)(EC_KEY *key,
  1156. const EC_GROUP *grp),
  1157. int (**pset_private)(EC_KEY *key,
  1158. const BIGNUM *priv_key),
  1159. int (**pset_public)(EC_KEY *key,
  1160. const EC_POINT *pub_key));
  1161. void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
  1162. int (**pkeygen)(EC_KEY *key));
  1163. void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
  1164. int (**pck)(unsigned char **psec,
  1165. size_t *pseclen,
  1166. const EC_POINT *pub_key,
  1167. const EC_KEY *ecdh));
  1168. void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth,
  1169. int (**psign)(int type, const unsigned char *dgst,
  1170. int dlen, unsigned char *sig,
  1171. unsigned int *siglen,
  1172. const BIGNUM *kinv, const BIGNUM *r,
  1173. EC_KEY *eckey),
  1174. int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
  1175. BIGNUM **kinvp, BIGNUM **rp),
  1176. ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
  1177. int dgst_len,
  1178. const BIGNUM *in_kinv,
  1179. const BIGNUM *in_r,
  1180. EC_KEY *eckey));
  1181. void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
  1182. int (**pverify)(int type, const unsigned
  1183. char *dgst, int dgst_len,
  1184. const unsigned char *sigbuf,
  1185. int sig_len, EC_KEY *eckey),
  1186. int (**pverify_sig)(const unsigned char *dgst,
  1187. int dgst_len,
  1188. const ECDSA_SIG *sig,
  1189. EC_KEY *eckey));
  1190. # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
  1191. # ifndef __cplusplus
  1192. # if defined(__SUNPRO_C)
  1193. # if __SUNPRO_C >= 0x520
  1194. # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
  1195. # endif
  1196. # endif
  1197. # endif
  1198. # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
  1199. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1200. EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
  1201. EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
  1202. # define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \
  1203. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1204. EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
  1205. EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL)
  1206. # define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \
  1207. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1208. EVP_PKEY_OP_DERIVE, \
  1209. EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL)
  1210. # define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \
  1211. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1212. EVP_PKEY_OP_DERIVE, \
  1213. EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL)
  1214. # define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \
  1215. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1216. EVP_PKEY_OP_DERIVE, \
  1217. EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL)
  1218. # define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \
  1219. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1220. EVP_PKEY_OP_DERIVE, \
  1221. EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL)
  1222. # define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \
  1223. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1224. EVP_PKEY_OP_DERIVE, \
  1225. EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)(md))
  1226. # define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \
  1227. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1228. EVP_PKEY_OP_DERIVE, \
  1229. EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)(pmd))
  1230. # define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \
  1231. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1232. EVP_PKEY_OP_DERIVE, \
  1233. EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL)
  1234. # define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \
  1235. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1236. EVP_PKEY_OP_DERIVE, \
  1237. EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, \
  1238. (void *)(plen))
  1239. # define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \
  1240. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1241. EVP_PKEY_OP_DERIVE, \
  1242. EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)(p))
  1243. # define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \
  1244. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
  1245. EVP_PKEY_OP_DERIVE, \
  1246. EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)(p))
  1247. /* SM2 will skip the operation check so no need to pass operation here */
  1248. # define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
  1249. EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
  1250. EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
  1251. # define EVP_PKEY_CTX_get1_id(ctx, id) \
  1252. EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
  1253. EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
  1254. # define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \
  1255. EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
  1256. EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len))
  1257. # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
  1258. # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2)
  1259. # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3)
  1260. # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4)
  1261. # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5)
  1262. # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6)
  1263. # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7)
  1264. # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8)
  1265. # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9)
  1266. # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10)
  1267. # define EVP_PKEY_CTRL_SET1_ID (EVP_PKEY_ALG_CTRL + 11)
  1268. # define EVP_PKEY_CTRL_GET1_ID (EVP_PKEY_ALG_CTRL + 12)
  1269. # define EVP_PKEY_CTRL_GET1_ID_LEN (EVP_PKEY_ALG_CTRL + 13)
  1270. /* KDF types */
  1271. # define EVP_PKEY_ECDH_KDF_NONE 1
  1272. # define EVP_PKEY_ECDH_KDF_X9_63 2
  1273. /** The old name for EVP_PKEY_ECDH_KDF_X9_63
  1274. * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
  1275. * it is actually specified in ANSI X9.63.
  1276. * This identifier is retained for backwards compatibility
  1277. */
  1278. # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63
  1279. # ifdef __cplusplus
  1280. }
  1281. # endif
  1282. # endif
  1283. #endif