cipher_wrap.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. /**
  2. * \file cipher_wrap.c
  3. *
  4. * \brief Generic cipher wrapper for mbed TLS
  5. *
  6. * \author Adriaan de Jong <[email protected]>
  7. *
  8. * Copyright The Mbed TLS Contributors
  9. * SPDX-License-Identifier: Apache-2.0 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 */