cipher_wrap.c 55 KB

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