evp.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /* evp.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/openssl/evp.h
  23. \brief evp.h defines mini evp openssl compatibility layer
  24. */
  25. #ifndef WOLFSSL_EVP_H_
  26. #define WOLFSSL_EVP_H_
  27. #include <wolfssl/wolfcrypt/types.h>
  28. #ifdef WOLFSSL_PREFIX
  29. #include "prefix_evp.h"
  30. #endif
  31. #ifndef NO_MD4
  32. #include <wolfssl/openssl/md4.h>
  33. #endif
  34. #ifndef NO_MD5
  35. #include <wolfssl/openssl/md5.h>
  36. #endif
  37. #include <wolfssl/openssl/sha.h>
  38. #include <wolfssl/openssl/sha3.h>
  39. #include <wolfssl/openssl/ripemd.h>
  40. #include <wolfssl/openssl/rsa.h>
  41. #include <wolfssl/openssl/dsa.h>
  42. #include <wolfssl/openssl/ec.h>
  43. #include <wolfssl/openssl/dh.h>
  44. #include <wolfssl/openssl/compat_types.h>
  45. #include <wolfssl/wolfcrypt/aes.h>
  46. #include <wolfssl/wolfcrypt/des3.h>
  47. #include <wolfssl/wolfcrypt/arc4.h>
  48. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  49. #include <wolfssl/wolfcrypt/hmac.h>
  50. #include <wolfssl/wolfcrypt/pwdbased.h>
  51. #ifdef WOLFSSL_SM3
  52. #include <wolfssl/wolfcrypt/sm3.h>
  53. #endif
  54. #ifdef WOLFSSL_SM4
  55. #include <wolfssl/wolfcrypt/sm4.h>
  56. #endif
  57. #if defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE)
  58. #include <wolfssl/wolfcrypt/coding.h>
  59. #endif
  60. #ifdef HAVE_ARIA
  61. #include <wolfssl/wolfcrypt/port/aria/aria-crypt.h>
  62. #endif
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66. #ifndef NO_MD4
  67. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md4(void);
  68. #endif
  69. #ifndef NO_MD5
  70. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void);
  71. #endif
  72. WOLFSSL_API void wolfSSL_EVP_set_pw_prompt(const char *prompt);
  73. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_mdc2(void);
  74. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha1(void);
  75. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha224(void);
  76. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void);
  77. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha384(void);
  78. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha512(void);
  79. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_shake128(void);
  80. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_shake256(void);
  81. WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_EVP_sha512_224(void);
  82. WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_EVP_sha512_256(void);
  83. WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_EVP_ripemd160(void);
  84. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_224(void);
  85. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_256(void);
  86. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_384(void);
  87. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_512(void);
  88. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sm3(void);
  89. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ecb(void);
  90. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ecb(void);
  91. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ecb(void);
  92. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_cbc(void);
  93. #if !defined(NO_AES) && (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT))
  94. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_cbc(void);
  95. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_cbc(void);
  96. #endif
  97. #ifndef NO_AES
  98. #ifdef WOLFSSL_AES_CFB
  99. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_cfb1(void);
  100. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_cfb1(void);
  101. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_cfb1(void);
  102. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_cfb8(void);
  103. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_cfb8(void);
  104. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_cfb8(void);
  105. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_cfb128(void);
  106. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_cfb128(void);
  107. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_cfb128(void);
  108. #endif
  109. #ifdef WOLFSSL_AES_OFB
  110. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ofb(void);
  111. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ofb(void);
  112. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ofb(void);
  113. #endif
  114. #ifdef WOLFSSL_AES_XTS
  115. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_xts(void);
  116. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_xts(void);
  117. #endif
  118. #endif /* NO_AES */
  119. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  120. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_gcm(void);
  121. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_gcm(void);
  122. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_gcm(void);
  123. #endif
  124. #if !defined(NO_AES) && defined(HAVE_AESCCM)
  125. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ccm(void);
  126. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ccm(void);
  127. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ccm(void);
  128. #endif
  129. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ctr(void);
  130. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ctr(void);
  131. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ctr(void);
  132. #if defined(HAVE_ARIA)
  133. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aria_128_gcm(void);
  134. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aria_192_gcm(void);
  135. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aria_256_gcm(void);
  136. #endif
  137. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ecb(void);
  138. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ede3_ecb(void);
  139. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_cbc(void);
  140. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ede3_cbc(void);
  141. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_rc4(void);
  142. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_enc_null(void);
  143. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_rc2_cbc(void);
  144. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  145. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_chacha20_poly1305(void);
  146. #endif
  147. #ifdef HAVE_CHACHA
  148. /* ChaCha IV + counter is set as one IV in EVP */
  149. #define WOLFSSL_EVP_CHACHA_IV_BYTES (CHACHA_IV_BYTES + sizeof(word32))
  150. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_chacha20(void);
  151. #endif
  152. #ifdef WOLFSSL_SM4_ECB
  153. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_sm4_ecb(void);
  154. #endif
  155. #ifdef WOLFSSL_SM4_CBC
  156. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_sm4_cbc(void);
  157. #endif
  158. #ifdef WOLFSSL_SM4_CTR
  159. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_sm4_ctr(void);
  160. #endif
  161. #ifdef WOLFSSL_SM4_GCM
  162. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_sm4_gcm(void);
  163. #endif
  164. #ifdef WOLFSSL_SM4_CCM
  165. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_sm4_ccm(void);
  166. #endif
  167. typedef union {
  168. #ifndef NO_MD4
  169. WOLFSSL_MD4_CTX md4;
  170. #endif
  171. #ifndef NO_MD5
  172. WOLFSSL_MD5_CTX md5;
  173. #endif
  174. #ifndef NO_SHA
  175. WOLFSSL_SHA_CTX sha;
  176. #endif
  177. #ifdef WOLFSSL_SHA224
  178. WOLFSSL_SHA224_CTX sha224;
  179. #endif
  180. #ifndef NO_SHA256
  181. WOLFSSL_SHA256_CTX sha256;
  182. #endif
  183. #ifdef WOLFSSL_SHA384
  184. WOLFSSL_SHA384_CTX sha384;
  185. #endif
  186. #ifdef WOLFSSL_SHA512
  187. WOLFSSL_SHA512_CTX sha512;
  188. #endif
  189. #ifdef WOLFSSL_RIPEMD
  190. WOLFSSL_RIPEMD_CTX ripemd;
  191. #endif
  192. #ifndef WOLFSSL_NOSHA3_224
  193. WOLFSSL_SHA3_224_CTX sha3_224;
  194. #endif
  195. #ifndef WOLFSSL_NOSHA3_256
  196. WOLFSSL_SHA3_256_CTX sha3_256;
  197. #endif
  198. WOLFSSL_SHA3_384_CTX sha3_384;
  199. #ifndef WOLFSSL_NOSHA3_512
  200. WOLFSSL_SHA3_512_CTX sha3_512;
  201. #endif
  202. #ifdef WOLFSSL_SM3
  203. wc_Sm3 sm3;
  204. #endif
  205. } WOLFSSL_Hasher;
  206. struct WOLFSSL_EVP_MD_CTX {
  207. union {
  208. WOLFSSL_Hasher digest;
  209. #ifndef NO_HMAC
  210. Hmac hmac;
  211. #endif
  212. } hash;
  213. enum wc_HashType macType;
  214. WOLFSSL_EVP_PKEY_CTX *pctx;
  215. #ifndef NO_HMAC
  216. unsigned int isHMAC;
  217. #endif
  218. };
  219. typedef union {
  220. #ifndef NO_AES
  221. Aes aes;
  222. #ifdef WOLFSSL_AES_XTS
  223. XtsAes xts;
  224. #endif
  225. #endif
  226. #ifdef HAVE_ARIA
  227. wc_Aria aria;
  228. #endif
  229. #ifndef NO_DES3
  230. Des des;
  231. Des3 des3;
  232. #endif
  233. Arc4 arc4;
  234. #ifdef WOLFSSL_QT
  235. int (*ctrl) (WOLFSSL_EVP_CIPHER_CTX *, int type, int arg, void *ptr);
  236. #endif
  237. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  238. ChaChaPoly_Aead chachaPoly;
  239. #endif
  240. #ifdef HAVE_CHACHA
  241. ChaCha chacha;
  242. #endif
  243. #ifdef WOLFSSL_SM4
  244. wc_Sm4 sm4;
  245. #endif
  246. } WOLFSSL_Cipher;
  247. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  248. #define NID_aes_128_cbc 419
  249. #define NID_aes_192_cbc 423
  250. #define NID_aes_256_cbc 427
  251. #define NID_aes_128_ccm 896
  252. #define NID_aes_192_ccm 899
  253. #define NID_aes_256_ccm 902
  254. #define NID_aes_128_gcm 895
  255. #define NID_aes_192_gcm 898
  256. #define NID_aes_256_gcm 901
  257. #define NID_aes_128_ctr 904
  258. #define NID_aes_192_ctr 905
  259. #define NID_aes_256_ctr 906
  260. #define NID_aes_128_ecb 418
  261. #define NID_aes_192_ecb 422
  262. #define NID_aes_256_ecb 426
  263. #define NID_des_cbc 31
  264. #define NID_des_ecb 29
  265. #define NID_des_ede3_cbc 44
  266. #define NID_des_ede3_ecb 33
  267. #define NID_aes_128_cfb1 650
  268. #define NID_aes_192_cfb1 651
  269. #define NID_aes_256_cfb1 652
  270. #define NID_aes_128_cfb8 653
  271. #define NID_aes_192_cfb8 654
  272. #define NID_aes_256_cfb8 655
  273. #define NID_aes_128_cfb128 421
  274. #define NID_aes_192_cfb128 425
  275. #define NID_aes_256_cfb128 429
  276. #define NID_aes_128_ofb 420
  277. #define NID_aes_192_ofb 424
  278. #define NID_aes_256_ofb 428
  279. #define NID_aes_128_xts 913
  280. #define NID_aes_256_xts 914
  281. #define NID_camellia_128_cbc 751
  282. #define NID_camellia_256_cbc 753
  283. #define NID_chacha20_poly1305 1018
  284. #define NID_chacha20 1019
  285. #define NID_sm4_ecb 1133
  286. #define NID_sm4_cbc 1134
  287. #define NID_sm4_ctr 1139
  288. #define NID_sm4_gcm 1248
  289. #define NID_sm4_ccm 1249
  290. #define NID_md5WithRSA 104
  291. #define NID_md2WithRSAEncryption 9
  292. #define NID_md5WithRSAEncryption 99
  293. #define NID_dsaWithSHA1 113
  294. #define NID_dsaWithSHA1_2 70
  295. #define NID_sha1WithRSA 115
  296. #define NID_sha1WithRSAEncryption 65
  297. #define NID_sha224WithRSAEncryption 671
  298. #define NID_sha256WithRSAEncryption 668
  299. #define NID_sha384WithRSAEncryption 669
  300. #define NID_sha512WithRSAEncryption 670
  301. #define NID_RSA_SHA3_224 1116
  302. #define NID_RSA_SHA3_256 1117
  303. #define NID_RSA_SHA3_384 1118
  304. #define NID_RSA_SHA3_512 1119
  305. #define NID_rsassaPss 912
  306. #define NID_ecdsa_with_SHA1 416
  307. #define NID_ecdsa_with_SHA224 793
  308. #define NID_ecdsa_with_SHA256 794
  309. #define NID_ecdsa_with_SHA384 795
  310. #define NID_ecdsa_with_SHA512 796
  311. #define NID_ecdsa_with_SHA3_224 1112
  312. #define NID_ecdsa_with_SHA3_256 1113
  313. #define NID_ecdsa_with_SHA3_384 1114
  314. #define NID_ecdsa_with_SHA3_512 1115
  315. #define NID_dsa_with_SHA224 802
  316. #define NID_dsa_with_SHA256 803
  317. #define NID_sha3_224 1096
  318. #define NID_sha3_256 1097
  319. #define NID_sha3_384 1098
  320. #define NID_sha3_512 1099
  321. #define NID_blake2b512 1056
  322. #define NID_blake2s256 1057
  323. #define NID_shake128 1100
  324. #define NID_shake256 1101
  325. #define NID_sha1 64
  326. #define NID_sha224 675
  327. #define NID_sm3 1143
  328. #define NID_md2 77
  329. #define NID_md4 257
  330. #define NID_md5 40
  331. #define NID_hmac 855
  332. #define NID_hmacWithSHA1 163
  333. #define NID_hmacWithSHA224 798
  334. #define NID_hmacWithSHA256 799
  335. #define NID_hmacWithSHA384 800
  336. #define NID_hmacWithSHA512 801
  337. #define NID_hkdf 1036
  338. #define NID_cmac 894
  339. #define NID_dhKeyAgreement 28
  340. #define NID_ffdhe2048 1126
  341. #define NID_ffdhe3072 1127
  342. #define NID_ffdhe4096 1128
  343. #define NID_rc4 5
  344. #define NID_bf_cbc 91
  345. #define NID_bf_ecb 92
  346. #define NID_bf_cfb64 93
  347. #define NID_bf_ofb64 94
  348. #define NID_cast5_cbc 108
  349. #define NID_cast5_ecb 109
  350. #define NID_cast5_cfb64 110
  351. #define NID_cast5_ofb64 111
  352. /* key exchange */
  353. #define NID_kx_rsa 1037
  354. #define NID_kx_ecdhe 1038
  355. #define NID_kx_dhe 1039
  356. #define NID_kx_ecdhe_psk 1040
  357. #define NID_kx_dhe_psk 1041
  358. #define NID_kx_rsa_psk 1042
  359. #define NID_kx_psk 1043
  360. #define NID_kx_srp 1044
  361. #define NID_kx_gost 1045
  362. #define NID_kx_any 1063
  363. /* server authentication */
  364. #define NID_auth_rsa 1046
  365. #define NID_auth_ecdsa 1047
  366. #define NID_auth_psk 1048
  367. #define NID_auth_dss 1049
  368. #define NID_auth_srp 1052
  369. #define NID_auth_null 1054
  370. #define NID_auth_any 1055
  371. /* Curve */
  372. #define NID_aria_128_gcm 1123
  373. #define NID_aria_192_gcm 1124
  374. #define NID_aria_256_gcm 1125
  375. #define NID_sm2 1172
  376. #define NID_X9_62_id_ecPublicKey EVP_PKEY_EC
  377. #define NID_rsaEncryption EVP_PKEY_RSA
  378. #define NID_dsa EVP_PKEY_DSA
  379. #define EVP_PKEY_OP_SIGN (1 << 3)
  380. #define EVP_PKEY_OP_VERIFY (1 << 5)
  381. #define EVP_PKEY_OP_ENCRYPT (1 << 6)
  382. #define EVP_PKEY_OP_DECRYPT (1 << 7)
  383. #define EVP_PKEY_OP_DERIVE (1 << 8)
  384. #define EVP_PKEY_PRINT_INDENT_MAX 128
  385. enum {
  386. AES_128_CBC_TYPE = 1,
  387. AES_192_CBC_TYPE = 2,
  388. AES_256_CBC_TYPE = 3,
  389. AES_128_CTR_TYPE = 4,
  390. AES_192_CTR_TYPE = 5,
  391. AES_256_CTR_TYPE = 6,
  392. AES_128_ECB_TYPE = 7,
  393. AES_192_ECB_TYPE = 8,
  394. AES_256_ECB_TYPE = 9,
  395. DES_CBC_TYPE = 10,
  396. DES_ECB_TYPE = 11,
  397. DES_EDE3_CBC_TYPE = 12,
  398. DES_EDE3_ECB_TYPE = 13,
  399. ARC4_TYPE = 14,
  400. NULL_CIPHER_TYPE = 15,
  401. EVP_PKEY_RSA = 16,
  402. EVP_PKEY_DSA = 17,
  403. EVP_PKEY_EC = 18,
  404. AES_128_GCM_TYPE = 21,
  405. AES_192_GCM_TYPE = 22,
  406. AES_256_GCM_TYPE = 23,
  407. EVP_PKEY_DH = NID_dhKeyAgreement,
  408. EVP_PKEY_HMAC = NID_hmac,
  409. EVP_PKEY_CMAC = NID_cmac,
  410. EVP_PKEY_HKDF = NID_hkdf,
  411. EVP_PKEY_FALCON = 300, /* Randomly picked value. */
  412. EVP_PKEY_DILITHIUM = 301, /* Randomly picked value. */
  413. AES_128_CFB1_TYPE = 24,
  414. AES_192_CFB1_TYPE = 25,
  415. AES_256_CFB1_TYPE = 26,
  416. AES_128_CFB8_TYPE = 27,
  417. AES_192_CFB8_TYPE = 28,
  418. AES_256_CFB8_TYPE = 29,
  419. AES_128_CFB128_TYPE = 30,
  420. AES_192_CFB128_TYPE = 31,
  421. AES_256_CFB128_TYPE = 32,
  422. AES_128_OFB_TYPE = 33,
  423. AES_192_OFB_TYPE = 34,
  424. AES_256_OFB_TYPE = 35,
  425. AES_128_XTS_TYPE = 36,
  426. AES_256_XTS_TYPE = 37,
  427. CHACHA20_POLY1305_TYPE = 38,
  428. CHACHA20_TYPE = 39,
  429. AES_128_CCM_TYPE = 40,
  430. AES_192_CCM_TYPE = 41,
  431. AES_256_CCM_TYPE = 42,
  432. SM4_ECB_TYPE = 43,
  433. SM4_CBC_TYPE = 44,
  434. SM4_CTR_TYPE = 45,
  435. SM4_GCM_TYPE = 46,
  436. SM4_CCM_TYPE = 47,
  437. ARIA_128_GCM_TYPE = 48,
  438. ARIA_192_GCM_TYPE = 49,
  439. ARIA_256_GCM_TYPE = 50
  440. };
  441. #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
  442. #define WOLFSSL_EVP_BUF_SIZE 16
  443. struct WOLFSSL_EVP_CIPHER_CTX {
  444. int keyLen; /* user may set for variable */
  445. int block_size;
  446. unsigned long flags;
  447. unsigned char enc; /* if encrypt side, then true */
  448. unsigned char cipherType;
  449. #if !defined(NO_AES)
  450. /* working iv pointer into cipher */
  451. ALIGN16 unsigned char iv[AES_BLOCK_SIZE];
  452. #elif defined(WOLFSSL_SM4)
  453. ALIGN16 unsigned char iv[SM4_BLOCK_SIZE];
  454. #elif defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  455. ALIGN16 unsigned char iv[CHACHA20_POLY1305_AEAD_IV_SIZE];
  456. #elif !defined(NO_DES3)
  457. ALIGN16 unsigned char iv[DES_BLOCK_SIZE];
  458. #endif
  459. WOLFSSL_Cipher cipher;
  460. ALIGN16 byte buf[WOLFSSL_EVP_BUF_SIZE];
  461. int bufUsed;
  462. ALIGN16 byte lastBlock[WOLFSSL_EVP_BUF_SIZE];
  463. int lastUsed;
  464. #if !defined(NO_AES) || !defined(NO_DES3) || defined(HAVE_AESGCM) || \
  465. defined (WOLFSSL_AES_XTS) || (defined(HAVE_CHACHA) || \
  466. defined(HAVE_POLY1305) || defined(HAVE_AESCCM)) || \
  467. defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM)
  468. #define HAVE_WOLFSSL_EVP_CIPHER_CTX_IV
  469. int ivSz;
  470. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
  471. defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM)
  472. byte* authBuffer;
  473. int authBufferLen;
  474. byte* authIn;
  475. int authInSz;
  476. #endif
  477. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  478. byte* key; /* used in partial Init()s */
  479. #endif
  480. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || defined(HAVE_ARIA) || \
  481. defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM) || \
  482. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  483. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || defined(HAVE_ARIA)
  484. ALIGN16 unsigned char authTag[AES_BLOCK_SIZE];
  485. #elif defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM)
  486. ALIGN16 unsigned char authTag[SM4_BLOCK_SIZE];
  487. #else
  488. ALIGN16 unsigned char authTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  489. #endif
  490. int authTagSz;
  491. #endif
  492. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
  493. defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM)
  494. byte authIvGenEnable:1;
  495. byte authIncIv:1;
  496. #endif
  497. #endif
  498. };
  499. struct WOLFSSL_EVP_PKEY_CTX {
  500. WOLFSSL_EVP_PKEY *pkey;
  501. WOLFSSL_EVP_PKEY *peerKey;
  502. int op; /* operation */
  503. int padding;
  504. int nbits;
  505. #ifdef HAVE_ECC
  506. int curveNID;
  507. #endif
  508. #ifndef NO_RSA
  509. const WOLFSSL_EVP_MD* md;
  510. #endif
  511. };
  512. struct WOLFSSL_ASN1_PCTX {
  513. int dummy;
  514. };
  515. #if defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE)
  516. #define BASE64_ENCODE_BLOCK_SIZE 48
  517. #define BASE64_ENCODE_RESULT_BLOCK_SIZE 64
  518. #define BASE64_DECODE_BLOCK_SIZE 4
  519. struct WOLFSSL_EVP_ENCODE_CTX {
  520. void* heap;
  521. int remaining; /* num of bytes in data[] */
  522. byte data[BASE64_ENCODE_BLOCK_SIZE];/* storage for unprocessed raw data */
  523. };
  524. typedef struct WOLFSSL_EVP_ENCODE_CTX WOLFSSL_EVP_ENCODE_CTX;
  525. WOLFSSL_API struct WOLFSSL_EVP_ENCODE_CTX* wolfSSL_EVP_ENCODE_CTX_new(void);
  526. WOLFSSL_API void wolfSSL_EVP_ENCODE_CTX_free(WOLFSSL_EVP_ENCODE_CTX* ctx);
  527. #endif /* WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE */
  528. #if defined(WOLFSSL_BASE64_ENCODE)
  529. WOLFSSL_API void wolfSSL_EVP_EncodeInit(WOLFSSL_EVP_ENCODE_CTX* ctx);
  530. WOLFSSL_API int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx,
  531. unsigned char*out, int *outl, const unsigned char*in, int inl);
  532. WOLFSSL_API void wolfSSL_EVP_EncodeFinal(WOLFSSL_EVP_ENCODE_CTX* ctx,
  533. unsigned char*out, int *outl);
  534. WOLFSSL_API int wolfSSL_EVP_EncodeBlock(unsigned char *out,
  535. const unsigned char *in, int inLen);
  536. WOLFSSL_API int wolfSSL_EVP_DecodeBlock(unsigned char *out,
  537. const unsigned char *in, int inLen);
  538. #endif /* WOLFSSL_BASE64_ENCODE */
  539. #if defined(WOLFSSL_BASE64_DECODE)
  540. WOLFSSL_API void wolfSSL_EVP_DecodeInit(WOLFSSL_EVP_ENCODE_CTX* ctx);
  541. WOLFSSL_API int wolfSSL_EVP_DecodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx,
  542. unsigned char*out, int *outl, const unsigned char*in, int inl);
  543. WOLFSSL_API int wolfSSL_EVP_DecodeFinal(WOLFSSL_EVP_ENCODE_CTX* ctx,
  544. unsigned char*out, int *outl);
  545. #endif /* WOLFSSL_BASE64_DECODE */
  546. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2b512(void);
  547. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2s256(void);
  548. WOLFSSL_API void wolfSSL_EVP_init(void);
  549. WOLFSSL_API int wolfSSL_EVP_MD_size(const WOLFSSL_EVP_MD* type);
  550. WOLFSSL_API int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type);
  551. WOLFSSL_API int wolfSSL_EVP_MD_block_size(const WOLFSSL_EVP_MD* type);
  552. WOLFSSL_API int wolfSSL_EVP_MD_pkey_type(const WOLFSSL_EVP_MD* type);
  553. WOLFSSL_API WOLFSSL_EVP_MD_CTX *wolfSSL_EVP_MD_CTX_new (void);
  554. WOLFSSL_API void wolfSSL_EVP_MD_CTX_free(WOLFSSL_EVP_MD_CTX* ctx);
  555. WOLFSSL_API void wolfSSL_EVP_MD_CTX_init(WOLFSSL_EVP_MD_CTX* ctx);
  556. WOLFSSL_API int wolfSSL_EVP_MD_CTX_cleanup(WOLFSSL_EVP_MD_CTX* ctx);
  557. WOLFSSL_API int wolfSSL_EVP_MD_CTX_copy(WOLFSSL_EVP_MD_CTX *out, const WOLFSSL_EVP_MD_CTX *in);
  558. WOLFSSL_API int wolfSSL_EVP_MD_CTX_copy_ex(WOLFSSL_EVP_MD_CTX *out, const WOLFSSL_EVP_MD_CTX *in);
  559. WOLFSSL_API int wolfSSL_EVP_MD_CTX_type(const WOLFSSL_EVP_MD_CTX *ctx);
  560. WOLFSSL_API int wolfSSL_EVP_MD_CTX_size(const WOLFSSL_EVP_MD_CTX *ctx);
  561. WOLFSSL_API int wolfSSL_EVP_MD_CTX_block_size(const WOLFSSL_EVP_MD_CTX *ctx);
  562. WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_EVP_MD_CTX_md(const WOLFSSL_EVP_MD_CTX *ctx);
  563. WOLFSSL_API const WOLFSSL_EVP_CIPHER *wolfSSL_EVP_get_cipherbyname(const char *name);
  564. WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_EVP_get_digestbyname(const char *name);
  565. WOLFSSL_API int wolfSSL_EVP_CIPHER_nid(const WOLFSSL_EVP_CIPHER *cipher);
  566. WOLFSSL_API int wolfSSL_EVP_DigestInit(WOLFSSL_EVP_MD_CTX* ctx,
  567. const WOLFSSL_EVP_MD* type);
  568. WOLFSSL_API int wolfSSL_EVP_DigestUpdate(WOLFSSL_EVP_MD_CTX* ctx, const void* data,
  569. size_t sz);
  570. WOLFSSL_API int wolfSSL_EVP_DigestFinal(WOLFSSL_EVP_MD_CTX* ctx, unsigned char* md,
  571. unsigned int* s);
  572. WOLFSSL_API int wolfSSL_EVP_DigestFinal_ex(WOLFSSL_EVP_MD_CTX* ctx,
  573. unsigned char* md, unsigned int* s);
  574. WOLFSSL_API int wolfSSL_EVP_DigestSignUpdate(WOLFSSL_EVP_MD_CTX *ctx,
  575. const void *d, unsigned int cnt);
  576. WOLFSSL_API int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx,
  577. unsigned char *sig, size_t *siglen);
  578. WOLFSSL_API int wolfSSL_EVP_DigestVerifyUpdate(WOLFSSL_EVP_MD_CTX *ctx,
  579. const void *d, size_t cnt);
  580. WOLFSSL_API int wolfSSL_EVP_DigestVerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
  581. const unsigned char *sig,
  582. size_t siglen);
  583. WOLFSSL_API int wolfSSL_EVP_BytesToKey(const WOLFSSL_EVP_CIPHER* type,
  584. const WOLFSSL_EVP_MD* md, const byte* salt,
  585. const byte* data, int sz, int count, byte* key, byte* iv);
  586. WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_init(WOLFSSL_EVP_CIPHER_CTX* ctx);
  587. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_cleanup(WOLFSSL_EVP_CIPHER_CTX* ctx);
  588. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_ctrl(WOLFSSL_EVP_CIPHER_CTX *ctx, \
  589. int type, int arg, void *ptr);
  590. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_iv_length(
  591. const WOLFSSL_EVP_CIPHER_CTX* ctx);
  592. WOLFSSL_API int wolfSSL_EVP_CIPHER_iv_length(const WOLFSSL_EVP_CIPHER* cipher);
  593. WOLFSSL_API int wolfSSL_EVP_Cipher_key_length(const WOLFSSL_EVP_CIPHER* c);
  594. WOLFSSL_API int wolfSSL_EVP_CipherInit(WOLFSSL_EVP_CIPHER_CTX* ctx,
  595. const WOLFSSL_EVP_CIPHER* type,
  596. const unsigned char* key,
  597. const unsigned char* iv,
  598. int enc);
  599. WOLFSSL_API int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
  600. unsigned char *out, int *outl,
  601. const unsigned char *in, int inl);
  602. WOLFSSL_API int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
  603. unsigned char *out, int *outl);
  604. WOLFSSL_API int wolfSSL_EVP_CipherFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx,
  605. unsigned char *out, int *outl, int enc);
  606. WOLFSSL_API int wolfSSL_EVP_EncryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
  607. unsigned char *out, int *outl);
  608. WOLFSSL_API int wolfSSL_EVP_EncryptFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx,
  609. unsigned char *out, int *outl);
  610. WOLFSSL_API int wolfSSL_EVP_DecryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
  611. unsigned char *out, int *outl);
  612. WOLFSSL_API int wolfSSL_EVP_DecryptFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx,
  613. unsigned char *out, int *outl);
  614. WOLFSSL_API int wolfSSL_EVP_DecryptFinal_legacy(WOLFSSL_EVP_CIPHER_CTX *ctx,
  615. unsigned char *out, int *outl);
  616. WOLFSSL_API WOLFSSL_EVP_CIPHER_CTX *wolfSSL_EVP_CIPHER_CTX_new(void);
  617. WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_free(WOLFSSL_EVP_CIPHER_CTX *ctx);
  618. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_reset(WOLFSSL_EVP_CIPHER_CTX *ctx);
  619. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_nid(const WOLFSSL_EVP_CIPHER_CTX *ctx);
  620. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx);
  621. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx,
  622. int keylen);
  623. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_iv_length(WOLFSSL_EVP_CIPHER_CTX* ctx,
  624. int ivLen);
  625. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
  626. int ivLen);
  627. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_get_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, byte* iv,
  628. int ivLen);
  629. WOLFSSL_API int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx,
  630. unsigned char* dst, unsigned char* src,
  631. unsigned int len);
  632. WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_get_cipherbynid(int id);
  633. WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_get_digestbynid(int id);
  634. WOLFSSL_API const WOLFSSL_EVP_CIPHER *wolfSSL_EVP_CIPHER_CTX_cipher(const WOLFSSL_EVP_CIPHER_CTX *ctx);
  635. WOLFSSL_API int wolfSSL_EVP_PKEY_assign_RSA(WOLFSSL_EVP_PKEY* pkey,
  636. WOLFSSL_RSA* key);
  637. WOLFSSL_API int wolfSSL_EVP_PKEY_assign_EC_KEY(WOLFSSL_EVP_PKEY* pkey,
  638. WOLFSSL_EC_KEY* key);
  639. WOLFSSL_API int wolfSSL_EVP_PKEY_assign_DSA(WOLFSSL_EVP_PKEY* pkey, WOLFSSL_DSA* key);
  640. WOLFSSL_API int wolfSSL_EVP_PKEY_assign_DH(WOLFSSL_EVP_PKEY* pkey, WOLFSSL_DH* key);
  641. WOLFSSL_API WOLFSSL_RSA* wolfSSL_EVP_PKEY_get0_RSA(WOLFSSL_EVP_PKEY *pkey);
  642. WOLFSSL_API WOLFSSL_DSA* wolfSSL_EVP_PKEY_get0_DSA(WOLFSSL_EVP_PKEY *pkey);
  643. WOLFSSL_API WOLFSSL_RSA* wolfSSL_EVP_PKEY_get1_RSA(WOLFSSL_EVP_PKEY* key);
  644. WOLFSSL_API WOLFSSL_DSA* wolfSSL_EVP_PKEY_get1_DSA(WOLFSSL_EVP_PKEY* key);
  645. WOLFSSL_API WOLFSSL_EC_KEY *wolfSSL_EVP_PKEY_get0_EC_KEY(WOLFSSL_EVP_PKEY *pkey);
  646. WOLFSSL_API WOLFSSL_EC_KEY *wolfSSL_EVP_PKEY_get1_EC_KEY(WOLFSSL_EVP_PKEY *key);
  647. WOLFSSL_API WOLFSSL_DH* wolfSSL_EVP_PKEY_get0_DH(WOLFSSL_EVP_PKEY* key);
  648. WOLFSSL_API WOLFSSL_DH* wolfSSL_EVP_PKEY_get1_DH(WOLFSSL_EVP_PKEY* key);
  649. WOLFSSL_API int wolfSSL_EVP_PKEY_set1_RSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_RSA *key);
  650. WOLFSSL_API int wolfSSL_EVP_PKEY_set1_DSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DSA *key);
  651. WOLFSSL_API int wolfSSL_EVP_PKEY_set1_DH(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DH *key);
  652. WOLFSSL_API int wolfSSL_EVP_PKEY_set1_EC_KEY(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_EC_KEY *key);
  653. WOLFSSL_API int wolfSSL_EVP_PKEY_assign(WOLFSSL_EVP_PKEY *pkey, int type, void *key);
  654. WOLFSSL_API const unsigned char* wolfSSL_EVP_PKEY_get0_hmac(const WOLFSSL_EVP_PKEY* pkey,
  655. size_t* len);
  656. WOLFSSL_API int wolfSSL_EVP_PKEY_sign_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  657. WOLFSSL_API int wolfSSL_EVP_PKEY_sign(WOLFSSL_EVP_PKEY_CTX *ctx,
  658. unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen);
  659. WOLFSSL_API int wolfSSL_EVP_PKEY_verify_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  660. WOLFSSL_API int wolfSSL_EVP_PKEY_verify(WOLFSSL_EVP_PKEY_CTX *ctx, const unsigned char *sig,
  661. size_t siglen, const unsigned char *tbs, size_t tbslen);
  662. WOLFSSL_API int wolfSSL_EVP_PKEY_paramgen_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  663. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_ec_paramgen_curve_nid(WOLFSSL_EVP_PKEY_CTX *ctx,
  664. int nid);
  665. WOLFSSL_API int wolfSSL_EVP_PKEY_paramgen(WOLFSSL_EVP_PKEY_CTX* ctx,
  666. WOLFSSL_EVP_PKEY** pkey);
  667. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_ec_param_enc(WOLFSSL_EVP_PKEY_CTX *ctx,
  668. int flag);
  669. WOLFSSL_API int wolfSSL_EVP_PKEY_keygen_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  670. WOLFSSL_API int wolfSSL_EVP_PKEY_keygen(WOLFSSL_EVP_PKEY_CTX *ctx,
  671. WOLFSSL_EVP_PKEY **ppkey);
  672. WOLFSSL_API int wolfSSL_EVP_PKEY_bits(const WOLFSSL_EVP_PKEY *pkey);
  673. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  674. WOLFSSL_API void wolfSSL_EVP_PKEY_CTX_free(WOLFSSL_EVP_PKEY_CTX *ctx);
  675. #else
  676. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_free(WOLFSSL_EVP_PKEY_CTX *ctx);
  677. #endif
  678. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_rsa_padding(WOLFSSL_EVP_PKEY_CTX *ctx, int padding);
  679. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_signature_md(WOLFSSL_EVP_PKEY_CTX *ctx,
  680. const WOLFSSL_EVP_MD* md);
  681. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(WOLFSSL_EVP_PKEY_CTX *ctx, int bits);
  682. WOLFSSL_API int wolfSSL_EVP_PKEY_derive_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  683. WOLFSSL_API int wolfSSL_EVP_PKEY_derive_set_peer(WOLFSSL_EVP_PKEY_CTX *ctx, WOLFSSL_EVP_PKEY *peer);
  684. WOLFSSL_API int wolfSSL_EVP_PKEY_derive(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
  685. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_ctrl_str(WOLFSSL_EVP_PKEY_CTX *ctx,
  686. const char *name, const char *value);
  687. WOLFSSL_API int wolfSSL_EVP_PKEY_decrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
  688. unsigned char *out, size_t *outlen,
  689. const unsigned char *in, size_t inlen);
  690. WOLFSSL_API int wolfSSL_EVP_PKEY_decrypt_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  691. WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
  692. unsigned char *out, size_t *outlen,
  693. const unsigned char *in, size_t inlen);
  694. WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt_init(WOLFSSL_EVP_PKEY_CTX *ctx);
  695. WOLFSSL_API WOLFSSL_EVP_PKEY *wolfSSL_EVP_PKEY_new(void);
  696. WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_ex(void* heap);
  697. WOLFSSL_API void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key);
  698. WOLFSSL_API int wolfSSL_EVP_PKEY_size(WOLFSSL_EVP_PKEY *pkey);
  699. WOLFSSL_API int wolfSSL_EVP_PKEY_copy_parameters(WOLFSSL_EVP_PKEY *to, const WOLFSSL_EVP_PKEY *from);
  700. WOLFSSL_API int wolfSSL_EVP_PKEY_missing_parameters(WOLFSSL_EVP_PKEY *pkey);
  701. WOLFSSL_API int wolfSSL_EVP_PKEY_cmp(const WOLFSSL_EVP_PKEY *a, const WOLFSSL_EVP_PKEY *b);
  702. WOLFSSL_API int wolfSSL_EVP_PKEY_type(int type);
  703. WOLFSSL_API int wolfSSL_EVP_PKEY_id(const WOLFSSL_EVP_PKEY *pkey);
  704. WOLFSSL_API int wolfSSL_EVP_PKEY_base_id(const WOLFSSL_EVP_PKEY *pkey);
  705. WOLFSSL_API int wolfSSL_EVP_PKEY_get_default_digest_nid(WOLFSSL_EVP_PKEY *pkey, int *pnid);
  706. WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKCS82PKEY(const WOLFSSL_PKCS8_PRIV_KEY_INFO* p8);
  707. WOLFSSL_API WOLFSSL_PKCS8_PRIV_KEY_INFO* wolfSSL_EVP_PKEY2PKCS8(const WOLFSSL_EVP_PKEY* pkey);
  708. WOLFSSL_API int wolfSSL_EVP_SignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sigret,
  709. unsigned int *siglen, WOLFSSL_EVP_PKEY *pkey);
  710. WOLFSSL_API int wolfSSL_EVP_SignInit(WOLFSSL_EVP_MD_CTX *ctx, const WOLFSSL_EVP_MD *type);
  711. WOLFSSL_API int wolfSSL_EVP_SignUpdate(WOLFSSL_EVP_MD_CTX *ctx, const void *data, size_t len);
  712. WOLFSSL_API int wolfSSL_EVP_VerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
  713. const unsigned char* sig, unsigned int sig_len, WOLFSSL_EVP_PKEY *pkey);
  714. WOLFSSL_API int wolfSSL_EVP_VerifyInit(WOLFSSL_EVP_MD_CTX *ctx, const WOLFSSL_EVP_MD *type);
  715. WOLFSSL_API int wolfSSL_EVP_VerifyUpdate(WOLFSSL_EVP_MD_CTX *ctx, const void *data, size_t len);
  716. /* these next ones don't need real OpenSSL type, for OpenSSH compat only */
  717. WOLFSSL_API void* wolfSSL_EVP_X_STATE(const WOLFSSL_EVP_CIPHER_CTX* ctx);
  718. WOLFSSL_API int wolfSSL_EVP_X_STATE_LEN(const WOLFSSL_EVP_CIPHER_CTX* ctx);
  719. WOLFSSL_API void wolfSSL_3des_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset,
  720. unsigned char* iv, int len);
  721. WOLFSSL_API void wolfSSL_aes_ctr_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset,
  722. unsigned char* iv, int len);
  723. WOLFSSL_API int wolfSSL_StoreExternalIV(WOLFSSL_EVP_CIPHER_CTX* ctx);
  724. WOLFSSL_API int wolfSSL_SetInternalIV(WOLFSSL_EVP_CIPHER_CTX* ctx);
  725. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_block_size(const WOLFSSL_EVP_CIPHER_CTX *ctx);
  726. WOLFSSL_API int wolfSSL_EVP_CIPHER_block_size(const WOLFSSL_EVP_CIPHER *cipher);
  727. WOLFSSL_API unsigned long WOLFSSL_EVP_CIPHER_mode(const WOLFSSL_EVP_CIPHER *cipher);
  728. WOLFSSL_API unsigned long WOLFSSL_CIPHER_mode(const WOLFSSL_EVP_CIPHER *cipher);
  729. WOLFSSL_API unsigned long wolfSSL_EVP_CIPHER_flags(const WOLFSSL_EVP_CIPHER *cipher);
  730. WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_set_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
  731. WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_clear_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
  732. WOLFSSL_API unsigned long wolfSSL_EVP_CIPHER_CTX_flags(const WOLFSSL_EVP_CIPHER_CTX *ctx);
  733. WOLFSSL_API unsigned long wolfSSL_EVP_CIPHER_CTX_mode(const WOLFSSL_EVP_CIPHER_CTX *ctx);
  734. WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_padding(WOLFSSL_EVP_CIPHER_CTX *c, int pad);
  735. WOLFSSL_API int wolfSSL_EVP_add_digest(const WOLFSSL_EVP_MD *digest);
  736. WOLFSSL_API int wolfSSL_EVP_add_cipher(const WOLFSSL_EVP_CIPHER *cipher);
  737. WOLFSSL_API void wolfSSL_EVP_cleanup(void);
  738. WOLFSSL_API int wolfSSL_add_all_algorithms(void);
  739. WOLFSSL_API int wolfSSL_OpenSSL_add_all_algorithms_conf(void);
  740. WOLFSSL_API int wolfSSL_OpenSSL_add_all_algorithms_noconf(void);
  741. WOLFSSL_API int wolfSSL_EVP_read_pw_string(char*, int, const char*, int);
  742. WOLFSSL_API int wolfSSL_PKCS5_PBKDF2_HMAC_SHA1(const char * pass, int passlen,
  743. const unsigned char * salt,
  744. int saltlen, int iter,
  745. int keylen, unsigned char *out);
  746. WOLFSSL_API int wolfSSL_PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
  747. const unsigned char *salt,
  748. int saltlen, int iter,
  749. const WOLFSSL_EVP_MD *digest,
  750. int keylen, unsigned char *out);
  751. #if defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && !defined(NO_PWDBASED) && \
  752. !defined(NO_SHA256)
  753. WOLFSSL_API int wolfSSL_EVP_PBE_scrypt(const char *pass, size_t passlen,
  754. const unsigned char *salt, size_t saltlen,
  755. word64 N, word64 r, word64 p,
  756. word64 maxmem, unsigned char *key, size_t keylen);
  757. #endif /* HAVE_SCRYPT && HAVE_PBKDF2 && !NO_PWDBASED && !NO_SHA256 */
  758. WOLFSSL_LOCAL int wolfSSL_EVP_get_hashinfo(const WOLFSSL_EVP_MD* evp,
  759. int* pHash, int* pHashSz);
  760. WOLFSSL_API void wolfSSL_EVP_MD_do_all(void (*fn) (const WOLFSSL_EVP_MD *md,
  761. const char* from, const char* to,
  762. void* xx), void* args);
  763. #ifdef HAVE_HKDF
  764. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set_hkdf_md(WOLFSSL_EVP_PKEY_CTX* ctx,
  765. const WOLFSSL_EVP_MD* md);
  766. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set1_hkdf_salt(WOLFSSL_EVP_PKEY_CTX* ctx,
  767. const byte* salt,
  768. int saltSz);
  769. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_set1_hkdf_key(WOLFSSL_EVP_PKEY_CTX* ctx,
  770. const byte* key, int keySz);
  771. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_add1_hkdf_info(WOLFSSL_EVP_PKEY_CTX* ctx,
  772. const byte* info,
  773. int infoSz);
  774. WOLFSSL_API int wolfSSL_EVP_PKEY_CTX_hkdf_mode(WOLFSSL_EVP_PKEY_CTX* ctx,
  775. int mode);
  776. #endif
  777. #define WOLFSSL_EVP_CIPH_MODE 0x0007
  778. #define WOLFSSL_EVP_CIPH_STREAM_CIPHER 0x0
  779. #define WOLFSSL_EVP_CIPH_ECB_MODE 0x1
  780. #define WOLFSSL_EVP_CIPH_CBC_MODE 0x2
  781. #define WOLFSSL_EVP_CIPH_CFB_MODE 0x3
  782. #define WOLFSSL_EVP_CIPH_OFB_MODE 0x4
  783. #define WOLFSSL_EVP_CIPH_CTR_MODE 0x5
  784. #define WOLFSSL_EVP_CIPH_GCM_MODE 0x6
  785. #define WOLFSSL_EVP_CIPH_CCM_MODE 0x7
  786. #define WOLFSSL_EVP_CIPH_XTS_MODE 0x10
  787. #define WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER 0x20
  788. #define WOLFSSL_EVP_CIPH_NO_PADDING 0x100
  789. #define WOLFSSL_EVP_CIPH_VARIABLE_LENGTH 0x200
  790. #define WOLFSSL_EVP_CIPH_TYPE_INIT 0xff
  791. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  792. /* EVP ENGINE API's */
  793. WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_mac_key(int type, WOLFSSL_ENGINE* e,
  794. const unsigned char* key, int keylen);
  795. WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_CMAC_key(WOLFSSL_ENGINE* e,
  796. const unsigned char* priv, size_t len,
  797. const WOLFSSL_EVP_CIPHER* cipher);
  798. WOLFSSL_API int wolfSSL_EVP_DigestInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
  799. const WOLFSSL_EVP_MD* type,
  800. WOLFSSL_ENGINE *impl);
  801. WOLFSSL_API int wolfSSL_EVP_DigestSignInit(WOLFSSL_EVP_MD_CTX *ctx,
  802. WOLFSSL_EVP_PKEY_CTX **pctx,
  803. const WOLFSSL_EVP_MD *type,
  804. WOLFSSL_ENGINE *e,
  805. WOLFSSL_EVP_PKEY *pkey);
  806. WOLFSSL_API int wolfSSL_EVP_DigestVerifyInit(WOLFSSL_EVP_MD_CTX *ctx,
  807. WOLFSSL_EVP_PKEY_CTX **pctx,
  808. const WOLFSSL_EVP_MD *type,
  809. WOLFSSL_ENGINE *e,
  810. WOLFSSL_EVP_PKEY *pkey);
  811. WOLFSSL_API int wolfSSL_EVP_Digest(const unsigned char* in, int inSz, unsigned char* out,
  812. unsigned int* outSz, const WOLFSSL_EVP_MD* evp,
  813. WOLFSSL_ENGINE* eng);
  814. WOLFSSL_API int wolfSSL_EVP_CipherInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
  815. const WOLFSSL_EVP_CIPHER* type,
  816. WOLFSSL_ENGINE *impl,
  817. const unsigned char* key,
  818. const unsigned char* iv,
  819. int enc);
  820. WOLFSSL_API int wolfSSL_EVP_EncryptInit(WOLFSSL_EVP_CIPHER_CTX* ctx,
  821. const WOLFSSL_EVP_CIPHER* type,
  822. const unsigned char* key,
  823. const unsigned char* iv);
  824. WOLFSSL_API int wolfSSL_EVP_EncryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
  825. const WOLFSSL_EVP_CIPHER* type,
  826. WOLFSSL_ENGINE *impl,
  827. const unsigned char* key,
  828. const unsigned char* iv);
  829. WOLFSSL_API int wolfSSL_EVP_DecryptInit(WOLFSSL_EVP_CIPHER_CTX* ctx,
  830. const WOLFSSL_EVP_CIPHER* type,
  831. const unsigned char* key,
  832. const unsigned char* iv);
  833. WOLFSSL_API int wolfSSL_EVP_DecryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
  834. const WOLFSSL_EVP_CIPHER* type,
  835. WOLFSSL_ENGINE *impl,
  836. const unsigned char* key,
  837. const unsigned char* iv);
  838. WOLFSSL_API WOLFSSL_EVP_PKEY_CTX *wolfSSL_EVP_PKEY_CTX_new(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_ENGINE *e);
  839. WOLFSSL_API WOLFSSL_EVP_PKEY_CTX *wolfSSL_EVP_PKEY_CTX_new_id(int id, WOLFSSL_ENGINE *e);
  840. WOLFSSL_API int wolfSSL_EVP_SignInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
  841. const WOLFSSL_EVP_MD* type,
  842. WOLFSSL_ENGINE *impl);
  843. #define EVP_CIPH_STREAM_CIPHER WOLFSSL_EVP_CIPH_STREAM_CIPHER
  844. #define EVP_CIPH_VARIABLE_LENGTH WOLFSSL_EVP_CIPH_VARIABLE_LENGTH
  845. #define EVP_CIPH_ECB_MODE WOLFSSL_EVP_CIPH_ECB_MODE
  846. #define EVP_CIPH_CBC_MODE WOLFSSL_EVP_CIPH_CBC_MODE
  847. #define EVP_CIPH_CFB_MODE WOLFSSL_EVP_CIPH_CFB_MODE
  848. #define EVP_CIPH_OFB_MODE WOLFSSL_EVP_CIPH_OFB_MODE
  849. #define EVP_CIPH_CTR_MODE WOLFSSL_EVP_CIPH_CTR_MODE
  850. #define EVP_CIPH_GCM_MODE WOLFSSL_EVP_CIPH_GCM_MODE
  851. #define EVP_CIPH_CCM_MODE WOLFSSL_EVP_CIPH_CCM_MODE
  852. #define EVP_CIPH_XTS_MODE WOLFSSL_EVP_CIPH_XTS_MODE
  853. #define EVP_CIPH_FLAG_AEAD_CIPHER WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER
  854. #ifndef NO_MD4
  855. #define EVP_md4 wolfSSL_EVP_md4
  856. #endif
  857. #ifndef NO_MD5
  858. #define EVP_md5 wolfSSL_EVP_md5
  859. #endif
  860. #define EVP_sha1 wolfSSL_EVP_sha1
  861. #define EVP_mdc2 wolfSSL_EVP_mdc2
  862. #define EVP_dds1 wolfSSL_EVP_sha1
  863. #define EVP_sha224 wolfSSL_EVP_sha224
  864. #define EVP_sha256 wolfSSL_EVP_sha256
  865. #define EVP_sha384 wolfSSL_EVP_sha384
  866. #define EVP_sha512 wolfSSL_EVP_sha512
  867. #define EVP_sha512_224 wolfSSL_EVP_sha512_224
  868. #define EVP_sha512_256 wolfSSL_EVP_sha512_256
  869. #define EVP_ripemd160 wolfSSL_EVP_ripemd160
  870. #define EVP_shake128 wolfSSL_EVP_shake128
  871. #define EVP_shake256 wolfSSL_EVP_shake256
  872. #define EVP_sm3 wolfSSL_EVP_sm3
  873. #define EVP_set_pw_prompt wolfSSL_EVP_set_pw_prompt
  874. #define EVP_sha3_224 wolfSSL_EVP_sha3_224
  875. #define EVP_sha3_256 wolfSSL_EVP_sha3_256
  876. #define EVP_sha3_384 wolfSSL_EVP_sha3_384
  877. #define EVP_sha3_512 wolfSSL_EVP_sha3_512
  878. #define EVP_aes_128_cbc wolfSSL_EVP_aes_128_cbc
  879. #define EVP_aes_192_cbc wolfSSL_EVP_aes_192_cbc
  880. #define EVP_aes_256_cbc wolfSSL_EVP_aes_256_cbc
  881. #define EVP_aes_128_cfb1 wolfSSL_EVP_aes_128_cfb1
  882. #define EVP_aes_192_cfb1 wolfSSL_EVP_aes_192_cfb1
  883. #define EVP_aes_256_cfb1 wolfSSL_EVP_aes_256_cfb1
  884. #define EVP_aes_128_cfb8 wolfSSL_EVP_aes_128_cfb8
  885. #define EVP_aes_192_cfb8 wolfSSL_EVP_aes_192_cfb8
  886. #define EVP_aes_256_cfb8 wolfSSL_EVP_aes_256_cfb8
  887. #define EVP_aes_128_cfb128 wolfSSL_EVP_aes_128_cfb128
  888. #define EVP_aes_192_cfb128 wolfSSL_EVP_aes_192_cfb128
  889. #define EVP_aes_256_cfb128 wolfSSL_EVP_aes_256_cfb128
  890. #define EVP_aes_128_cfb wolfSSL_EVP_aes_128_cfb128
  891. #define EVP_aes_192_cfb wolfSSL_EVP_aes_192_cfb128
  892. #define EVP_aes_256_cfb wolfSSL_EVP_aes_256_cfb128
  893. #define EVP_aes_128_ofb wolfSSL_EVP_aes_128_ofb
  894. #define EVP_aes_192_ofb wolfSSL_EVP_aes_192_ofb
  895. #define EVP_aes_256_ofb wolfSSL_EVP_aes_256_ofb
  896. #define EVP_aes_128_xts wolfSSL_EVP_aes_128_xts
  897. #define EVP_aes_256_xts wolfSSL_EVP_aes_256_xts
  898. #define EVP_aes_128_gcm wolfSSL_EVP_aes_128_gcm
  899. #define EVP_aes_192_gcm wolfSSL_EVP_aes_192_gcm
  900. #define EVP_aes_256_gcm wolfSSL_EVP_aes_256_gcm
  901. #define EVP_aes_128_ccm wolfSSL_EVP_aes_128_ccm
  902. #define EVP_aes_192_ccm wolfSSL_EVP_aes_192_ccm
  903. #define EVP_aes_256_ccm wolfSSL_EVP_aes_256_ccm
  904. #define EVP_aes_128_ecb wolfSSL_EVP_aes_128_ecb
  905. #define EVP_aes_192_ecb wolfSSL_EVP_aes_192_ecb
  906. #define EVP_aes_256_ecb wolfSSL_EVP_aes_256_ecb
  907. #define EVP_aes_128_ctr wolfSSL_EVP_aes_128_ctr
  908. #define EVP_aes_192_ctr wolfSSL_EVP_aes_192_ctr
  909. #define EVP_aes_256_ctr wolfSSL_EVP_aes_256_ctr
  910. #define EVP_des_cbc wolfSSL_EVP_des_cbc
  911. #define EVP_des_ecb wolfSSL_EVP_des_ecb
  912. #define EVP_des_ede3_cbc wolfSSL_EVP_des_ede3_cbc
  913. #define EVP_des_ede3_ecb wolfSSL_EVP_des_ede3_ecb
  914. #define EVP_rc4 wolfSSL_EVP_rc4
  915. #define EVP_chacha20 wolfSSL_EVP_chacha20
  916. #define EVP_chacha20_poly1305 wolfSSL_EVP_chacha20_poly1305
  917. #define EVP_aria_128_gcm wolfSSL_EVP_aria_128_gcm
  918. #define EVP_aria_192_gcm wolfSSL_EVP_aria_192_gcm
  919. #define EVP_aria_256_gcm wolfSSL_EVP_aria_256_gcm
  920. #define EVP_sm4_ecb wolfSSL_EVP_sm4_ecb
  921. #define EVP_sm4_cbc wolfSSL_EVP_sm4_cbc
  922. #define EVP_sm4_ctr wolfSSL_EVP_sm4_ctr
  923. #define EVP_sm4_gcm wolfSSL_EVP_sm4_gcm
  924. #define EVP_sm4_ccm wolfSSL_EVP_sm4_ccm
  925. #define EVP_enc_null wolfSSL_EVP_enc_null
  926. #define EVP_MD_size wolfSSL_EVP_MD_size
  927. #define EVP_MD_pkey_type wolfSSL_EVP_MD_pkey_type
  928. #define EVP_MD_CTX_new wolfSSL_EVP_MD_CTX_new
  929. #define EVP_MD_CTX_create wolfSSL_EVP_MD_CTX_new
  930. #define EVP_MD_CTX_free wolfSSL_EVP_MD_CTX_free
  931. #define EVP_MD_CTX_destroy wolfSSL_EVP_MD_CTX_free
  932. #define EVP_MD_CTX_init wolfSSL_EVP_MD_CTX_init
  933. #define EVP_MD_CTX_cleanup wolfSSL_EVP_MD_CTX_cleanup
  934. #define EVP_MD_CTX_reset wolfSSL_EVP_MD_CTX_cleanup
  935. #define EVP_MD_CTX_md wolfSSL_EVP_MD_CTX_md
  936. #define EVP_MD_CTX_type wolfSSL_EVP_MD_CTX_type
  937. #define EVP_MD_CTX_size wolfSSL_EVP_MD_CTX_size
  938. #define EVP_MD_CTX_block_size wolfSSL_EVP_MD_CTX_block_size
  939. #define EVP_MD_block_size wolfSSL_EVP_MD_block_size
  940. #define EVP_MD_type wolfSSL_EVP_MD_type
  941. #ifndef NO_WOLFSSL_STUB
  942. #define EVP_MD_CTX_set_flags(...) WC_DO_NOTHING
  943. #endif
  944. #define EVP_Digest wolfSSL_EVP_Digest
  945. #define EVP_DigestInit wolfSSL_EVP_DigestInit
  946. #define EVP_DigestInit_ex wolfSSL_EVP_DigestInit_ex
  947. #define EVP_DigestUpdate wolfSSL_EVP_DigestUpdate
  948. #define EVP_DigestFinal wolfSSL_EVP_DigestFinal
  949. #define EVP_DigestFinal_ex wolfSSL_EVP_DigestFinal_ex
  950. #define EVP_DigestSignInit wolfSSL_EVP_DigestSignInit
  951. #define EVP_DigestSignUpdate wolfSSL_EVP_DigestSignUpdate
  952. #define EVP_DigestSignFinal wolfSSL_EVP_DigestSignFinal
  953. #define EVP_DigestVerifyInit wolfSSL_EVP_DigestVerifyInit
  954. #define EVP_DigestVerifyUpdate wolfSSL_EVP_DigestVerifyUpdate
  955. #define EVP_DigestVerifyFinal wolfSSL_EVP_DigestVerifyFinal
  956. #define EVP_BytesToKey wolfSSL_EVP_BytesToKey
  957. #define EVP_get_cipherbyname wolfSSL_EVP_get_cipherbyname
  958. #define EVP_get_digestbyname wolfSSL_EVP_get_digestbyname
  959. #define EVP_CIPHER_CTX_init wolfSSL_EVP_CIPHER_CTX_init
  960. #define EVP_CIPHER_CTX_cleanup wolfSSL_EVP_CIPHER_CTX_cleanup
  961. #define EVP_CIPHER_CTX_iv_length wolfSSL_EVP_CIPHER_CTX_iv_length
  962. #define EVP_CIPHER_CTX_nid wolfSSL_EVP_CIPHER_CTX_nid
  963. #define EVP_CIPHER_CTX_key_length wolfSSL_EVP_CIPHER_CTX_key_length
  964. #define EVP_CIPHER_CTX_set_key_length wolfSSL_EVP_CIPHER_CTX_set_key_length
  965. #define EVP_CIPHER_CTX_set_iv_length wolfSSL_EVP_CIPHER_CTX_set_iv_length
  966. #define EVP_CIPHER_CTX_mode wolfSSL_EVP_CIPHER_CTX_mode
  967. #define EVP_CIPHER_CTX_cipher wolfSSL_EVP_CIPHER_CTX_cipher
  968. #define EVP_CIPHER_iv_length wolfSSL_EVP_CIPHER_iv_length
  969. #define EVP_CIPHER_key_length wolfSSL_EVP_Cipher_key_length
  970. #define EVP_CipherInit wolfSSL_EVP_CipherInit
  971. #define EVP_CipherInit_ex wolfSSL_EVP_CipherInit_ex
  972. #define EVP_EncryptInit wolfSSL_EVP_EncryptInit
  973. #define EVP_EncryptInit_ex wolfSSL_EVP_EncryptInit_ex
  974. #define EVP_DecryptInit wolfSSL_EVP_DecryptInit
  975. #define EVP_DecryptInit_ex wolfSSL_EVP_DecryptInit_ex
  976. #define EVP_Cipher wolfSSL_EVP_Cipher
  977. #define EVP_CipherUpdate wolfSSL_EVP_CipherUpdate
  978. #define EVP_EncryptUpdate wolfSSL_EVP_CipherUpdate
  979. #define EVP_DecryptUpdate wolfSSL_EVP_CipherUpdate
  980. #define EVP_CipherFinal wolfSSL_EVP_CipherFinal
  981. #define EVP_CipherFinal_ex wolfSSL_EVP_CipherFinal
  982. #define EVP_EncryptFinal wolfSSL_EVP_CipherFinal
  983. #define EVP_EncryptFinal_ex wolfSSL_EVP_CipherFinal
  984. #define EVP_DecryptFinal wolfSSL_EVP_CipherFinal
  985. #define EVP_DecryptFinal_ex wolfSSL_EVP_CipherFinal
  986. #define EVP_CIPHER_CTX_free wolfSSL_EVP_CIPHER_CTX_free
  987. #define EVP_CIPHER_CTX_reset wolfSSL_EVP_CIPHER_CTX_reset
  988. #define EVP_CIPHER_CTX_new wolfSSL_EVP_CIPHER_CTX_new
  989. #define EVP_get_cipherbynid wolfSSL_EVP_get_cipherbynid
  990. #define EVP_get_digestbynid wolfSSL_EVP_get_digestbynid
  991. #define EVP_MD_nid wolfSSL_EVP_MD_type
  992. #define EVP_PKEY_assign wolfSSL_EVP_PKEY_assign
  993. #define EVP_PKEY_assign_RSA wolfSSL_EVP_PKEY_assign_RSA
  994. #define EVP_PKEY_assign_DSA wolfSSL_EVP_PKEY_assign_DSA
  995. #define EVP_PKEY_assign_DH wolfSSL_EVP_PKEY_assign_DH
  996. #define EVP_PKEY_assign_EC_KEY wolfSSL_EVP_PKEY_assign_EC_KEY
  997. #define EVP_PKEY_get1_DSA wolfSSL_EVP_PKEY_get1_DSA
  998. #define EVP_PKEY_set1_DSA wolfSSL_EVP_PKEY_set1_DSA
  999. #define EVP_PKEY_get0_RSA wolfSSL_EVP_PKEY_get0_RSA
  1000. #define EVP_PKEY_get1_RSA wolfSSL_EVP_PKEY_get1_RSA
  1001. #define EVP_PKEY_set1_RSA wolfSSL_EVP_PKEY_set1_RSA
  1002. #define EVP_PKEY_set1_EC_KEY wolfSSL_EVP_PKEY_set1_EC_KEY
  1003. #define EVP_PKEY_get1_EC_KEY wolfSSL_EVP_PKEY_get1_EC_KEY
  1004. #define EVP_PKEY_set1_DH wolfSSL_EVP_PKEY_set1_DH
  1005. #define EVP_PKEY_get0_DH wolfSSL_EVP_PKEY_get0_DH
  1006. #define EVP_PKEY_get1_DH wolfSSL_EVP_PKEY_get1_DH
  1007. #define EVP_PKEY_get0_EC_KEY wolfSSL_EVP_PKEY_get0_EC_KEY
  1008. #define EVP_PKEY_get0_hmac wolfSSL_EVP_PKEY_get0_hmac
  1009. #define EVP_PKEY_new_mac_key wolfSSL_EVP_PKEY_new_mac_key
  1010. #define EVP_PKEY_new_CMAC_key wolfSSL_EVP_PKEY_new_CMAC_key
  1011. #define EVP_MD_CTX_copy wolfSSL_EVP_MD_CTX_copy
  1012. #define EVP_MD_CTX_copy_ex wolfSSL_EVP_MD_CTX_copy_ex
  1013. #define EVP_PKEY_sign_init wolfSSL_EVP_PKEY_sign_init
  1014. #define EVP_PKEY_sign wolfSSL_EVP_PKEY_sign
  1015. #define EVP_PKEY_verify_init wolfSSL_EVP_PKEY_verify_init
  1016. #define EVP_PKEY_verify wolfSSL_EVP_PKEY_verify
  1017. #define EVP_PKEY_paramgen_init wolfSSL_EVP_PKEY_paramgen_init
  1018. #define EVP_PKEY_CTX_set_ec_param_enc wolfSSL_EVP_PKEY_CTX_set_ec_param_enc
  1019. #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid wolfSSL_EVP_PKEY_CTX_set_ec_paramgen_curve_nid
  1020. #define EVP_PKEY_paramgen wolfSSL_EVP_PKEY_paramgen
  1021. #define EVP_PKEY_keygen wolfSSL_EVP_PKEY_keygen
  1022. #define EVP_PKEY_keygen_init wolfSSL_EVP_PKEY_keygen_init
  1023. #define EVP_PKEY_bits wolfSSL_EVP_PKEY_bits
  1024. #define EVP_PKEY_CTX_free wolfSSL_EVP_PKEY_CTX_free
  1025. #define EVP_PKEY_CTX_new wolfSSL_EVP_PKEY_CTX_new
  1026. #define EVP_PKEY_CTX_set_rsa_padding wolfSSL_EVP_PKEY_CTX_set_rsa_padding
  1027. #define EVP_PKEY_CTX_set_signature_md wolfSSL_EVP_PKEY_CTX_set_signature_md
  1028. #define EVP_PKEY_CTX_new_id wolfSSL_EVP_PKEY_CTX_new_id
  1029. #define EVP_PKEY_CTX_set_rsa_keygen_bits wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits
  1030. #define EVP_PKEY_derive_init wolfSSL_EVP_PKEY_derive_init
  1031. #define EVP_PKEY_derive_set_peer wolfSSL_EVP_PKEY_derive_set_peer
  1032. #define EVP_PKEY_derive wolfSSL_EVP_PKEY_derive
  1033. #define EVP_PKEY_decrypt wolfSSL_EVP_PKEY_decrypt
  1034. #define EVP_PKEY_decrypt_init wolfSSL_EVP_PKEY_decrypt_init
  1035. #define EVP_PKEY_encrypt wolfSSL_EVP_PKEY_encrypt
  1036. #define EVP_PKEY_encrypt_init wolfSSL_EVP_PKEY_encrypt_init
  1037. #define EVP_PKEY_new wolfSSL_EVP_PKEY_new
  1038. #define EVP_PKEY_free wolfSSL_EVP_PKEY_free
  1039. #define EVP_PKEY_up_ref wolfSSL_EVP_PKEY_up_ref
  1040. #define EVP_PKEY_size wolfSSL_EVP_PKEY_size
  1041. #define EVP_PKEY_copy_parameters wolfSSL_EVP_PKEY_copy_parameters
  1042. #define EVP_PKEY_missing_parameters wolfSSL_EVP_PKEY_missing_parameters
  1043. #define EVP_PKEY_cmp wolfSSL_EVP_PKEY_cmp
  1044. #define EVP_PKEY_type wolfSSL_EVP_PKEY_type
  1045. #define EVP_PKEY_base_id wolfSSL_EVP_PKEY_base_id
  1046. #define EVP_PKEY_get_default_digest_nid wolfSSL_EVP_PKEY_get_default_digest_nid
  1047. #define EVP_PKEY_id wolfSSL_EVP_PKEY_id
  1048. #define EVP_PKEY_CTX_ctrl_str wolfSSL_EVP_PKEY_CTX_ctrl_str
  1049. #define EVP_PKCS82PKEY wolfSSL_EVP_PKCS82PKEY
  1050. #define EVP_PKEY2PKCS8 wolfSSL_EVP_PKEY2PKCS8
  1051. #define EVP_SignFinal wolfSSL_EVP_SignFinal
  1052. #define EVP_SignInit wolfSSL_EVP_SignInit
  1053. #define EVP_SignInit_ex wolfSSL_EVP_SignInit_ex
  1054. #define EVP_SignUpdate wolfSSL_EVP_SignUpdate
  1055. #define EVP_VerifyFinal wolfSSL_EVP_VerifyFinal
  1056. #define EVP_VerifyInit wolfSSL_EVP_VerifyInit
  1057. #define EVP_VerifyUpdate wolfSSL_EVP_VerifyUpdate
  1058. #define EVP_CIPHER_CTX_ctrl wolfSSL_EVP_CIPHER_CTX_ctrl
  1059. #define EVP_CIPHER_CTX_block_size wolfSSL_EVP_CIPHER_CTX_block_size
  1060. #define EVP_CIPHER_block_size wolfSSL_EVP_CIPHER_block_size
  1061. #define EVP_CIPHER_flags wolfSSL_EVP_CIPHER_flags
  1062. #define EVP_CIPHER_CTX_set_flags wolfSSL_EVP_CIPHER_CTX_set_flags
  1063. #define EVP_CIPHER_CTX_clear_flags wolfSSL_EVP_CIPHER_CTX_clear_flags
  1064. #define EVP_CIPHER_CTX_set_padding wolfSSL_EVP_CIPHER_CTX_set_padding
  1065. #define EVP_CIPHER_CTX_flags wolfSSL_EVP_CIPHER_CTX_flags
  1066. #define EVP_CIPHER_CTX_set_iv wolfSSL_EVP_CIPHER_CTX_set_iv
  1067. #define EVP_CIPHER_CTX_get_iv wolfSSL_EVP_CIPHER_CTX_get_iv
  1068. #define EVP_add_digest wolfSSL_EVP_add_digest
  1069. #define EVP_add_cipher wolfSSL_EVP_add_cipher
  1070. #define EVP_cleanup wolfSSL_EVP_cleanup
  1071. #define EVP_read_pw_string wolfSSL_EVP_read_pw_string
  1072. #define EVP_rc2_cbc wolfSSL_EVP_rc2_cbc
  1073. #define OpenSSL_add_all_digests() wolfSSL_EVP_init()
  1074. #define OpenSSL_add_all_ciphers() wolfSSL_EVP_init()
  1075. #define OpenSSL_add_all_algorithms wolfSSL_add_all_algorithms
  1076. #define OpenSSL_add_all_algorithms_noconf wolfSSL_OpenSSL_add_all_algorithms_noconf
  1077. #define OpenSSL_add_all_algorithms_conf wolfSSL_OpenSSL_add_all_algorithms_conf
  1078. #define wolfSSL_OPENSSL_add_all_algorithms_noconf wolfSSL_OpenSSL_add_all_algorithms_noconf
  1079. #define wolfSSL_OPENSSL_add_all_algorithms_conf wolfSSL_OpenSSL_add_all_algorithms_conf
  1080. /* provides older OpenSSL API compatibility */
  1081. #define OPENSSL_add_all_algorithms OpenSSL_add_all_algorithms
  1082. #define OPENSSL_add_all_algorithms_noconf OpenSSL_add_all_algorithms_noconf
  1083. #define OPENSSL_add_all_algorithms_conf OpenSSL_add_all_algorithms_conf
  1084. #define NO_PADDING_BLOCK_SIZE 1
  1085. #define PKCS5_PBKDF2_HMAC_SHA1 wolfSSL_PKCS5_PBKDF2_HMAC_SHA1
  1086. #define PKCS5_PBKDF2_HMAC wolfSSL_PKCS5_PBKDF2_HMAC
  1087. #define EVP_PBE_scrypt wolfSSL_EVP_PBE_scrypt
  1088. /* OpenSSL compat. ctrl values */
  1089. #define EVP_CTRL_INIT 0x0
  1090. #define EVP_CTRL_SET_KEY_LENGTH 0x1
  1091. #define EVP_CTRL_SET_RC2_KEY_BITS 0x3 /* needed for qt compilation */
  1092. #define EVP_CTRL_AEAD_SET_IVLEN 0x9
  1093. #define EVP_CTRL_AEAD_GET_TAG 0x10
  1094. #define EVP_CTRL_AEAD_SET_TAG 0x11
  1095. #define EVP_CTRL_AEAD_SET_IV_FIXED 0x12
  1096. #define EVP_CTRL_GCM_IV_GEN 0x13
  1097. #define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
  1098. #define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
  1099. #define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
  1100. #define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED
  1101. #define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
  1102. #define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
  1103. #define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
  1104. #define EVP_CTRL_CCM_SET_L 0x14
  1105. #define EVP_CTRL_CCM_SET_MSGLEN 0x15
  1106. #define EVP_PKEY_print_public wolfSSL_EVP_PKEY_print_public
  1107. #define EVP_PKEY_print_private(arg1, arg2, arg3, arg4) WC_DO_NOTHING
  1108. #ifndef EVP_MAX_MD_SIZE
  1109. #define EVP_MAX_MD_SIZE 64 /* sha512 */
  1110. #endif
  1111. #ifndef EVP_MAX_KEY_LENGTH
  1112. #define EVP_MAX_KEY_LENGTH 64
  1113. #endif
  1114. #ifndef EVP_MAX_IV_LENGTH
  1115. #define EVP_MAX_IV_LENGTH 16
  1116. #endif
  1117. #ifndef EVP_MAX_BLOCK_LENGTH
  1118. #define EVP_MAX_BLOCK_LENGTH 32 /* 2 * blocklen(AES)? */
  1119. /* They define this as 32. Using the same value here. */
  1120. #endif
  1121. #ifndef EVP_MAX_IV_LENGTH
  1122. #define EVP_MAX_IV_LENGTH 16
  1123. #endif
  1124. #define EVP_R_BAD_DECRYPT (-MIN_CODE_E + 100 + 1)
  1125. #define EVP_R_BN_DECODE_ERROR (-MIN_CODE_E + 100 + 2)
  1126. #define EVP_R_DECODE_ERROR (-MIN_CODE_E + 100 + 3)
  1127. #define EVP_R_PRIVATE_KEY_DECODE_ERROR (-MIN_CODE_E + 100 + 4)
  1128. #define EVP_PKEY_NONE NID_undef
  1129. #define EVP_PKEY_DH 28
  1130. #define EVP_CIPHER_mode WOLFSSL_EVP_CIPHER_mode
  1131. /* WOLFSSL_EVP_CIPHER is just the string name of the cipher */
  1132. #define EVP_CIPHER_name(x) x
  1133. #define EVP_MD_CTX_reset wolfSSL_EVP_MD_CTX_cleanup
  1134. /* WOLFSSL_EVP_MD is just the string name of the digest */
  1135. #define EVP_MD_name(x) x
  1136. #define EVP_CIPHER_nid wolfSSL_EVP_CIPHER_nid
  1137. /* Base64 encoding/decoding APIs */
  1138. #if defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE)
  1139. #define EVP_ENCODE_CTX WOLFSSL_EVP_ENCODE_CTX
  1140. #define EVP_ENCODE_CTX_new wolfSSL_EVP_ENCODE_CTX_new
  1141. #define EVP_ENCODE_CTX_free wolfSSL_EVP_ENCODE_CTX_free
  1142. #endif /* WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE*/
  1143. #if defined(WOLFSSL_BASE64_ENCODE)
  1144. #define EVP_EncodeInit wolfSSL_EVP_EncodeInit
  1145. #define EVP_EncodeUpdate wolfSSL_EVP_EncodeUpdate
  1146. #define EVP_EncodeFinal wolfSSL_EVP_EncodeFinal
  1147. #define EVP_EncodeBlock wolfSSL_EVP_EncodeBlock
  1148. #define EVP_DecodeBlock wolfSSL_EVP_DecodeBlock
  1149. #endif /* WOLFSSL_BASE64_ENCODE */
  1150. #if defined(WOLFSSL_BASE64_DECODE)
  1151. #define EVP_DecodeInit wolfSSL_EVP_DecodeInit
  1152. #define EVP_DecodeUpdate wolfSSL_EVP_DecodeUpdate
  1153. #define EVP_DecodeFinal wolfSSL_EVP_DecodeFinal
  1154. #endif /* WOLFSSL_BASE64_DECODE */
  1155. #define EVP_blake2b512 wolfSSL_EVP_blake2b512
  1156. #define EVP_blake2s256 wolfSSL_EVP_blake2s256
  1157. #define EVP_MD_do_all wolfSSL_EVP_MD_do_all
  1158. #ifdef HAVE_HKDF
  1159. #define EVP_PKEY_CTX_set_hkdf_md wolfSSL_EVP_PKEY_CTX_set_hkdf_md
  1160. #define EVP_PKEY_CTX_set1_hkdf_salt wolfSSL_EVP_PKEY_CTX_set1_hkdf_salt
  1161. #define EVP_PKEY_CTX_set1_hkdf_key wolfSSL_EVP_PKEY_CTX_set1_hkdf_key
  1162. #define EVP_PKEY_CTX_add1_hkdf_info wolfSSL_EVP_PKEY_CTX_add1_hkdf_info
  1163. #define EVP_PKEY_CTX_hkdf_mode wolfSSL_EVP_PKEY_CTX_hkdf_mode
  1164. #endif
  1165. WOLFSSL_API void printPKEY(WOLFSSL_EVP_PKEY *k);
  1166. #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
  1167. #ifdef __cplusplus
  1168. } /* extern "C" */
  1169. #endif
  1170. #include <wolfssl/openssl/objects.h>
  1171. #endif /* WOLFSSL_EVP_H_ */