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