ReactOS 0.4.15-dev-7924-g5949c20
cipher_wrap.c
Go to the documentation of this file.
1
51#if !defined(MBEDTLS_CONFIG_FILE)
52#include "mbedtls/config.h"
53#else
54#include MBEDTLS_CONFIG_FILE
55#endif
56
57#if defined(MBEDTLS_CIPHER_C)
58
60
61#if defined(MBEDTLS_CHACHAPOLY_C)
62#include "mbedtls/chachapoly.h"
63#endif
64
65#if defined(MBEDTLS_AES_C)
66#include "mbedtls/aes.h"
67#endif
68
69#if defined(MBEDTLS_ARC4_C)
70#include "mbedtls/arc4.h"
71#endif
72
73#if defined(MBEDTLS_CAMELLIA_C)
74#include "mbedtls/camellia.h"
75#endif
76
77#if defined(MBEDTLS_ARIA_C)
78#include "mbedtls/aria.h"
79#endif
80
81#if defined(MBEDTLS_DES_C)
82#include "mbedtls/des.h"
83#endif
84
85#if defined(MBEDTLS_BLOWFISH_C)
86#include "mbedtls/blowfish.h"
87#endif
88
89#if defined(MBEDTLS_CHACHA20_C)
90#include "mbedtls/chacha20.h"
91#endif
92
93#if defined(MBEDTLS_GCM_C)
94#include "mbedtls/gcm.h"
95#endif
96
97#if defined(MBEDTLS_CCM_C)
98#include "mbedtls/ccm.h"
99#endif
100
101#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
102#include <string.h>
103#endif
104
105#if defined(MBEDTLS_PLATFORM_C)
106#include "mbedtls/platform.h"
107#else
108#include <stdlib.h>
109#define mbedtls_calloc calloc
110#define mbedtls_free free
111#endif
112
113#if defined(MBEDTLS_GCM_C)
114/* shared by all GCM ciphers */
115static void *gcm_ctx_alloc( void )
116{
117 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
118
119 if( ctx != NULL )
121
122 return( ctx );
123}
124
125static void gcm_ctx_free( void *ctx )
126{
128 mbedtls_free( ctx );
129}
130#endif /* MBEDTLS_GCM_C */
131
132#if defined(MBEDTLS_CCM_C)
133/* shared by all CCM ciphers */
134static void *ccm_ctx_alloc( void )
135{
136 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
137
138 if( ctx != NULL )
140
141 return( ctx );
142}
143
144static void ccm_ctx_free( void *ctx )
145{
147 mbedtls_free( ctx );
148}
149#endif /* MBEDTLS_CCM_C */
150
151#if defined(MBEDTLS_AES_C)
152
153static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
154 const unsigned char *input, unsigned char *output )
155{
157}
158
159#if defined(MBEDTLS_CIPHER_MODE_CBC)
160static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
161 unsigned char *iv, const unsigned char *input, unsigned char *output )
162{
164 output );
165}
166#endif /* MBEDTLS_CIPHER_MODE_CBC */
167
168#if defined(MBEDTLS_CIPHER_MODE_CFB)
169static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
170 size_t length, size_t *iv_off, unsigned char *iv,
171 const unsigned char *input, unsigned char *output )
172{
174 input, output );
175}
176#endif /* MBEDTLS_CIPHER_MODE_CFB */
177
178#if defined(MBEDTLS_CIPHER_MODE_OFB)
179static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
180 unsigned char *iv, const unsigned char *input, unsigned char *output )
181{
183 iv, input, output );
184}
185#endif /* MBEDTLS_CIPHER_MODE_OFB */
186
187#if defined(MBEDTLS_CIPHER_MODE_CTR)
188static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
189 unsigned char *nonce_counter, unsigned char *stream_block,
190 const unsigned char *input, unsigned char *output )
191{
192 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
193 stream_block, input, output );
194}
195#endif /* MBEDTLS_CIPHER_MODE_CTR */
196
197#if defined(MBEDTLS_CIPHER_MODE_XTS)
198static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
199 size_t length,
200 const unsigned char data_unit[16],
201 const unsigned char *input,
202 unsigned char *output )
203{
204 mbedtls_aes_xts_context *xts_ctx = ctx;
205 int mode;
206
207 switch( operation )
208 {
209 case MBEDTLS_ENCRYPT:
211 break;
212 case MBEDTLS_DECRYPT:
214 break;
215 default:
217 }
218
219 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
220 data_unit, input, output );
221}
222#endif /* MBEDTLS_CIPHER_MODE_XTS */
223
224static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
225 unsigned int key_bitlen )
226{
227 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
228}
229
230static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
231 unsigned int key_bitlen )
232{
233 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
234}
235
236static void * aes_ctx_alloc( void )
237{
239
240 if( aes == NULL )
241 return( NULL );
242
243 mbedtls_aes_init( aes );
244
245 return( aes );
246}
247
248static void aes_ctx_free( void *ctx )
249{
251 mbedtls_free( ctx );
252}
253
254static const mbedtls_cipher_base_t aes_info = {
256 aes_crypt_ecb_wrap,
257#if defined(MBEDTLS_CIPHER_MODE_CBC)
258 aes_crypt_cbc_wrap,
259#endif
260#if defined(MBEDTLS_CIPHER_MODE_CFB)
261 aes_crypt_cfb128_wrap,
262#endif
263#if defined(MBEDTLS_CIPHER_MODE_OFB)
264 aes_crypt_ofb_wrap,
265#endif
266#if defined(MBEDTLS_CIPHER_MODE_CTR)
267 aes_crypt_ctr_wrap,
268#endif
269#if defined(MBEDTLS_CIPHER_MODE_XTS)
270 NULL,
271#endif
272#if defined(MBEDTLS_CIPHER_MODE_STREAM)
273 NULL,
274#endif
275 aes_setkey_enc_wrap,
276 aes_setkey_dec_wrap,
277 aes_ctx_alloc,
278 aes_ctx_free
279};
280
281static const mbedtls_cipher_info_t aes_128_ecb_info = {
284 128,
285 "AES-128-ECB",
286 0,
287 0,
288 16,
289 &aes_info
290};
291
292static const mbedtls_cipher_info_t aes_192_ecb_info = {
295 192,
296 "AES-192-ECB",
297 0,
298 0,
299 16,
300 &aes_info
301};
302
303static const mbedtls_cipher_info_t aes_256_ecb_info = {
306 256,
307 "AES-256-ECB",
308 0,
309 0,
310 16,
311 &aes_info
312};
313
314#if defined(MBEDTLS_CIPHER_MODE_CBC)
315static const mbedtls_cipher_info_t aes_128_cbc_info = {
318 128,
319 "AES-128-CBC",
320 16,
321 0,
322 16,
323 &aes_info
324};
325
326static const mbedtls_cipher_info_t aes_192_cbc_info = {
329 192,
330 "AES-192-CBC",
331 16,
332 0,
333 16,
334 &aes_info
335};
336
337static const mbedtls_cipher_info_t aes_256_cbc_info = {
340 256,
341 "AES-256-CBC",
342 16,
343 0,
344 16,
345 &aes_info
346};
347#endif /* MBEDTLS_CIPHER_MODE_CBC */
348
349#if defined(MBEDTLS_CIPHER_MODE_CFB)
350static const mbedtls_cipher_info_t aes_128_cfb128_info = {
353 128,
354 "AES-128-CFB128",
355 16,
356 0,
357 16,
358 &aes_info
359};
360
361static const mbedtls_cipher_info_t aes_192_cfb128_info = {
364 192,
365 "AES-192-CFB128",
366 16,
367 0,
368 16,
369 &aes_info
370};
371
372static const mbedtls_cipher_info_t aes_256_cfb128_info = {
375 256,
376 "AES-256-CFB128",
377 16,
378 0,
379 16,
380 &aes_info
381};
382#endif /* MBEDTLS_CIPHER_MODE_CFB */
383
384#if defined(MBEDTLS_CIPHER_MODE_OFB)
385static const mbedtls_cipher_info_t aes_128_ofb_info = {
388 128,
389 "AES-128-OFB",
390 16,
391 0,
392 16,
393 &aes_info
394};
395
396static const mbedtls_cipher_info_t aes_192_ofb_info = {
399 192,
400 "AES-192-OFB",
401 16,
402 0,
403 16,
404 &aes_info
405};
406
407static const mbedtls_cipher_info_t aes_256_ofb_info = {
410 256,
411 "AES-256-OFB",
412 16,
413 0,
414 16,
415 &aes_info
416};
417#endif /* MBEDTLS_CIPHER_MODE_OFB */
418
419#if defined(MBEDTLS_CIPHER_MODE_CTR)
420static const mbedtls_cipher_info_t aes_128_ctr_info = {
423 128,
424 "AES-128-CTR",
425 16,
426 0,
427 16,
428 &aes_info
429};
430
431static const mbedtls_cipher_info_t aes_192_ctr_info = {
434 192,
435 "AES-192-CTR",
436 16,
437 0,
438 16,
439 &aes_info
440};
441
442static const mbedtls_cipher_info_t aes_256_ctr_info = {
445 256,
446 "AES-256-CTR",
447 16,
448 0,
449 16,
450 &aes_info
451};
452#endif /* MBEDTLS_CIPHER_MODE_CTR */
453
454#if defined(MBEDTLS_CIPHER_MODE_XTS)
455static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
456 unsigned int key_bitlen )
457{
458 mbedtls_aes_xts_context *xts_ctx = ctx;
459 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
460}
461
462static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
463 unsigned int key_bitlen )
464{
465 mbedtls_aes_xts_context *xts_ctx = ctx;
466 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
467}
468
469static void *xts_aes_ctx_alloc( void )
470{
471 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
472
473 if( xts_ctx != NULL )
474 mbedtls_aes_xts_init( xts_ctx );
475
476 return( xts_ctx );
477}
478
479static void xts_aes_ctx_free( void *ctx )
480{
481 mbedtls_aes_xts_context *xts_ctx = ctx;
482
483 if( xts_ctx == NULL )
484 return;
485
486 mbedtls_aes_xts_free( xts_ctx );
487 mbedtls_free( xts_ctx );
488}
489
490static const mbedtls_cipher_base_t xts_aes_info = {
492 NULL,
493#if defined(MBEDTLS_CIPHER_MODE_CBC)
494 NULL,
495#endif
496#if defined(MBEDTLS_CIPHER_MODE_CFB)
497 NULL,
498#endif
499#if defined(MBEDTLS_CIPHER_MODE_OFB)
500 NULL,
501#endif
502#if defined(MBEDTLS_CIPHER_MODE_CTR)
503 NULL,
504#endif
505#if defined(MBEDTLS_CIPHER_MODE_XTS)
506 aes_crypt_xts_wrap,
507#endif
508#if defined(MBEDTLS_CIPHER_MODE_STREAM)
509 NULL,
510#endif
511 xts_aes_setkey_enc_wrap,
512 xts_aes_setkey_dec_wrap,
513 xts_aes_ctx_alloc,
514 xts_aes_ctx_free
515};
516
517static const mbedtls_cipher_info_t aes_128_xts_info = {
520 256,
521 "AES-128-XTS",
522 16,
523 0,
524 16,
525 &xts_aes_info
526};
527
528static const mbedtls_cipher_info_t aes_256_xts_info = {
531 512,
532 "AES-256-XTS",
533 16,
534 0,
535 16,
536 &xts_aes_info
537};
538#endif /* MBEDTLS_CIPHER_MODE_XTS */
539
540#if defined(MBEDTLS_GCM_C)
541static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
542 unsigned int key_bitlen )
543{
545 key, key_bitlen );
546}
547
548static const mbedtls_cipher_base_t gcm_aes_info = {
550 NULL,
551#if defined(MBEDTLS_CIPHER_MODE_CBC)
552 NULL,
553#endif
554#if defined(MBEDTLS_CIPHER_MODE_CFB)
555 NULL,
556#endif
557#if defined(MBEDTLS_CIPHER_MODE_OFB)
558 NULL,
559#endif
560#if defined(MBEDTLS_CIPHER_MODE_CTR)
561 NULL,
562#endif
563#if defined(MBEDTLS_CIPHER_MODE_XTS)
564 NULL,
565#endif
566#if defined(MBEDTLS_CIPHER_MODE_STREAM)
567 NULL,
568#endif
569 gcm_aes_setkey_wrap,
570 gcm_aes_setkey_wrap,
571 gcm_ctx_alloc,
572 gcm_ctx_free,
573};
574
575static const mbedtls_cipher_info_t aes_128_gcm_info = {
578 128,
579 "AES-128-GCM",
580 12,
582 16,
583 &gcm_aes_info
584};
585
586static const mbedtls_cipher_info_t aes_192_gcm_info = {
589 192,
590 "AES-192-GCM",
591 12,
593 16,
594 &gcm_aes_info
595};
596
597static const mbedtls_cipher_info_t aes_256_gcm_info = {
600 256,
601 "AES-256-GCM",
602 12,
604 16,
605 &gcm_aes_info
606};
607#endif /* MBEDTLS_GCM_C */
608
609#if defined(MBEDTLS_CCM_C)
610static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
611 unsigned int key_bitlen )
612{
614 key, key_bitlen );
615}
616
617static const mbedtls_cipher_base_t ccm_aes_info = {
619 NULL,
620#if defined(MBEDTLS_CIPHER_MODE_CBC)
621 NULL,
622#endif
623#if defined(MBEDTLS_CIPHER_MODE_CFB)
624 NULL,
625#endif
626#if defined(MBEDTLS_CIPHER_MODE_OFB)
627 NULL,
628#endif
629#if defined(MBEDTLS_CIPHER_MODE_CTR)
630 NULL,
631#endif
632#if defined(MBEDTLS_CIPHER_MODE_XTS)
633 NULL,
634#endif
635#if defined(MBEDTLS_CIPHER_MODE_STREAM)
636 NULL,
637#endif
638 ccm_aes_setkey_wrap,
639 ccm_aes_setkey_wrap,
640 ccm_ctx_alloc,
641 ccm_ctx_free,
642};
643
644static const mbedtls_cipher_info_t aes_128_ccm_info = {
647 128,
648 "AES-128-CCM",
649 12,
651 16,
652 &ccm_aes_info
653};
654
655static const mbedtls_cipher_info_t aes_192_ccm_info = {
658 192,
659 "AES-192-CCM",
660 12,
662 16,
663 &ccm_aes_info
664};
665
666static const mbedtls_cipher_info_t aes_256_ccm_info = {
669 256,
670 "AES-256-CCM",
671 12,
673 16,
674 &ccm_aes_info
675};
676#endif /* MBEDTLS_CCM_C */
677
678#endif /* MBEDTLS_AES_C */
679
680#if defined(MBEDTLS_CAMELLIA_C)
681
682static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
683 const unsigned char *input, unsigned char *output )
684{
686 output );
687}
688
689#if defined(MBEDTLS_CIPHER_MODE_CBC)
690static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
691 size_t length, unsigned char *iv,
692 const unsigned char *input, unsigned char *output )
693{
695 input, output );
696}
697#endif /* MBEDTLS_CIPHER_MODE_CBC */
698
699#if defined(MBEDTLS_CIPHER_MODE_CFB)
700static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
701 size_t length, size_t *iv_off, unsigned char *iv,
702 const unsigned char *input, unsigned char *output )
703{
705 iv_off, iv, input, output );
706}
707#endif /* MBEDTLS_CIPHER_MODE_CFB */
708
709#if defined(MBEDTLS_CIPHER_MODE_CTR)
710static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
711 unsigned char *nonce_counter, unsigned char *stream_block,
712 const unsigned char *input, unsigned char *output )
713{
715 nonce_counter, stream_block, input, output );
716}
717#endif /* MBEDTLS_CIPHER_MODE_CTR */
718
719static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
720 unsigned int key_bitlen )
721{
723}
724
725static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
726 unsigned int key_bitlen )
727{
729}
730
731static void * camellia_ctx_alloc( void )
732{
735
736 if( ctx == NULL )
737 return( NULL );
738
740
741 return( ctx );
742}
743
744static void camellia_ctx_free( void *ctx )
745{
747 mbedtls_free( ctx );
748}
749
750static const mbedtls_cipher_base_t camellia_info = {
752 camellia_crypt_ecb_wrap,
753#if defined(MBEDTLS_CIPHER_MODE_CBC)
754 camellia_crypt_cbc_wrap,
755#endif
756#if defined(MBEDTLS_CIPHER_MODE_CFB)
757 camellia_crypt_cfb128_wrap,
758#endif
759#if defined(MBEDTLS_CIPHER_MODE_OFB)
760 NULL,
761#endif
762#if defined(MBEDTLS_CIPHER_MODE_CTR)
763 camellia_crypt_ctr_wrap,
764#endif
765#if defined(MBEDTLS_CIPHER_MODE_XTS)
766 NULL,
767#endif
768#if defined(MBEDTLS_CIPHER_MODE_STREAM)
769 NULL,
770#endif
771 camellia_setkey_enc_wrap,
772 camellia_setkey_dec_wrap,
773 camellia_ctx_alloc,
774 camellia_ctx_free
775};
776
777static const mbedtls_cipher_info_t camellia_128_ecb_info = {
780 128,
781 "CAMELLIA-128-ECB",
782 0,
783 0,
784 16,
785 &camellia_info
786};
787
788static const mbedtls_cipher_info_t camellia_192_ecb_info = {
791 192,
792 "CAMELLIA-192-ECB",
793 0,
794 0,
795 16,
796 &camellia_info
797};
798
799static const mbedtls_cipher_info_t camellia_256_ecb_info = {
802 256,
803 "CAMELLIA-256-ECB",
804 0,
805 0,
806 16,
807 &camellia_info
808};
809
810#if defined(MBEDTLS_CIPHER_MODE_CBC)
811static const mbedtls_cipher_info_t camellia_128_cbc_info = {
814 128,
815 "CAMELLIA-128-CBC",
816 16,
817 0,
818 16,
819 &camellia_info
820};
821
822static const mbedtls_cipher_info_t camellia_192_cbc_info = {
825 192,
826 "CAMELLIA-192-CBC",
827 16,
828 0,
829 16,
830 &camellia_info
831};
832
833static const mbedtls_cipher_info_t camellia_256_cbc_info = {
836 256,
837 "CAMELLIA-256-CBC",
838 16,
839 0,
840 16,
841 &camellia_info
842};
843#endif /* MBEDTLS_CIPHER_MODE_CBC */
844
845#if defined(MBEDTLS_CIPHER_MODE_CFB)
846static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
849 128,
850 "CAMELLIA-128-CFB128",
851 16,
852 0,
853 16,
854 &camellia_info
855};
856
857static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
860 192,
861 "CAMELLIA-192-CFB128",
862 16,
863 0,
864 16,
865 &camellia_info
866};
867
868static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
871 256,
872 "CAMELLIA-256-CFB128",
873 16,
874 0,
875 16,
876 &camellia_info
877};
878#endif /* MBEDTLS_CIPHER_MODE_CFB */
879
880#if defined(MBEDTLS_CIPHER_MODE_CTR)
881static const mbedtls_cipher_info_t camellia_128_ctr_info = {
884 128,
885 "CAMELLIA-128-CTR",
886 16,
887 0,
888 16,
889 &camellia_info
890};
891
892static const mbedtls_cipher_info_t camellia_192_ctr_info = {
895 192,
896 "CAMELLIA-192-CTR",
897 16,
898 0,
899 16,
900 &camellia_info
901};
902
903static const mbedtls_cipher_info_t camellia_256_ctr_info = {
906 256,
907 "CAMELLIA-256-CTR",
908 16,
909 0,
910 16,
911 &camellia_info
912};
913#endif /* MBEDTLS_CIPHER_MODE_CTR */
914
915#if defined(MBEDTLS_GCM_C)
916static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
917 unsigned int key_bitlen )
918{
920 key, key_bitlen );
921}
922
923static const mbedtls_cipher_base_t gcm_camellia_info = {
925 NULL,
926#if defined(MBEDTLS_CIPHER_MODE_CBC)
927 NULL,
928#endif
929#if defined(MBEDTLS_CIPHER_MODE_CFB)
930 NULL,
931#endif
932#if defined(MBEDTLS_CIPHER_MODE_OFB)
933 NULL,
934#endif
935#if defined(MBEDTLS_CIPHER_MODE_CTR)
936 NULL,
937#endif
938#if defined(MBEDTLS_CIPHER_MODE_XTS)
939 NULL,
940#endif
941#if defined(MBEDTLS_CIPHER_MODE_STREAM)
942 NULL,
943#endif
944 gcm_camellia_setkey_wrap,
945 gcm_camellia_setkey_wrap,
946 gcm_ctx_alloc,
947 gcm_ctx_free,
948};
949
950static const mbedtls_cipher_info_t camellia_128_gcm_info = {
953 128,
954 "CAMELLIA-128-GCM",
955 12,
957 16,
958 &gcm_camellia_info
959};
960
961static const mbedtls_cipher_info_t camellia_192_gcm_info = {
964 192,
965 "CAMELLIA-192-GCM",
966 12,
968 16,
969 &gcm_camellia_info
970};
971
972static const mbedtls_cipher_info_t camellia_256_gcm_info = {
975 256,
976 "CAMELLIA-256-GCM",
977 12,
979 16,
980 &gcm_camellia_info
981};
982#endif /* MBEDTLS_GCM_C */
983
984#if defined(MBEDTLS_CCM_C)
985static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
986 unsigned int key_bitlen )
987{
989 key, key_bitlen );
990}
991
992static const mbedtls_cipher_base_t ccm_camellia_info = {
994 NULL,
995#if defined(MBEDTLS_CIPHER_MODE_CBC)
996 NULL,
997#endif
998#if defined(MBEDTLS_CIPHER_MODE_CFB)
999 NULL,
1000#endif
1001#if defined(MBEDTLS_CIPHER_MODE_OFB)
1002 NULL,
1003#endif
1004#if defined(MBEDTLS_CIPHER_MODE_CTR)
1005 NULL,
1006#endif
1007#if defined(MBEDTLS_CIPHER_MODE_XTS)
1008 NULL,
1009#endif
1010#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1011 NULL,
1012#endif
1013 ccm_camellia_setkey_wrap,
1014 ccm_camellia_setkey_wrap,
1015 ccm_ctx_alloc,
1016 ccm_ctx_free,
1017};
1018
1019static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1022 128,
1023 "CAMELLIA-128-CCM",
1024 12,
1026 16,
1027 &ccm_camellia_info
1028};
1029
1030static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1033 192,
1034 "CAMELLIA-192-CCM",
1035 12,
1037 16,
1038 &ccm_camellia_info
1039};
1040
1041static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1044 256,
1045 "CAMELLIA-256-CCM",
1046 12,
1048 16,
1049 &ccm_camellia_info
1050};
1051#endif /* MBEDTLS_CCM_C */
1052
1053#endif /* MBEDTLS_CAMELLIA_C */
1054
1055#if defined(MBEDTLS_ARIA_C)
1056
1057static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1058 const unsigned char *input, unsigned char *output )
1059{
1060 (void) operation;
1062 output );
1063}
1064
1065#if defined(MBEDTLS_CIPHER_MODE_CBC)
1066static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1067 size_t length, unsigned char *iv,
1068 const unsigned char *input, unsigned char *output )
1069{
1071 input, output );
1072}
1073#endif /* MBEDTLS_CIPHER_MODE_CBC */
1074
1075#if defined(MBEDTLS_CIPHER_MODE_CFB)
1076static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1077 size_t length, size_t *iv_off, unsigned char *iv,
1078 const unsigned char *input, unsigned char *output )
1079{
1081 iv_off, iv, input, output );
1082}
1083#endif /* MBEDTLS_CIPHER_MODE_CFB */
1084
1085#if defined(MBEDTLS_CIPHER_MODE_CTR)
1086static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1087 unsigned char *nonce_counter, unsigned char *stream_block,
1088 const unsigned char *input, unsigned char *output )
1089{
1091 nonce_counter, stream_block, input, output );
1092}
1093#endif /* MBEDTLS_CIPHER_MODE_CTR */
1094
1095static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1096 unsigned int key_bitlen )
1097{
1098 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1099}
1100
1101static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1102 unsigned int key_bitlen )
1103{
1104 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1105}
1106
1107static void * aria_ctx_alloc( void )
1108{
1110 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1111
1112 if( ctx == NULL )
1113 return( NULL );
1114
1116
1117 return( ctx );
1118}
1119
1120static void aria_ctx_free( void *ctx )
1121{
1123 mbedtls_free( ctx );
1124}
1125
1126static const mbedtls_cipher_base_t aria_info = {
1128 aria_crypt_ecb_wrap,
1129#if defined(MBEDTLS_CIPHER_MODE_CBC)
1130 aria_crypt_cbc_wrap,
1131#endif
1132#if defined(MBEDTLS_CIPHER_MODE_CFB)
1133 aria_crypt_cfb128_wrap,
1134#endif
1135#if defined(MBEDTLS_CIPHER_MODE_OFB)
1136 NULL,
1137#endif
1138#if defined(MBEDTLS_CIPHER_MODE_CTR)
1139 aria_crypt_ctr_wrap,
1140#endif
1141#if defined(MBEDTLS_CIPHER_MODE_XTS)
1142 NULL,
1143#endif
1144#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1145 NULL,
1146#endif
1147 aria_setkey_enc_wrap,
1148 aria_setkey_dec_wrap,
1149 aria_ctx_alloc,
1150 aria_ctx_free
1151};
1152
1153static const mbedtls_cipher_info_t aria_128_ecb_info = {
1156 128,
1157 "ARIA-128-ECB",
1158 0,
1159 0,
1160 16,
1161 &aria_info
1162};
1163
1164static const mbedtls_cipher_info_t aria_192_ecb_info = {
1167 192,
1168 "ARIA-192-ECB",
1169 0,
1170 0,
1171 16,
1172 &aria_info
1173};
1174
1175static const mbedtls_cipher_info_t aria_256_ecb_info = {
1178 256,
1179 "ARIA-256-ECB",
1180 0,
1181 0,
1182 16,
1183 &aria_info
1184};
1185
1186#if defined(MBEDTLS_CIPHER_MODE_CBC)
1187static const mbedtls_cipher_info_t aria_128_cbc_info = {
1190 128,
1191 "ARIA-128-CBC",
1192 16,
1193 0,
1194 16,
1195 &aria_info
1196};
1197
1198static const mbedtls_cipher_info_t aria_192_cbc_info = {
1201 192,
1202 "ARIA-192-CBC",
1203 16,
1204 0,
1205 16,
1206 &aria_info
1207};
1208
1209static const mbedtls_cipher_info_t aria_256_cbc_info = {
1212 256,
1213 "ARIA-256-CBC",
1214 16,
1215 0,
1216 16,
1217 &aria_info
1218};
1219#endif /* MBEDTLS_CIPHER_MODE_CBC */
1220
1221#if defined(MBEDTLS_CIPHER_MODE_CFB)
1222static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1225 128,
1226 "ARIA-128-CFB128",
1227 16,
1228 0,
1229 16,
1230 &aria_info
1231};
1232
1233static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1236 192,
1237 "ARIA-192-CFB128",
1238 16,
1239 0,
1240 16,
1241 &aria_info
1242};
1243
1244static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1247 256,
1248 "ARIA-256-CFB128",
1249 16,
1250 0,
1251 16,
1252 &aria_info
1253};
1254#endif /* MBEDTLS_CIPHER_MODE_CFB */
1255
1256#if defined(MBEDTLS_CIPHER_MODE_CTR)
1257static const mbedtls_cipher_info_t aria_128_ctr_info = {
1260 128,
1261 "ARIA-128-CTR",
1262 16,
1263 0,
1264 16,
1265 &aria_info
1266};
1267
1268static const mbedtls_cipher_info_t aria_192_ctr_info = {
1271 192,
1272 "ARIA-192-CTR",
1273 16,
1274 0,
1275 16,
1276 &aria_info
1277};
1278
1279static const mbedtls_cipher_info_t aria_256_ctr_info = {
1282 256,
1283 "ARIA-256-CTR",
1284 16,
1285 0,
1286 16,
1287 &aria_info
1288};
1289#endif /* MBEDTLS_CIPHER_MODE_CTR */
1290
1291#if defined(MBEDTLS_GCM_C)
1292static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1293 unsigned int key_bitlen )
1294{
1296 key, key_bitlen );
1297}
1298
1299static const mbedtls_cipher_base_t gcm_aria_info = {
1301 NULL,
1302#if defined(MBEDTLS_CIPHER_MODE_CBC)
1303 NULL,
1304#endif
1305#if defined(MBEDTLS_CIPHER_MODE_CFB)
1306 NULL,
1307#endif
1308#if defined(MBEDTLS_CIPHER_MODE_OFB)
1309 NULL,
1310#endif
1311#if defined(MBEDTLS_CIPHER_MODE_CTR)
1312 NULL,
1313#endif
1314#if defined(MBEDTLS_CIPHER_MODE_XTS)
1315 NULL,
1316#endif
1317#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1318 NULL,
1319#endif
1320 gcm_aria_setkey_wrap,
1321 gcm_aria_setkey_wrap,
1322 gcm_ctx_alloc,
1323 gcm_ctx_free,
1324};
1325
1326static const mbedtls_cipher_info_t aria_128_gcm_info = {
1329 128,
1330 "ARIA-128-GCM",
1331 12,
1333 16,
1334 &gcm_aria_info
1335};
1336
1337static const mbedtls_cipher_info_t aria_192_gcm_info = {
1340 192,
1341 "ARIA-192-GCM",
1342 12,
1344 16,
1345 &gcm_aria_info
1346};
1347
1348static const mbedtls_cipher_info_t aria_256_gcm_info = {
1351 256,
1352 "ARIA-256-GCM",
1353 12,
1355 16,
1356 &gcm_aria_info
1357};
1358#endif /* MBEDTLS_GCM_C */
1359
1360#if defined(MBEDTLS_CCM_C)
1361static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1362 unsigned int key_bitlen )
1363{
1365 key, key_bitlen );
1366}
1367
1368static const mbedtls_cipher_base_t ccm_aria_info = {
1370 NULL,
1371#if defined(MBEDTLS_CIPHER_MODE_CBC)
1372 NULL,
1373#endif
1374#if defined(MBEDTLS_CIPHER_MODE_CFB)
1375 NULL,
1376#endif
1377#if defined(MBEDTLS_CIPHER_MODE_OFB)
1378 NULL,
1379#endif
1380#if defined(MBEDTLS_CIPHER_MODE_CTR)
1381 NULL,
1382#endif
1383#if defined(MBEDTLS_CIPHER_MODE_XTS)
1384 NULL,
1385#endif
1386#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1387 NULL,
1388#endif
1389 ccm_aria_setkey_wrap,
1390 ccm_aria_setkey_wrap,
1391 ccm_ctx_alloc,
1392 ccm_ctx_free,
1393};
1394
1395static const mbedtls_cipher_info_t aria_128_ccm_info = {
1398 128,
1399 "ARIA-128-CCM",
1400 12,
1402 16,
1403 &ccm_aria_info
1404};
1405
1406static const mbedtls_cipher_info_t aria_192_ccm_info = {
1409 192,
1410 "ARIA-192-CCM",
1411 12,
1413 16,
1414 &ccm_aria_info
1415};
1416
1417static const mbedtls_cipher_info_t aria_256_ccm_info = {
1420 256,
1421 "ARIA-256-CCM",
1422 12,
1424 16,
1425 &ccm_aria_info
1426};
1427#endif /* MBEDTLS_CCM_C */
1428
1429#endif /* MBEDTLS_ARIA_C */
1430
1431#if defined(MBEDTLS_DES_C)
1432
1433static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1434 const unsigned char *input, unsigned char *output )
1435{
1436 ((void) operation);
1437 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
1438}
1439
1440static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1441 const unsigned char *input, unsigned char *output )
1442{
1443 ((void) operation);
1445}
1446
1447#if defined(MBEDTLS_CIPHER_MODE_CBC)
1448static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
1449 unsigned char *iv, const unsigned char *input, unsigned char *output )
1450{
1452 output );
1453}
1454#endif /* MBEDTLS_CIPHER_MODE_CBC */
1455
1456#if defined(MBEDTLS_CIPHER_MODE_CBC)
1457static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
1458 unsigned char *iv, const unsigned char *input, unsigned char *output )
1459{
1461 output );
1462}
1463#endif /* MBEDTLS_CIPHER_MODE_CBC */
1464
1465static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
1466 unsigned int key_bitlen )
1467{
1468 ((void) key_bitlen);
1469
1471}
1472
1473static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
1474 unsigned int key_bitlen )
1475{
1476 ((void) key_bitlen);
1477
1479}
1480
1481static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
1482 unsigned int key_bitlen )
1483{
1484 ((void) key_bitlen);
1485
1487}
1488
1489static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
1490 unsigned int key_bitlen )
1491{
1492 ((void) key_bitlen);
1493
1495}
1496
1497static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
1498 unsigned int key_bitlen )
1499{
1500 ((void) key_bitlen);
1501
1503}
1504
1505static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
1506 unsigned int key_bitlen )
1507{
1508 ((void) key_bitlen);
1509
1511}
1512
1513static void * des_ctx_alloc( void )
1514{
1516
1517 if( des == NULL )
1518 return( NULL );
1519
1521
1522 return( des );
1523}
1524
1525static void des_ctx_free( void *ctx )
1526{
1528 mbedtls_free( ctx );
1529}
1530
1531static void * des3_ctx_alloc( void )
1532{
1534 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
1535
1536 if( des3 == NULL )
1537 return( NULL );
1538
1539 mbedtls_des3_init( des3 );
1540
1541 return( des3 );
1542}
1543
1544static void des3_ctx_free( void *ctx )
1545{
1547 mbedtls_free( ctx );
1548}
1549
1550static const mbedtls_cipher_base_t des_info = {
1552 des_crypt_ecb_wrap,
1553#if defined(MBEDTLS_CIPHER_MODE_CBC)
1554 des_crypt_cbc_wrap,
1555#endif
1556#if defined(MBEDTLS_CIPHER_MODE_CFB)
1557 NULL,
1558#endif
1559#if defined(MBEDTLS_CIPHER_MODE_OFB)
1560 NULL,
1561#endif
1562#if defined(MBEDTLS_CIPHER_MODE_CTR)
1563 NULL,
1564#endif
1565#if defined(MBEDTLS_CIPHER_MODE_XTS)
1566 NULL,
1567#endif
1568#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1569 NULL,
1570#endif
1571 des_setkey_enc_wrap,
1572 des_setkey_dec_wrap,
1573 des_ctx_alloc,
1574 des_ctx_free
1575};
1576
1577static const mbedtls_cipher_info_t des_ecb_info = {
1581 "DES-ECB",
1582 0,
1583 0,
1584 8,
1585 &des_info
1586};
1587
1588#if defined(MBEDTLS_CIPHER_MODE_CBC)
1589static const mbedtls_cipher_info_t des_cbc_info = {
1593 "DES-CBC",
1594 8,
1595 0,
1596 8,
1597 &des_info
1598};
1599#endif /* MBEDTLS_CIPHER_MODE_CBC */
1600
1601static const mbedtls_cipher_base_t des_ede_info = {
1603 des3_crypt_ecb_wrap,
1604#if defined(MBEDTLS_CIPHER_MODE_CBC)
1605 des3_crypt_cbc_wrap,
1606#endif
1607#if defined(MBEDTLS_CIPHER_MODE_CFB)
1608 NULL,
1609#endif
1610#if defined(MBEDTLS_CIPHER_MODE_OFB)
1611 NULL,
1612#endif
1613#if defined(MBEDTLS_CIPHER_MODE_CTR)
1614 NULL,
1615#endif
1616#if defined(MBEDTLS_CIPHER_MODE_XTS)
1617 NULL,
1618#endif
1619#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1620 NULL,
1621#endif
1622 des3_set2key_enc_wrap,
1623 des3_set2key_dec_wrap,
1624 des3_ctx_alloc,
1625 des3_ctx_free
1626};
1627
1628static const mbedtls_cipher_info_t des_ede_ecb_info = {
1632 "DES-EDE-ECB",
1633 0,
1634 0,
1635 8,
1636 &des_ede_info
1637};
1638
1639#if defined(MBEDTLS_CIPHER_MODE_CBC)
1640static const mbedtls_cipher_info_t des_ede_cbc_info = {
1644 "DES-EDE-CBC",
1645 8,
1646 0,
1647 8,
1648 &des_ede_info
1649};
1650#endif /* MBEDTLS_CIPHER_MODE_CBC */
1651
1652static const mbedtls_cipher_base_t des_ede3_info = {
1654 des3_crypt_ecb_wrap,
1655#if defined(MBEDTLS_CIPHER_MODE_CBC)
1656 des3_crypt_cbc_wrap,
1657#endif
1658#if defined(MBEDTLS_CIPHER_MODE_CFB)
1659 NULL,
1660#endif
1661#if defined(MBEDTLS_CIPHER_MODE_OFB)
1662 NULL,
1663#endif
1664#if defined(MBEDTLS_CIPHER_MODE_CTR)
1665 NULL,
1666#endif
1667#if defined(MBEDTLS_CIPHER_MODE_XTS)
1668 NULL,
1669#endif
1670#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1671 NULL,
1672#endif
1673 des3_set3key_enc_wrap,
1674 des3_set3key_dec_wrap,
1675 des3_ctx_alloc,
1676 des3_ctx_free
1677};
1678
1679static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1683 "DES-EDE3-ECB",
1684 0,
1685 0,
1686 8,
1687 &des_ede3_info
1688};
1689#if defined(MBEDTLS_CIPHER_MODE_CBC)
1690static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1694 "DES-EDE3-CBC",
1695 8,
1696 0,
1697 8,
1698 &des_ede3_info
1699};
1700#endif /* MBEDTLS_CIPHER_MODE_CBC */
1701#endif /* MBEDTLS_DES_C */
1702
1703#if defined(MBEDTLS_BLOWFISH_C)
1704
1705static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1706 const unsigned char *input, unsigned char *output )
1707{
1709 output );
1710}
1711
1712#if defined(MBEDTLS_CIPHER_MODE_CBC)
1713static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1714 size_t length, unsigned char *iv, const unsigned char *input,
1715 unsigned char *output )
1716{
1718 input, output );
1719}
1720#endif /* MBEDTLS_CIPHER_MODE_CBC */
1721
1722#if defined(MBEDTLS_CIPHER_MODE_CFB)
1723static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
1724 size_t length, size_t *iv_off, unsigned char *iv,
1725 const unsigned char *input, unsigned char *output )
1726{
1728 iv_off, iv, input, output );
1729}
1730#endif /* MBEDTLS_CIPHER_MODE_CFB */
1731
1732#if defined(MBEDTLS_CIPHER_MODE_CTR)
1733static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1734 unsigned char *nonce_counter, unsigned char *stream_block,
1735 const unsigned char *input, unsigned char *output )
1736{
1738 nonce_counter, stream_block, input, output );
1739}
1740#endif /* MBEDTLS_CIPHER_MODE_CTR */
1741
1742static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1743 unsigned int key_bitlen )
1744{
1745 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
1746}
1747
1748static void * blowfish_ctx_alloc( void )
1749{
1752
1753 if( ctx == NULL )
1754 return( NULL );
1755
1757
1758 return( ctx );
1759}
1760
1761static void blowfish_ctx_free( void *ctx )
1762{
1764 mbedtls_free( ctx );
1765}
1766
1767static const mbedtls_cipher_base_t blowfish_info = {
1769 blowfish_crypt_ecb_wrap,
1770#if defined(MBEDTLS_CIPHER_MODE_CBC)
1771 blowfish_crypt_cbc_wrap,
1772#endif
1773#if defined(MBEDTLS_CIPHER_MODE_CFB)
1774 blowfish_crypt_cfb64_wrap,
1775#endif
1776#if defined(MBEDTLS_CIPHER_MODE_OFB)
1777 NULL,
1778#endif
1779#if defined(MBEDTLS_CIPHER_MODE_CTR)
1780 blowfish_crypt_ctr_wrap,
1781#endif
1782#if defined(MBEDTLS_CIPHER_MODE_XTS)
1783 NULL,
1784#endif
1785#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1786 NULL,
1787#endif
1788 blowfish_setkey_wrap,
1789 blowfish_setkey_wrap,
1790 blowfish_ctx_alloc,
1791 blowfish_ctx_free
1792};
1793
1794static const mbedtls_cipher_info_t blowfish_ecb_info = {
1797 128,
1798 "BLOWFISH-ECB",
1799 0,
1801 8,
1802 &blowfish_info
1803};
1804
1805#if defined(MBEDTLS_CIPHER_MODE_CBC)
1806static const mbedtls_cipher_info_t blowfish_cbc_info = {
1809 128,
1810 "BLOWFISH-CBC",
1811 8,
1813 8,
1814 &blowfish_info
1815};
1816#endif /* MBEDTLS_CIPHER_MODE_CBC */
1817
1818#if defined(MBEDTLS_CIPHER_MODE_CFB)
1819static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1822 128,
1823 "BLOWFISH-CFB64",
1824 8,
1826 8,
1827 &blowfish_info
1828};
1829#endif /* MBEDTLS_CIPHER_MODE_CFB */
1830
1831#if defined(MBEDTLS_CIPHER_MODE_CTR)
1832static const mbedtls_cipher_info_t blowfish_ctr_info = {
1835 128,
1836 "BLOWFISH-CTR",
1837 8,
1839 8,
1840 &blowfish_info
1841};
1842#endif /* MBEDTLS_CIPHER_MODE_CTR */
1843#endif /* MBEDTLS_BLOWFISH_C */
1844
1845#if defined(MBEDTLS_ARC4_C)
1846static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1847 const unsigned char *input,
1848 unsigned char *output )
1849{
1850 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
1851}
1852
1853static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1854 unsigned int key_bitlen )
1855{
1856 /* we get key_bitlen in bits, arc4 expects it in bytes */
1857 if( key_bitlen % 8 != 0 )
1859
1860 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
1861 return( 0 );
1862}
1863
1864static void * arc4_ctx_alloc( void )
1865{
1867 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
1868
1869 if( ctx == NULL )
1870 return( NULL );
1871
1873
1874 return( ctx );
1875}
1876
1877static void arc4_ctx_free( void *ctx )
1878{
1880 mbedtls_free( ctx );
1881}
1882
1883static const mbedtls_cipher_base_t arc4_base_info = {
1885 NULL,
1886#if defined(MBEDTLS_CIPHER_MODE_CBC)
1887 NULL,
1888#endif
1889#if defined(MBEDTLS_CIPHER_MODE_CFB)
1890 NULL,
1891#endif
1892#if defined(MBEDTLS_CIPHER_MODE_OFB)
1893 NULL,
1894#endif
1895#if defined(MBEDTLS_CIPHER_MODE_CTR)
1896 NULL,
1897#endif
1898#if defined(MBEDTLS_CIPHER_MODE_XTS)
1899 NULL,
1900#endif
1901#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1902 arc4_crypt_stream_wrap,
1903#endif
1904 arc4_setkey_wrap,
1905 arc4_setkey_wrap,
1906 arc4_ctx_alloc,
1907 arc4_ctx_free
1908};
1909
1910static const mbedtls_cipher_info_t arc4_128_info = {
1913 128,
1914 "ARC4-128",
1915 0,
1916 0,
1917 1,
1918 &arc4_base_info
1919};
1920#endif /* MBEDTLS_ARC4_C */
1921
1922#if defined(MBEDTLS_CHACHA20_C)
1923
1924static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1925 unsigned int key_bitlen )
1926{
1927 if( key_bitlen != 256U )
1929
1932
1933 return( 0 );
1934}
1935
1936static int chacha20_stream_wrap( void *ctx, size_t length,
1937 const unsigned char *input,
1938 unsigned char *output )
1939{
1940 int ret;
1941
1945
1946 return( ret );
1947}
1948
1949static void * chacha20_ctx_alloc( void )
1950{
1953
1954 if( ctx == NULL )
1955 return( NULL );
1956
1958
1959 return( ctx );
1960}
1961
1962static void chacha20_ctx_free( void *ctx )
1963{
1965 mbedtls_free( ctx );
1966}
1967
1968static const mbedtls_cipher_base_t chacha20_base_info = {
1970 NULL,
1971#if defined(MBEDTLS_CIPHER_MODE_CBC)
1972 NULL,
1973#endif
1974#if defined(MBEDTLS_CIPHER_MODE_CFB)
1975 NULL,
1976#endif
1977#if defined(MBEDTLS_CIPHER_MODE_OFB)
1978 NULL,
1979#endif
1980#if defined(MBEDTLS_CIPHER_MODE_CTR)
1981 NULL,
1982#endif
1983#if defined(MBEDTLS_CIPHER_MODE_XTS)
1984 NULL,
1985#endif
1986#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1987 chacha20_stream_wrap,
1988#endif
1989 chacha20_setkey_wrap,
1990 chacha20_setkey_wrap,
1991 chacha20_ctx_alloc,
1992 chacha20_ctx_free
1993};
1994static const mbedtls_cipher_info_t chacha20_info = {
1997 256,
1998 "CHACHA20",
1999 12,
2000 0,
2001 1,
2002 &chacha20_base_info
2003};
2004#endif /* MBEDTLS_CHACHA20_C */
2005
2006#if defined(MBEDTLS_CHACHAPOLY_C)
2007
2008static int chachapoly_setkey_wrap( void *ctx,
2009 const unsigned char *key,
2010 unsigned int key_bitlen )
2011{
2012 if( key_bitlen != 256U )
2014
2017
2018 return( 0 );
2019}
2020
2021static void * chachapoly_ctx_alloc( void )
2022{
2025
2026 if( ctx == NULL )
2027 return( NULL );
2028
2030
2031 return( ctx );
2032}
2033
2034static void chachapoly_ctx_free( void *ctx )
2035{
2037 mbedtls_free( ctx );
2038}
2039
2040static const mbedtls_cipher_base_t chachapoly_base_info = {
2042 NULL,
2043#if defined(MBEDTLS_CIPHER_MODE_CBC)
2044 NULL,
2045#endif
2046#if defined(MBEDTLS_CIPHER_MODE_CFB)
2047 NULL,
2048#endif
2049#if defined(MBEDTLS_CIPHER_MODE_OFB)
2050 NULL,
2051#endif
2052#if defined(MBEDTLS_CIPHER_MODE_CTR)
2053 NULL,
2054#endif
2055#if defined(MBEDTLS_CIPHER_MODE_XTS)
2056 NULL,
2057#endif
2058#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2059 NULL,
2060#endif
2061 chachapoly_setkey_wrap,
2062 chachapoly_setkey_wrap,
2063 chachapoly_ctx_alloc,
2064 chachapoly_ctx_free
2065};
2066static const mbedtls_cipher_info_t chachapoly_info = {
2069 256,
2070 "CHACHA20-POLY1305",
2071 12,
2072 0,
2073 1,
2074 &chachapoly_base_info
2075};
2076#endif /* MBEDTLS_CHACHAPOLY_C */
2077
2078#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2079static int null_crypt_stream( void *ctx, size_t length,
2080 const unsigned char *input,
2081 unsigned char *output )
2082{
2083 ((void) ctx);
2084 memmove( output, input, length );
2085 return( 0 );
2086}
2087
2088static int null_setkey( void *ctx, const unsigned char *key,
2089 unsigned int key_bitlen )
2090{
2091 ((void) ctx);
2092 ((void) key);
2093 ((void) key_bitlen);
2094
2095 return( 0 );
2096}
2097
2098static void * null_ctx_alloc( void )
2099{
2100 return( (void *) 1 );
2101}
2102
2103static void null_ctx_free( void *ctx )
2104{
2105 ((void) ctx);
2106}
2107
2108static const mbedtls_cipher_base_t null_base_info = {
2110 NULL,
2111#if defined(MBEDTLS_CIPHER_MODE_CBC)
2112 NULL,
2113#endif
2114#if defined(MBEDTLS_CIPHER_MODE_CFB)
2115 NULL,
2116#endif
2117#if defined(MBEDTLS_CIPHER_MODE_OFB)
2118 NULL,
2119#endif
2120#if defined(MBEDTLS_CIPHER_MODE_CTR)
2121 NULL,
2122#endif
2123#if defined(MBEDTLS_CIPHER_MODE_XTS)
2124 NULL,
2125#endif
2126#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2127 null_crypt_stream,
2128#endif
2129 null_setkey,
2130 null_setkey,
2131 null_ctx_alloc,
2132 null_ctx_free
2133};
2134
2135static const mbedtls_cipher_info_t null_cipher_info = {
2138 0,
2139 "NULL",
2140 0,
2141 0,
2142 1,
2143 &null_base_info
2144};
2145#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
2146
2148{
2149#if defined(MBEDTLS_AES_C)
2150 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2151 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2152 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2153#if defined(MBEDTLS_CIPHER_MODE_CBC)
2154 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2155 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2156 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
2157#endif
2158#if defined(MBEDTLS_CIPHER_MODE_CFB)
2159 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2160 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2161 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
2162#endif
2163#if defined(MBEDTLS_CIPHER_MODE_OFB)
2164 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2165 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2166 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2167#endif
2168#if defined(MBEDTLS_CIPHER_MODE_CTR)
2169 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2170 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2171 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
2172#endif
2173#if defined(MBEDTLS_CIPHER_MODE_XTS)
2174 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2175 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2176#endif
2177#if defined(MBEDTLS_GCM_C)
2178 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2179 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2180 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
2181#endif
2182#if defined(MBEDTLS_CCM_C)
2183 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2184 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2185 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
2186#endif
2187#endif /* MBEDTLS_AES_C */
2188
2189#if defined(MBEDTLS_ARC4_C)
2190 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
2191#endif
2192
2193#if defined(MBEDTLS_BLOWFISH_C)
2194 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2195#if defined(MBEDTLS_CIPHER_MODE_CBC)
2196 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
2197#endif
2198#if defined(MBEDTLS_CIPHER_MODE_CFB)
2199 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
2200#endif
2201#if defined(MBEDTLS_CIPHER_MODE_CTR)
2202 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
2203#endif
2204#endif /* MBEDTLS_BLOWFISH_C */
2205
2206#if defined(MBEDTLS_CAMELLIA_C)
2207 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2208 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2209 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2210#if defined(MBEDTLS_CIPHER_MODE_CBC)
2211 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2212 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2213 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
2214#endif
2215#if defined(MBEDTLS_CIPHER_MODE_CFB)
2216 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2217 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2218 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
2219#endif
2220#if defined(MBEDTLS_CIPHER_MODE_CTR)
2221 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2222 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2223 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
2224#endif
2225#if defined(MBEDTLS_GCM_C)
2226 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2227 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2228 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
2229#endif
2230#if defined(MBEDTLS_CCM_C)
2231 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2232 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2233 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
2234#endif
2235#endif /* MBEDTLS_CAMELLIA_C */
2236
2237#if defined(MBEDTLS_ARIA_C)
2238 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2239 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2240 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2241#if defined(MBEDTLS_CIPHER_MODE_CBC)
2242 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2243 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2244 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2245#endif
2246#if defined(MBEDTLS_CIPHER_MODE_CFB)
2247 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2248 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2249 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2250#endif
2251#if defined(MBEDTLS_CIPHER_MODE_CTR)
2252 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2253 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2254 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2255#endif
2256#if defined(MBEDTLS_GCM_C)
2257 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2258 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2259 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2260#endif
2261#if defined(MBEDTLS_CCM_C)
2262 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2263 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2264 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2265#endif
2266#endif /* MBEDTLS_ARIA_C */
2267
2268#if defined(MBEDTLS_DES_C)
2269 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2270 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2271 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2272#if defined(MBEDTLS_CIPHER_MODE_CBC)
2273 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2274 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2275 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
2276#endif
2277#endif /* MBEDTLS_DES_C */
2278
2279#if defined(MBEDTLS_CHACHA20_C)
2280 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2281#endif
2282
2283#if defined(MBEDTLS_CHACHAPOLY_C)
2284 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
2285#endif
2286
2287#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2288 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2289#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
2290
2292};
2293
2294#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2295int mbedtls_cipher_supported[NUM_CIPHERS];
2296
2297#endif /* MBEDTLS_CIPHER_C */
This file contains AES definitions and functions.
int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
This function performs an AES single-block encryption or decryption operation.
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-OFB (Output Feedback Mode) encryption or decryption operation.
int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CBC encryption or decryption operation on full blocks.
int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CTR encryption or decryption operation.
int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for decryption and sets the decryption key.
int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char *input, unsigned char *output)
This function performs an AES-XTS encryption or decryption operation for an entire XTS data unit.
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CFB128 encryption or decryption operation.
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
#define MBEDTLS_AES_DECRYPT
Definition: aes.h:81
#define MBEDTLS_AES_ENCRYPT
Definition: aes.h:80
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
void mbedtls_aes_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for encryption and sets the encryption key.
The ARCFOUR stream cipher.
int mbedtls_arc4_crypt(mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
void mbedtls_arc4_setup(mbedtls_arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
void mbedtls_arc4_init(mbedtls_arc4_context *ctx)
Initialize ARC4 context.
void mbedtls_arc4_free(mbedtls_arc4_context *ctx)
Clear ARC4 context.
ARIA block cipher.
int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx, int mode, size_t length, unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], const unsigned char *input, unsigned char *output)
This function performs an ARIA-CBC encryption or decryption operation on full blocks.
int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], const unsigned char *input, unsigned char *output)
This function performs an ARIA-CFB128 encryption or decryption operation.
void mbedtls_aria_init(mbedtls_aria_context *ctx)
This function initializes the specified ARIA context.
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx, const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], unsigned char output[MBEDTLS_ARIA_BLOCKSIZE])
This function performs an ARIA single-block encryption or decryption operation.
void mbedtls_aria_free(mbedtls_aria_context *ctx)
This function releases and clears the specified ARIA context.
int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE], unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE], const unsigned char *input, unsigned char *output)
This function performs an ARIA-CTR encryption or decryption operation.
operation
Definition: copy.c:29
Blowfish block cipher.
int mbedtls_blowfish_crypt_cbc(mbedtls_blowfish_context *ctx, int mode, size_t length, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish-CBC buffer encryption/decryption operation.
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a Blowfish key schedule operation.
int mbedtls_blowfish_crypt_ctr(mbedtls_blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish-CTR buffer encryption/decryption operation.
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize a Blowfish context.
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.
int mbedtls_blowfish_crypt_cfb64(mbedtls_blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish CFB buffer encryption/decryption operation.
int mbedtls_blowfish_crypt_ecb(mbedtls_blowfish_context *ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE])
Perform a Blowfish-ECB block encryption/decryption operation.
Camellia block cipher.
int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a CAMELLIA key schedule operation for encryption.
int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
Perform a CAMELLIA-ECB block encryption/decryption operation.
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a CAMELLIA key schedule operation for decryption.
int mbedtls_camellia_crypt_cbc(mbedtls_camellia_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
Perform a CAMELLIA-CBC buffer encryption/decryption operation.
void mbedtls_camellia_init(mbedtls_camellia_context *ctx)
Initialize a CAMELLIA context.
void mbedtls_camellia_free(mbedtls_camellia_context *ctx)
Clear a CAMELLIA context.
int mbedtls_camellia_crypt_ctr(mbedtls_camellia_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output)
Perform a CAMELLIA-CTR buffer encryption/decryption operation.
int mbedtls_camellia_crypt_cfb128(mbedtls_camellia_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
Perform a CAMELLIA-CFB128 buffer encryption/decryption operation.
This file provides an API for the CCM authenticated encryption mode for block ciphers.
void mbedtls_ccm_free(mbedtls_ccm_context *ctx)
This function releases and clears the specified CCM context and underlying cipher sub-context.
int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
This function initializes the CCM context set in the ctx parameter and sets the encryption key.
void mbedtls_ccm_init(mbedtls_ccm_context *ctx)
This function initializes the specified CCM context, to make references valid, and prepare the contex...
This file contains ChaCha20 definitions and functions.
void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx)
This function releases and clears the specified ChaCha20 context.
int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx, const unsigned char key[32])
This function sets the encryption/decryption key.
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx)
This function initializes the specified ChaCha20 context.
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA
Definition: chacha20.h:71
int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx, size_t size, const unsigned char *input, unsigned char *output)
This function encrypts or decrypts data.
This file contains the AEAD-ChaCha20-Poly1305 definitions and functions.
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
This function initializes the specified ChaCha20-Poly1305 context.
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx, const unsigned char key[32])
This function sets the ChaCha20-Poly1305 symmetric encryption key.
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
This function releases and clears the specified ChaCha20-Poly1305 context.
@ MBEDTLS_CIPHER_AES_128_ECB
Definition: cipher.h:132
@ MBEDTLS_CIPHER_ARIA_256_CTR
Definition: cipher.h:190
@ MBEDTLS_CIPHER_CAMELLIA_128_GCM
Definition: cipher.h:159
@ MBEDTLS_CIPHER_AES_128_XTS
Definition: cipher.h:200
@ MBEDTLS_CIPHER_CHACHA20
Definition: cipher.h:202
@ MBEDTLS_CIPHER_DES_EDE3_CBC
Definition: cipher.h:167
@ MBEDTLS_CIPHER_DES_ECB
Definition: cipher.h:162
@ MBEDTLS_CIPHER_ARIA_128_GCM
Definition: cipher.h:191
@ MBEDTLS_CIPHER_AES_128_CBC
Definition: cipher.h:135
@ MBEDTLS_CIPHER_AES_192_GCM
Definition: cipher.h:145
@ MBEDTLS_CIPHER_BLOWFISH_CTR
Definition: cipher.h:171
@ MBEDTLS_CIPHER_AES_128_OFB
Definition: cipher.h:197
@ MBEDTLS_CIPHER_ARIA_192_ECB
Definition: cipher.h:180
@ MBEDTLS_CIPHER_CAMELLIA_256_GCM
Definition: cipher.h:161
@ MBEDTLS_CIPHER_DES_EDE_ECB
Definition: cipher.h:164
@ MBEDTLS_CIPHER_BLOWFISH_CFB64
Definition: cipher.h:170
@ MBEDTLS_CIPHER_ARIA_256_CFB128
Definition: cipher.h:187
@ MBEDTLS_CIPHER_ARIA_192_CBC
Definition: cipher.h:183
@ MBEDTLS_CIPHER_CAMELLIA_192_CBC
Definition: cipher.h:151
@ MBEDTLS_CIPHER_ARIA_128_CTR
Definition: cipher.h:188
@ MBEDTLS_CIPHER_ARIA_192_CCM
Definition: cipher.h:195
@ MBEDTLS_CIPHER_CAMELLIA_192_GCM
Definition: cipher.h:160
@ MBEDTLS_CIPHER_AES_192_OFB
Definition: cipher.h:198
@ MBEDTLS_CIPHER_AES_256_ECB
Definition: cipher.h:134
@ MBEDTLS_CIPHER_AES_256_CTR
Definition: cipher.h:143
@ MBEDTLS_CIPHER_AES_192_CCM
Definition: cipher.h:174
@ MBEDTLS_CIPHER_AES_128_CFB128
Definition: cipher.h:138
@ MBEDTLS_CIPHER_CAMELLIA_192_CFB128
Definition: cipher.h:154
@ MBEDTLS_CIPHER_CAMELLIA_128_CCM
Definition: cipher.h:176
@ MBEDTLS_CIPHER_AES_128_CTR
Definition: cipher.h:141
@ MBEDTLS_CIPHER_ARIA_192_GCM
Definition: cipher.h:192
@ MBEDTLS_CIPHER_AES_256_XTS
Definition: cipher.h:201
@ MBEDTLS_CIPHER_AES_192_CFB128
Definition: cipher.h:139
@ MBEDTLS_CIPHER_ARIA_256_ECB
Definition: cipher.h:181
@ MBEDTLS_CIPHER_CAMELLIA_256_CCM
Definition: cipher.h:178
@ MBEDTLS_CIPHER_AES_256_GCM
Definition: cipher.h:146
@ MBEDTLS_CIPHER_DES_CBC
Definition: cipher.h:163
@ MBEDTLS_CIPHER_CAMELLIA_128_CFB128
Definition: cipher.h:153
@ MBEDTLS_CIPHER_CAMELLIA_128_CBC
Definition: cipher.h:150
@ MBEDTLS_CIPHER_AES_256_CCM
Definition: cipher.h:175
@ MBEDTLS_CIPHER_CAMELLIA_256_CFB128
Definition: cipher.h:155
@ MBEDTLS_CIPHER_ARIA_192_CTR
Definition: cipher.h:189
@ MBEDTLS_CIPHER_BLOWFISH_CBC
Definition: cipher.h:169
@ MBEDTLS_CIPHER_CAMELLIA_256_ECB
Definition: cipher.h:149
@ MBEDTLS_CIPHER_AES_128_GCM
Definition: cipher.h:144
@ MBEDTLS_CIPHER_CAMELLIA_192_ECB
Definition: cipher.h:148
@ MBEDTLS_CIPHER_AES_256_CFB128
Definition: cipher.h:140
@ MBEDTLS_CIPHER_NONE
Definition: cipher.h:130
@ MBEDTLS_CIPHER_CHACHA20_POLY1305
Definition: cipher.h:203
@ MBEDTLS_CIPHER_CAMELLIA_128_ECB
Definition: cipher.h:147
@ MBEDTLS_CIPHER_AES_192_CBC
Definition: cipher.h:136
@ MBEDTLS_CIPHER_CAMELLIA_192_CCM
Definition: cipher.h:177
@ MBEDTLS_CIPHER_ARIA_128_CCM
Definition: cipher.h:194
@ MBEDTLS_CIPHER_AES_192_CTR
Definition: cipher.h:142
@ MBEDTLS_CIPHER_AES_128_CCM
Definition: cipher.h:173
@ MBEDTLS_CIPHER_DES_EDE_CBC
Definition: cipher.h:165
@ MBEDTLS_CIPHER_NULL
Definition: cipher.h:131
@ MBEDTLS_CIPHER_ARIA_256_CBC
Definition: cipher.h:184
@ MBEDTLS_CIPHER_AES_256_OFB
Definition: cipher.h:199
@ MBEDTLS_CIPHER_ARIA_192_CFB128
Definition: cipher.h:186
@ MBEDTLS_CIPHER_CAMELLIA_128_CTR
Definition: cipher.h:156
@ MBEDTLS_CIPHER_BLOWFISH_ECB
Definition: cipher.h:168
@ MBEDTLS_CIPHER_AES_256_CBC
Definition: cipher.h:137
@ MBEDTLS_CIPHER_ARC4_128
Definition: cipher.h:172
@ MBEDTLS_CIPHER_CAMELLIA_192_CTR
Definition: cipher.h:157
@ MBEDTLS_CIPHER_AES_192_ECB
Definition: cipher.h:133
@ MBEDTLS_CIPHER_ARIA_256_GCM
Definition: cipher.h:193
@ MBEDTLS_CIPHER_DES_EDE3_ECB
Definition: cipher.h:166
@ MBEDTLS_CIPHER_ARIA_128_CBC
Definition: cipher.h:182
@ MBEDTLS_CIPHER_CAMELLIA_256_CTR
Definition: cipher.h:158
@ MBEDTLS_CIPHER_ARIA_128_ECB
Definition: cipher.h:179
@ MBEDTLS_CIPHER_CAMELLIA_256_CBC
Definition: cipher.h:152
@ MBEDTLS_CIPHER_ARIA_256_CCM
Definition: cipher.h:196
@ MBEDTLS_CIPHER_ARIA_128_CFB128
Definition: cipher.h:185
@ MBEDTLS_KEY_LENGTH_DES
Definition: cipher.h:241
@ MBEDTLS_KEY_LENGTH_DES_EDE
Definition: cipher.h:243
@ MBEDTLS_KEY_LENGTH_DES_EDE3
Definition: cipher.h:245
#define MBEDTLS_CIPHER_VARIABLE_IV_LEN
Definition: cipher.h:95
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
Definition: cipher.h:85
#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN
Definition: cipher.h:96
mbedtls_operation_t
Definition: cipher.h:231
@ MBEDTLS_DECRYPT
Definition: cipher.h:233
@ MBEDTLS_ENCRYPT
Definition: cipher.h:234
@ MBEDTLS_MODE_ECB
Definition: cipher.h:209
@ MBEDTLS_MODE_CCM
Definition: cipher.h:216
@ MBEDTLS_MODE_STREAM
Definition: cipher.h:215
@ MBEDTLS_MODE_CFB
Definition: cipher.h:211
@ MBEDTLS_MODE_CTR
Definition: cipher.h:213
@ MBEDTLS_MODE_GCM
Definition: cipher.h:214
@ MBEDTLS_MODE_CBC
Definition: cipher.h:210
@ MBEDTLS_MODE_OFB
Definition: cipher.h:212
@ MBEDTLS_MODE_CHACHAPOLY
Definition: cipher.h:218
@ MBEDTLS_MODE_XTS
Definition: cipher.h:217
@ MBEDTLS_CIPHER_ID_3DES
Definition: cipher.h:114
@ MBEDTLS_CIPHER_ID_CAMELLIA
Definition: cipher.h:115
@ MBEDTLS_CIPHER_ID_DES
Definition: cipher.h:113
@ MBEDTLS_CIPHER_ID_ARC4
Definition: cipher.h:117
@ MBEDTLS_CIPHER_ID_NULL
Definition: cipher.h:111
@ MBEDTLS_CIPHER_ID_AES
Definition: cipher.h:112
@ MBEDTLS_CIPHER_ID_ARIA
Definition: cipher.h:118
@ MBEDTLS_CIPHER_ID_CHACHA20
Definition: cipher.h:119
@ MBEDTLS_CIPHER_ID_BLOWFISH
Definition: cipher.h:116
Cipher wrappers.
const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]
int mbedtls_cipher_supported[]
#define NULL
Definition: types.h:112
static const WCHAR des[]
Definition: oid.c:1212
This file contains GCM definitions and functions.
void mbedtls_gcm_init(mbedtls_gcm_context *ctx)
This function initializes the specified GCM context, to make references valid, and prepares the conte...
int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
This function associates a GCM context with a cipher algorithm and a key.
void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
This function clears a GCM context and the underlying cipher sub-context.
GLenum mode
Definition: glext.h:6217
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum GLenum GLenum input
Definition: glext.h:9031
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
Configuration options (set of defines)
DES block cipher.
void mbedtls_des_init(mbedtls_des_context *ctx)
Initialize DES context.
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
void mbedtls_des3_free(mbedtls_des3_context *ctx)
Clear Triple-DES context.
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
3DES-CBC buffer encryption/decryption
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
DES-CBC buffer encryption/decryption.
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
void mbedtls_des3_init(mbedtls_des3_context *ctx)
Initialize Triple-DES context.
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
void mbedtls_des_free(mbedtls_des_context *ctx)
Clear DES context.
This file contains the definitions and functions of the Mbed TLS platform abstraction layer.
#define mbedtls_free
Definition: platform.h:168
#define mbedtls_calloc
Definition: platform.h:169
Definition: copy.c:22
The AES context-type definition.
Definition: aes.h:113
The AES XTS context-type definition.
Definition: aes.h:132
ARC4 context structure.
Definition: arc4.h:83
The ARIA context-type definition.
Definition: aria.h:103
Blowfish context structure.
Definition: blowfish.h:93
CAMELLIA context structure.
Definition: camellia.h:89
The CCM context-type definition. The CCM context is passed to the APIs called.
Definition: ccm.h:104
Triple-DES context structure.
Definition: des.h:101
DES context structure.
Definition: des.h:92
The GCM context structure.
Definition: gcm.h:91
int ret