You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ec.h 65 kB

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