cipher_wrap.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  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
  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. #if defined(MBEDTLS_PLATFORM_C)
  64. #include "mbedtls/platform.h"
  65. #else
  66. #include <stdlib.h>
  67. #define mbedtls_calloc calloc
  68. #define mbedtls_free free
  69. #endif
  70. #if defined(MBEDTLS_GCM_C)
  71. /* shared by all GCM ciphers */
  72. static void *gcm_ctx_alloc( void )
  73. {
  74. void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
  75. if( ctx != NULL )
  76. mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
  77. return( ctx );
  78. }
  79. static void gcm_ctx_free( void *ctx )
  80. {
  81. mbedtls_gcm_free( ctx );
  82. mbedtls_free( ctx );
  83. }
  84. #endif /* MBEDTLS_GCM_C */
  85. #if defined(MBEDTLS_CCM_C)
  86. /* shared by all CCM ciphers */
  87. static void *ccm_ctx_alloc( void )
  88. {
  89. void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
  90. if( ctx != NULL )
  91. mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
  92. return( ctx );
  93. }
  94. static void ccm_ctx_free( void *ctx )
  95. {
  96. mbedtls_ccm_free( ctx );
  97. mbedtls_free( ctx );
  98. }
  99. #endif /* MBEDTLS_CCM_C */
  100. #if defined(MBEDTLS_AES_C)
  101. static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
  102. const unsigned char *input, unsigned char *output )
  103. {
  104. return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
  105. }
  106. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  107. static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
  108. unsigned char *iv, const unsigned char *input, unsigned char *output )
  109. {
  110. return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
  111. output );
  112. }
  113. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  114. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  115. static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
  116. size_t length, size_t *iv_off, unsigned char *iv,
  117. const unsigned char *input, unsigned char *output )
  118. {
  119. return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
  120. input, output );
  121. }
  122. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  123. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  124. static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
  125. unsigned char *iv, const unsigned char *input, unsigned char *output )
  126. {
  127. return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
  128. iv, input, output );
  129. }
  130. #endif /* MBEDTLS_CIPHER_MODE_OFB */
  131. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  132. static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
  133. unsigned char *nonce_counter, unsigned char *stream_block,
  134. const unsigned char *input, unsigned char *output )
  135. {
  136. return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
  137. stream_block, input, output );
  138. }
  139. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  140. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  141. static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
  142. size_t length,
  143. const unsigned char data_unit[16],
  144. const unsigned char *input,
  145. unsigned char *output )
  146. {
  147. mbedtls_aes_xts_context *xts_ctx = ctx;
  148. int mode;
  149. switch( operation )
  150. {
  151. case MBEDTLS_ENCRYPT:
  152. mode = MBEDTLS_AES_ENCRYPT;
  153. break;
  154. case MBEDTLS_DECRYPT:
  155. mode = MBEDTLS_AES_DECRYPT;
  156. break;
  157. default:
  158. return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
  159. }
  160. return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
  161. data_unit, input, output );
  162. }
  163. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  164. static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
  165. unsigned int key_bitlen )
  166. {
  167. return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
  168. }
  169. static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
  170. unsigned int key_bitlen )
  171. {
  172. return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
  173. }
  174. static void * aes_ctx_alloc( void )
  175. {
  176. mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
  177. if( aes == NULL )
  178. return( NULL );
  179. mbedtls_aes_init( aes );
  180. return( aes );
  181. }
  182. static void aes_ctx_free( void *ctx )
  183. {
  184. mbedtls_aes_free( (mbedtls_aes_context *) ctx );
  185. mbedtls_free( ctx );
  186. }
  187. static const mbedtls_cipher_base_t aes_info = {
  188. MBEDTLS_CIPHER_ID_AES,
  189. aes_crypt_ecb_wrap,
  190. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  191. aes_crypt_cbc_wrap,
  192. #endif
  193. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  194. aes_crypt_cfb128_wrap,
  195. #endif
  196. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  197. aes_crypt_ofb_wrap,
  198. #endif
  199. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  200. aes_crypt_ctr_wrap,
  201. #endif
  202. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  203. NULL,
  204. #endif
  205. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  206. NULL,
  207. #endif
  208. aes_setkey_enc_wrap,
  209. aes_setkey_dec_wrap,
  210. aes_ctx_alloc,
  211. aes_ctx_free
  212. };
  213. static const mbedtls_cipher_info_t aes_128_ecb_info = {
  214. MBEDTLS_CIPHER_AES_128_ECB,
  215. MBEDTLS_MODE_ECB,
  216. 128,
  217. "AES-128-ECB",
  218. 0,
  219. 0,
  220. 16,
  221. &aes_info
  222. };
  223. static const mbedtls_cipher_info_t aes_192_ecb_info = {
  224. MBEDTLS_CIPHER_AES_192_ECB,
  225. MBEDTLS_MODE_ECB,
  226. 192,
  227. "AES-192-ECB",
  228. 0,
  229. 0,
  230. 16,
  231. &aes_info
  232. };
  233. static const mbedtls_cipher_info_t aes_256_ecb_info = {
  234. MBEDTLS_CIPHER_AES_256_ECB,
  235. MBEDTLS_MODE_ECB,
  236. 256,
  237. "AES-256-ECB",
  238. 0,
  239. 0,
  240. 16,
  241. &aes_info
  242. };
  243. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  244. static const mbedtls_cipher_info_t aes_128_cbc_info = {
  245. MBEDTLS_CIPHER_AES_128_CBC,
  246. MBEDTLS_MODE_CBC,
  247. 128,
  248. "AES-128-CBC",
  249. 16,
  250. 0,
  251. 16,
  252. &aes_info
  253. };
  254. static const mbedtls_cipher_info_t aes_192_cbc_info = {
  255. MBEDTLS_CIPHER_AES_192_CBC,
  256. MBEDTLS_MODE_CBC,
  257. 192,
  258. "AES-192-CBC",
  259. 16,
  260. 0,
  261. 16,
  262. &aes_info
  263. };
  264. static const mbedtls_cipher_info_t aes_256_cbc_info = {
  265. MBEDTLS_CIPHER_AES_256_CBC,
  266. MBEDTLS_MODE_CBC,
  267. 256,
  268. "AES-256-CBC",
  269. 16,
  270. 0,
  271. 16,
  272. &aes_info
  273. };
  274. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  275. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  276. static const mbedtls_cipher_info_t aes_128_cfb128_info = {
  277. MBEDTLS_CIPHER_AES_128_CFB128,
  278. MBEDTLS_MODE_CFB,
  279. 128,
  280. "AES-128-CFB128",
  281. 16,
  282. 0,
  283. 16,
  284. &aes_info
  285. };
  286. static const mbedtls_cipher_info_t aes_192_cfb128_info = {
  287. MBEDTLS_CIPHER_AES_192_CFB128,
  288. MBEDTLS_MODE_CFB,
  289. 192,
  290. "AES-192-CFB128",
  291. 16,
  292. 0,
  293. 16,
  294. &aes_info
  295. };
  296. static const mbedtls_cipher_info_t aes_256_cfb128_info = {
  297. MBEDTLS_CIPHER_AES_256_CFB128,
  298. MBEDTLS_MODE_CFB,
  299. 256,
  300. "AES-256-CFB128",
  301. 16,
  302. 0,
  303. 16,
  304. &aes_info
  305. };
  306. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  307. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  308. static const mbedtls_cipher_info_t aes_128_ofb_info = {
  309. MBEDTLS_CIPHER_AES_128_OFB,
  310. MBEDTLS_MODE_OFB,
  311. 128,
  312. "AES-128-OFB",
  313. 16,
  314. 0,
  315. 16,
  316. &aes_info
  317. };
  318. static const mbedtls_cipher_info_t aes_192_ofb_info = {
  319. MBEDTLS_CIPHER_AES_192_OFB,
  320. MBEDTLS_MODE_OFB,
  321. 192,
  322. "AES-192-OFB",
  323. 16,
  324. 0,
  325. 16,
  326. &aes_info
  327. };
  328. static const mbedtls_cipher_info_t aes_256_ofb_info = {
  329. MBEDTLS_CIPHER_AES_256_OFB,
  330. MBEDTLS_MODE_OFB,
  331. 256,
  332. "AES-256-OFB",
  333. 16,
  334. 0,
  335. 16,
  336. &aes_info
  337. };
  338. #endif /* MBEDTLS_CIPHER_MODE_OFB */
  339. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  340. static const mbedtls_cipher_info_t aes_128_ctr_info = {
  341. MBEDTLS_CIPHER_AES_128_CTR,
  342. MBEDTLS_MODE_CTR,
  343. 128,
  344. "AES-128-CTR",
  345. 16,
  346. 0,
  347. 16,
  348. &aes_info
  349. };
  350. static const mbedtls_cipher_info_t aes_192_ctr_info = {
  351. MBEDTLS_CIPHER_AES_192_CTR,
  352. MBEDTLS_MODE_CTR,
  353. 192,
  354. "AES-192-CTR",
  355. 16,
  356. 0,
  357. 16,
  358. &aes_info
  359. };
  360. static const mbedtls_cipher_info_t aes_256_ctr_info = {
  361. MBEDTLS_CIPHER_AES_256_CTR,
  362. MBEDTLS_MODE_CTR,
  363. 256,
  364. "AES-256-CTR",
  365. 16,
  366. 0,
  367. 16,
  368. &aes_info
  369. };
  370. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  371. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  372. static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
  373. unsigned int key_bitlen )
  374. {
  375. mbedtls_aes_xts_context *xts_ctx = ctx;
  376. return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
  377. }
  378. static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
  379. unsigned int key_bitlen )
  380. {
  381. mbedtls_aes_xts_context *xts_ctx = ctx;
  382. return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
  383. }
  384. static void *xts_aes_ctx_alloc( void )
  385. {
  386. mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
  387. if( xts_ctx != NULL )
  388. mbedtls_aes_xts_init( xts_ctx );
  389. return( xts_ctx );
  390. }
  391. static void xts_aes_ctx_free( void *ctx )
  392. {
  393. mbedtls_aes_xts_context *xts_ctx = ctx;
  394. if( xts_ctx == NULL )
  395. return;
  396. mbedtls_aes_xts_free( xts_ctx );
  397. mbedtls_free( xts_ctx );
  398. }
  399. static const mbedtls_cipher_base_t xts_aes_info = {
  400. MBEDTLS_CIPHER_ID_AES,
  401. NULL,
  402. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  403. NULL,
  404. #endif
  405. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  406. NULL,
  407. #endif
  408. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  409. NULL,
  410. #endif
  411. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  412. NULL,
  413. #endif
  414. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  415. aes_crypt_xts_wrap,
  416. #endif
  417. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  418. NULL,
  419. #endif
  420. xts_aes_setkey_enc_wrap,
  421. xts_aes_setkey_dec_wrap,
  422. xts_aes_ctx_alloc,
  423. xts_aes_ctx_free
  424. };
  425. static const mbedtls_cipher_info_t aes_128_xts_info = {
  426. MBEDTLS_CIPHER_AES_128_XTS,
  427. MBEDTLS_MODE_XTS,
  428. 256,
  429. "AES-128-XTS",
  430. 16,
  431. 0,
  432. 16,
  433. &xts_aes_info
  434. };
  435. static const mbedtls_cipher_info_t aes_256_xts_info = {
  436. MBEDTLS_CIPHER_AES_256_XTS,
  437. MBEDTLS_MODE_XTS,
  438. 512,
  439. "AES-256-XTS",
  440. 16,
  441. 0,
  442. 16,
  443. &xts_aes_info
  444. };
  445. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  446. #if defined(MBEDTLS_GCM_C)
  447. static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
  448. unsigned int key_bitlen )
  449. {
  450. return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
  451. key, key_bitlen );
  452. }
  453. static const mbedtls_cipher_base_t gcm_aes_info = {
  454. MBEDTLS_CIPHER_ID_AES,
  455. NULL,
  456. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  457. NULL,
  458. #endif
  459. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  460. NULL,
  461. #endif
  462. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  463. NULL,
  464. #endif
  465. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  466. NULL,
  467. #endif
  468. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  469. NULL,
  470. #endif
  471. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  472. NULL,
  473. #endif
  474. gcm_aes_setkey_wrap,
  475. gcm_aes_setkey_wrap,
  476. gcm_ctx_alloc,
  477. gcm_ctx_free,
  478. };
  479. static const mbedtls_cipher_info_t aes_128_gcm_info = {
  480. MBEDTLS_CIPHER_AES_128_GCM,
  481. MBEDTLS_MODE_GCM,
  482. 128,
  483. "AES-128-GCM",
  484. 12,
  485. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  486. 16,
  487. &gcm_aes_info
  488. };
  489. static const mbedtls_cipher_info_t aes_192_gcm_info = {
  490. MBEDTLS_CIPHER_AES_192_GCM,
  491. MBEDTLS_MODE_GCM,
  492. 192,
  493. "AES-192-GCM",
  494. 12,
  495. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  496. 16,
  497. &gcm_aes_info
  498. };
  499. static const mbedtls_cipher_info_t aes_256_gcm_info = {
  500. MBEDTLS_CIPHER_AES_256_GCM,
  501. MBEDTLS_MODE_GCM,
  502. 256,
  503. "AES-256-GCM",
  504. 12,
  505. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  506. 16,
  507. &gcm_aes_info
  508. };
  509. #endif /* MBEDTLS_GCM_C */
  510. #if defined(MBEDTLS_CCM_C)
  511. static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
  512. unsigned int key_bitlen )
  513. {
  514. return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
  515. key, key_bitlen );
  516. }
  517. static const mbedtls_cipher_base_t ccm_aes_info = {
  518. MBEDTLS_CIPHER_ID_AES,
  519. NULL,
  520. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  521. NULL,
  522. #endif
  523. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  524. NULL,
  525. #endif
  526. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  527. NULL,
  528. #endif
  529. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  530. NULL,
  531. #endif
  532. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  533. NULL,
  534. #endif
  535. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  536. NULL,
  537. #endif
  538. ccm_aes_setkey_wrap,
  539. ccm_aes_setkey_wrap,
  540. ccm_ctx_alloc,
  541. ccm_ctx_free,
  542. };
  543. static const mbedtls_cipher_info_t aes_128_ccm_info = {
  544. MBEDTLS_CIPHER_AES_128_CCM,
  545. MBEDTLS_MODE_CCM,
  546. 128,
  547. "AES-128-CCM",
  548. 12,
  549. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  550. 16,
  551. &ccm_aes_info
  552. };
  553. static const mbedtls_cipher_info_t aes_192_ccm_info = {
  554. MBEDTLS_CIPHER_AES_192_CCM,
  555. MBEDTLS_MODE_CCM,
  556. 192,
  557. "AES-192-CCM",
  558. 12,
  559. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  560. 16,
  561. &ccm_aes_info
  562. };
  563. static const mbedtls_cipher_info_t aes_256_ccm_info = {
  564. MBEDTLS_CIPHER_AES_256_CCM,
  565. MBEDTLS_MODE_CCM,
  566. 256,
  567. "AES-256-CCM",
  568. 12,
  569. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  570. 16,
  571. &ccm_aes_info
  572. };
  573. #endif /* MBEDTLS_CCM_C */
  574. #endif /* MBEDTLS_AES_C */
  575. #if defined(MBEDTLS_CAMELLIA_C)
  576. static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
  577. const unsigned char *input, unsigned char *output )
  578. {
  579. return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
  580. output );
  581. }
  582. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  583. static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
  584. size_t length, unsigned char *iv,
  585. const unsigned char *input, unsigned char *output )
  586. {
  587. return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
  588. input, output );
  589. }
  590. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  591. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  592. static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
  593. size_t length, size_t *iv_off, unsigned char *iv,
  594. const unsigned char *input, unsigned char *output )
  595. {
  596. return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
  597. iv_off, iv, input, output );
  598. }
  599. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  600. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  601. static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
  602. unsigned char *nonce_counter, unsigned char *stream_block,
  603. const unsigned char *input, unsigned char *output )
  604. {
  605. return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
  606. nonce_counter, stream_block, input, output );
  607. }
  608. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  609. static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
  610. unsigned int key_bitlen )
  611. {
  612. return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
  613. }
  614. static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
  615. unsigned int key_bitlen )
  616. {
  617. return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
  618. }
  619. static void * camellia_ctx_alloc( void )
  620. {
  621. mbedtls_camellia_context *ctx;
  622. ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
  623. if( ctx == NULL )
  624. return( NULL );
  625. mbedtls_camellia_init( ctx );
  626. return( ctx );
  627. }
  628. static void camellia_ctx_free( void *ctx )
  629. {
  630. mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
  631. mbedtls_free( ctx );
  632. }
  633. static const mbedtls_cipher_base_t camellia_info = {
  634. MBEDTLS_CIPHER_ID_CAMELLIA,
  635. camellia_crypt_ecb_wrap,
  636. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  637. camellia_crypt_cbc_wrap,
  638. #endif
  639. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  640. camellia_crypt_cfb128_wrap,
  641. #endif
  642. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  643. NULL,
  644. #endif
  645. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  646. camellia_crypt_ctr_wrap,
  647. #endif
  648. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  649. NULL,
  650. #endif
  651. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  652. NULL,
  653. #endif
  654. camellia_setkey_enc_wrap,
  655. camellia_setkey_dec_wrap,
  656. camellia_ctx_alloc,
  657. camellia_ctx_free
  658. };
  659. static const mbedtls_cipher_info_t camellia_128_ecb_info = {
  660. MBEDTLS_CIPHER_CAMELLIA_128_ECB,
  661. MBEDTLS_MODE_ECB,
  662. 128,
  663. "CAMELLIA-128-ECB",
  664. 0,
  665. 0,
  666. 16,
  667. &camellia_info
  668. };
  669. static const mbedtls_cipher_info_t camellia_192_ecb_info = {
  670. MBEDTLS_CIPHER_CAMELLIA_192_ECB,
  671. MBEDTLS_MODE_ECB,
  672. 192,
  673. "CAMELLIA-192-ECB",
  674. 0,
  675. 0,
  676. 16,
  677. &camellia_info
  678. };
  679. static const mbedtls_cipher_info_t camellia_256_ecb_info = {
  680. MBEDTLS_CIPHER_CAMELLIA_256_ECB,
  681. MBEDTLS_MODE_ECB,
  682. 256,
  683. "CAMELLIA-256-ECB",
  684. 0,
  685. 0,
  686. 16,
  687. &camellia_info
  688. };
  689. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  690. static const mbedtls_cipher_info_t camellia_128_cbc_info = {
  691. MBEDTLS_CIPHER_CAMELLIA_128_CBC,
  692. MBEDTLS_MODE_CBC,
  693. 128,
  694. "CAMELLIA-128-CBC",
  695. 16,
  696. 0,
  697. 16,
  698. &camellia_info
  699. };
  700. static const mbedtls_cipher_info_t camellia_192_cbc_info = {
  701. MBEDTLS_CIPHER_CAMELLIA_192_CBC,
  702. MBEDTLS_MODE_CBC,
  703. 192,
  704. "CAMELLIA-192-CBC",
  705. 16,
  706. 0,
  707. 16,
  708. &camellia_info
  709. };
  710. static const mbedtls_cipher_info_t camellia_256_cbc_info = {
  711. MBEDTLS_CIPHER_CAMELLIA_256_CBC,
  712. MBEDTLS_MODE_CBC,
  713. 256,
  714. "CAMELLIA-256-CBC",
  715. 16,
  716. 0,
  717. 16,
  718. &camellia_info
  719. };
  720. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  721. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  722. static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
  723. MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
  724. MBEDTLS_MODE_CFB,
  725. 128,
  726. "CAMELLIA-128-CFB128",
  727. 16,
  728. 0,
  729. 16,
  730. &camellia_info
  731. };
  732. static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
  733. MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
  734. MBEDTLS_MODE_CFB,
  735. 192,
  736. "CAMELLIA-192-CFB128",
  737. 16,
  738. 0,
  739. 16,
  740. &camellia_info
  741. };
  742. static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
  743. MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
  744. MBEDTLS_MODE_CFB,
  745. 256,
  746. "CAMELLIA-256-CFB128",
  747. 16,
  748. 0,
  749. 16,
  750. &camellia_info
  751. };
  752. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  753. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  754. static const mbedtls_cipher_info_t camellia_128_ctr_info = {
  755. MBEDTLS_CIPHER_CAMELLIA_128_CTR,
  756. MBEDTLS_MODE_CTR,
  757. 128,
  758. "CAMELLIA-128-CTR",
  759. 16,
  760. 0,
  761. 16,
  762. &camellia_info
  763. };
  764. static const mbedtls_cipher_info_t camellia_192_ctr_info = {
  765. MBEDTLS_CIPHER_CAMELLIA_192_CTR,
  766. MBEDTLS_MODE_CTR,
  767. 192,
  768. "CAMELLIA-192-CTR",
  769. 16,
  770. 0,
  771. 16,
  772. &camellia_info
  773. };
  774. static const mbedtls_cipher_info_t camellia_256_ctr_info = {
  775. MBEDTLS_CIPHER_CAMELLIA_256_CTR,
  776. MBEDTLS_MODE_CTR,
  777. 256,
  778. "CAMELLIA-256-CTR",
  779. 16,
  780. 0,
  781. 16,
  782. &camellia_info
  783. };
  784. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  785. #if defined(MBEDTLS_GCM_C)
  786. static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
  787. unsigned int key_bitlen )
  788. {
  789. return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
  790. key, key_bitlen );
  791. }
  792. static const mbedtls_cipher_base_t gcm_camellia_info = {
  793. MBEDTLS_CIPHER_ID_CAMELLIA,
  794. NULL,
  795. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  796. NULL,
  797. #endif
  798. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  799. NULL,
  800. #endif
  801. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  802. NULL,
  803. #endif
  804. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  805. NULL,
  806. #endif
  807. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  808. NULL,
  809. #endif
  810. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  811. NULL,
  812. #endif
  813. gcm_camellia_setkey_wrap,
  814. gcm_camellia_setkey_wrap,
  815. gcm_ctx_alloc,
  816. gcm_ctx_free,
  817. };
  818. static const mbedtls_cipher_info_t camellia_128_gcm_info = {
  819. MBEDTLS_CIPHER_CAMELLIA_128_GCM,
  820. MBEDTLS_MODE_GCM,
  821. 128,
  822. "CAMELLIA-128-GCM",
  823. 12,
  824. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  825. 16,
  826. &gcm_camellia_info
  827. };
  828. static const mbedtls_cipher_info_t camellia_192_gcm_info = {
  829. MBEDTLS_CIPHER_CAMELLIA_192_GCM,
  830. MBEDTLS_MODE_GCM,
  831. 192,
  832. "CAMELLIA-192-GCM",
  833. 12,
  834. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  835. 16,
  836. &gcm_camellia_info
  837. };
  838. static const mbedtls_cipher_info_t camellia_256_gcm_info = {
  839. MBEDTLS_CIPHER_CAMELLIA_256_GCM,
  840. MBEDTLS_MODE_GCM,
  841. 256,
  842. "CAMELLIA-256-GCM",
  843. 12,
  844. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  845. 16,
  846. &gcm_camellia_info
  847. };
  848. #endif /* MBEDTLS_GCM_C */
  849. #if defined(MBEDTLS_CCM_C)
  850. static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
  851. unsigned int key_bitlen )
  852. {
  853. return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
  854. key, key_bitlen );
  855. }
  856. static const mbedtls_cipher_base_t ccm_camellia_info = {
  857. MBEDTLS_CIPHER_ID_CAMELLIA,
  858. NULL,
  859. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  860. NULL,
  861. #endif
  862. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  863. NULL,
  864. #endif
  865. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  866. NULL,
  867. #endif
  868. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  869. NULL,
  870. #endif
  871. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  872. NULL,
  873. #endif
  874. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  875. NULL,
  876. #endif
  877. ccm_camellia_setkey_wrap,
  878. ccm_camellia_setkey_wrap,
  879. ccm_ctx_alloc,
  880. ccm_ctx_free,
  881. };
  882. static const mbedtls_cipher_info_t camellia_128_ccm_info = {
  883. MBEDTLS_CIPHER_CAMELLIA_128_CCM,
  884. MBEDTLS_MODE_CCM,
  885. 128,
  886. "CAMELLIA-128-CCM",
  887. 12,
  888. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  889. 16,
  890. &ccm_camellia_info
  891. };
  892. static const mbedtls_cipher_info_t camellia_192_ccm_info = {
  893. MBEDTLS_CIPHER_CAMELLIA_192_CCM,
  894. MBEDTLS_MODE_CCM,
  895. 192,
  896. "CAMELLIA-192-CCM",
  897. 12,
  898. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  899. 16,
  900. &ccm_camellia_info
  901. };
  902. static const mbedtls_cipher_info_t camellia_256_ccm_info = {
  903. MBEDTLS_CIPHER_CAMELLIA_256_CCM,
  904. MBEDTLS_MODE_CCM,
  905. 256,
  906. "CAMELLIA-256-CCM",
  907. 12,
  908. MBEDTLS_CIPHER_VARIABLE_IV_LEN,
  909. 16,
  910. &ccm_camellia_info
  911. };
  912. #endif /* MBEDTLS_CCM_C */
  913. #endif /* MBEDTLS_CAMELLIA_C */
  914. #if defined(MBEDTLS_ARIA_C)
  915. static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
  916. const unsigned char *input, unsigned char *output )
  917. {
  918. (void) operation;
  919. return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
  920. output );
  921. }
  922. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  923. static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
  924. size_t length, unsigned char *iv,
  925. const unsigned char *input, unsigned char *output )
  926. {
  927. return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
  928. input, output );
  929. }
  930. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  931. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  932. static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
  933. size_t length, size_t *iv_off, unsigned char *iv,
  934. const unsigned char *input, unsigned char *output )
  935. {
  936. return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
  937. iv_off, iv, input, output );
  938. }
  939. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  940. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  941. static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
  942. unsigned char *nonce_counter, unsigned char *stream_block,
  943. const unsigned char *input, unsigned char *output )
  944. {
  945. return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
  946. nonce_counter, stream_block, input, output );
  947. }
  948. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  949. static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
  950. unsigned int key_bitlen )
  951. {
  952. return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
  953. }
  954. static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
  955. unsigned int key_bitlen )
  956. {
  957. return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
  958. }
  959. static void * aria_ctx_alloc( void )
  960. {
  961. mbedtls_aria_context *ctx;
  962. ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
  963. if( ctx == NULL )
  964. return( NULL );
  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. mbedtls_des_init( des );
  1325. return( des );
  1326. }
  1327. static void des_ctx_free( void *ctx )
  1328. {
  1329. mbedtls_des_free( (mbedtls_des_context *) ctx );
  1330. mbedtls_free( ctx );
  1331. }
  1332. static void * des3_ctx_alloc( void )
  1333. {
  1334. mbedtls_des3_context *des3;
  1335. des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
  1336. if( des3 == NULL )
  1337. return( NULL );
  1338. mbedtls_des3_init( des3 );
  1339. return( des3 );
  1340. }
  1341. static void des3_ctx_free( void *ctx )
  1342. {
  1343. mbedtls_des3_free( (mbedtls_des3_context *) ctx );
  1344. mbedtls_free( ctx );
  1345. }
  1346. static const mbedtls_cipher_base_t des_info = {
  1347. MBEDTLS_CIPHER_ID_DES,
  1348. des_crypt_ecb_wrap,
  1349. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1350. des_crypt_cbc_wrap,
  1351. #endif
  1352. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1353. NULL,
  1354. #endif
  1355. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1356. NULL,
  1357. #endif
  1358. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1359. NULL,
  1360. #endif
  1361. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1362. NULL,
  1363. #endif
  1364. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1365. NULL,
  1366. #endif
  1367. des_setkey_enc_wrap,
  1368. des_setkey_dec_wrap,
  1369. des_ctx_alloc,
  1370. des_ctx_free
  1371. };
  1372. static const mbedtls_cipher_info_t des_ecb_info = {
  1373. MBEDTLS_CIPHER_DES_ECB,
  1374. MBEDTLS_MODE_ECB,
  1375. MBEDTLS_KEY_LENGTH_DES,
  1376. "DES-ECB",
  1377. 0,
  1378. 0,
  1379. 8,
  1380. &des_info
  1381. };
  1382. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1383. static const mbedtls_cipher_info_t des_cbc_info = {
  1384. MBEDTLS_CIPHER_DES_CBC,
  1385. MBEDTLS_MODE_CBC,
  1386. MBEDTLS_KEY_LENGTH_DES,
  1387. "DES-CBC",
  1388. 8,
  1389. 0,
  1390. 8,
  1391. &des_info
  1392. };
  1393. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1394. static const mbedtls_cipher_base_t des_ede_info = {
  1395. MBEDTLS_CIPHER_ID_DES,
  1396. des3_crypt_ecb_wrap,
  1397. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1398. des3_crypt_cbc_wrap,
  1399. #endif
  1400. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1401. NULL,
  1402. #endif
  1403. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1404. NULL,
  1405. #endif
  1406. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1407. NULL,
  1408. #endif
  1409. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1410. NULL,
  1411. #endif
  1412. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1413. NULL,
  1414. #endif
  1415. des3_set2key_enc_wrap,
  1416. des3_set2key_dec_wrap,
  1417. des3_ctx_alloc,
  1418. des3_ctx_free
  1419. };
  1420. static const mbedtls_cipher_info_t des_ede_ecb_info = {
  1421. MBEDTLS_CIPHER_DES_EDE_ECB,
  1422. MBEDTLS_MODE_ECB,
  1423. MBEDTLS_KEY_LENGTH_DES_EDE,
  1424. "DES-EDE-ECB",
  1425. 0,
  1426. 0,
  1427. 8,
  1428. &des_ede_info
  1429. };
  1430. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1431. static const mbedtls_cipher_info_t des_ede_cbc_info = {
  1432. MBEDTLS_CIPHER_DES_EDE_CBC,
  1433. MBEDTLS_MODE_CBC,
  1434. MBEDTLS_KEY_LENGTH_DES_EDE,
  1435. "DES-EDE-CBC",
  1436. 8,
  1437. 0,
  1438. 8,
  1439. &des_ede_info
  1440. };
  1441. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1442. static const mbedtls_cipher_base_t des_ede3_info = {
  1443. MBEDTLS_CIPHER_ID_3DES,
  1444. des3_crypt_ecb_wrap,
  1445. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1446. des3_crypt_cbc_wrap,
  1447. #endif
  1448. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1449. NULL,
  1450. #endif
  1451. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1452. NULL,
  1453. #endif
  1454. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1455. NULL,
  1456. #endif
  1457. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1458. NULL,
  1459. #endif
  1460. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1461. NULL,
  1462. #endif
  1463. des3_set3key_enc_wrap,
  1464. des3_set3key_dec_wrap,
  1465. des3_ctx_alloc,
  1466. des3_ctx_free
  1467. };
  1468. static const mbedtls_cipher_info_t des_ede3_ecb_info = {
  1469. MBEDTLS_CIPHER_DES_EDE3_ECB,
  1470. MBEDTLS_MODE_ECB,
  1471. MBEDTLS_KEY_LENGTH_DES_EDE3,
  1472. "DES-EDE3-ECB",
  1473. 0,
  1474. 0,
  1475. 8,
  1476. &des_ede3_info
  1477. };
  1478. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1479. static const mbedtls_cipher_info_t des_ede3_cbc_info = {
  1480. MBEDTLS_CIPHER_DES_EDE3_CBC,
  1481. MBEDTLS_MODE_CBC,
  1482. MBEDTLS_KEY_LENGTH_DES_EDE3,
  1483. "DES-EDE3-CBC",
  1484. 8,
  1485. 0,
  1486. 8,
  1487. &des_ede3_info
  1488. };
  1489. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1490. #endif /* MBEDTLS_DES_C */
  1491. #if defined(MBEDTLS_BLOWFISH_C)
  1492. static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
  1493. const unsigned char *input, unsigned char *output )
  1494. {
  1495. return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
  1496. output );
  1497. }
  1498. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1499. static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
  1500. size_t length, unsigned char *iv, const unsigned char *input,
  1501. unsigned char *output )
  1502. {
  1503. return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
  1504. input, output );
  1505. }
  1506. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1507. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1508. static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
  1509. size_t length, size_t *iv_off, unsigned char *iv,
  1510. const unsigned char *input, unsigned char *output )
  1511. {
  1512. return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
  1513. iv_off, iv, input, output );
  1514. }
  1515. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  1516. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1517. static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
  1518. unsigned char *nonce_counter, unsigned char *stream_block,
  1519. const unsigned char *input, unsigned char *output )
  1520. {
  1521. return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
  1522. nonce_counter, stream_block, input, output );
  1523. }
  1524. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  1525. static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
  1526. unsigned int key_bitlen )
  1527. {
  1528. return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
  1529. }
  1530. static void * blowfish_ctx_alloc( void )
  1531. {
  1532. mbedtls_blowfish_context *ctx;
  1533. ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
  1534. if( ctx == NULL )
  1535. return( NULL );
  1536. mbedtls_blowfish_init( ctx );
  1537. return( ctx );
  1538. }
  1539. static void blowfish_ctx_free( void *ctx )
  1540. {
  1541. mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
  1542. mbedtls_free( ctx );
  1543. }
  1544. static const mbedtls_cipher_base_t blowfish_info = {
  1545. MBEDTLS_CIPHER_ID_BLOWFISH,
  1546. blowfish_crypt_ecb_wrap,
  1547. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1548. blowfish_crypt_cbc_wrap,
  1549. #endif
  1550. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1551. blowfish_crypt_cfb64_wrap,
  1552. #endif
  1553. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1554. NULL,
  1555. #endif
  1556. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1557. blowfish_crypt_ctr_wrap,
  1558. #endif
  1559. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1560. NULL,
  1561. #endif
  1562. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1563. NULL,
  1564. #endif
  1565. blowfish_setkey_wrap,
  1566. blowfish_setkey_wrap,
  1567. blowfish_ctx_alloc,
  1568. blowfish_ctx_free
  1569. };
  1570. static const mbedtls_cipher_info_t blowfish_ecb_info = {
  1571. MBEDTLS_CIPHER_BLOWFISH_ECB,
  1572. MBEDTLS_MODE_ECB,
  1573. 128,
  1574. "BLOWFISH-ECB",
  1575. 0,
  1576. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1577. 8,
  1578. &blowfish_info
  1579. };
  1580. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1581. static const mbedtls_cipher_info_t blowfish_cbc_info = {
  1582. MBEDTLS_CIPHER_BLOWFISH_CBC,
  1583. MBEDTLS_MODE_CBC,
  1584. 128,
  1585. "BLOWFISH-CBC",
  1586. 8,
  1587. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1588. 8,
  1589. &blowfish_info
  1590. };
  1591. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  1592. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1593. static const mbedtls_cipher_info_t blowfish_cfb64_info = {
  1594. MBEDTLS_CIPHER_BLOWFISH_CFB64,
  1595. MBEDTLS_MODE_CFB,
  1596. 128,
  1597. "BLOWFISH-CFB64",
  1598. 8,
  1599. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1600. 8,
  1601. &blowfish_info
  1602. };
  1603. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  1604. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1605. static const mbedtls_cipher_info_t blowfish_ctr_info = {
  1606. MBEDTLS_CIPHER_BLOWFISH_CTR,
  1607. MBEDTLS_MODE_CTR,
  1608. 128,
  1609. "BLOWFISH-CTR",
  1610. 8,
  1611. MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
  1612. 8,
  1613. &blowfish_info
  1614. };
  1615. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  1616. #endif /* MBEDTLS_BLOWFISH_C */
  1617. #if defined(MBEDTLS_ARC4_C)
  1618. static int arc4_crypt_stream_wrap( void *ctx, size_t length,
  1619. const unsigned char *input,
  1620. unsigned char *output )
  1621. {
  1622. return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
  1623. }
  1624. static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
  1625. unsigned int key_bitlen )
  1626. {
  1627. /* we get key_bitlen in bits, arc4 expects it in bytes */
  1628. if( key_bitlen % 8 != 0 )
  1629. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1630. mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
  1631. return( 0 );
  1632. }
  1633. static void * arc4_ctx_alloc( void )
  1634. {
  1635. mbedtls_arc4_context *ctx;
  1636. ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
  1637. if( ctx == NULL )
  1638. return( NULL );
  1639. mbedtls_arc4_init( ctx );
  1640. return( ctx );
  1641. }
  1642. static void arc4_ctx_free( void *ctx )
  1643. {
  1644. mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
  1645. mbedtls_free( ctx );
  1646. }
  1647. static const mbedtls_cipher_base_t arc4_base_info = {
  1648. MBEDTLS_CIPHER_ID_ARC4,
  1649. NULL,
  1650. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1651. NULL,
  1652. #endif
  1653. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1654. NULL,
  1655. #endif
  1656. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1657. NULL,
  1658. #endif
  1659. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1660. NULL,
  1661. #endif
  1662. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1663. NULL,
  1664. #endif
  1665. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1666. arc4_crypt_stream_wrap,
  1667. #endif
  1668. arc4_setkey_wrap,
  1669. arc4_setkey_wrap,
  1670. arc4_ctx_alloc,
  1671. arc4_ctx_free
  1672. };
  1673. static const mbedtls_cipher_info_t arc4_128_info = {
  1674. MBEDTLS_CIPHER_ARC4_128,
  1675. MBEDTLS_MODE_STREAM,
  1676. 128,
  1677. "ARC4-128",
  1678. 0,
  1679. 0,
  1680. 1,
  1681. &arc4_base_info
  1682. };
  1683. #endif /* MBEDTLS_ARC4_C */
  1684. #if defined(MBEDTLS_CHACHA20_C)
  1685. static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
  1686. unsigned int key_bitlen )
  1687. {
  1688. if( key_bitlen != 256U )
  1689. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1690. if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
  1691. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1692. return( 0 );
  1693. }
  1694. static int chacha20_stream_wrap( void *ctx, size_t length,
  1695. const unsigned char *input,
  1696. unsigned char *output )
  1697. {
  1698. int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  1699. ret = mbedtls_chacha20_update( ctx, length, input, output );
  1700. if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
  1701. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1702. return( ret );
  1703. }
  1704. static void * chacha20_ctx_alloc( void )
  1705. {
  1706. mbedtls_chacha20_context *ctx;
  1707. ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
  1708. if( ctx == NULL )
  1709. return( NULL );
  1710. mbedtls_chacha20_init( ctx );
  1711. return( ctx );
  1712. }
  1713. static void chacha20_ctx_free( void *ctx )
  1714. {
  1715. mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
  1716. mbedtls_free( ctx );
  1717. }
  1718. static const mbedtls_cipher_base_t chacha20_base_info = {
  1719. MBEDTLS_CIPHER_ID_CHACHA20,
  1720. NULL,
  1721. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1722. NULL,
  1723. #endif
  1724. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1725. NULL,
  1726. #endif
  1727. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1728. NULL,
  1729. #endif
  1730. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1731. NULL,
  1732. #endif
  1733. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1734. NULL,
  1735. #endif
  1736. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1737. chacha20_stream_wrap,
  1738. #endif
  1739. chacha20_setkey_wrap,
  1740. chacha20_setkey_wrap,
  1741. chacha20_ctx_alloc,
  1742. chacha20_ctx_free
  1743. };
  1744. static const mbedtls_cipher_info_t chacha20_info = {
  1745. MBEDTLS_CIPHER_CHACHA20,
  1746. MBEDTLS_MODE_STREAM,
  1747. 256,
  1748. "CHACHA20",
  1749. 12,
  1750. 0,
  1751. 1,
  1752. &chacha20_base_info
  1753. };
  1754. #endif /* MBEDTLS_CHACHA20_C */
  1755. #if defined(MBEDTLS_CHACHAPOLY_C)
  1756. static int chachapoly_setkey_wrap( void *ctx,
  1757. const unsigned char *key,
  1758. unsigned int key_bitlen )
  1759. {
  1760. if( key_bitlen != 256U )
  1761. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1762. if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
  1763. return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
  1764. return( 0 );
  1765. }
  1766. static void * chachapoly_ctx_alloc( void )
  1767. {
  1768. mbedtls_chachapoly_context *ctx;
  1769. ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
  1770. if( ctx == NULL )
  1771. return( NULL );
  1772. mbedtls_chachapoly_init( ctx );
  1773. return( ctx );
  1774. }
  1775. static void chachapoly_ctx_free( void *ctx )
  1776. {
  1777. mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
  1778. mbedtls_free( ctx );
  1779. }
  1780. static const mbedtls_cipher_base_t chachapoly_base_info = {
  1781. MBEDTLS_CIPHER_ID_CHACHA20,
  1782. NULL,
  1783. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1784. NULL,
  1785. #endif
  1786. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1787. NULL,
  1788. #endif
  1789. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1790. NULL,
  1791. #endif
  1792. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1793. NULL,
  1794. #endif
  1795. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1796. NULL,
  1797. #endif
  1798. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1799. NULL,
  1800. #endif
  1801. chachapoly_setkey_wrap,
  1802. chachapoly_setkey_wrap,
  1803. chachapoly_ctx_alloc,
  1804. chachapoly_ctx_free
  1805. };
  1806. static const mbedtls_cipher_info_t chachapoly_info = {
  1807. MBEDTLS_CIPHER_CHACHA20_POLY1305,
  1808. MBEDTLS_MODE_CHACHAPOLY,
  1809. 256,
  1810. "CHACHA20-POLY1305",
  1811. 12,
  1812. 0,
  1813. 1,
  1814. &chachapoly_base_info
  1815. };
  1816. #endif /* MBEDTLS_CHACHAPOLY_C */
  1817. #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
  1818. static int null_crypt_stream( void *ctx, size_t length,
  1819. const unsigned char *input,
  1820. unsigned char *output )
  1821. {
  1822. ((void) ctx);
  1823. memmove( output, input, length );
  1824. return( 0 );
  1825. }
  1826. static int null_setkey( void *ctx, const unsigned char *key,
  1827. unsigned int key_bitlen )
  1828. {
  1829. ((void) ctx);
  1830. ((void) key);
  1831. ((void) key_bitlen);
  1832. return( 0 );
  1833. }
  1834. static void * null_ctx_alloc( void )
  1835. {
  1836. return( (void *) 1 );
  1837. }
  1838. static void null_ctx_free( void *ctx )
  1839. {
  1840. ((void) ctx);
  1841. }
  1842. static const mbedtls_cipher_base_t null_base_info = {
  1843. MBEDTLS_CIPHER_ID_NULL,
  1844. NULL,
  1845. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1846. NULL,
  1847. #endif
  1848. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1849. NULL,
  1850. #endif
  1851. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1852. NULL,
  1853. #endif
  1854. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1855. NULL,
  1856. #endif
  1857. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1858. NULL,
  1859. #endif
  1860. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1861. null_crypt_stream,
  1862. #endif
  1863. null_setkey,
  1864. null_setkey,
  1865. null_ctx_alloc,
  1866. null_ctx_free
  1867. };
  1868. static const mbedtls_cipher_info_t null_cipher_info = {
  1869. MBEDTLS_CIPHER_NULL,
  1870. MBEDTLS_MODE_STREAM,
  1871. 0,
  1872. "NULL",
  1873. 0,
  1874. 0,
  1875. 1,
  1876. &null_base_info
  1877. };
  1878. #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
  1879. #if defined(MBEDTLS_NIST_KW_C)
  1880. static void *kw_ctx_alloc( void )
  1881. {
  1882. void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
  1883. if( ctx != NULL )
  1884. mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
  1885. return( ctx );
  1886. }
  1887. static void kw_ctx_free( void *ctx )
  1888. {
  1889. mbedtls_nist_kw_free( ctx );
  1890. mbedtls_free( ctx );
  1891. }
  1892. static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
  1893. unsigned int key_bitlen )
  1894. {
  1895. return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
  1896. MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
  1897. }
  1898. static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
  1899. unsigned int key_bitlen )
  1900. {
  1901. return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
  1902. MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
  1903. }
  1904. static const mbedtls_cipher_base_t kw_aes_info = {
  1905. MBEDTLS_CIPHER_ID_AES,
  1906. NULL,
  1907. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1908. NULL,
  1909. #endif
  1910. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  1911. NULL,
  1912. #endif
  1913. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  1914. NULL,
  1915. #endif
  1916. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  1917. NULL,
  1918. #endif
  1919. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  1920. NULL,
  1921. #endif
  1922. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  1923. NULL,
  1924. #endif
  1925. kw_aes_setkey_wrap,
  1926. kw_aes_setkey_unwrap,
  1927. kw_ctx_alloc,
  1928. kw_ctx_free,
  1929. };
  1930. static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
  1931. MBEDTLS_CIPHER_AES_128_KW,
  1932. MBEDTLS_MODE_KW,
  1933. 128,
  1934. "AES-128-KW",
  1935. 0,
  1936. 0,
  1937. 16,
  1938. &kw_aes_info
  1939. };
  1940. static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
  1941. MBEDTLS_CIPHER_AES_192_KW,
  1942. MBEDTLS_MODE_KW,
  1943. 192,
  1944. "AES-192-KW",
  1945. 0,
  1946. 0,
  1947. 16,
  1948. &kw_aes_info
  1949. };
  1950. static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
  1951. MBEDTLS_CIPHER_AES_256_KW,
  1952. MBEDTLS_MODE_KW,
  1953. 256,
  1954. "AES-256-KW",
  1955. 0,
  1956. 0,
  1957. 16,
  1958. &kw_aes_info
  1959. };
  1960. static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
  1961. MBEDTLS_CIPHER_AES_128_KWP,
  1962. MBEDTLS_MODE_KWP,
  1963. 128,
  1964. "AES-128-KWP",
  1965. 0,
  1966. 0,
  1967. 16,
  1968. &kw_aes_info
  1969. };
  1970. static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
  1971. MBEDTLS_CIPHER_AES_192_KWP,
  1972. MBEDTLS_MODE_KWP,
  1973. 192,
  1974. "AES-192-KWP",
  1975. 0,
  1976. 0,
  1977. 16,
  1978. &kw_aes_info
  1979. };
  1980. static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
  1981. MBEDTLS_CIPHER_AES_256_KWP,
  1982. MBEDTLS_MODE_KWP,
  1983. 256,
  1984. "AES-256-KWP",
  1985. 0,
  1986. 0,
  1987. 16,
  1988. &kw_aes_info
  1989. };
  1990. #endif /* MBEDTLS_NIST_KW_C */
  1991. const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
  1992. {
  1993. #if defined(MBEDTLS_AES_C)
  1994. { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
  1995. { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
  1996. { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
  1997. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  1998. { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
  1999. { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
  2000. { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
  2001. #endif
  2002. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2003. { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
  2004. { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
  2005. { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
  2006. #endif
  2007. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  2008. { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
  2009. { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
  2010. { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
  2011. #endif
  2012. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2013. { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
  2014. { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
  2015. { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
  2016. #endif
  2017. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  2018. { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
  2019. { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
  2020. #endif
  2021. #if defined(MBEDTLS_GCM_C)
  2022. { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
  2023. { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
  2024. { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
  2025. #endif
  2026. #if defined(MBEDTLS_CCM_C)
  2027. { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
  2028. { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
  2029. { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
  2030. #endif
  2031. #endif /* MBEDTLS_AES_C */
  2032. #if defined(MBEDTLS_ARC4_C)
  2033. { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
  2034. #endif
  2035. #if defined(MBEDTLS_BLOWFISH_C)
  2036. { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
  2037. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2038. { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
  2039. #endif
  2040. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2041. { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
  2042. #endif
  2043. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2044. { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
  2045. #endif
  2046. #endif /* MBEDTLS_BLOWFISH_C */
  2047. #if defined(MBEDTLS_CAMELLIA_C)
  2048. { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
  2049. { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
  2050. { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
  2051. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2052. { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
  2053. { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
  2054. { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
  2055. #endif
  2056. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2057. { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
  2058. { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
  2059. { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
  2060. #endif
  2061. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2062. { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
  2063. { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
  2064. { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
  2065. #endif
  2066. #if defined(MBEDTLS_GCM_C)
  2067. { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
  2068. { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
  2069. { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
  2070. #endif
  2071. #if defined(MBEDTLS_CCM_C)
  2072. { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
  2073. { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
  2074. { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
  2075. #endif
  2076. #endif /* MBEDTLS_CAMELLIA_C */
  2077. #if defined(MBEDTLS_ARIA_C)
  2078. { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
  2079. { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
  2080. { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
  2081. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2082. { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
  2083. { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
  2084. { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
  2085. #endif
  2086. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  2087. { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
  2088. { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
  2089. { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
  2090. #endif
  2091. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  2092. { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
  2093. { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
  2094. { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
  2095. #endif
  2096. #if defined(MBEDTLS_GCM_C)
  2097. { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
  2098. { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
  2099. { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
  2100. #endif
  2101. #if defined(MBEDTLS_CCM_C)
  2102. { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
  2103. { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
  2104. { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
  2105. #endif
  2106. #endif /* MBEDTLS_ARIA_C */
  2107. #if defined(MBEDTLS_DES_C)
  2108. { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
  2109. { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
  2110. { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
  2111. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  2112. { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
  2113. { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
  2114. { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
  2115. #endif
  2116. #endif /* MBEDTLS_DES_C */
  2117. #if defined(MBEDTLS_CHACHA20_C)
  2118. { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
  2119. #endif
  2120. #if defined(MBEDTLS_CHACHAPOLY_C)
  2121. { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
  2122. #endif
  2123. #if defined(MBEDTLS_NIST_KW_C)
  2124. { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
  2125. { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
  2126. { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
  2127. { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
  2128. { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
  2129. { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
  2130. #endif
  2131. #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
  2132. { MBEDTLS_CIPHER_NULL, &null_cipher_info },
  2133. #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
  2134. { MBEDTLS_CIPHER_NONE, NULL }
  2135. };
  2136. #define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
  2137. sizeof(mbedtls_cipher_definitions[0]) )
  2138. int mbedtls_cipher_supported[NUM_CIPHERS];
  2139. #endif /* MBEDTLS_CIPHER_C */