xref: /reactos/dll/3rdparty/mbedtls/cipher_wrap.c (revision a1fc312a)
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 (C) 2006-2015, ARM Limited, All Rights Reserved
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  *  This file is part of mbed TLS (https://tls.mbed.org)
51  */
52 
53 #if !defined(MBEDTLS_CONFIG_FILE)
54 #include "mbedtls/config.h"
55 #else
56 #include MBEDTLS_CONFIG_FILE
57 #endif
58 
59 #if defined(MBEDTLS_CIPHER_C)
60 
61 #include "mbedtls/cipher_internal.h"
62 
63 #if defined(MBEDTLS_AES_C)
64 #include "mbedtls/aes.h"
65 #endif
66 
67 #if defined(MBEDTLS_ARC4_C)
68 #include "mbedtls/arc4.h"
69 #endif
70 
71 #if defined(MBEDTLS_CAMELLIA_C)
72 #include "mbedtls/camellia.h"
73 #endif
74 
75 #if defined(MBEDTLS_DES_C)
76 #include "mbedtls/des.h"
77 #endif
78 
79 #if defined(MBEDTLS_BLOWFISH_C)
80 #include "mbedtls/blowfish.h"
81 #endif
82 
83 #if defined(MBEDTLS_GCM_C)
84 #include "mbedtls/gcm.h"
85 #endif
86 
87 #if defined(MBEDTLS_CCM_C)
88 #include "mbedtls/ccm.h"
89 #endif
90 
91 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
92 #include <string.h>
93 #endif
94 
95 #if defined(MBEDTLS_PLATFORM_C)
96 #include "mbedtls/platform.h"
97 #else
98 #include <stdlib.h>
99 #define mbedtls_calloc    calloc
100 #define mbedtls_free       free
101 #endif
102 
103 #if defined(MBEDTLS_GCM_C)
104 /* shared by all GCM ciphers */
105 static void *gcm_ctx_alloc( void )
106 {
107     void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
108 
109     if( ctx != NULL )
110         mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
111 
112     return( ctx );
113 }
114 
115 static void gcm_ctx_free( void *ctx )
116 {
117     mbedtls_gcm_free( ctx );
118     mbedtls_free( ctx );
119 }
120 #endif /* MBEDTLS_GCM_C */
121 
122 #if defined(MBEDTLS_CCM_C)
123 /* shared by all CCM ciphers */
124 static void *ccm_ctx_alloc( void )
125 {
126     void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
127 
128     if( ctx != NULL )
129         mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
130 
131     return( ctx );
132 }
133 
134 static void ccm_ctx_free( void *ctx )
135 {
136     mbedtls_ccm_free( ctx );
137     mbedtls_free( ctx );
138 }
139 #endif /* MBEDTLS_CCM_C */
140 
141 #if defined(MBEDTLS_AES_C)
142 
143 static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
144         const unsigned char *input, unsigned char *output )
145 {
146     return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
147 }
148 
149 #if defined(MBEDTLS_CIPHER_MODE_CBC)
150 static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
151         unsigned char *iv, const unsigned char *input, unsigned char *output )
152 {
153     return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
154                           output );
155 }
156 #endif /* MBEDTLS_CIPHER_MODE_CBC */
157 
158 #if defined(MBEDTLS_CIPHER_MODE_CFB)
159 static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
160         size_t length, size_t *iv_off, unsigned char *iv,
161         const unsigned char *input, unsigned char *output )
162 {
163     return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
164                              input, output );
165 }
166 #endif /* MBEDTLS_CIPHER_MODE_CFB */
167 
168 #if defined(MBEDTLS_CIPHER_MODE_CTR)
169 static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
170         unsigned char *nonce_counter, unsigned char *stream_block,
171         const unsigned char *input, unsigned char *output )
172 {
173     return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
174                           stream_block, input, output );
175 }
176 #endif /* MBEDTLS_CIPHER_MODE_CTR */
177 
178 static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
179                                 unsigned int key_bitlen )
180 {
181     return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
182 }
183 
184 static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
185                                 unsigned int key_bitlen )
186 {
187     return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
188 }
189 
190 static void * aes_ctx_alloc( void )
191 {
192     mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
193 
194     if( aes == NULL )
195         return( NULL );
196 
197     mbedtls_aes_init( aes );
198 
199     return( aes );
200 }
201 
202 static void aes_ctx_free( void *ctx )
203 {
204     mbedtls_aes_free( (mbedtls_aes_context *) ctx );
205     mbedtls_free( ctx );
206 }
207 
208 static const mbedtls_cipher_base_t aes_info = {
209     MBEDTLS_CIPHER_ID_AES,
210     aes_crypt_ecb_wrap,
211 #if defined(MBEDTLS_CIPHER_MODE_CBC)
212     aes_crypt_cbc_wrap,
213 #endif
214 #if defined(MBEDTLS_CIPHER_MODE_CFB)
215     aes_crypt_cfb128_wrap,
216 #endif
217 #if defined(MBEDTLS_CIPHER_MODE_CTR)
218     aes_crypt_ctr_wrap,
219 #endif
220 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
221     NULL,
222 #endif
223     aes_setkey_enc_wrap,
224     aes_setkey_dec_wrap,
225     aes_ctx_alloc,
226     aes_ctx_free
227 };
228 
229 static const mbedtls_cipher_info_t aes_128_ecb_info = {
230     MBEDTLS_CIPHER_AES_128_ECB,
231     MBEDTLS_MODE_ECB,
232     128,
233     "AES-128-ECB",
234     0,
235     0,
236     16,
237     &aes_info
238 };
239 
240 static const mbedtls_cipher_info_t aes_192_ecb_info = {
241     MBEDTLS_CIPHER_AES_192_ECB,
242     MBEDTLS_MODE_ECB,
243     192,
244     "AES-192-ECB",
245     0,
246     0,
247     16,
248     &aes_info
249 };
250 
251 static const mbedtls_cipher_info_t aes_256_ecb_info = {
252     MBEDTLS_CIPHER_AES_256_ECB,
253     MBEDTLS_MODE_ECB,
254     256,
255     "AES-256-ECB",
256     0,
257     0,
258     16,
259     &aes_info
260 };
261 
262 #if defined(MBEDTLS_CIPHER_MODE_CBC)
263 static const mbedtls_cipher_info_t aes_128_cbc_info = {
264     MBEDTLS_CIPHER_AES_128_CBC,
265     MBEDTLS_MODE_CBC,
266     128,
267     "AES-128-CBC",
268     16,
269     0,
270     16,
271     &aes_info
272 };
273 
274 static const mbedtls_cipher_info_t aes_192_cbc_info = {
275     MBEDTLS_CIPHER_AES_192_CBC,
276     MBEDTLS_MODE_CBC,
277     192,
278     "AES-192-CBC",
279     16,
280     0,
281     16,
282     &aes_info
283 };
284 
285 static const mbedtls_cipher_info_t aes_256_cbc_info = {
286     MBEDTLS_CIPHER_AES_256_CBC,
287     MBEDTLS_MODE_CBC,
288     256,
289     "AES-256-CBC",
290     16,
291     0,
292     16,
293     &aes_info
294 };
295 #endif /* MBEDTLS_CIPHER_MODE_CBC */
296 
297 #if defined(MBEDTLS_CIPHER_MODE_CFB)
298 static const mbedtls_cipher_info_t aes_128_cfb128_info = {
299     MBEDTLS_CIPHER_AES_128_CFB128,
300     MBEDTLS_MODE_CFB,
301     128,
302     "AES-128-CFB128",
303     16,
304     0,
305     16,
306     &aes_info
307 };
308 
309 static const mbedtls_cipher_info_t aes_192_cfb128_info = {
310     MBEDTLS_CIPHER_AES_192_CFB128,
311     MBEDTLS_MODE_CFB,
312     192,
313     "AES-192-CFB128",
314     16,
315     0,
316     16,
317     &aes_info
318 };
319 
320 static const mbedtls_cipher_info_t aes_256_cfb128_info = {
321     MBEDTLS_CIPHER_AES_256_CFB128,
322     MBEDTLS_MODE_CFB,
323     256,
324     "AES-256-CFB128",
325     16,
326     0,
327     16,
328     &aes_info
329 };
330 #endif /* MBEDTLS_CIPHER_MODE_CFB */
331 
332 #if defined(MBEDTLS_CIPHER_MODE_CTR)
333 static const mbedtls_cipher_info_t aes_128_ctr_info = {
334     MBEDTLS_CIPHER_AES_128_CTR,
335     MBEDTLS_MODE_CTR,
336     128,
337     "AES-128-CTR",
338     16,
339     0,
340     16,
341     &aes_info
342 };
343 
344 static const mbedtls_cipher_info_t aes_192_ctr_info = {
345     MBEDTLS_CIPHER_AES_192_CTR,
346     MBEDTLS_MODE_CTR,
347     192,
348     "AES-192-CTR",
349     16,
350     0,
351     16,
352     &aes_info
353 };
354 
355 static const mbedtls_cipher_info_t aes_256_ctr_info = {
356     MBEDTLS_CIPHER_AES_256_CTR,
357     MBEDTLS_MODE_CTR,
358     256,
359     "AES-256-CTR",
360     16,
361     0,
362     16,
363     &aes_info
364 };
365 #endif /* MBEDTLS_CIPHER_MODE_CTR */
366 
367 #if defined(MBEDTLS_GCM_C)
368 static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
369                                 unsigned int key_bitlen )
370 {
371     return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
372                      key, key_bitlen );
373 }
374 
375 static const mbedtls_cipher_base_t gcm_aes_info = {
376     MBEDTLS_CIPHER_ID_AES,
377     NULL,
378 #if defined(MBEDTLS_CIPHER_MODE_CBC)
379     NULL,
380 #endif
381 #if defined(MBEDTLS_CIPHER_MODE_CFB)
382     NULL,
383 #endif
384 #if defined(MBEDTLS_CIPHER_MODE_CTR)
385     NULL,
386 #endif
387 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
388     NULL,
389 #endif
390     gcm_aes_setkey_wrap,
391     gcm_aes_setkey_wrap,
392     gcm_ctx_alloc,
393     gcm_ctx_free,
394 };
395 
396 static const mbedtls_cipher_info_t aes_128_gcm_info = {
397     MBEDTLS_CIPHER_AES_128_GCM,
398     MBEDTLS_MODE_GCM,
399     128,
400     "AES-128-GCM",
401     12,
402     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
403     16,
404     &gcm_aes_info
405 };
406 
407 static const mbedtls_cipher_info_t aes_192_gcm_info = {
408     MBEDTLS_CIPHER_AES_192_GCM,
409     MBEDTLS_MODE_GCM,
410     192,
411     "AES-192-GCM",
412     12,
413     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
414     16,
415     &gcm_aes_info
416 };
417 
418 static const mbedtls_cipher_info_t aes_256_gcm_info = {
419     MBEDTLS_CIPHER_AES_256_GCM,
420     MBEDTLS_MODE_GCM,
421     256,
422     "AES-256-GCM",
423     12,
424     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
425     16,
426     &gcm_aes_info
427 };
428 #endif /* MBEDTLS_GCM_C */
429 
430 #if defined(MBEDTLS_CCM_C)
431 static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
432                                 unsigned int key_bitlen )
433 {
434     return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
435                      key, key_bitlen );
436 }
437 
438 static const mbedtls_cipher_base_t ccm_aes_info = {
439     MBEDTLS_CIPHER_ID_AES,
440     NULL,
441 #if defined(MBEDTLS_CIPHER_MODE_CBC)
442     NULL,
443 #endif
444 #if defined(MBEDTLS_CIPHER_MODE_CFB)
445     NULL,
446 #endif
447 #if defined(MBEDTLS_CIPHER_MODE_CTR)
448     NULL,
449 #endif
450 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
451     NULL,
452 #endif
453     ccm_aes_setkey_wrap,
454     ccm_aes_setkey_wrap,
455     ccm_ctx_alloc,
456     ccm_ctx_free,
457 };
458 
459 static const mbedtls_cipher_info_t aes_128_ccm_info = {
460     MBEDTLS_CIPHER_AES_128_CCM,
461     MBEDTLS_MODE_CCM,
462     128,
463     "AES-128-CCM",
464     12,
465     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
466     16,
467     &ccm_aes_info
468 };
469 
470 static const mbedtls_cipher_info_t aes_192_ccm_info = {
471     MBEDTLS_CIPHER_AES_192_CCM,
472     MBEDTLS_MODE_CCM,
473     192,
474     "AES-192-CCM",
475     12,
476     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
477     16,
478     &ccm_aes_info
479 };
480 
481 static const mbedtls_cipher_info_t aes_256_ccm_info = {
482     MBEDTLS_CIPHER_AES_256_CCM,
483     MBEDTLS_MODE_CCM,
484     256,
485     "AES-256-CCM",
486     12,
487     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
488     16,
489     &ccm_aes_info
490 };
491 #endif /* MBEDTLS_CCM_C */
492 
493 #endif /* MBEDTLS_AES_C */
494 
495 #if defined(MBEDTLS_CAMELLIA_C)
496 
497 static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
498         const unsigned char *input, unsigned char *output )
499 {
500     return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
501                                output );
502 }
503 
504 #if defined(MBEDTLS_CIPHER_MODE_CBC)
505 static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
506         size_t length, unsigned char *iv,
507         const unsigned char *input, unsigned char *output )
508 {
509     return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
510                                input, output );
511 }
512 #endif /* MBEDTLS_CIPHER_MODE_CBC */
513 
514 #if defined(MBEDTLS_CIPHER_MODE_CFB)
515 static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
516         size_t length, size_t *iv_off, unsigned char *iv,
517         const unsigned char *input, unsigned char *output )
518 {
519     return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
520                                   iv_off, iv, input, output );
521 }
522 #endif /* MBEDTLS_CIPHER_MODE_CFB */
523 
524 #if defined(MBEDTLS_CIPHER_MODE_CTR)
525 static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
526         unsigned char *nonce_counter, unsigned char *stream_block,
527         const unsigned char *input, unsigned char *output )
528 {
529     return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
530                                nonce_counter, stream_block, input, output );
531 }
532 #endif /* MBEDTLS_CIPHER_MODE_CTR */
533 
534 static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
535                                      unsigned int key_bitlen )
536 {
537     return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
538 }
539 
540 static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
541                                      unsigned int key_bitlen )
542 {
543     return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
544 }
545 
546 static void * camellia_ctx_alloc( void )
547 {
548     mbedtls_camellia_context *ctx;
549     ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
550 
551     if( ctx == NULL )
552         return( NULL );
553 
554     mbedtls_camellia_init( ctx );
555 
556     return( ctx );
557 }
558 
559 static void camellia_ctx_free( void *ctx )
560 {
561     mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
562     mbedtls_free( ctx );
563 }
564 
565 static const mbedtls_cipher_base_t camellia_info = {
566     MBEDTLS_CIPHER_ID_CAMELLIA,
567     camellia_crypt_ecb_wrap,
568 #if defined(MBEDTLS_CIPHER_MODE_CBC)
569     camellia_crypt_cbc_wrap,
570 #endif
571 #if defined(MBEDTLS_CIPHER_MODE_CFB)
572     camellia_crypt_cfb128_wrap,
573 #endif
574 #if defined(MBEDTLS_CIPHER_MODE_CTR)
575     camellia_crypt_ctr_wrap,
576 #endif
577 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
578     NULL,
579 #endif
580     camellia_setkey_enc_wrap,
581     camellia_setkey_dec_wrap,
582     camellia_ctx_alloc,
583     camellia_ctx_free
584 };
585 
586 static const mbedtls_cipher_info_t camellia_128_ecb_info = {
587     MBEDTLS_CIPHER_CAMELLIA_128_ECB,
588     MBEDTLS_MODE_ECB,
589     128,
590     "CAMELLIA-128-ECB",
591     16,
592     0,
593     16,
594     &camellia_info
595 };
596 
597 static const mbedtls_cipher_info_t camellia_192_ecb_info = {
598     MBEDTLS_CIPHER_CAMELLIA_192_ECB,
599     MBEDTLS_MODE_ECB,
600     192,
601     "CAMELLIA-192-ECB",
602     16,
603     0,
604     16,
605     &camellia_info
606 };
607 
608 static const mbedtls_cipher_info_t camellia_256_ecb_info = {
609     MBEDTLS_CIPHER_CAMELLIA_256_ECB,
610     MBEDTLS_MODE_ECB,
611     256,
612     "CAMELLIA-256-ECB",
613     16,
614     0,
615     16,
616     &camellia_info
617 };
618 
619 #if defined(MBEDTLS_CIPHER_MODE_CBC)
620 static const mbedtls_cipher_info_t camellia_128_cbc_info = {
621     MBEDTLS_CIPHER_CAMELLIA_128_CBC,
622     MBEDTLS_MODE_CBC,
623     128,
624     "CAMELLIA-128-CBC",
625     16,
626     0,
627     16,
628     &camellia_info
629 };
630 
631 static const mbedtls_cipher_info_t camellia_192_cbc_info = {
632     MBEDTLS_CIPHER_CAMELLIA_192_CBC,
633     MBEDTLS_MODE_CBC,
634     192,
635     "CAMELLIA-192-CBC",
636     16,
637     0,
638     16,
639     &camellia_info
640 };
641 
642 static const mbedtls_cipher_info_t camellia_256_cbc_info = {
643     MBEDTLS_CIPHER_CAMELLIA_256_CBC,
644     MBEDTLS_MODE_CBC,
645     256,
646     "CAMELLIA-256-CBC",
647     16,
648     0,
649     16,
650     &camellia_info
651 };
652 #endif /* MBEDTLS_CIPHER_MODE_CBC */
653 
654 #if defined(MBEDTLS_CIPHER_MODE_CFB)
655 static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
656     MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
657     MBEDTLS_MODE_CFB,
658     128,
659     "CAMELLIA-128-CFB128",
660     16,
661     0,
662     16,
663     &camellia_info
664 };
665 
666 static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
667     MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
668     MBEDTLS_MODE_CFB,
669     192,
670     "CAMELLIA-192-CFB128",
671     16,
672     0,
673     16,
674     &camellia_info
675 };
676 
677 static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
678     MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
679     MBEDTLS_MODE_CFB,
680     256,
681     "CAMELLIA-256-CFB128",
682     16,
683     0,
684     16,
685     &camellia_info
686 };
687 #endif /* MBEDTLS_CIPHER_MODE_CFB */
688 
689 #if defined(MBEDTLS_CIPHER_MODE_CTR)
690 static const mbedtls_cipher_info_t camellia_128_ctr_info = {
691     MBEDTLS_CIPHER_CAMELLIA_128_CTR,
692     MBEDTLS_MODE_CTR,
693     128,
694     "CAMELLIA-128-CTR",
695     16,
696     0,
697     16,
698     &camellia_info
699 };
700 
701 static const mbedtls_cipher_info_t camellia_192_ctr_info = {
702     MBEDTLS_CIPHER_CAMELLIA_192_CTR,
703     MBEDTLS_MODE_CTR,
704     192,
705     "CAMELLIA-192-CTR",
706     16,
707     0,
708     16,
709     &camellia_info
710 };
711 
712 static const mbedtls_cipher_info_t camellia_256_ctr_info = {
713     MBEDTLS_CIPHER_CAMELLIA_256_CTR,
714     MBEDTLS_MODE_CTR,
715     256,
716     "CAMELLIA-256-CTR",
717     16,
718     0,
719     16,
720     &camellia_info
721 };
722 #endif /* MBEDTLS_CIPHER_MODE_CTR */
723 
724 #if defined(MBEDTLS_GCM_C)
725 static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
726                                      unsigned int key_bitlen )
727 {
728     return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
729                      key, key_bitlen );
730 }
731 
732 static const mbedtls_cipher_base_t gcm_camellia_info = {
733     MBEDTLS_CIPHER_ID_CAMELLIA,
734     NULL,
735 #if defined(MBEDTLS_CIPHER_MODE_CBC)
736     NULL,
737 #endif
738 #if defined(MBEDTLS_CIPHER_MODE_CFB)
739     NULL,
740 #endif
741 #if defined(MBEDTLS_CIPHER_MODE_CTR)
742     NULL,
743 #endif
744 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
745     NULL,
746 #endif
747     gcm_camellia_setkey_wrap,
748     gcm_camellia_setkey_wrap,
749     gcm_ctx_alloc,
750     gcm_ctx_free,
751 };
752 
753 static const mbedtls_cipher_info_t camellia_128_gcm_info = {
754     MBEDTLS_CIPHER_CAMELLIA_128_GCM,
755     MBEDTLS_MODE_GCM,
756     128,
757     "CAMELLIA-128-GCM",
758     12,
759     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
760     16,
761     &gcm_camellia_info
762 };
763 
764 static const mbedtls_cipher_info_t camellia_192_gcm_info = {
765     MBEDTLS_CIPHER_CAMELLIA_192_GCM,
766     MBEDTLS_MODE_GCM,
767     192,
768     "CAMELLIA-192-GCM",
769     12,
770     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
771     16,
772     &gcm_camellia_info
773 };
774 
775 static const mbedtls_cipher_info_t camellia_256_gcm_info = {
776     MBEDTLS_CIPHER_CAMELLIA_256_GCM,
777     MBEDTLS_MODE_GCM,
778     256,
779     "CAMELLIA-256-GCM",
780     12,
781     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
782     16,
783     &gcm_camellia_info
784 };
785 #endif /* MBEDTLS_GCM_C */
786 
787 #if defined(MBEDTLS_CCM_C)
788 static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
789                                      unsigned int key_bitlen )
790 {
791     return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
792                      key, key_bitlen );
793 }
794 
795 static const mbedtls_cipher_base_t ccm_camellia_info = {
796     MBEDTLS_CIPHER_ID_CAMELLIA,
797     NULL,
798 #if defined(MBEDTLS_CIPHER_MODE_CBC)
799     NULL,
800 #endif
801 #if defined(MBEDTLS_CIPHER_MODE_CFB)
802     NULL,
803 #endif
804 #if defined(MBEDTLS_CIPHER_MODE_CTR)
805     NULL,
806 #endif
807 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
808     NULL,
809 #endif
810     ccm_camellia_setkey_wrap,
811     ccm_camellia_setkey_wrap,
812     ccm_ctx_alloc,
813     ccm_ctx_free,
814 };
815 
816 static const mbedtls_cipher_info_t camellia_128_ccm_info = {
817     MBEDTLS_CIPHER_CAMELLIA_128_CCM,
818     MBEDTLS_MODE_CCM,
819     128,
820     "CAMELLIA-128-CCM",
821     12,
822     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
823     16,
824     &ccm_camellia_info
825 };
826 
827 static const mbedtls_cipher_info_t camellia_192_ccm_info = {
828     MBEDTLS_CIPHER_CAMELLIA_192_CCM,
829     MBEDTLS_MODE_CCM,
830     192,
831     "CAMELLIA-192-CCM",
832     12,
833     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
834     16,
835     &ccm_camellia_info
836 };
837 
838 static const mbedtls_cipher_info_t camellia_256_ccm_info = {
839     MBEDTLS_CIPHER_CAMELLIA_256_CCM,
840     MBEDTLS_MODE_CCM,
841     256,
842     "CAMELLIA-256-CCM",
843     12,
844     MBEDTLS_CIPHER_VARIABLE_IV_LEN,
845     16,
846     &ccm_camellia_info
847 };
848 #endif /* MBEDTLS_CCM_C */
849 
850 #endif /* MBEDTLS_CAMELLIA_C */
851 
852 #if defined(MBEDTLS_DES_C)
853 
854 static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
855         const unsigned char *input, unsigned char *output )
856 {
857     ((void) operation);
858     return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
859 }
860 
861 static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
862         const unsigned char *input, unsigned char *output )
863 {
864     ((void) operation);
865     return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
866 }
867 
868 #if defined(MBEDTLS_CIPHER_MODE_CBC)
869 static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
870         unsigned char *iv, const unsigned char *input, unsigned char *output )
871 {
872     return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
873                           output );
874 }
875 #endif /* MBEDTLS_CIPHER_MODE_CBC */
876 
877 #if defined(MBEDTLS_CIPHER_MODE_CBC)
878 static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
879         unsigned char *iv, const unsigned char *input, unsigned char *output )
880 {
881     return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
882                            output );
883 }
884 #endif /* MBEDTLS_CIPHER_MODE_CBC */
885 
886 static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
887                                 unsigned int key_bitlen )
888 {
889     ((void) key_bitlen);
890 
891     return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
892 }
893 
894 static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
895                                 unsigned int key_bitlen )
896 {
897     ((void) key_bitlen);
898 
899     return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
900 }
901 
902 static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
903                                   unsigned int key_bitlen )
904 {
905     ((void) key_bitlen);
906 
907     return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
908 }
909 
910 static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
911                                   unsigned int key_bitlen )
912 {
913     ((void) key_bitlen);
914 
915     return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
916 }
917 
918 static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
919                                   unsigned int key_bitlen )
920 {
921     ((void) key_bitlen);
922 
923     return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
924 }
925 
926 static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
927                                   unsigned int key_bitlen )
928 {
929     ((void) key_bitlen);
930 
931     return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
932 }
933 
934 static void * des_ctx_alloc( void )
935 {
936     mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
937 
938     if( des == NULL )
939         return( NULL );
940 
941     mbedtls_des_init( des );
942 
943     return( des );
944 }
945 
946 static void des_ctx_free( void *ctx )
947 {
948     mbedtls_des_free( (mbedtls_des_context *) ctx );
949     mbedtls_free( ctx );
950 }
951 
952 static void * des3_ctx_alloc( void )
953 {
954     mbedtls_des3_context *des3;
955     des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
956 
957     if( des3 == NULL )
958         return( NULL );
959 
960     mbedtls_des3_init( des3 );
961 
962     return( des3 );
963 }
964 
965 static void des3_ctx_free( void *ctx )
966 {
967     mbedtls_des3_free( (mbedtls_des3_context *) ctx );
968     mbedtls_free( ctx );
969 }
970 
971 static const mbedtls_cipher_base_t des_info = {
972     MBEDTLS_CIPHER_ID_DES,
973     des_crypt_ecb_wrap,
974 #if defined(MBEDTLS_CIPHER_MODE_CBC)
975     des_crypt_cbc_wrap,
976 #endif
977 #if defined(MBEDTLS_CIPHER_MODE_CFB)
978     NULL,
979 #endif
980 #if defined(MBEDTLS_CIPHER_MODE_CTR)
981     NULL,
982 #endif
983 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
984     NULL,
985 #endif
986     des_setkey_enc_wrap,
987     des_setkey_dec_wrap,
988     des_ctx_alloc,
989     des_ctx_free
990 };
991 
992 static const mbedtls_cipher_info_t des_ecb_info = {
993     MBEDTLS_CIPHER_DES_ECB,
994     MBEDTLS_MODE_ECB,
995     MBEDTLS_KEY_LENGTH_DES,
996     "DES-ECB",
997     8,
998     0,
999     8,
1000     &des_info
1001 };
1002 
1003 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1004 static const mbedtls_cipher_info_t des_cbc_info = {
1005     MBEDTLS_CIPHER_DES_CBC,
1006     MBEDTLS_MODE_CBC,
1007     MBEDTLS_KEY_LENGTH_DES,
1008     "DES-CBC",
1009     8,
1010     0,
1011     8,
1012     &des_info
1013 };
1014 #endif /* MBEDTLS_CIPHER_MODE_CBC */
1015 
1016 static const mbedtls_cipher_base_t des_ede_info = {
1017     MBEDTLS_CIPHER_ID_DES,
1018     des3_crypt_ecb_wrap,
1019 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1020     des3_crypt_cbc_wrap,
1021 #endif
1022 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1023     NULL,
1024 #endif
1025 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1026     NULL,
1027 #endif
1028 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
1029     NULL,
1030 #endif
1031     des3_set2key_enc_wrap,
1032     des3_set2key_dec_wrap,
1033     des3_ctx_alloc,
1034     des3_ctx_free
1035 };
1036 
1037 static const mbedtls_cipher_info_t des_ede_ecb_info = {
1038     MBEDTLS_CIPHER_DES_EDE_ECB,
1039     MBEDTLS_MODE_ECB,
1040     MBEDTLS_KEY_LENGTH_DES_EDE,
1041     "DES-EDE-ECB",
1042     8,
1043     0,
1044     8,
1045     &des_ede_info
1046 };
1047 
1048 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1049 static const mbedtls_cipher_info_t des_ede_cbc_info = {
1050     MBEDTLS_CIPHER_DES_EDE_CBC,
1051     MBEDTLS_MODE_CBC,
1052     MBEDTLS_KEY_LENGTH_DES_EDE,
1053     "DES-EDE-CBC",
1054     8,
1055     0,
1056     8,
1057     &des_ede_info
1058 };
1059 #endif /* MBEDTLS_CIPHER_MODE_CBC */
1060 
1061 static const mbedtls_cipher_base_t des_ede3_info = {
1062     MBEDTLS_CIPHER_ID_3DES,
1063     des3_crypt_ecb_wrap,
1064 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1065     des3_crypt_cbc_wrap,
1066 #endif
1067 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1068     NULL,
1069 #endif
1070 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1071     NULL,
1072 #endif
1073 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
1074     NULL,
1075 #endif
1076     des3_set3key_enc_wrap,
1077     des3_set3key_dec_wrap,
1078     des3_ctx_alloc,
1079     des3_ctx_free
1080 };
1081 
1082 static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1083     MBEDTLS_CIPHER_DES_EDE3_ECB,
1084     MBEDTLS_MODE_ECB,
1085     MBEDTLS_KEY_LENGTH_DES_EDE3,
1086     "DES-EDE3-ECB",
1087     8,
1088     0,
1089     8,
1090     &des_ede3_info
1091 };
1092 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1093 static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1094     MBEDTLS_CIPHER_DES_EDE3_CBC,
1095     MBEDTLS_MODE_CBC,
1096     MBEDTLS_KEY_LENGTH_DES_EDE3,
1097     "DES-EDE3-CBC",
1098     8,
1099     0,
1100     8,
1101     &des_ede3_info
1102 };
1103 #endif /* MBEDTLS_CIPHER_MODE_CBC */
1104 #endif /* MBEDTLS_DES_C */
1105 
1106 #if defined(MBEDTLS_BLOWFISH_C)
1107 
1108 static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1109         const unsigned char *input, unsigned char *output )
1110 {
1111     return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
1112                                output );
1113 }
1114 
1115 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1116 static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1117         size_t length, unsigned char *iv, const unsigned char *input,
1118         unsigned char *output )
1119 {
1120     return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
1121                                input, output );
1122 }
1123 #endif /* MBEDTLS_CIPHER_MODE_CBC */
1124 
1125 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1126 static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
1127         size_t length, size_t *iv_off, unsigned char *iv,
1128         const unsigned char *input, unsigned char *output )
1129 {
1130     return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
1131                                  iv_off, iv, input, output );
1132 }
1133 #endif /* MBEDTLS_CIPHER_MODE_CFB */
1134 
1135 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1136 static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1137         unsigned char *nonce_counter, unsigned char *stream_block,
1138         const unsigned char *input, unsigned char *output )
1139 {
1140     return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
1141                                nonce_counter, stream_block, input, output );
1142 }
1143 #endif /* MBEDTLS_CIPHER_MODE_CTR */
1144 
1145 static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1146                                  unsigned int key_bitlen )
1147 {
1148     return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
1149 }
1150 
1151 static void * blowfish_ctx_alloc( void )
1152 {
1153     mbedtls_blowfish_context *ctx;
1154     ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
1155 
1156     if( ctx == NULL )
1157         return( NULL );
1158 
1159     mbedtls_blowfish_init( ctx );
1160 
1161     return( ctx );
1162 }
1163 
1164 static void blowfish_ctx_free( void *ctx )
1165 {
1166     mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1167     mbedtls_free( ctx );
1168 }
1169 
1170 static const mbedtls_cipher_base_t blowfish_info = {
1171     MBEDTLS_CIPHER_ID_BLOWFISH,
1172     blowfish_crypt_ecb_wrap,
1173 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1174     blowfish_crypt_cbc_wrap,
1175 #endif
1176 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1177     blowfish_crypt_cfb64_wrap,
1178 #endif
1179 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1180     blowfish_crypt_ctr_wrap,
1181 #endif
1182 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
1183     NULL,
1184 #endif
1185     blowfish_setkey_wrap,
1186     blowfish_setkey_wrap,
1187     blowfish_ctx_alloc,
1188     blowfish_ctx_free
1189 };
1190 
1191 static const mbedtls_cipher_info_t blowfish_ecb_info = {
1192     MBEDTLS_CIPHER_BLOWFISH_ECB,
1193     MBEDTLS_MODE_ECB,
1194     128,
1195     "BLOWFISH-ECB",
1196     8,
1197     MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1198     8,
1199     &blowfish_info
1200 };
1201 
1202 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1203 static const mbedtls_cipher_info_t blowfish_cbc_info = {
1204     MBEDTLS_CIPHER_BLOWFISH_CBC,
1205     MBEDTLS_MODE_CBC,
1206     128,
1207     "BLOWFISH-CBC",
1208     8,
1209     MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1210     8,
1211     &blowfish_info
1212 };
1213 #endif /* MBEDTLS_CIPHER_MODE_CBC */
1214 
1215 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1216 static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1217     MBEDTLS_CIPHER_BLOWFISH_CFB64,
1218     MBEDTLS_MODE_CFB,
1219     128,
1220     "BLOWFISH-CFB64",
1221     8,
1222     MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1223     8,
1224     &blowfish_info
1225 };
1226 #endif /* MBEDTLS_CIPHER_MODE_CFB */
1227 
1228 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1229 static const mbedtls_cipher_info_t blowfish_ctr_info = {
1230     MBEDTLS_CIPHER_BLOWFISH_CTR,
1231     MBEDTLS_MODE_CTR,
1232     128,
1233     "BLOWFISH-CTR",
1234     8,
1235     MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1236     8,
1237     &blowfish_info
1238 };
1239 #endif /* MBEDTLS_CIPHER_MODE_CTR */
1240 #endif /* MBEDTLS_BLOWFISH_C */
1241 
1242 #if defined(MBEDTLS_ARC4_C)
1243 static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1244                                    const unsigned char *input,
1245                                    unsigned char *output )
1246 {
1247     return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
1248 }
1249 
1250 static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1251                              unsigned int key_bitlen )
1252 {
1253     /* we get key_bitlen in bits, arc4 expects it in bytes */
1254     if( key_bitlen % 8 != 0 )
1255         return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1256 
1257     mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
1258     return( 0 );
1259 }
1260 
1261 static void * arc4_ctx_alloc( void )
1262 {
1263     mbedtls_arc4_context *ctx;
1264     ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
1265 
1266     if( ctx == NULL )
1267         return( NULL );
1268 
1269     mbedtls_arc4_init( ctx );
1270 
1271     return( ctx );
1272 }
1273 
1274 static void arc4_ctx_free( void *ctx )
1275 {
1276     mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1277     mbedtls_free( ctx );
1278 }
1279 
1280 static const mbedtls_cipher_base_t arc4_base_info = {
1281     MBEDTLS_CIPHER_ID_ARC4,
1282     NULL,
1283 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1284     NULL,
1285 #endif
1286 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1287     NULL,
1288 #endif
1289 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1290     NULL,
1291 #endif
1292 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
1293     arc4_crypt_stream_wrap,
1294 #endif
1295     arc4_setkey_wrap,
1296     arc4_setkey_wrap,
1297     arc4_ctx_alloc,
1298     arc4_ctx_free
1299 };
1300 
1301 static const mbedtls_cipher_info_t arc4_128_info = {
1302     MBEDTLS_CIPHER_ARC4_128,
1303     MBEDTLS_MODE_STREAM,
1304     128,
1305     "ARC4-128",
1306     0,
1307     0,
1308     1,
1309     &arc4_base_info
1310 };
1311 #endif /* MBEDTLS_ARC4_C */
1312 
1313 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1314 static int null_crypt_stream( void *ctx, size_t length,
1315                               const unsigned char *input,
1316                               unsigned char *output )
1317 {
1318     ((void) ctx);
1319     memmove( output, input, length );
1320     return( 0 );
1321 }
1322 
1323 static int null_setkey( void *ctx, const unsigned char *key,
1324                         unsigned int key_bitlen )
1325 {
1326     ((void) ctx);
1327     ((void) key);
1328     ((void) key_bitlen);
1329 
1330     return( 0 );
1331 }
1332 
1333 static void * null_ctx_alloc( void )
1334 {
1335     return( (void *) 1 );
1336 }
1337 
1338 static void null_ctx_free( void *ctx )
1339 {
1340     ((void) ctx);
1341 }
1342 
1343 static const mbedtls_cipher_base_t null_base_info = {
1344     MBEDTLS_CIPHER_ID_NULL,
1345     NULL,
1346 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1347     NULL,
1348 #endif
1349 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1350     NULL,
1351 #endif
1352 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1353     NULL,
1354 #endif
1355 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
1356     null_crypt_stream,
1357 #endif
1358     null_setkey,
1359     null_setkey,
1360     null_ctx_alloc,
1361     null_ctx_free
1362 };
1363 
1364 static const mbedtls_cipher_info_t null_cipher_info = {
1365     MBEDTLS_CIPHER_NULL,
1366     MBEDTLS_MODE_STREAM,
1367     0,
1368     "NULL",
1369     0,
1370     0,
1371     1,
1372     &null_base_info
1373 };
1374 #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
1375 
1376 const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
1377 {
1378 #if defined(MBEDTLS_AES_C)
1379     { MBEDTLS_CIPHER_AES_128_ECB,          &aes_128_ecb_info },
1380     { MBEDTLS_CIPHER_AES_192_ECB,          &aes_192_ecb_info },
1381     { MBEDTLS_CIPHER_AES_256_ECB,          &aes_256_ecb_info },
1382 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1383     { MBEDTLS_CIPHER_AES_128_CBC,          &aes_128_cbc_info },
1384     { MBEDTLS_CIPHER_AES_192_CBC,          &aes_192_cbc_info },
1385     { MBEDTLS_CIPHER_AES_256_CBC,          &aes_256_cbc_info },
1386 #endif
1387 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1388     { MBEDTLS_CIPHER_AES_128_CFB128,       &aes_128_cfb128_info },
1389     { MBEDTLS_CIPHER_AES_192_CFB128,       &aes_192_cfb128_info },
1390     { MBEDTLS_CIPHER_AES_256_CFB128,       &aes_256_cfb128_info },
1391 #endif
1392 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1393     { MBEDTLS_CIPHER_AES_128_CTR,          &aes_128_ctr_info },
1394     { MBEDTLS_CIPHER_AES_192_CTR,          &aes_192_ctr_info },
1395     { MBEDTLS_CIPHER_AES_256_CTR,          &aes_256_ctr_info },
1396 #endif
1397 #if defined(MBEDTLS_GCM_C)
1398     { MBEDTLS_CIPHER_AES_128_GCM,          &aes_128_gcm_info },
1399     { MBEDTLS_CIPHER_AES_192_GCM,          &aes_192_gcm_info },
1400     { MBEDTLS_CIPHER_AES_256_GCM,          &aes_256_gcm_info },
1401 #endif
1402 #if defined(MBEDTLS_CCM_C)
1403     { MBEDTLS_CIPHER_AES_128_CCM,          &aes_128_ccm_info },
1404     { MBEDTLS_CIPHER_AES_192_CCM,          &aes_192_ccm_info },
1405     { MBEDTLS_CIPHER_AES_256_CCM,          &aes_256_ccm_info },
1406 #endif
1407 #endif /* MBEDTLS_AES_C */
1408 
1409 #if defined(MBEDTLS_ARC4_C)
1410     { MBEDTLS_CIPHER_ARC4_128,             &arc4_128_info },
1411 #endif
1412 
1413 #if defined(MBEDTLS_BLOWFISH_C)
1414     { MBEDTLS_CIPHER_BLOWFISH_ECB,         &blowfish_ecb_info },
1415 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1416     { MBEDTLS_CIPHER_BLOWFISH_CBC,         &blowfish_cbc_info },
1417 #endif
1418 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1419     { MBEDTLS_CIPHER_BLOWFISH_CFB64,       &blowfish_cfb64_info },
1420 #endif
1421 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1422     { MBEDTLS_CIPHER_BLOWFISH_CTR,         &blowfish_ctr_info },
1423 #endif
1424 #endif /* MBEDTLS_BLOWFISH_C */
1425 
1426 #if defined(MBEDTLS_CAMELLIA_C)
1427     { MBEDTLS_CIPHER_CAMELLIA_128_ECB,     &camellia_128_ecb_info },
1428     { MBEDTLS_CIPHER_CAMELLIA_192_ECB,     &camellia_192_ecb_info },
1429     { MBEDTLS_CIPHER_CAMELLIA_256_ECB,     &camellia_256_ecb_info },
1430 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1431     { MBEDTLS_CIPHER_CAMELLIA_128_CBC,     &camellia_128_cbc_info },
1432     { MBEDTLS_CIPHER_CAMELLIA_192_CBC,     &camellia_192_cbc_info },
1433     { MBEDTLS_CIPHER_CAMELLIA_256_CBC,     &camellia_256_cbc_info },
1434 #endif
1435 #if defined(MBEDTLS_CIPHER_MODE_CFB)
1436     { MBEDTLS_CIPHER_CAMELLIA_128_CFB128,  &camellia_128_cfb128_info },
1437     { MBEDTLS_CIPHER_CAMELLIA_192_CFB128,  &camellia_192_cfb128_info },
1438     { MBEDTLS_CIPHER_CAMELLIA_256_CFB128,  &camellia_256_cfb128_info },
1439 #endif
1440 #if defined(MBEDTLS_CIPHER_MODE_CTR)
1441     { MBEDTLS_CIPHER_CAMELLIA_128_CTR,     &camellia_128_ctr_info },
1442     { MBEDTLS_CIPHER_CAMELLIA_192_CTR,     &camellia_192_ctr_info },
1443     { MBEDTLS_CIPHER_CAMELLIA_256_CTR,     &camellia_256_ctr_info },
1444 #endif
1445 #if defined(MBEDTLS_GCM_C)
1446     { MBEDTLS_CIPHER_CAMELLIA_128_GCM,     &camellia_128_gcm_info },
1447     { MBEDTLS_CIPHER_CAMELLIA_192_GCM,     &camellia_192_gcm_info },
1448     { MBEDTLS_CIPHER_CAMELLIA_256_GCM,     &camellia_256_gcm_info },
1449 #endif
1450 #if defined(MBEDTLS_CCM_C)
1451     { MBEDTLS_CIPHER_CAMELLIA_128_CCM,     &camellia_128_ccm_info },
1452     { MBEDTLS_CIPHER_CAMELLIA_192_CCM,     &camellia_192_ccm_info },
1453     { MBEDTLS_CIPHER_CAMELLIA_256_CCM,     &camellia_256_ccm_info },
1454 #endif
1455 #endif /* MBEDTLS_CAMELLIA_C */
1456 
1457 #if defined(MBEDTLS_DES_C)
1458     { MBEDTLS_CIPHER_DES_ECB,              &des_ecb_info },
1459     { MBEDTLS_CIPHER_DES_EDE_ECB,          &des_ede_ecb_info },
1460     { MBEDTLS_CIPHER_DES_EDE3_ECB,         &des_ede3_ecb_info },
1461 #if defined(MBEDTLS_CIPHER_MODE_CBC)
1462     { MBEDTLS_CIPHER_DES_CBC,              &des_cbc_info },
1463     { MBEDTLS_CIPHER_DES_EDE_CBC,          &des_ede_cbc_info },
1464     { MBEDTLS_CIPHER_DES_EDE3_CBC,         &des_ede3_cbc_info },
1465 #endif
1466 #endif /* MBEDTLS_DES_C */
1467 
1468 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1469     { MBEDTLS_CIPHER_NULL,                 &null_cipher_info },
1470 #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
1471 
1472     { MBEDTLS_CIPHER_NONE, NULL }
1473 };
1474 
1475 #define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1476 int mbedtls_cipher_supported[NUM_CIPHERS];
1477 
1478 #endif /* MBEDTLS_CIPHER_C */
1479