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