cipher_wrap.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  1. /**
  2. * \file cipher_wrap.c
  3. *
  4. * \brief Generic cipher wrapper for mbed TLS
  5. *
  6. * \author Adriaan de Jong <[email protected]>
  7. *
  8. * Copyright The Mbed TLS Contributors
  9. * SPDX-License-Identifier: Apache-2.0
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  12. * not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  19. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. #include "common.h"
  24. #if defined(MBEDTLS_CIPHER_C)
  25. #include "mbedtls/cipher_internal.h"
  26. #include "mbedtls/error.h"
  27. #if defined(MBEDTLS_CHACHAPOLY_C)
  28. #include "mbedtls/chachapoly.h"
  29. #endif
  30. #if defined(MBEDTLS_AES_C)
  31. #include "mbedtls/aes.h"
  32. #endif
  33. #if defined(MBEDTLS_ARC4_C)
  34. #include "mbedtls/arc4.h"
  35. #endif
  36. #if defined(MBEDTLS_CAMELLIA_C)
  37. #include "mbedtls/camellia.h"
  38. #endif
  39. #if defined(MBEDTLS_ARIA_C)
  40. #include "mbedtls/aria.h"
  41. #endif
  42. #if defined(MBEDTLS_DES_C)
  43. #include "mbedtls/des.h"
  44. #endif
  45. #if defined(MBEDTLS_BLOWFISH_C)
  46. #include "mbedtls/blowfish.h"
  47. #endif
  48. #if defined(MBEDTLS_CHACHA20_C)
  49. #include "mbedtls/chacha20.h"
  50. #endif
  51. #if defined(MBEDTLS_GCM_C)
  52. #include "mbedtls/gcm.h"
  53. #endif
  54. #if defined(MBEDTLS_CCM_C)
  55. #include "mbedtls/ccm.h"
  56. #endif
  57. #if defined(MBEDTLS_NIST_KW_C)
  58. #include "mbedtls/nist_kw.h"
  59. #endif
  60. #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
  61. #include <string.h>
  62. #endif
  63. #include "mbedtls/platform.h"
  64. #if defined(MBEDTLS_GCM_C)
  65. /* shared by all GCM ciphers */
  66. static void *gcm_ctx_alloc(void)
  67. {
  68. void *ctx = mbedtls_calloc(1, sizeof(mbedtls_gcm_context));
  69. if (ctx != NULL) {
  70. mbedtls_gcm_init((mbedtls_gcm_context *) ctx);
  71. }
  72. return ctx;
  73. }
  74. static void gcm_ctx_free(void *ctx)
  75. {
  76. mbedtls_gcm_free(ctx);
  77. mbedtls_free(ctx);
  78. }
  79. #endif /* MBEDTLS_GCM_C */
  80. #if defined(MBEDTLS_CCM_C)
  81. /* shared by all CCM ciphers */
  82. static void *ccm_ctx_alloc(void)
  83. {
  84. void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ccm_context));
  85. if (ctx != NULL) {
  86. mbedtls_ccm_init((mbedtls_ccm_context *) ctx);
  87. }
  88. return ctx;
  89. }
  90. static void ccm_ctx_free(void *ctx)
  91. {
  92. mbedtls_ccm_free(ctx);
  93. mbedtls_free(ctx);
  94. }
  95. #endif /* MBEDTLS_CCM_C */
  96. #if defined(MBEDTLS_AES_C)
  97. static int aes_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  98. const unsigned char *input, unsigned char *output)
  99. {
  100. return mbedtls_aes_crypt_ecb((mbedtls_aes_context *) ctx, operation, input, output);
  101. }
  102. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  103. static int aes_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
  104. unsigned char *iv, const unsigned char *input, unsigned char *output)
  105. {
  106. return mbedtls_aes_crypt_cbc((mbedtls_aes_context *) ctx, operation, length, iv, input,
  107. output);
  108. }
  109. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  110. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  111. static int aes_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
  112. size_t length, size_t *iv_off, unsigned char *iv,
  113. const unsigned char *input, unsigned char *output)
  114. {
  115. return mbedtls_aes_crypt_cfb128((mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
  116. input, output);
  117. }
  118. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  119. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  120. static int aes_crypt_ofb_wrap(void *ctx, size_t length, size_t *iv_off,
  121. unsigned char *iv, const unsigned char *input, unsigned char *output)
  122. {
  123. return mbedtls_aes_crypt_ofb((mbedtls_aes_context *) ctx, length, iv_off,
  124. iv, input, output);
  125. }
  126. #endif /* MBEDTLS_CIPHER_MODE_OFB */
  127. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  128. static int aes_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
  129. unsigned char *nonce_counter, unsigned char *stream_block,
  130. const unsigned char *input, unsigned char *output)
  131. {
  132. return mbedtls_aes_crypt_ctr((mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
  133. stream_block, input, output);
  134. }
  135. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  136. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  137. static int aes_crypt_xts_wrap(void *ctx, mbedtls_operation_t operation,
  138. size_t length,
  139. const unsigned char data_unit[16],
  140. const unsigned char *input,
  141. unsigned char *output)
  142. {
  143. mbedtls_aes_xts_context *xts_ctx = ctx;
  144. int mode;
  145. switch (operation) {
  146. case MBEDTLS_ENCRYPT:
  147. mode = MBEDTLS_AES_ENCRYPT;
  148. break;
  149. case MBEDTLS_DECRYPT:
  150. mode = MBEDTLS_AES_DECRYPT;
  151. break;
  152. default:
  153. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  154. }
  155. return mbedtls_aes_crypt_xts(xts_ctx, mode, length,
  156. data_unit, input, output);
  157. }
  158. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  159. static int aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
  160. unsigned int key_bitlen)
  161. {
  162. return mbedtls_aes_setkey_dec((mbedtls_aes_context *) ctx, key, key_bitlen);
  163. }
  164. static int aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
  165. unsigned int key_bitlen)
  166. {
  167. return mbedtls_aes_setkey_enc((mbedtls_aes_context *) ctx, key, key_bitlen);
  168. }
  169. static void *aes_ctx_alloc(void)
  170. {
  171. mbedtls_aes_context *aes = mbedtls_calloc(1, sizeof(mbedtls_aes_context));
  172. if (aes == NULL) {
  173. return NULL;
  174. }
  175. mbedtls_aes_init(aes);
  176. return aes;
  177. }
  178. static void aes_ctx_free(void *ctx)
  179. {
  180. mbedtls_aes_free((mbedtls_aes_context *) ctx);
  181. mbedtls_free(ctx);
  182. }
  183. static const mbedtls_cipher_base_t aes_info = {
  184. MBEDTLS_CIPHER_ID_AES,
  185. aes_crypt_ecb_wrap,
  186. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  187. aes_crypt_cbc_wrap,
  188. #endif
  189. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  190. aes_crypt_cfb128_wrap,
  191. #endif
  192. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  193. aes_crypt_ofb_wrap,
  194. #endif
  195. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  196. aes_crypt_ctr_wrap,
  197. #endif
  198. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  199. NULL,
  200. #endif
  201. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  202. NULL,
  203. #endif
  204. aes_setkey_enc_wrap,
  205. aes_setkey_dec_wrap,
  206. aes_ctx_alloc,
  207. aes_ctx_free
  208. };
  209. static const mbedtls_cipher_info_t aes_128_ecb_info = {
  210. MBEDTLS_CIPHER_AES_128_ECB,
  211. MBEDTLS_MODE_ECB,
  212. 128,
  213. "AES-128-ECB",
  214. 0,
  215. 0,
  216. 16,
  217. &aes_info
  218. };
  219. static const mbedtls_cipher_info_t aes_192_ecb_info = {
  220. MBEDTLS_CIPHER_AES_192_ECB,
  221. MBEDTLS_MODE_ECB,
  222. 192,
  223. "AES-192-ECB",
  224. 0,
  225. 0,
  226. 16,
  227. &aes_info
  228. };
  229. static const mbedtls_cipher_info_t aes_256_ecb_info = {
  230. MBEDTLS_CIPHER_AES_256_ECB,
  231. MBEDTLS_MODE_ECB,
  232. 256,
  233. "AES-256-ECB",
  234. 0,
  235. 0,
  236. 16,
  237. &aes_info
  238. };
  239. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  240. static const mbedtls_cipher_info_t aes_128_cbc_info = {
  241. MBEDTLS_CIPHER_AES_128_CBC,
  242. MBEDTLS_MODE_CBC,
  243. 128,
  244. "AES-128-CBC",
  245. 16,
  246. 0,
  247. 16,
  248. &aes_info
  249. };
  250. static const mbedtls_cipher_info_t aes_192_cbc_info = {
  251. MBEDTLS_CIPHER_AES_192_CBC,
  252. MBEDTLS_MODE_CBC,
  253. 192,
  254. "AES-192-CBC",
  255. 16,
  256. 0,
  257. 16,
  258. &aes_info
  259. };
  260. static const mbedtls_cipher_info_t aes_256_cbc_info = {
  261. MBEDTLS_CIPHER_AES_256_CBC,
  262. MBEDTLS_MODE_CBC,
  263. 256,
  264. "AES-256-CBC",
  265. 16,
  266. 0,
  267. 16,
  268. &aes_info
  269. };
  270. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  271. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  272. static const mbedtls_cipher_info_t aes_128_cfb128_info = {
  273. MBEDTLS_CIPHER_AES_128_CFB128,
  274. MBEDTLS_MODE_CFB,
  275. 128,
  276. "AES-128-CFB128",
  277. 16,
  278. 0,
  279. 16,
  280. &aes_info
  281. };
  282. static const mbedtls_cipher_info_t aes_192_cfb128_info = {
  283. MBEDTLS_CIPHER_AES_192_CFB128,
  284. MBEDTLS_MODE_CFB,
  285. 192,
  286. "AES-192-CFB128",
  287. 16,
  288. 0,
  289. 16,
  290. &aes_info
  291. };
  292. static const mbedtls_cipher_info_t aes_256_cfb128_info = {
  293. MBEDTLS_CIPHER_AES_256_CFB128,
  294. MBEDTLS_MODE_CFB,
  295. 256,
  296. "AES-256-CFB128",
  297. 16,
  298. 0,
  299. 16,
  300. &aes_info
  301. };
  302. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  303. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  304. static const mbedtls_cipher_info_t aes_128_ofb_info = {
  305. MBEDTLS_CIPHER_AES_128_OFB,
  306. MBEDTLS_MODE_OFB,
  307. 128,
  308. "AES-128-OFB",
  309. 16,
  310. 0,
  311. 16,
  312. &aes_info
  313. };
  314. static const mbedtls_cipher_info_t aes_192_ofb_info = {
  315. MBEDTLS_CIPHER_AES_192_OFB,
  316. MBEDTLS_MODE_OFB,
  317. 192,
  318. "AES-192-OFB",
  319. 16,
  320. 0,
  321. 16,
  322. &aes_info
  323. };
  324. static const mbedtls_cipher_info_t aes_256_ofb_info = {
  325. MBEDTLS_CIPHER_AES_256_OFB,
  326. MBEDTLS_MODE_OFB,
  327. 256,
  328. "AES-256-OFB",
  329. 16,
  330. 0,
  331. 16,
  332. &aes_info
  333. };
  334. #endif /* MBEDTLS_CIPHER_MODE_OFB */
  335. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  336. static const mbedtls_cipher_info_t aes_128_ctr_info = {
  337. MBEDTLS_CIPHER_AES_128_CTR,
  338. MBEDTLS_MODE_CTR,
  339. 128,
  340. "AES-128-CTR",
  341. 16,
  342. 0,
  343. 16,
  344. &aes_info
  345. };
  346. static const mbedtls_cipher_info_t aes_192_ctr_info = {
  347. MBEDTLS_CIPHER_AES_192_CTR,
  348. MBEDTLS_MODE_CTR,
  349. 192,
  350. "AES-192-CTR",
  351. 16,
  352. 0,
  353. 16,
  354. &aes_info
  355. };
  356. static const mbedtls_cipher_info_t aes_256_ctr_info = {
  357. MBEDTLS_CIPHER_AES_256_CTR,
  358. MBEDTLS_MODE_CTR,
  359. 256,
  360. "AES-256-CTR",
  361. 16,
  362. 0,
  363. 16,
  364. &aes_info
  365. };
  366. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  367. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  368. static int xts_aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
  369. unsigned int key_bitlen)
  370. {
  371. mbedtls_aes_xts_context *xts_ctx = ctx;
  372. return mbedtls_aes_xts_setkey_enc(xts_ctx, key, key_bitlen);
  373. }
  374. static int xts_aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
  375. unsigned int key_bitlen)
  376. {
  377. mbedtls_aes_xts_context *xts_ctx = ctx;
  378. return mbedtls_aes_xts_setkey_dec(xts_ctx, key, key_bitlen);
  379. }
  380. static void *xts_aes_ctx_alloc(void)
  381. {
  382. mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc(1, sizeof(*xts_ctx));
  383. if (xts_ctx != NULL) {
  384. mbedtls_aes_xts_init(xts_ctx);
  385. }
  386. return xts_ctx;
  387. }
  388. static void xts_aes_ctx_free(void *ctx)
  389. {
  390. mbedtls_aes_xts_context *xts_ctx = ctx;
  391. if (xts_ctx == NULL) {
  392. return;
  393. }
  394. mbedtls_aes_xts_free(xts_ctx);
  395. mbedtls_free(xts_ctx);
  396. }
  397. static const mbedtls_cipher_base_t xts_aes_info = {
  398. MBEDTLS_CIPHER_ID_AES,
  399. NULL,
  400. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  401. NULL,
  402. #endif
  403. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  404. NULL,
  405. #endif
  406. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  407. NULL,
  408. #endif
  409. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  410. NULL,
  411. #endif
  412. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  413. aes_crypt_xts_wrap,
  414. #endif
  415. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  416. NULL,
  417. #endif
  418. xts_aes_setkey_enc_wrap,
  419. xts_aes_setkey_dec_wrap,
  420. xts_aes_ctx_alloc,
  421. xts_aes_ctx_free
  422. };
  423. static const mbedtls_cipher_info_t aes_128_xts_info = {
  424. MBEDTLS_CIPHER_AES_128_XTS,
  425. MBEDTLS_MODE_XTS,
  426. 256,
  427. "AES-128-XTS",
  428. 16,
  429. 0,
  430. 16,
  431. &xts_aes_info
  432. };
  433. static const mbedtls_cipher_info_t aes_256_xts_info = {
  434. MBEDTLS_CIPHER_AES_256_XTS,
  435. MBEDTLS_MODE_XTS,
  436. 512,
  437. "AES-256-XTS",
  438. 16,
  439. 0,
  440. 16,
  441. &xts_aes_info
  442. };
  443. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  444. #if defined(MBEDTLS_GCM_C)
  445. static int gcm_aes_setkey_wrap(void *ctx, const unsigned char *key,
  446. unsigned int key_bitlen)
  447. {
  448. return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
  449. key, key_bitlen);
  450. }
  451. static const mbedtls_cipher_base_t gcm_aes_info = {
  452. MBEDTLS_CIPHER_ID_AES,
  453. NULL,
  454. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  455. NULL,
  456. #endif
  457. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  458. NULL,
  459. #endif
  460. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  461. NULL,
  462. #endif
  463. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  464. NULL,
  465. #endif
  466. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  467. NULL,
  468. #endif
  469. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  470. NULL,
  471. #endif
  472. gcm_aes_setkey_wrap,
  473. gcm_aes_setkey_wrap,
  474. gcm_ctx_alloc,
  475. gcm_ctx_free,
  476. };
  477. static const mbedtls_cipher_info_t aes_128_gcm_info = {
  478. MBEDTLS_CIPHER_AES_128_GCM,
  479. MBEDTLS_MODE_GCM,
  480. 128,
  481. "AES-128-GCM",
  482. 12,
  483. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  484. 16,
  485. &gcm_aes_info
  486. };
  487. static const mbedtls_cipher_info_t aes_192_gcm_info = {
  488. MBEDTLS_CIPHER_AES_192_GCM,
  489. MBEDTLS_MODE_GCM,
  490. 192,
  491. "AES-192-GCM",
  492. 12,
  493. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  494. 16,
  495. &gcm_aes_info
  496. };
  497. static const mbedtls_cipher_info_t aes_256_gcm_info = {
  498. MBEDTLS_CIPHER_AES_256_GCM,
  499. MBEDTLS_MODE_GCM,
  500. 256,
  501. "AES-256-GCM",
  502. 12,
  503. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  504. 16,
  505. &gcm_aes_info
  506. };
  507. #endif /* MBEDTLS_GCM_C */
  508. #if defined(MBEDTLS_CCM_C)
  509. static int ccm_aes_setkey_wrap(void *ctx, const unsigned char *key,
  510. unsigned int key_bitlen)
  511. {
  512. return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
  513. key, key_bitlen);
  514. }
  515. static const mbedtls_cipher_base_t ccm_aes_info = {
  516. MBEDTLS_CIPHER_ID_AES,
  517. NULL,
  518. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  519. NULL,
  520. #endif
  521. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  522. NULL,
  523. #endif
  524. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  525. NULL,
  526. #endif
  527. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  528. NULL,
  529. #endif
  530. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  531. NULL,
  532. #endif
  533. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  534. NULL,
  535. #endif
  536. ccm_aes_setkey_wrap,
  537. ccm_aes_setkey_wrap,
  538. ccm_ctx_alloc,
  539. ccm_ctx_free,
  540. };
  541. static const mbedtls_cipher_info_t aes_128_ccm_info = {
  542. MBEDTLS_CIPHER_AES_128_CCM,
  543. MBEDTLS_MODE_CCM,
  544. 128,
  545. "AES-128-CCM",
  546. 12,
  547. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  548. 16,
  549. &ccm_aes_info
  550. };
  551. static const mbedtls_cipher_info_t aes_192_ccm_info = {
  552. MBEDTLS_CIPHER_AES_192_CCM,
  553. MBEDTLS_MODE_CCM,
  554. 192,
  555. "AES-192-CCM",
  556. 12,
  557. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  558. 16,
  559. &ccm_aes_info
  560. };
  561. static const mbedtls_cipher_info_t aes_256_ccm_info = {
  562. MBEDTLS_CIPHER_AES_256_CCM,
  563. MBEDTLS_MODE_CCM,
  564. 256,
  565. "AES-256-CCM",
  566. 12,
  567. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  568. 16,
  569. &ccm_aes_info
  570. };
  571. #endif /* MBEDTLS_CCM_C */
  572. #endif /* MBEDTLS_AES_C */
  573. #if defined(MBEDTLS_CAMELLIA_C)
  574. static int camellia_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  575. const unsigned char *input, unsigned char *output)
  576. {
  577. return mbedtls_camellia_crypt_ecb((mbedtls_camellia_context *) ctx, operation, input,
  578. output);
  579. }
  580. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  581. static int camellia_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation,
  582. size_t length, unsigned char *iv,
  583. const unsigned char *input, unsigned char *output)
  584. {
  585. return mbedtls_camellia_crypt_cbc((mbedtls_camellia_context *) ctx, operation, length, iv,
  586. input, output);
  587. }
  588. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  589. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  590. static int camellia_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
  591. size_t length, size_t *iv_off, unsigned char *iv,
  592. const unsigned char *input, unsigned char *output)
  593. {
  594. return mbedtls_camellia_crypt_cfb128((mbedtls_camellia_context *) ctx, operation, length,
  595. iv_off, iv, input, output);
  596. }
  597. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  598. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  599. static int camellia_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
  600. unsigned char *nonce_counter, unsigned char *stream_block,
  601. const unsigned char *input, unsigned char *output)
  602. {
  603. return mbedtls_camellia_crypt_ctr((mbedtls_camellia_context *) ctx, length, nc_off,
  604. nonce_counter, stream_block, input, output);
  605. }
  606. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  607. static int camellia_setkey_dec_wrap(void *ctx, const unsigned char *key,
  608. unsigned int key_bitlen)
  609. {
  610. return mbedtls_camellia_setkey_dec((mbedtls_camellia_context *) ctx, key, key_bitlen);
  611. }
  612. static int camellia_setkey_enc_wrap(void *ctx, const unsigned char *key,
  613. unsigned int key_bitlen)
  614. {
  615. return mbedtls_camellia_setkey_enc((mbedtls_camellia_context *) ctx, key, key_bitlen);
  616. }
  617. static void *camellia_ctx_alloc(void)
  618. {
  619. mbedtls_camellia_context *ctx;
  620. ctx = mbedtls_calloc(1, sizeof(mbedtls_camellia_context));
  621. if (ctx == NULL) {
  622. return NULL;
  623. }
  624. mbedtls_camellia_init(ctx);
  625. return ctx;
  626. }
  627. static void camellia_ctx_free(void *ctx)
  628. {
  629. mbedtls_camellia_free((mbedtls_camellia_context *) ctx);
  630. mbedtls_free(ctx);
  631. }
  632. static const mbedtls_cipher_base_t camellia_info = {
  633. MBEDTLS_CIPHER_ID_CAMELLIA,
  634. camellia_crypt_ecb_wrap,
  635. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  636. camellia_crypt_cbc_wrap,
  637. #endif
  638. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  639. camellia_crypt_cfb128_wrap,
  640. #endif
  641. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  642. NULL,
  643. #endif
  644. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  645. camellia_crypt_ctr_wrap,
  646. #endif
  647. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  648. NULL,
  649. #endif
  650. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  651. NULL,
  652. #endif
  653. camellia_setkey_enc_wrap,
  654. camellia_setkey_dec_wrap,
  655. camellia_ctx_alloc,
  656. camellia_ctx_free
  657. };
  658. static const mbedtls_cipher_info_t camellia_128_ecb_info = {
  659. MBEDTLS_CIPHER_CAMELLIA_128_ECB,
  660. MBEDTLS_MODE_ECB,
  661. 128,
  662. "CAMELLIA-128-ECB",
  663. 0,
  664. 0,
  665. 16,
  666. &camellia_info
  667. };
  668. static const mbedtls_cipher_info_t camellia_192_ecb_info = {
  669. MBEDTLS_CIPHER_CAMELLIA_192_ECB,
  670. MBEDTLS_MODE_ECB,
  671. 192,
  672. "CAMELLIA-192-ECB",
  673. 0,
  674. 0,
  675. 16,
  676. &camellia_info
  677. };
  678. static const mbedtls_cipher_info_t camellia_256_ecb_info = {
  679. MBEDTLS_CIPHER_CAMELLIA_256_ECB,
  680. MBEDTLS_MODE_ECB,
  681. 256,
  682. "CAMELLIA-256-ECB",
  683. 0,
  684. 0,
  685. 16,
  686. &camellia_info
  687. };
  688. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  689. static const mbedtls_cipher_info_t camellia_128_cbc_info = {
  690. MBEDTLS_CIPHER_CAMELLIA_128_CBC,
  691. MBEDTLS_MODE_CBC,
  692. 128,
  693. "CAMELLIA-128-CBC",
  694. 16,
  695. 0,
  696. 16,
  697. &camellia_info
  698. };
  699. static const mbedtls_cipher_info_t camellia_192_cbc_info = {
  700. MBEDTLS_CIPHER_CAMELLIA_192_CBC,
  701. MBEDTLS_MODE_CBC,
  702. 192,
  703. "CAMELLIA-192-CBC",
  704. 16,
  705. 0,
  706. 16,
  707. &camellia_info
  708. };
  709. static const mbedtls_cipher_info_t camellia_256_cbc_info = {
  710. MBEDTLS_CIPHER_CAMELLIA_256_CBC,
  711. MBEDTLS_MODE_CBC,
  712. 256,
  713. "CAMELLIA-256-CBC",
  714. 16,
  715. 0,
  716. 16,
  717. &camellia_info
  718. };
  719. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  720. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  721. static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
  722. MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
  723. MBEDTLS_MODE_CFB,
  724. 128,
  725. "CAMELLIA-128-CFB128",
  726. 16,
  727. 0,
  728. 16,
  729. &camellia_info
  730. };
  731. static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
  732. MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
  733. MBEDTLS_MODE_CFB,
  734. 192,
  735. "CAMELLIA-192-CFB128",
  736. 16,
  737. 0,
  738. 16,
  739. &camellia_info
  740. };
  741. static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
  742. MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
  743. MBEDTLS_MODE_CFB,
  744. 256,
  745. "CAMELLIA-256-CFB128",
  746. 16,
  747. 0,
  748. 16,
  749. &camellia_info
  750. };
  751. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  752. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  753. static const mbedtls_cipher_info_t camellia_128_ctr_info = {
  754. MBEDTLS_CIPHER_CAMELLIA_128_CTR,
  755. MBEDTLS_MODE_CTR,
  756. 128,
  757. "CAMELLIA-128-CTR",
  758. 16,
  759. 0,
  760. 16,
  761. &camellia_info
  762. };
  763. static const mbedtls_cipher_info_t camellia_192_ctr_info = {
  764. MBEDTLS_CIPHER_CAMELLIA_192_CTR,
  765. MBEDTLS_MODE_CTR,
  766. 192,
  767. "CAMELLIA-192-CTR",
  768. 16,
  769. 0,
  770. 16,
  771. &camellia_info
  772. };
  773. static const mbedtls_cipher_info_t camellia_256_ctr_info = {
  774. MBEDTLS_CIPHER_CAMELLIA_256_CTR,
  775. MBEDTLS_MODE_CTR,
  776. 256,
  777. "CAMELLIA-256-CTR",
  778. 16,
  779. 0,
  780. 16,
  781. &camellia_info
  782. };
  783. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  784. #if defined(MBEDTLS_GCM_C)
  785. static int gcm_camellia_setkey_wrap(void *ctx, const unsigned char *key,
  786. unsigned int key_bitlen)
  787. {
  788. return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
  789. key, key_bitlen);
  790. }
  791. static const mbedtls_cipher_base_t gcm_camellia_info = {
  792. MBEDTLS_CIPHER_ID_CAMELLIA,
  793. NULL,
  794. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  795. NULL,
  796. #endif
  797. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  798. NULL,
  799. #endif
  800. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  801. NULL,
  802. #endif
  803. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  804. NULL,
  805. #endif
  806. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  807. NULL,
  808. #endif
  809. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  810. NULL,
  811. #endif
  812. gcm_camellia_setkey_wrap,
  813. gcm_camellia_setkey_wrap,
  814. gcm_ctx_alloc,
  815. gcm_ctx_free,
  816. };
  817. static const mbedtls_cipher_info_t camellia_128_gcm_info = {
  818. MBEDTLS_CIPHER_CAMELLIA_128_GCM,
  819. MBEDTLS_MODE_GCM,
  820. 128,
  821. "CAMELLIA-128-GCM",
  822. 12,
  823. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  824. 16,
  825. &gcm_camellia_info
  826. };
  827. static const mbedtls_cipher_info_t camellia_192_gcm_info = {
  828. MBEDTLS_CIPHER_CAMELLIA_192_GCM,
  829. MBEDTLS_MODE_GCM,
  830. 192,
  831. "CAMELLIA-192-GCM",
  832. 12,
  833. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  834. 16,
  835. &gcm_camellia_info
  836. };
  837. static const mbedtls_cipher_info_t camellia_256_gcm_info = {
  838. MBEDTLS_CIPHER_CAMELLIA_256_GCM,
  839. MBEDTLS_MODE_GCM,
  840. 256,
  841. "CAMELLIA-256-GCM",
  842. 12,
  843. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  844. 16,
  845. &gcm_camellia_info
  846. };
  847. #endif /* MBEDTLS_GCM_C */
  848. #if defined(MBEDTLS_CCM_C)
  849. static int ccm_camellia_setkey_wrap(void *ctx, const unsigned char *key,
  850. unsigned int key_bitlen)
  851. {
  852. return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
  853. key, key_bitlen);
  854. }
  855. static const mbedtls_cipher_base_t ccm_camellia_info = {
  856. MBEDTLS_CIPHER_ID_CAMELLIA,
  857. NULL,
  858. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  859. NULL,
  860. #endif
  861. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  862. NULL,
  863. #endif
  864. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  865. NULL,
  866. #endif
  867. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  868. NULL,
  869. #endif
  870. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  871. NULL,
  872. #endif
  873. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  874. NULL,
  875. #endif
  876. ccm_camellia_setkey_wrap,
  877. ccm_camellia_setkey_wrap,
  878. ccm_ctx_alloc,
  879. ccm_ctx_free,
  880. };
  881. static const mbedtls_cipher_info_t camellia_128_ccm_info = {
  882. MBEDTLS_CIPHER_CAMELLIA_128_CCM,
  883. MBEDTLS_MODE_CCM,
  884. 128,
  885. "CAMELLIA-128-CCM",
  886. 12,
  887. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  888. 16,
  889. &ccm_camellia_info
  890. };
  891. static const mbedtls_cipher_info_t camellia_192_ccm_info = {
  892. MBEDTLS_CIPHER_CAMELLIA_192_CCM,
  893. MBEDTLS_MODE_CCM,
  894. 192,
  895. "CAMELLIA-192-CCM",
  896. 12,
  897. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  898. 16,
  899. &ccm_camellia_info
  900. };
  901. static const mbedtls_cipher_info_t camellia_256_ccm_info = {
  902. MBEDTLS_CIPHER_CAMELLIA_256_CCM,
  903. MBEDTLS_MODE_CCM,
  904. 256,
  905. "CAMELLIA-256-CCM",
  906. 12,
  907. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  908. 16,
  909. &ccm_camellia_info
  910. };
  911. #endif /* MBEDTLS_CCM_C */
  912. #endif /* MBEDTLS_CAMELLIA_C */
  913. #if defined(MBEDTLS_ARIA_C)
  914. static int aria_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  915. const unsigned char *input, unsigned char *output)
  916. {
  917. (void) operation;
  918. return mbedtls_aria_crypt_ecb((mbedtls_aria_context *) ctx, input,
  919. output);
  920. }
  921. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  922. static int aria_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation,
  923. size_t length, unsigned char *iv,
  924. const unsigned char *input, unsigned char *output)
  925. {
  926. return mbedtls_aria_crypt_cbc((mbedtls_aria_context *) ctx, operation, length, iv,
  927. input, output);
  928. }
  929. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  930. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  931. static int aria_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation,
  932. size_t length, size_t *iv_off, unsigned char *iv,
  933. const unsigned char *input, unsigned char *output)
  934. {
  935. return mbedtls_aria_crypt_cfb128((mbedtls_aria_context *) ctx, operation, length,
  936. iv_off, iv, input, output);
  937. }
  938. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  939. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  940. static int aria_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
  941. unsigned char *nonce_counter, unsigned char *stream_block,
  942. const unsigned char *input, unsigned char *output)
  943. {
  944. return mbedtls_aria_crypt_ctr((mbedtls_aria_context *) ctx, length, nc_off,
  945. nonce_counter, stream_block, input, output);
  946. }
  947. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  948. static int aria_setkey_dec_wrap(void *ctx, const unsigned char *key,
  949. unsigned int key_bitlen)
  950. {
  951. return mbedtls_aria_setkey_dec((mbedtls_aria_context *) ctx, key, key_bitlen);
  952. }
  953. static int aria_setkey_enc_wrap(void *ctx, const unsigned char *key,
  954. unsigned int key_bitlen)
  955. {
  956. return mbedtls_aria_setkey_enc((mbedtls_aria_context *) ctx, key, key_bitlen);
  957. }
  958. static void *aria_ctx_alloc(void)
  959. {
  960. mbedtls_aria_context *ctx;
  961. ctx = mbedtls_calloc(1, sizeof(mbedtls_aria_context));
  962. if (ctx == NULL) {
  963. return NULL;
  964. }
  965. mbedtls_aria_init(ctx);
  966. return ctx;
  967. }
  968. static void aria_ctx_free(void *ctx)
  969. {
  970. mbedtls_aria_free((mbedtls_aria_context *) ctx);
  971. mbedtls_free(ctx);
  972. }
  973. static const mbedtls_cipher_base_t aria_info = {
  974. MBEDTLS_CIPHER_ID_ARIA,
  975. aria_crypt_ecb_wrap,
  976. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  977. aria_crypt_cbc_wrap,
  978. #endif
  979. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  980. aria_crypt_cfb128_wrap,
  981. #endif
  982. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  983. NULL,
  984. #endif
  985. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  986. aria_crypt_ctr_wrap,
  987. #endif
  988. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  989. NULL,
  990. #endif
  991. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  992. NULL,
  993. #endif
  994. aria_setkey_enc_wrap,
  995. aria_setkey_dec_wrap,
  996. aria_ctx_alloc,
  997. aria_ctx_free
  998. };
  999. static const mbedtls_cipher_info_t aria_128_ecb_info = {
  1000. MBEDTLS_CIPHER_ARIA_128_ECB,
  1001. MBEDTLS_MODE_ECB,
  1002. 128,
  1003. "ARIA-128-ECB",
  1004. 0,
  1005. 0,
  1006. 16,
  1007. &aria_info
  1008. };
  1009. static const mbedtls_cipher_info_t aria_192_ecb_info = {
  1010. MBEDTLS_CIPHER_ARIA_192_ECB,
  1011. MBEDTLS_MODE_ECB,
  1012. 192,
  1013. "ARIA-192-ECB",
  1014. 0,
  1015. 0,
  1016. 16,
  1017. &aria_info
  1018. };
  1019. static const mbedtls_cipher_info_t aria_256_ecb_info = {
  1020. MBEDTLS_CIPHER_ARIA_256_ECB,
  1021. MBEDTLS_MODE_ECB,
  1022. 256,
  1023. "ARIA-256-ECB",
  1024. 0,
  1025. 0,
  1026. 16,
  1027. &aria_info
  1028. };
  1029. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1030. static const mbedtls_cipher_info_t aria_128_cbc_info = {
  1031. MBEDTLS_CIPHER_ARIA_128_CBC,
  1032. MBEDTLS_MODE_CBC,
  1033. 128,
  1034. "ARIA-128-CBC",
  1035. 16,
  1036. 0,
  1037. 16,
  1038. &aria_info
  1039. };
  1040. static const mbedtls_cipher_info_t aria_192_cbc_info = {
  1041. MBEDTLS_CIPHER_ARIA_192_CBC,
  1042. MBEDTLS_MODE_CBC,
  1043. 192,
  1044. "ARIA-192-CBC",
  1045. 16,
  1046. 0,
  1047. 16,
  1048. &aria_info
  1049. };
  1050. static const mbedtls_cipher_info_t aria_256_cbc_info = {
  1051. MBEDTLS_CIPHER_ARIA_256_CBC,
  1052. MBEDTLS_MODE_CBC,
  1053. 256,
  1054. "ARIA-256-CBC",
  1055. 16,
  1056. 0,
  1057. 16,
  1058. &aria_info
  1059. };
  1060. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1061. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1062. static const mbedtls_cipher_info_t aria_128_cfb128_info = {
  1063. MBEDTLS_CIPHER_ARIA_128_CFB128,
  1064. MBEDTLS_MODE_CFB,
  1065. 128,
  1066. "ARIA-128-CFB128",
  1067. 16,
  1068. 0,
  1069. 16,
  1070. &aria_info
  1071. };
  1072. static const mbedtls_cipher_info_t aria_192_cfb128_info = {
  1073. MBEDTLS_CIPHER_ARIA_192_CFB128,
  1074. MBEDTLS_MODE_CFB,
  1075. 192,
  1076. "ARIA-192-CFB128",
  1077. 16,
  1078. 0,
  1079. 16,
  1080. &aria_info
  1081. };
  1082. static const mbedtls_cipher_info_t aria_256_cfb128_info = {
  1083. MBEDTLS_CIPHER_ARIA_256_CFB128,
  1084. MBEDTLS_MODE_CFB,
  1085. 256,
  1086. "ARIA-256-CFB128",
  1087. 16,
  1088. 0,
  1089. 16,
  1090. &aria_info
  1091. };
  1092. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  1093. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1094. static const mbedtls_cipher_info_t aria_128_ctr_info = {
  1095. MBEDTLS_CIPHER_ARIA_128_CTR,
  1096. MBEDTLS_MODE_CTR,
  1097. 128,
  1098. "ARIA-128-CTR",
  1099. 16,
  1100. 0,
  1101. 16,
  1102. &aria_info
  1103. };
  1104. static const mbedtls_cipher_info_t aria_192_ctr_info = {
  1105. MBEDTLS_CIPHER_ARIA_192_CTR,
  1106. MBEDTLS_MODE_CTR,
  1107. 192,
  1108. "ARIA-192-CTR",
  1109. 16,
  1110. 0,
  1111. 16,
  1112. &aria_info
  1113. };
  1114. static const mbedtls_cipher_info_t aria_256_ctr_info = {
  1115. MBEDTLS_CIPHER_ARIA_256_CTR,
  1116. MBEDTLS_MODE_CTR,
  1117. 256,
  1118. "ARIA-256-CTR",
  1119. 16,
  1120. 0,
  1121. 16,
  1122. &aria_info
  1123. };
  1124. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  1125. #if defined(MBEDTLS_GCM_C)
  1126. static int gcm_aria_setkey_wrap(void *ctx, const unsigned char *key,
  1127. unsigned int key_bitlen)
  1128. {
  1129. return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
  1130. key, key_bitlen);
  1131. }
  1132. static const mbedtls_cipher_base_t gcm_aria_info = {
  1133. MBEDTLS_CIPHER_ID_ARIA,
  1134. NULL,
  1135. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1136. NULL,
  1137. #endif
  1138. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1139. NULL,
  1140. #endif
  1141. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1142. NULL,
  1143. #endif
  1144. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1145. NULL,
  1146. #endif
  1147. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1148. NULL,
  1149. #endif
  1150. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1151. NULL,
  1152. #endif
  1153. gcm_aria_setkey_wrap,
  1154. gcm_aria_setkey_wrap,
  1155. gcm_ctx_alloc,
  1156. gcm_ctx_free,
  1157. };
  1158. static const mbedtls_cipher_info_t aria_128_gcm_info = {
  1159. MBEDTLS_CIPHER_ARIA_128_GCM,
  1160. MBEDTLS_MODE_GCM,
  1161. 128,
  1162. "ARIA-128-GCM",
  1163. 12,
  1164. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1165. 16,
  1166. &gcm_aria_info
  1167. };
  1168. static const mbedtls_cipher_info_t aria_192_gcm_info = {
  1169. MBEDTLS_CIPHER_ARIA_192_GCM,
  1170. MBEDTLS_MODE_GCM,
  1171. 192,
  1172. "ARIA-192-GCM",
  1173. 12,
  1174. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1175. 16,
  1176. &gcm_aria_info
  1177. };
  1178. static const mbedtls_cipher_info_t aria_256_gcm_info = {
  1179. MBEDTLS_CIPHER_ARIA_256_GCM,
  1180. MBEDTLS_MODE_GCM,
  1181. 256,
  1182. "ARIA-256-GCM",
  1183. 12,
  1184. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1185. 16,
  1186. &gcm_aria_info
  1187. };
  1188. #endif /* MBEDTLS_GCM_C */
  1189. #if defined(MBEDTLS_CCM_C)
  1190. static int ccm_aria_setkey_wrap(void *ctx, const unsigned char *key,
  1191. unsigned int key_bitlen)
  1192. {
  1193. return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
  1194. key, key_bitlen);
  1195. }
  1196. static const mbedtls_cipher_base_t ccm_aria_info = {
  1197. MBEDTLS_CIPHER_ID_ARIA,
  1198. NULL,
  1199. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1200. NULL,
  1201. #endif
  1202. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1203. NULL,
  1204. #endif
  1205. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1206. NULL,
  1207. #endif
  1208. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1209. NULL,
  1210. #endif
  1211. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1212. NULL,
  1213. #endif
  1214. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1215. NULL,
  1216. #endif
  1217. ccm_aria_setkey_wrap,
  1218. ccm_aria_setkey_wrap,
  1219. ccm_ctx_alloc,
  1220. ccm_ctx_free,
  1221. };
  1222. static const mbedtls_cipher_info_t aria_128_ccm_info = {
  1223. MBEDTLS_CIPHER_ARIA_128_CCM,
  1224. MBEDTLS_MODE_CCM,
  1225. 128,
  1226. "ARIA-128-CCM",
  1227. 12,
  1228. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1229. 16,
  1230. &ccm_aria_info
  1231. };
  1232. static const mbedtls_cipher_info_t aria_192_ccm_info = {
  1233. MBEDTLS_CIPHER_ARIA_192_CCM,
  1234. MBEDTLS_MODE_CCM,
  1235. 192,
  1236. "ARIA-192-CCM",
  1237. 12,
  1238. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1239. 16,
  1240. &ccm_aria_info
  1241. };
  1242. static const mbedtls_cipher_info_t aria_256_ccm_info = {
  1243. MBEDTLS_CIPHER_ARIA_256_CCM,
  1244. MBEDTLS_MODE_CCM,
  1245. 256,
  1246. "ARIA-256-CCM",
  1247. 12,
  1248. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  1249. 16,
  1250. &ccm_aria_info
  1251. };
  1252. #endif /* MBEDTLS_CCM_C */
  1253. #endif /* MBEDTLS_ARIA_C */
  1254. #if defined(MBEDTLS_DES_C)
  1255. static int des_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  1256. const unsigned char *input, unsigned char *output)
  1257. {
  1258. ((void) operation);
  1259. return mbedtls_des_crypt_ecb((mbedtls_des_context *) ctx, input, output);
  1260. }
  1261. static int des3_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  1262. const unsigned char *input, unsigned char *output)
  1263. {
  1264. ((void) operation);
  1265. return mbedtls_des3_crypt_ecb((mbedtls_des3_context *) ctx, input, output);
  1266. }
  1267. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1268. static int des_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
  1269. unsigned char *iv, const unsigned char *input, unsigned char *output)
  1270. {
  1271. return mbedtls_des_crypt_cbc((mbedtls_des_context *) ctx, operation, length, iv, input,
  1272. output);
  1273. }
  1274. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1275. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1276. static int des3_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length,
  1277. unsigned char *iv, const unsigned char *input, unsigned char *output)
  1278. {
  1279. return mbedtls_des3_crypt_cbc((mbedtls_des3_context *) ctx, operation, length, iv, input,
  1280. output);
  1281. }
  1282. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1283. static int des_setkey_dec_wrap(void *ctx, const unsigned char *key,
  1284. unsigned int key_bitlen)
  1285. {
  1286. ((void) key_bitlen);
  1287. return mbedtls_des_setkey_dec((mbedtls_des_context *) ctx, key);
  1288. }
  1289. static int des_setkey_enc_wrap(void *ctx, const unsigned char *key,
  1290. unsigned int key_bitlen)
  1291. {
  1292. ((void) key_bitlen);
  1293. return mbedtls_des_setkey_enc((mbedtls_des_context *) ctx, key);
  1294. }
  1295. static int des3_set2key_dec_wrap(void *ctx, const unsigned char *key,
  1296. unsigned int key_bitlen)
  1297. {
  1298. ((void) key_bitlen);
  1299. return mbedtls_des3_set2key_dec((mbedtls_des3_context *) ctx, key);
  1300. }
  1301. static int des3_set2key_enc_wrap(void *ctx, const unsigned char *key,
  1302. unsigned int key_bitlen)
  1303. {
  1304. ((void) key_bitlen);
  1305. return mbedtls_des3_set2key_enc((mbedtls_des3_context *) ctx, key);
  1306. }
  1307. static int des3_set3key_dec_wrap(void *ctx, const unsigned char *key,
  1308. unsigned int key_bitlen)
  1309. {
  1310. ((void) key_bitlen);
  1311. return mbedtls_des3_set3key_dec((mbedtls_des3_context *) ctx, key);
  1312. }
  1313. static int des3_set3key_enc_wrap(void *ctx, const unsigned char *key,
  1314. unsigned int key_bitlen)
  1315. {
  1316. ((void) key_bitlen);
  1317. return mbedtls_des3_set3key_enc((mbedtls_des3_context *) ctx, key);
  1318. }
  1319. static void *des_ctx_alloc(void)
  1320. {
  1321. mbedtls_des_context *des = mbedtls_calloc(1, sizeof(mbedtls_des_context));
  1322. if (des == NULL) {
  1323. return NULL;
  1324. }
  1325. mbedtls_des_init(des);
  1326. return des;
  1327. }
  1328. static void des_ctx_free(void *ctx)
  1329. {
  1330. mbedtls_des_free((mbedtls_des_context *) ctx);
  1331. mbedtls_free(ctx);
  1332. }
  1333. static void *des3_ctx_alloc(void)
  1334. {
  1335. mbedtls_des3_context *des3;
  1336. des3 = mbedtls_calloc(1, sizeof(mbedtls_des3_context));
  1337. if (des3 == NULL) {
  1338. return NULL;
  1339. }
  1340. mbedtls_des3_init(des3);
  1341. return des3;
  1342. }
  1343. static void des3_ctx_free(void *ctx)
  1344. {
  1345. mbedtls_des3_free((mbedtls_des3_context *) ctx);
  1346. mbedtls_free(ctx);
  1347. }
  1348. static const mbedtls_cipher_base_t des_info = {
  1349. MBEDTLS_CIPHER_ID_DES,
  1350. des_crypt_ecb_wrap,
  1351. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1352. des_crypt_cbc_wrap,
  1353. #endif
  1354. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1355. NULL,
  1356. #endif
  1357. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1358. NULL,
  1359. #endif
  1360. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1361. NULL,
  1362. #endif
  1363. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1364. NULL,
  1365. #endif
  1366. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1367. NULL,
  1368. #endif
  1369. des_setkey_enc_wrap,
  1370. des_setkey_dec_wrap,
  1371. des_ctx_alloc,
  1372. des_ctx_free
  1373. };
  1374. static const mbedtls_cipher_info_t des_ecb_info = {
  1375. MBEDTLS_CIPHER_DES_ECB,
  1376. MBEDTLS_MODE_ECB,
  1377. MBEDTLS_KEY_LENGTH_DES,
  1378. "DES-ECB",
  1379. 0,
  1380. 0,
  1381. 8,
  1382. &des_info
  1383. };
  1384. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1385. static const mbedtls_cipher_info_t des_cbc_info = {
  1386. MBEDTLS_CIPHER_DES_CBC,
  1387. MBEDTLS_MODE_CBC,
  1388. MBEDTLS_KEY_LENGTH_DES,
  1389. "DES-CBC",
  1390. 8,
  1391. 0,
  1392. 8,
  1393. &des_info
  1394. };
  1395. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1396. static const mbedtls_cipher_base_t des_ede_info = {
  1397. MBEDTLS_CIPHER_ID_DES,
  1398. des3_crypt_ecb_wrap,
  1399. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1400. des3_crypt_cbc_wrap,
  1401. #endif
  1402. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1403. NULL,
  1404. #endif
  1405. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1406. NULL,
  1407. #endif
  1408. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1409. NULL,
  1410. #endif
  1411. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1412. NULL,
  1413. #endif
  1414. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1415. NULL,
  1416. #endif
  1417. des3_set2key_enc_wrap,
  1418. des3_set2key_dec_wrap,
  1419. des3_ctx_alloc,
  1420. des3_ctx_free
  1421. };
  1422. static const mbedtls_cipher_info_t des_ede_ecb_info = {
  1423. MBEDTLS_CIPHER_DES_EDE_ECB,
  1424. MBEDTLS_MODE_ECB,
  1425. MBEDTLS_KEY_LENGTH_DES_EDE,
  1426. "DES-EDE-ECB",
  1427. 0,
  1428. 0,
  1429. 8,
  1430. &des_ede_info
  1431. };
  1432. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1433. static const mbedtls_cipher_info_t des_ede_cbc_info = {
  1434. MBEDTLS_CIPHER_DES_EDE_CBC,
  1435. MBEDTLS_MODE_CBC,
  1436. MBEDTLS_KEY_LENGTH_DES_EDE,
  1437. "DES-EDE-CBC",
  1438. 8,
  1439. 0,
  1440. 8,
  1441. &des_ede_info
  1442. };
  1443. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1444. static const mbedtls_cipher_base_t des_ede3_info = {
  1445. MBEDTLS_CIPHER_ID_3DES,
  1446. des3_crypt_ecb_wrap,
  1447. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1448. des3_crypt_cbc_wrap,
  1449. #endif
  1450. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1451. NULL,
  1452. #endif
  1453. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1454. NULL,
  1455. #endif
  1456. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1457. NULL,
  1458. #endif
  1459. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1460. NULL,
  1461. #endif
  1462. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1463. NULL,
  1464. #endif
  1465. des3_set3key_enc_wrap,
  1466. des3_set3key_dec_wrap,
  1467. des3_ctx_alloc,
  1468. des3_ctx_free
  1469. };
  1470. static const mbedtls_cipher_info_t des_ede3_ecb_info = {
  1471. MBEDTLS_CIPHER_DES_EDE3_ECB,
  1472. MBEDTLS_MODE_ECB,
  1473. MBEDTLS_KEY_LENGTH_DES_EDE3,
  1474. "DES-EDE3-ECB",
  1475. 0,
  1476. 0,
  1477. 8,
  1478. &des_ede3_info
  1479. };
  1480. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1481. static const mbedtls_cipher_info_t des_ede3_cbc_info = {
  1482. MBEDTLS_CIPHER_DES_EDE3_CBC,
  1483. MBEDTLS_MODE_CBC,
  1484. MBEDTLS_KEY_LENGTH_DES_EDE3,
  1485. "DES-EDE3-CBC",
  1486. 8,
  1487. 0,
  1488. 8,
  1489. &des_ede3_info
  1490. };
  1491. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1492. #endif /* MBEDTLS_DES_C */
  1493. #if defined(MBEDTLS_BLOWFISH_C)
  1494. static int blowfish_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
  1495. const unsigned char *input, unsigned char *output)
  1496. {
  1497. return mbedtls_blowfish_crypt_ecb((mbedtls_blowfish_context *) ctx, operation, input,
  1498. output);
  1499. }
  1500. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1501. static int blowfish_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation,
  1502. size_t length, unsigned char *iv, const unsigned char *input,
  1503. unsigned char *output)
  1504. {
  1505. return mbedtls_blowfish_crypt_cbc((mbedtls_blowfish_context *) ctx, operation, length, iv,
  1506. input, output);
  1507. }
  1508. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1509. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1510. static int blowfish_crypt_cfb64_wrap(void *ctx, mbedtls_operation_t operation,
  1511. size_t length, size_t *iv_off, unsigned char *iv,
  1512. const unsigned char *input, unsigned char *output)
  1513. {
  1514. return mbedtls_blowfish_crypt_cfb64((mbedtls_blowfish_context *) ctx, operation, length,
  1515. iv_off, iv, input, output);
  1516. }
  1517. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  1518. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1519. static int blowfish_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
  1520. unsigned char *nonce_counter, unsigned char *stream_block,
  1521. const unsigned char *input, unsigned char *output)
  1522. {
  1523. return mbedtls_blowfish_crypt_ctr((mbedtls_blowfish_context *) ctx, length, nc_off,
  1524. nonce_counter, stream_block, input, output);
  1525. }
  1526. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  1527. static int blowfish_setkey_wrap(void *ctx, const unsigned char *key,
  1528. unsigned int key_bitlen)
  1529. {
  1530. return mbedtls_blowfish_setkey((mbedtls_blowfish_context *) ctx, key, key_bitlen);
  1531. }
  1532. static void *blowfish_ctx_alloc(void)
  1533. {
  1534. mbedtls_blowfish_context *ctx;
  1535. ctx = mbedtls_calloc(1, sizeof(mbedtls_blowfish_context));
  1536. if (ctx == NULL) {
  1537. return NULL;
  1538. }
  1539. mbedtls_blowfish_init(ctx);
  1540. return ctx;
  1541. }
  1542. static void blowfish_ctx_free(void *ctx)
  1543. {
  1544. mbedtls_blowfish_free((mbedtls_blowfish_context *) ctx);
  1545. mbedtls_free(ctx);
  1546. }
  1547. static const mbedtls_cipher_base_t blowfish_info = {
  1548. MBEDTLS_CIPHER_ID_BLOWFISH,
  1549. blowfish_crypt_ecb_wrap,
  1550. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1551. blowfish_crypt_cbc_wrap,
  1552. #endif
  1553. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1554. blowfish_crypt_cfb64_wrap,
  1555. #endif
  1556. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1557. NULL,
  1558. #endif
  1559. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1560. blowfish_crypt_ctr_wrap,
  1561. #endif
  1562. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1563. NULL,
  1564. #endif
  1565. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1566. NULL,
  1567. #endif
  1568. blowfish_setkey_wrap,
  1569. blowfish_setkey_wrap,
  1570. blowfish_ctx_alloc,
  1571. blowfish_ctx_free
  1572. };
  1573. static const mbedtls_cipher_info_t blowfish_ecb_info = {
  1574. MBEDTLS_CIPHER_BLOWFISH_ECB,
  1575. MBEDTLS_MODE_ECB,
  1576. 128,
  1577. "BLOWFISH-ECB",
  1578. 0,
  1579. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1580. 8,
  1581. &blowfish_info
  1582. };
  1583. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1584. static const mbedtls_cipher_info_t blowfish_cbc_info = {
  1585. MBEDTLS_CIPHER_BLOWFISH_CBC,
  1586. MBEDTLS_MODE_CBC,
  1587. 128,
  1588. "BLOWFISH-CBC",
  1589. 8,
  1590. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1591. 8,
  1592. &blowfish_info
  1593. };
  1594. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1595. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1596. static const mbedtls_cipher_info_t blowfish_cfb64_info = {
  1597. MBEDTLS_CIPHER_BLOWFISH_CFB64,
  1598. MBEDTLS_MODE_CFB,
  1599. 128,
  1600. "BLOWFISH-CFB64",
  1601. 8,
  1602. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1603. 8,
  1604. &blowfish_info
  1605. };
  1606. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  1607. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1608. static const mbedtls_cipher_info_t blowfish_ctr_info = {
  1609. MBEDTLS_CIPHER_BLOWFISH_CTR,
  1610. MBEDTLS_MODE_CTR,
  1611. 128,
  1612. "BLOWFISH-CTR",
  1613. 8,
  1614. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1615. 8,
  1616. &blowfish_info
  1617. };
  1618. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  1619. #endif /* MBEDTLS_BLOWFISH_C */
  1620. #if defined(MBEDTLS_ARC4_C)
  1621. static int arc4_crypt_stream_wrap(void *ctx, size_t length,
  1622. const unsigned char *input,
  1623. unsigned char *output)
  1624. {
  1625. return mbedtls_arc4_crypt((mbedtls_arc4_context *) ctx, length, input, output);
  1626. }
  1627. static int arc4_setkey_wrap(void *ctx, const unsigned char *key,
  1628. unsigned int key_bitlen)
  1629. {
  1630. /* we get key_bitlen in bits, arc4 expects it in bytes */
  1631. if (key_bitlen % 8 != 0) {
  1632. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1633. }
  1634. mbedtls_arc4_setup((mbedtls_arc4_context *) ctx, key, key_bitlen / 8);
  1635. return 0;
  1636. }
  1637. static void *arc4_ctx_alloc(void)
  1638. {
  1639. mbedtls_arc4_context *ctx;
  1640. ctx = mbedtls_calloc(1, sizeof(mbedtls_arc4_context));
  1641. if (ctx == NULL) {
  1642. return NULL;
  1643. }
  1644. mbedtls_arc4_init(ctx);
  1645. return ctx;
  1646. }
  1647. static void arc4_ctx_free(void *ctx)
  1648. {
  1649. mbedtls_arc4_free((mbedtls_arc4_context *) ctx);
  1650. mbedtls_free(ctx);
  1651. }
  1652. static const mbedtls_cipher_base_t arc4_base_info = {
  1653. MBEDTLS_CIPHER_ID_ARC4,
  1654. NULL,
  1655. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1656. NULL,
  1657. #endif
  1658. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1659. NULL,
  1660. #endif
  1661. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1662. NULL,
  1663. #endif
  1664. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1665. NULL,
  1666. #endif
  1667. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1668. NULL,
  1669. #endif
  1670. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1671. arc4_crypt_stream_wrap,
  1672. #endif
  1673. arc4_setkey_wrap,
  1674. arc4_setkey_wrap,
  1675. arc4_ctx_alloc,
  1676. arc4_ctx_free
  1677. };
  1678. static const mbedtls_cipher_info_t arc4_128_info = {
  1679. MBEDTLS_CIPHER_ARC4_128,
  1680. MBEDTLS_MODE_STREAM,
  1681. 128,
  1682. "ARC4-128",
  1683. 0,
  1684. 0,
  1685. 1,
  1686. &arc4_base_info
  1687. };
  1688. #endif /* MBEDTLS_ARC4_C */
  1689. #if defined(MBEDTLS_CHACHA20_C)
  1690. static int chacha20_setkey_wrap(void *ctx, const unsigned char *key,
  1691. unsigned int key_bitlen)
  1692. {
  1693. if (key_bitlen != 256U) {
  1694. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1695. }
  1696. if (0 != mbedtls_chacha20_setkey((mbedtls_chacha20_context *) ctx, key)) {
  1697. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1698. }
  1699. return 0;
  1700. }
  1701. static int chacha20_stream_wrap(void *ctx, size_t length,
  1702. const unsigned char *input,
  1703. unsigned char *output)
  1704. {
  1705. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  1706. ret = mbedtls_chacha20_update(ctx, length, input, output);
  1707. if (ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) {
  1708. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1709. }
  1710. return ret;
  1711. }
  1712. static void *chacha20_ctx_alloc(void)
  1713. {
  1714. mbedtls_chacha20_context *ctx;
  1715. ctx = mbedtls_calloc(1, sizeof(mbedtls_chacha20_context));
  1716. if (ctx == NULL) {
  1717. return NULL;
  1718. }
  1719. mbedtls_chacha20_init(ctx);
  1720. return ctx;
  1721. }
  1722. static void chacha20_ctx_free(void *ctx)
  1723. {
  1724. mbedtls_chacha20_free((mbedtls_chacha20_context *) ctx);
  1725. mbedtls_free(ctx);
  1726. }
  1727. static const mbedtls_cipher_base_t chacha20_base_info = {
  1728. MBEDTLS_CIPHER_ID_CHACHA20,
  1729. NULL,
  1730. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1731. NULL,
  1732. #endif
  1733. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1734. NULL,
  1735. #endif
  1736. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1737. NULL,
  1738. #endif
  1739. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1740. NULL,
  1741. #endif
  1742. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1743. NULL,
  1744. #endif
  1745. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1746. chacha20_stream_wrap,
  1747. #endif
  1748. chacha20_setkey_wrap,
  1749. chacha20_setkey_wrap,
  1750. chacha20_ctx_alloc,
  1751. chacha20_ctx_free
  1752. };
  1753. static const mbedtls_cipher_info_t chacha20_info = {
  1754. MBEDTLS_CIPHER_CHACHA20,
  1755. MBEDTLS_MODE_STREAM,
  1756. 256,
  1757. "CHACHA20",
  1758. 12,
  1759. 0,
  1760. 1,
  1761. &chacha20_base_info
  1762. };
  1763. #endif /* MBEDTLS_CHACHA20_C */
  1764. #if defined(MBEDTLS_CHACHAPOLY_C)
  1765. static int chachapoly_setkey_wrap(void *ctx,
  1766. const unsigned char *key,
  1767. unsigned int key_bitlen)
  1768. {
  1769. if (key_bitlen != 256U) {
  1770. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1771. }
  1772. if (0 != mbedtls_chachapoly_setkey((mbedtls_chachapoly_context *) ctx, key)) {
  1773. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  1774. }
  1775. return 0;
  1776. }
  1777. static void *chachapoly_ctx_alloc(void)
  1778. {
  1779. mbedtls_chachapoly_context *ctx;
  1780. ctx = mbedtls_calloc(1, sizeof(mbedtls_chachapoly_context));
  1781. if (ctx == NULL) {
  1782. return NULL;
  1783. }
  1784. mbedtls_chachapoly_init(ctx);
  1785. return ctx;
  1786. }
  1787. static void chachapoly_ctx_free(void *ctx)
  1788. {
  1789. mbedtls_chachapoly_free((mbedtls_chachapoly_context *) ctx);
  1790. mbedtls_free(ctx);
  1791. }
  1792. static const mbedtls_cipher_base_t chachapoly_base_info = {
  1793. MBEDTLS_CIPHER_ID_CHACHA20,
  1794. NULL,
  1795. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1796. NULL,
  1797. #endif
  1798. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1799. NULL,
  1800. #endif
  1801. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1802. NULL,
  1803. #endif
  1804. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1805. NULL,
  1806. #endif
  1807. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1808. NULL,
  1809. #endif
  1810. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1811. NULL,
  1812. #endif
  1813. chachapoly_setkey_wrap,
  1814. chachapoly_setkey_wrap,
  1815. chachapoly_ctx_alloc,
  1816. chachapoly_ctx_free
  1817. };
  1818. static const mbedtls_cipher_info_t chachapoly_info = {
  1819. MBEDTLS_CIPHER_CHACHA20_POLY1305,
  1820. MBEDTLS_MODE_CHACHAPOLY,
  1821. 256,
  1822. "CHACHA20-POLY1305",
  1823. 12,
  1824. 0,
  1825. 1,
  1826. &chachapoly_base_info
  1827. };
  1828. #endif /* MBEDTLS_CHACHAPOLY_C */
  1829. #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
  1830. static int null_crypt_stream(void *ctx, size_t length,
  1831. const unsigned char *input,
  1832. unsigned char *output)
  1833. {
  1834. ((void) ctx);
  1835. memmove(output, input, length);
  1836. return 0;
  1837. }
  1838. static int null_setkey(void *ctx, const unsigned char *key,
  1839. unsigned int key_bitlen)
  1840. {
  1841. ((void) ctx);
  1842. ((void) key);
  1843. ((void) key_bitlen);
  1844. return 0;
  1845. }
  1846. static void *null_ctx_alloc(void)
  1847. {
  1848. return (void *) 1;
  1849. }
  1850. static void null_ctx_free(void *ctx)
  1851. {
  1852. ((void) ctx);
  1853. }
  1854. static const mbedtls_cipher_base_t null_base_info = {
  1855. MBEDTLS_CIPHER_ID_NULL,
  1856. NULL,
  1857. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1858. NULL,
  1859. #endif
  1860. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1861. NULL,
  1862. #endif
  1863. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1864. NULL,
  1865. #endif
  1866. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1867. NULL,
  1868. #endif
  1869. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1870. NULL,
  1871. #endif
  1872. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1873. null_crypt_stream,
  1874. #endif
  1875. null_setkey,
  1876. null_setkey,
  1877. null_ctx_alloc,
  1878. null_ctx_free
  1879. };
  1880. static const mbedtls_cipher_info_t null_cipher_info = {
  1881. MBEDTLS_CIPHER_NULL,
  1882. MBEDTLS_MODE_STREAM,
  1883. 0,
  1884. "NULL",
  1885. 0,
  1886. 0,
  1887. 1,
  1888. &null_base_info
  1889. };
  1890. #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
  1891. #if defined(MBEDTLS_NIST_KW_C)
  1892. static void *kw_ctx_alloc(void)
  1893. {
  1894. void *ctx = mbedtls_calloc(1, sizeof(mbedtls_nist_kw_context));
  1895. if (ctx != NULL) {
  1896. mbedtls_nist_kw_init((mbedtls_nist_kw_context *) ctx);
  1897. }
  1898. return ctx;
  1899. }
  1900. static void kw_ctx_free(void *ctx)
  1901. {
  1902. mbedtls_nist_kw_free(ctx);
  1903. mbedtls_free(ctx);
  1904. }
  1905. static int kw_aes_setkey_wrap(void *ctx, const unsigned char *key,
  1906. unsigned int key_bitlen)
  1907. {
  1908. return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx,
  1909. MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1);
  1910. }
  1911. static int kw_aes_setkey_unwrap(void *ctx, const unsigned char *key,
  1912. unsigned int key_bitlen)
  1913. {
  1914. return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx,
  1915. MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0);
  1916. }
  1917. static const mbedtls_cipher_base_t kw_aes_info = {
  1918. MBEDTLS_CIPHER_ID_AES,
  1919. NULL,
  1920. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1921. NULL,
  1922. #endif
  1923. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1924. NULL,
  1925. #endif
  1926. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1927. NULL,
  1928. #endif
  1929. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1930. NULL,
  1931. #endif
  1932. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1933. NULL,
  1934. #endif
  1935. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1936. NULL,
  1937. #endif
  1938. kw_aes_setkey_wrap,
  1939. kw_aes_setkey_unwrap,
  1940. kw_ctx_alloc,
  1941. kw_ctx_free,
  1942. };
  1943. static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
  1944. MBEDTLS_CIPHER_AES_128_KW,
  1945. MBEDTLS_MODE_KW,
  1946. 128,
  1947. "AES-128-KW",
  1948. 0,
  1949. 0,
  1950. 16,
  1951. &kw_aes_info
  1952. };
  1953. static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
  1954. MBEDTLS_CIPHER_AES_192_KW,
  1955. MBEDTLS_MODE_KW,
  1956. 192,
  1957. "AES-192-KW",
  1958. 0,
  1959. 0,
  1960. 16,
  1961. &kw_aes_info
  1962. };
  1963. static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
  1964. MBEDTLS_CIPHER_AES_256_KW,
  1965. MBEDTLS_MODE_KW,
  1966. 256,
  1967. "AES-256-KW",
  1968. 0,
  1969. 0,
  1970. 16,
  1971. &kw_aes_info
  1972. };
  1973. static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
  1974. MBEDTLS_CIPHER_AES_128_KWP,
  1975. MBEDTLS_MODE_KWP,
  1976. 128,
  1977. "AES-128-KWP",
  1978. 0,
  1979. 0,
  1980. 16,
  1981. &kw_aes_info
  1982. };
  1983. static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
  1984. MBEDTLS_CIPHER_AES_192_KWP,
  1985. MBEDTLS_MODE_KWP,
  1986. 192,
  1987. "AES-192-KWP",
  1988. 0,
  1989. 0,
  1990. 16,
  1991. &kw_aes_info
  1992. };
  1993. static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
  1994. MBEDTLS_CIPHER_AES_256_KWP,
  1995. MBEDTLS_MODE_KWP,
  1996. 256,
  1997. "AES-256-KWP",
  1998. 0,
  1999. 0,
  2000. 16,
  2001. &kw_aes_info
  2002. };
  2003. #endif /* MBEDTLS_NIST_KW_C */
  2004. const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
  2005. {
  2006. #if defined(MBEDTLS_AES_C)
  2007. { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
  2008. { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
  2009. { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
  2010. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2011. { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
  2012. { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
  2013. { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
  2014. #endif
  2015. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2016. { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
  2017. { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
  2018. { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
  2019. #endif
  2020. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  2021. { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
  2022. { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
  2023. { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
  2024. #endif
  2025. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2026. { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
  2027. { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
  2028. { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
  2029. #endif
  2030. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  2031. { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
  2032. { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
  2033. #endif
  2034. #if defined(MBEDTLS_GCM_C)
  2035. { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
  2036. { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
  2037. { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
  2038. #endif
  2039. #if defined(MBEDTLS_CCM_C)
  2040. { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
  2041. { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
  2042. { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
  2043. #endif
  2044. #endif /* MBEDTLS_AES_C */
  2045. #if defined(MBEDTLS_ARC4_C)
  2046. { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
  2047. #endif
  2048. #if defined(MBEDTLS_BLOWFISH_C)
  2049. { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
  2050. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2051. { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
  2052. #endif
  2053. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2054. { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
  2055. #endif
  2056. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2057. { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
  2058. #endif
  2059. #endif /* MBEDTLS_BLOWFISH_C */
  2060. #if defined(MBEDTLS_CAMELLIA_C)
  2061. { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
  2062. { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
  2063. { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
  2064. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2065. { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
  2066. { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
  2067. { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
  2068. #endif
  2069. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2070. { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
  2071. { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
  2072. { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
  2073. #endif
  2074. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2075. { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
  2076. { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
  2077. { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
  2078. #endif
  2079. #if defined(MBEDTLS_GCM_C)
  2080. { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
  2081. { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
  2082. { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
  2083. #endif
  2084. #if defined(MBEDTLS_CCM_C)
  2085. { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
  2086. { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
  2087. { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
  2088. #endif
  2089. #endif /* MBEDTLS_CAMELLIA_C */
  2090. #if defined(MBEDTLS_ARIA_C)
  2091. { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
  2092. { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
  2093. { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
  2094. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2095. { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
  2096. { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
  2097. { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
  2098. #endif
  2099. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2100. { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
  2101. { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
  2102. { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
  2103. #endif
  2104. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2105. { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
  2106. { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
  2107. { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
  2108. #endif
  2109. #if defined(MBEDTLS_GCM_C)
  2110. { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
  2111. { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
  2112. { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
  2113. #endif
  2114. #if defined(MBEDTLS_CCM_C)
  2115. { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
  2116. { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
  2117. { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
  2118. #endif
  2119. #endif /* MBEDTLS_ARIA_C */
  2120. #if defined(MBEDTLS_DES_C)
  2121. { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
  2122. { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
  2123. { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
  2124. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2125. { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
  2126. { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
  2127. { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
  2128. #endif
  2129. #endif /* MBEDTLS_DES_C */
  2130. #if defined(MBEDTLS_CHACHA20_C)
  2131. { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
  2132. #endif
  2133. #if defined(MBEDTLS_CHACHAPOLY_C)
  2134. { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
  2135. #endif
  2136. #if defined(MBEDTLS_NIST_KW_C)
  2137. { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
  2138. { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
  2139. { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
  2140. { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
  2141. { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
  2142. { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
  2143. #endif
  2144. #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
  2145. { MBEDTLS_CIPHER_NULL, &null_cipher_info },
  2146. #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
  2147. { MBEDTLS_CIPHER_NONE, NULL }
  2148. };
  2149. #define NUM_CIPHERS (sizeof(mbedtls_cipher_definitions) / \
  2150. sizeof(mbedtls_cipher_definitions[0]))
  2151. int mbedtls_cipher_supported[NUM_CIPHERS];
  2152. #endif /* MBEDTLS_CIPHER_C */