PolarSSL v1.3.9
cipher_wrap.c
Go to the documentation of this file.
1
30#if !defined(POLARSSL_CONFIG_FILE)
31#include "polarssl/config.h"
32#else
33#include POLARSSL_CONFIG_FILE
34#endif
35
36#if defined(POLARSSL_CIPHER_C)
37
39
40#if defined(POLARSSL_AES_C)
41#include "polarssl/aes.h"
42#endif
43
44#if defined(POLARSSL_ARC4_C)
45#include "polarssl/arc4.h"
46#endif
47
48#if defined(POLARSSL_CAMELLIA_C)
49#include "polarssl/camellia.h"
50#endif
51
52#if defined(POLARSSL_DES_C)
53#include "polarssl/des.h"
54#endif
55
56#if defined(POLARSSL_BLOWFISH_C)
57#include "polarssl/blowfish.h"
58#endif
59
60#if defined(POLARSSL_GCM_C)
61#include "polarssl/gcm.h"
62#endif
63
64#if defined(POLARSSL_CCM_C)
65#include "polarssl/ccm.h"
66#endif
67
68#if defined(POLARSSL_PLATFORM_C)
69#include "polarssl/platform.h"
70#else
71#define polarssl_malloc malloc
72#define polarssl_free free
73#endif
74
75#include <stdlib.h>
76
77#if defined(POLARSSL_GCM_C)
78/* shared by all GCM ciphers */
79static void *gcm_ctx_alloc( void )
80{
81 return polarssl_malloc( sizeof( gcm_context ) );
82}
83
84static void gcm_ctx_free( void *ctx )
85{
86 gcm_free( ctx );
87 polarssl_free( ctx );
88}
89#endif /* POLARSSL_GCM_C */
90
91#if defined(POLARSSL_CCM_C)
92/* shared by all CCM ciphers */
93static void *ccm_ctx_alloc( void )
94{
95 return polarssl_malloc( sizeof( ccm_context ) );
96}
97
98static void ccm_ctx_free( void *ctx )
99{
100 ccm_free( ctx );
101 polarssl_free( ctx );
102}
103#endif /* POLARSSL_CCM_C */
104
105#if defined(POLARSSL_AES_C)
106
107static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
108 const unsigned char *input, unsigned char *output )
109{
110 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
111}
112
113static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
114 unsigned char *iv, const unsigned char *input, unsigned char *output )
115{
116#if defined(POLARSSL_CIPHER_MODE_CBC)
117 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
118 output );
119#else
120 ((void) ctx);
121 ((void) operation);
122 ((void) length);
123 ((void) iv);
124 ((void) input);
125 ((void) output);
126
128#endif /* POLARSSL_CIPHER_MODE_CBC */
129}
130
131static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
132 size_t length, size_t *iv_off, unsigned char *iv,
133 const unsigned char *input, unsigned char *output )
134{
135#if defined(POLARSSL_CIPHER_MODE_CFB)
136 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
137 input, output );
138#else
139 ((void) ctx);
140 ((void) operation);
141 ((void) length);
142 ((void) iv_off);
143 ((void) iv);
144 ((void) input);
145 ((void) output);
146
148#endif /* POLARSSL_CIPHER_MODE_CFB */
149}
150
151static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
152 unsigned char *nonce_counter, unsigned char *stream_block,
153 const unsigned char *input, unsigned char *output )
154{
155#if defined(POLARSSL_CIPHER_MODE_CTR)
156 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
157 stream_block, input, output );
158#else
159 ((void) ctx);
160 ((void) length);
161 ((void) nc_off);
162 ((void) nonce_counter);
163 ((void) stream_block);
164 ((void) input);
165 ((void) output);
166
168#endif /* POLARSSL_CIPHER_MODE_CTR */
169}
170
171static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
172 unsigned int key_length )
173{
174 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
175}
176
177static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
178 unsigned int key_length )
179{
180 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
181}
182
183static void * aes_ctx_alloc( void )
184{
185 aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
186
187 if( aes == NULL )
188 return( NULL );
189
190 aes_init( aes );
191
192 return( aes );
193}
194
195static void aes_ctx_free( void *ctx )
196{
197 aes_free( (aes_context *) ctx );
198 polarssl_free( ctx );
199}
200
201const cipher_base_t aes_info = {
203 aes_crypt_ecb_wrap,
204 aes_crypt_cbc_wrap,
205 aes_crypt_cfb128_wrap,
206 aes_crypt_ctr_wrap,
207 NULL,
208 aes_setkey_enc_wrap,
209 aes_setkey_dec_wrap,
210 aes_ctx_alloc,
211 aes_ctx_free
212};
213
214const cipher_info_t aes_128_ecb_info = {
217 128,
218 "AES-128-ECB",
219 16,
220 0,
221 16,
222 &aes_info
223};
224
225const cipher_info_t aes_192_ecb_info = {
228 192,
229 "AES-192-ECB",
230 16,
231 0,
232 16,
233 &aes_info
234};
235
236const cipher_info_t aes_256_ecb_info = {
239 256,
240 "AES-256-ECB",
241 16,
242 0,
243 16,
244 &aes_info
245};
246
247#if defined(POLARSSL_CIPHER_MODE_CBC)
248const cipher_info_t aes_128_cbc_info = {
251 128,
252 "AES-128-CBC",
253 16,
254 0,
255 16,
256 &aes_info
257};
258
259const cipher_info_t aes_192_cbc_info = {
262 192,
263 "AES-192-CBC",
264 16,
265 0,
266 16,
267 &aes_info
268};
269
270const cipher_info_t aes_256_cbc_info = {
273 256,
274 "AES-256-CBC",
275 16,
276 0,
277 16,
278 &aes_info
279};
280#endif /* POLARSSL_CIPHER_MODE_CBC */
281
282#if defined(POLARSSL_CIPHER_MODE_CFB)
283const cipher_info_t aes_128_cfb128_info = {
286 128,
287 "AES-128-CFB128",
288 16,
289 0,
290 16,
291 &aes_info
292};
293
294const cipher_info_t aes_192_cfb128_info = {
297 192,
298 "AES-192-CFB128",
299 16,
300 0,
301 16,
302 &aes_info
303};
304
305const cipher_info_t aes_256_cfb128_info = {
308 256,
309 "AES-256-CFB128",
310 16,
311 0,
312 16,
313 &aes_info
314};
315#endif /* POLARSSL_CIPHER_MODE_CFB */
316
317#if defined(POLARSSL_CIPHER_MODE_CTR)
318const cipher_info_t aes_128_ctr_info = {
321 128,
322 "AES-128-CTR",
323 16,
324 0,
325 16,
326 &aes_info
327};
328
329const cipher_info_t aes_192_ctr_info = {
332 192,
333 "AES-192-CTR",
334 16,
335 0,
336 16,
337 &aes_info
338};
339
340const cipher_info_t aes_256_ctr_info = {
343 256,
344 "AES-256-CTR",
345 16,
346 0,
347 16,
348 &aes_info
349};
350#endif /* POLARSSL_CIPHER_MODE_CTR */
351
352#if defined(POLARSSL_GCM_C)
353static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
354 unsigned int key_length )
355{
357 key, key_length );
358}
359
360const cipher_base_t gcm_aes_info = {
362 NULL,
363 NULL,
364 NULL,
365 NULL,
366 NULL,
367 gcm_aes_setkey_wrap,
368 gcm_aes_setkey_wrap,
369 gcm_ctx_alloc,
370 gcm_ctx_free,
371};
372
373const cipher_info_t aes_128_gcm_info = {
376 128,
377 "AES-128-GCM",
378 12,
380 16,
381 &gcm_aes_info
382};
383
384const cipher_info_t aes_192_gcm_info = {
387 192,
388 "AES-192-GCM",
389 12,
391 16,
392 &gcm_aes_info
393};
394
395const cipher_info_t aes_256_gcm_info = {
398 256,
399 "AES-256-GCM",
400 12,
402 16,
403 &gcm_aes_info
404};
405#endif /* POLARSSL_GCM_C */
406
407#if defined(POLARSSL_CCM_C)
408static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
409 unsigned int key_length )
410{
412 key, key_length );
413}
414
415const cipher_base_t ccm_aes_info = {
417 NULL,
418 NULL,
419 NULL,
420 NULL,
421 NULL,
422 ccm_aes_setkey_wrap,
423 ccm_aes_setkey_wrap,
424 ccm_ctx_alloc,
425 ccm_ctx_free,
426};
427
428const cipher_info_t aes_128_ccm_info = {
431 128,
432 "AES-128-CCM",
433 12,
435 16,
436 &ccm_aes_info
437};
438
439const cipher_info_t aes_192_ccm_info = {
442 192,
443 "AES-192-CCM",
444 12,
446 16,
447 &ccm_aes_info
448};
449
450const cipher_info_t aes_256_ccm_info = {
453 256,
454 "AES-256-CCM",
455 12,
457 16,
458 &ccm_aes_info
459};
460#endif /* POLARSSL_CCM_C */
461
462#endif /* POLARSSL_AES_C */
463
464#if defined(POLARSSL_CAMELLIA_C)
465
466static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
467 const unsigned char *input, unsigned char *output )
468{
469 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
470 output );
471}
472
473static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
474 size_t length, unsigned char *iv,
475 const unsigned char *input, unsigned char *output )
476{
477#if defined(POLARSSL_CIPHER_MODE_CBC)
478 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
479 input, output );
480#else
481 ((void) ctx);
482 ((void) operation);
483 ((void) length);
484 ((void) iv);
485 ((void) input);
486 ((void) output);
487
489#endif /* POLARSSL_CIPHER_MODE_CBC */
490}
491
492static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
493 size_t length, size_t *iv_off, unsigned char *iv,
494 const unsigned char *input, unsigned char *output )
495{
496#if defined(POLARSSL_CIPHER_MODE_CFB)
497 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
498 iv_off, iv, input, output );
499#else
500 ((void) ctx);
501 ((void) operation);
502 ((void) length);
503 ((void) iv_off);
504 ((void) iv);
505 ((void) input);
506 ((void) output);
507
509#endif /* POLARSSL_CIPHER_MODE_CFB */
510}
511
512static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
513 unsigned char *nonce_counter, unsigned char *stream_block,
514 const unsigned char *input, unsigned char *output )
515{
516#if defined(POLARSSL_CIPHER_MODE_CTR)
517 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
518 nonce_counter, stream_block, input, output );
519#else
520 ((void) ctx);
521 ((void) length);
522 ((void) nc_off);
523 ((void) nonce_counter);
524 ((void) stream_block);
525 ((void) input);
526 ((void) output);
527
529#endif /* POLARSSL_CIPHER_MODE_CTR */
530}
531
532static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
533 unsigned int key_length )
534{
535 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
536}
537
538static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
539 unsigned int key_length )
540{
541 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
542}
543
544static void * camellia_ctx_alloc( void )
545{
546 camellia_context *ctx;
548
549 if( ctx == NULL )
550 return( NULL );
551
552 camellia_init( ctx );
553
554 return( ctx );
555}
556
557static void camellia_ctx_free( void *ctx )
558{
560 polarssl_free( ctx );
561}
562
563const cipher_base_t camellia_info = {
565 camellia_crypt_ecb_wrap,
566 camellia_crypt_cbc_wrap,
567 camellia_crypt_cfb128_wrap,
568 camellia_crypt_ctr_wrap,
569 NULL,
570 camellia_setkey_enc_wrap,
571 camellia_setkey_dec_wrap,
572 camellia_ctx_alloc,
573 camellia_ctx_free
574};
575
576const cipher_info_t camellia_128_ecb_info = {
579 128,
580 "CAMELLIA-128-ECB",
581 16,
582 0,
583 16,
584 &camellia_info
585};
586
587const cipher_info_t camellia_192_ecb_info = {
590 192,
591 "CAMELLIA-192-ECB",
592 16,
593 0,
594 16,
595 &camellia_info
596};
597
598const cipher_info_t camellia_256_ecb_info = {
601 256,
602 "CAMELLIA-256-ECB",
603 16,
604 0,
605 16,
606 &camellia_info
607};
608
609#if defined(POLARSSL_CIPHER_MODE_CBC)
610const cipher_info_t camellia_128_cbc_info = {
613 128,
614 "CAMELLIA-128-CBC",
615 16,
616 0,
617 16,
618 &camellia_info
619};
620
621const cipher_info_t camellia_192_cbc_info = {
624 192,
625 "CAMELLIA-192-CBC",
626 16,
627 0,
628 16,
629 &camellia_info
630};
631
632const cipher_info_t camellia_256_cbc_info = {
635 256,
636 "CAMELLIA-256-CBC",
637 16,
638 0,
639 16,
640 &camellia_info
641};
642#endif /* POLARSSL_CIPHER_MODE_CBC */
643
644#if defined(POLARSSL_CIPHER_MODE_CFB)
645const cipher_info_t camellia_128_cfb128_info = {
648 128,
649 "CAMELLIA-128-CFB128",
650 16,
651 0,
652 16,
653 &camellia_info
654};
655
656const cipher_info_t camellia_192_cfb128_info = {
659 192,
660 "CAMELLIA-192-CFB128",
661 16,
662 0,
663 16,
664 &camellia_info
665};
666
667const cipher_info_t camellia_256_cfb128_info = {
670 256,
671 "CAMELLIA-256-CFB128",
672 16,
673 0,
674 16,
675 &camellia_info
676};
677#endif /* POLARSSL_CIPHER_MODE_CFB */
678
679#if defined(POLARSSL_CIPHER_MODE_CTR)
680const cipher_info_t camellia_128_ctr_info = {
683 128,
684 "CAMELLIA-128-CTR",
685 16,
686 0,
687 16,
688 &camellia_info
689};
690
691const cipher_info_t camellia_192_ctr_info = {
694 192,
695 "CAMELLIA-192-CTR",
696 16,
697 0,
698 16,
699 &camellia_info
700};
701
702const cipher_info_t camellia_256_ctr_info = {
705 256,
706 "CAMELLIA-256-CTR",
707 16,
708 0,
709 16,
710 &camellia_info
711};
712#endif /* POLARSSL_CIPHER_MODE_CTR */
713
714#if defined(POLARSSL_GCM_C)
715static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
716 unsigned int key_length )
717{
719 key, key_length );
720}
721
722const cipher_base_t gcm_camellia_info = {
724 NULL,
725 NULL,
726 NULL,
727 NULL,
728 NULL,
729 gcm_camellia_setkey_wrap,
730 gcm_camellia_setkey_wrap,
731 gcm_ctx_alloc,
732 gcm_ctx_free,
733};
734
735const cipher_info_t camellia_128_gcm_info = {
738 128,
739 "CAMELLIA-128-GCM",
740 12,
742 16,
743 &gcm_camellia_info
744};
745
746const cipher_info_t camellia_192_gcm_info = {
749 192,
750 "CAMELLIA-192-GCM",
751 12,
753 16,
754 &gcm_camellia_info
755};
756
757const cipher_info_t camellia_256_gcm_info = {
760 256,
761 "CAMELLIA-256-GCM",
762 12,
764 16,
765 &gcm_camellia_info
766};
767#endif /* POLARSSL_GCM_C */
768
769#if defined(POLARSSL_CCM_C)
770static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
771 unsigned int key_length )
772{
774 key, key_length );
775}
776
777const cipher_base_t ccm_camellia_info = {
779 NULL,
780 NULL,
781 NULL,
782 NULL,
783 NULL,
784 ccm_camellia_setkey_wrap,
785 ccm_camellia_setkey_wrap,
786 ccm_ctx_alloc,
787 ccm_ctx_free,
788};
789
790const cipher_info_t camellia_128_ccm_info = {
793 128,
794 "CAMELLIA-128-CCM",
795 12,
797 16,
798 &ccm_camellia_info
799};
800
801const cipher_info_t camellia_192_ccm_info = {
804 192,
805 "CAMELLIA-192-CCM",
806 12,
808 16,
809 &ccm_camellia_info
810};
811
812const cipher_info_t camellia_256_ccm_info = {
815 256,
816 "CAMELLIA-256-CCM",
817 12,
819 16,
820 &ccm_camellia_info
821};
822#endif /* POLARSSL_CCM_C */
823
824#endif /* POLARSSL_CAMELLIA_C */
825
826#if defined(POLARSSL_DES_C)
827
828static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
829 const unsigned char *input, unsigned char *output )
830{
831 ((void) operation);
832 return des_crypt_ecb( (des_context *) ctx, input, output );
833}
834
835static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
836 const unsigned char *input, unsigned char *output )
837{
838 ((void) operation);
839 return des3_crypt_ecb( (des3_context *) ctx, input, output );
840}
841
842static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
843 unsigned char *iv, const unsigned char *input, unsigned char *output )
844{
845#if defined(POLARSSL_CIPHER_MODE_CBC)
846 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
847 output );
848#else
849 ((void) ctx);
850 ((void) operation);
851 ((void) length);
852 ((void) iv);
853 ((void) input);
854 ((void) output);
855
857#endif /* POLARSSL_CIPHER_MODE_CBC */
858}
859
860static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
861 unsigned char *iv, const unsigned char *input, unsigned char *output )
862{
863#if defined(POLARSSL_CIPHER_MODE_CBC)
864 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
865 output );
866#else
867 ((void) ctx);
868 ((void) operation);
869 ((void) length);
870 ((void) iv);
871 ((void) input);
872 ((void) output);
873
875#endif /* POLARSSL_CIPHER_MODE_CBC */
876}
877
878static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
879 unsigned int key_length )
880{
881 ((void) key_length);
882
883 return des_setkey_dec( (des_context *) ctx, key );
884}
885
886static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
887 unsigned int key_length )
888{
889 ((void) key_length);
890
891 return des_setkey_enc( (des_context *) ctx, key );
892}
893
894static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
895 unsigned int key_length )
896{
897 ((void) key_length);
898
899 return des3_set2key_dec( (des3_context *) ctx, key );
900}
901
902static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
903 unsigned int key_length )
904{
905 ((void) key_length);
906
907 return des3_set2key_enc( (des3_context *) ctx, key );
908}
909
910static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
911 unsigned int key_length )
912{
913 ((void) key_length);
914
915 return des3_set3key_dec( (des3_context *) ctx, key );
916}
917
918static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
919 unsigned int key_length )
920{
921 ((void) key_length);
922
923 return des3_set3key_enc( (des3_context *) ctx, key );
924}
925
926static void * des_ctx_alloc( void )
927{
928 des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
929
930 if( des == NULL )
931 return( NULL );
932
933 des_init( des );
934
935 return( des );
936}
937
938static void des_ctx_free( void *ctx )
939{
940 des_free( (des_context *) ctx );
941 polarssl_free( ctx );
942}
943
944static void * des3_ctx_alloc( void )
945{
946 des3_context *des3;
947 des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
948
949 if( des3 == NULL )
950 return( NULL );
951
952 des3_init( des3 );
953
954 return( des3 );
955}
956
957static void des3_ctx_free( void *ctx )
958{
959 des3_free( (des3_context *) ctx );
960 polarssl_free( ctx );
961}
962
963const cipher_base_t des_info = {
965 des_crypt_ecb_wrap,
966 des_crypt_cbc_wrap,
967 NULL,
968 NULL,
969 NULL,
970 des_setkey_enc_wrap,
971 des_setkey_dec_wrap,
972 des_ctx_alloc,
973 des_ctx_free
974};
975
976const cipher_info_t des_ecb_info = {
980 "DES-ECB",
981 8,
982 0,
983 8,
984 &des_info
985};
986
987#if defined(POLARSSL_CIPHER_MODE_CBC)
988const cipher_info_t des_cbc_info = {
992 "DES-CBC",
993 8,
994 0,
995 8,
996 &des_info
997};
998#endif /* POLARSSL_CIPHER_MODE_CBC */
999
1000const cipher_base_t des_ede_info = {
1002 des3_crypt_ecb_wrap,
1003 des3_crypt_cbc_wrap,
1004 NULL,
1005 NULL,
1006 NULL,
1007 des3_set2key_enc_wrap,
1008 des3_set2key_dec_wrap,
1009 des3_ctx_alloc,
1010 des3_ctx_free
1011};
1012
1013const cipher_info_t des_ede_ecb_info = {
1017 "DES-EDE-ECB",
1018 8,
1019 0,
1020 8,
1021 &des_ede_info
1022};
1023
1024#if defined(POLARSSL_CIPHER_MODE_CBC)
1025const cipher_info_t des_ede_cbc_info = {
1029 "DES-EDE-CBC",
1030 8,
1031 0,
1032 8,
1033 &des_ede_info
1034};
1035#endif /* POLARSSL_CIPHER_MODE_CBC */
1036
1037const cipher_base_t des_ede3_info = {
1039 des3_crypt_ecb_wrap,
1040 des3_crypt_cbc_wrap,
1041 NULL,
1042 NULL,
1043 NULL,
1044 des3_set3key_enc_wrap,
1045 des3_set3key_dec_wrap,
1046 des3_ctx_alloc,
1047 des3_ctx_free
1048};
1049
1050const cipher_info_t des_ede3_ecb_info = {
1054 "DES-EDE3-ECB",
1055 8,
1056 0,
1057 8,
1058 &des_ede3_info
1059};
1060#if defined(POLARSSL_CIPHER_MODE_CBC)
1061const cipher_info_t des_ede3_cbc_info = {
1065 "DES-EDE3-CBC",
1066 8,
1067 0,
1068 8,
1069 &des_ede3_info
1070};
1071#endif /* POLARSSL_CIPHER_MODE_CBC */
1072#endif /* POLARSSL_DES_C */
1073
1074#if defined(POLARSSL_BLOWFISH_C)
1075
1076static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1077 const unsigned char *input, unsigned char *output )
1078{
1079 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1080 output );
1081}
1082
1083static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1084 size_t length, unsigned char *iv, const unsigned char *input,
1085 unsigned char *output )
1086{
1087#if defined(POLARSSL_CIPHER_MODE_CBC)
1088 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1089 input, output );
1090#else
1091 ((void) ctx);
1092 ((void) operation);
1093 ((void) length);
1094 ((void) iv);
1095 ((void) input);
1096 ((void) output);
1097
1099#endif /* POLARSSL_CIPHER_MODE_CBC */
1100}
1101
1102static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1103 size_t length, size_t *iv_off, unsigned char *iv,
1104 const unsigned char *input, unsigned char *output )
1105{
1106#if defined(POLARSSL_CIPHER_MODE_CFB)
1107 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1108 iv_off, iv, input, output );
1109#else
1110 ((void) ctx);
1111 ((void) operation);
1112 ((void) length);
1113 ((void) iv_off);
1114 ((void) iv);
1115 ((void) input);
1116 ((void) output);
1117
1119#endif /* POLARSSL_CIPHER_MODE_CFB */
1120}
1121
1122static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1123 unsigned char *nonce_counter, unsigned char *stream_block,
1124 const unsigned char *input, unsigned char *output )
1125{
1126#if defined(POLARSSL_CIPHER_MODE_CTR)
1127 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1128 nonce_counter, stream_block, input, output );
1129#else
1130 ((void) ctx);
1131 ((void) length);
1132 ((void) nc_off);
1133 ((void) nonce_counter);
1134 ((void) stream_block);
1135 ((void) input);
1136 ((void) output);
1137
1139#endif /* POLARSSL_CIPHER_MODE_CTR */
1140}
1141
1142static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1143 unsigned int key_length )
1144{
1145 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1146}
1147
1148static void * blowfish_ctx_alloc( void )
1149{
1150 blowfish_context *ctx;
1151 ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
1152
1153 if( ctx == NULL )
1154 return( NULL );
1155
1156 blowfish_init( ctx );
1157
1158 return( ctx );
1159}
1160
1161static void blowfish_ctx_free( void *ctx )
1162{
1164 polarssl_free( ctx );
1165}
1166
1167const cipher_base_t blowfish_info = {
1169 blowfish_crypt_ecb_wrap,
1170 blowfish_crypt_cbc_wrap,
1171 blowfish_crypt_cfb64_wrap,
1172 blowfish_crypt_ctr_wrap,
1173 NULL,
1174 blowfish_setkey_wrap,
1175 blowfish_setkey_wrap,
1176 blowfish_ctx_alloc,
1177 blowfish_ctx_free
1178};
1179
1180const cipher_info_t blowfish_ecb_info = {
1183 128,
1184 "BLOWFISH-ECB",
1185 8,
1187 8,
1188 &blowfish_info
1189};
1190
1191#if defined(POLARSSL_CIPHER_MODE_CBC)
1192const cipher_info_t blowfish_cbc_info = {
1195 128,
1196 "BLOWFISH-CBC",
1197 8,
1199 8,
1200 &blowfish_info
1201};
1202#endif /* POLARSSL_CIPHER_MODE_CBC */
1203
1204#if defined(POLARSSL_CIPHER_MODE_CFB)
1205const cipher_info_t blowfish_cfb64_info = {
1208 128,
1209 "BLOWFISH-CFB64",
1210 8,
1212 8,
1213 &blowfish_info
1214};
1215#endif /* POLARSSL_CIPHER_MODE_CFB */
1216
1217#if defined(POLARSSL_CIPHER_MODE_CTR)
1218const cipher_info_t blowfish_ctr_info = {
1221 128,
1222 "BLOWFISH-CTR",
1223 8,
1225 8,
1226 &blowfish_info
1227};
1228#endif /* POLARSSL_CIPHER_MODE_CTR */
1229#endif /* POLARSSL_BLOWFISH_C */
1230
1231#if defined(POLARSSL_ARC4_C)
1232static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1233 const unsigned char *input,
1234 unsigned char *output )
1235{
1236 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
1237}
1238
1239static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1240 unsigned int key_length )
1241{
1242 /* we get key_length in bits, arc4 expects it in bytes */
1243 if( key_length % 8 != 0 )
1245
1246 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
1247 return( 0 );
1248}
1249
1250static void * arc4_ctx_alloc( void )
1251{
1252 arc4_context *ctx;
1253 ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
1254
1255 if( ctx == NULL )
1256 return( NULL );
1257
1258 arc4_init( ctx );
1259
1260 return( ctx );
1261}
1262
1263static void arc4_ctx_free( void *ctx )
1264{
1265 arc4_free( (arc4_context *) ctx );
1266 polarssl_free( ctx );
1267}
1268
1269const cipher_base_t arc4_base_info = {
1271 NULL,
1272 NULL,
1273 NULL,
1274 NULL,
1275 arc4_crypt_stream_wrap,
1276 arc4_setkey_wrap,
1277 arc4_setkey_wrap,
1278 arc4_ctx_alloc,
1279 arc4_ctx_free
1280};
1281
1282const cipher_info_t arc4_128_info = {
1285 128,
1286 "ARC4-128",
1287 0,
1288 0,
1289 1,
1290 &arc4_base_info
1291};
1292#endif /* POLARSSL_ARC4_C */
1293
1294#if defined(POLARSSL_CIPHER_NULL_CIPHER)
1295static int null_crypt_stream( void *ctx, size_t length,
1296 const unsigned char *input,
1297 unsigned char *output )
1298{
1299 ((void) ctx);
1300 memmove( output, input, length );
1301 return( 0 );
1302}
1303
1304static int null_setkey( void *ctx, const unsigned char *key,
1305 unsigned int key_length )
1306{
1307 ((void) ctx);
1308 ((void) key);
1309 ((void) key_length);
1310
1311 return( 0 );
1312}
1313
1314static void * null_ctx_alloc( void )
1315{
1316 return( (void *) 1 );
1317}
1318
1319static void null_ctx_free( void *ctx )
1320{
1321 ((void) ctx);
1322}
1323
1324const cipher_base_t null_base_info = {
1326 NULL,
1327 NULL,
1328 NULL,
1329 NULL,
1330 null_crypt_stream,
1331 null_setkey,
1332 null_setkey,
1333 null_ctx_alloc,
1334 null_ctx_free
1335};
1336
1337const cipher_info_t null_cipher_info = {
1340 0,
1341 "NULL",
1342 0,
1343 0,
1344 1,
1345 &null_base_info
1346};
1347#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1348
1350{
1351#if defined(POLARSSL_AES_C)
1352 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1353 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1354 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1355#if defined(POLARSSL_CIPHER_MODE_CBC)
1356 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1357 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1358 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1359#endif
1360#if defined(POLARSSL_CIPHER_MODE_CFB)
1361 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1362 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1363 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1364#endif
1365#if defined(POLARSSL_CIPHER_MODE_CTR)
1366 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1367 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1368 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1369#endif
1370#if defined(POLARSSL_GCM_C)
1371 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1372 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1373 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1374#endif
1375#if defined(POLARSSL_CCM_C)
1376 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1377 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1378 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1379#endif
1380#endif /* POLARSSL_AES_C */
1381
1382#if defined(POLARSSL_ARC4_C)
1383 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1384#endif
1385
1386#if defined(POLARSSL_BLOWFISH_C)
1387 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1388#if defined(POLARSSL_CIPHER_MODE_CBC)
1389 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1390#endif
1391#if defined(POLARSSL_CIPHER_MODE_CFB)
1392 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1393#endif
1394#if defined(POLARSSL_CIPHER_MODE_CTR)
1395 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1396#endif
1397#endif /* POLARSSL_BLOWFISH_C */
1398
1399#if defined(POLARSSL_CAMELLIA_C)
1400 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1401 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1402 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1403#if defined(POLARSSL_CIPHER_MODE_CBC)
1404 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1405 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1406 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1407#endif
1408#if defined(POLARSSL_CIPHER_MODE_CFB)
1409 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1410 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1411 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1412#endif
1413#if defined(POLARSSL_CIPHER_MODE_CTR)
1414 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1415 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1416 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1417#endif
1418#if defined(POLARSSL_GCM_C)
1419 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1420 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1421 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1422#endif
1423#if defined(POLARSSL_CCM_C)
1424 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1425 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1426 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1427#endif
1428#endif /* POLARSSL_CAMELLIA_C */
1429
1430#if defined(POLARSSL_DES_C)
1431 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1432 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1433 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1434#if defined(POLARSSL_CIPHER_MODE_CBC)
1435 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1436 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1437 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1438#endif
1439#endif /* POLARSSL_DES_C */
1440
1441#if defined(POLARSSL_CIPHER_NULL_CIPHER)
1442 { POLARSSL_CIPHER_NULL, &null_cipher_info },
1443#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1444
1445 { 0, NULL }
1446};
1447
1448#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1449int supported_ciphers[NUM_CIPHERS];
1450
1451#endif /* POLARSSL_CIPHER_C */
AES block cipher.
int aes_crypt_ctr(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)
AES-CTR buffer encryption/decryption.
int aes_crypt_ecb(aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
AES-ECB block encryption/decryption.
int aes_setkey_enc(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (encryption)
int aes_crypt_cbc(aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes)
int aes_crypt_cfb128(aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CFB128 buffer encryption/decryption.
void aes_free(aes_context *ctx)
Clear AES context.
int aes_setkey_dec(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (decryption)
void aes_init(aes_context *ctx)
Initialize AES context.
The ARCFOUR stream cipher.
void arc4_setup(arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
void arc4_init(arc4_context *ctx)
Initialize ARC4 context.
int arc4_crypt(arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
void arc4_free(arc4_context *ctx)
Clear ARC4 context.
Blowfish block cipher.
int blowfish_setkey(blowfish_context *ctx, const unsigned char *key, unsigned int keysize)
Blowfish key schedule.
int blowfish_crypt_ecb(blowfish_context *ctx, int mode, const unsigned char input[BLOWFISH_BLOCKSIZE], unsigned char output[BLOWFISH_BLOCKSIZE])
Blowfish-ECB block encryption/decryption.
int blowfish_crypt_cfb64(blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish CFB buffer encryption/decryption.
int blowfish_crypt_cbc(blowfish_context *ctx, int mode, size_t length, unsigned char iv[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CBC buffer encryption/decryption Length should be a multiple of the block size (8 bytes)
int blowfish_crypt_ctr(blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[BLOWFISH_BLOCKSIZE], unsigned char stream_block[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CTR buffer encryption/decryption.
void blowfish_free(blowfish_context *ctx)
Clear Blowfish context.
void blowfish_init(blowfish_context *ctx)
Initialize Blowfish context.
Camellia block cipher.
int camellia_crypt_cbc(camellia_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
CAMELLIA-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes)
int camellia_crypt_cfb128(camellia_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
CAMELLIA-CFB128 buffer encryption/decryption.
int camellia_setkey_enc(camellia_context *ctx, const unsigned char *key, unsigned int keysize)
CAMELLIA key schedule (encryption)
int camellia_crypt_ecb(camellia_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
CAMELLIA-ECB block encryption/decryption.
int camellia_setkey_dec(camellia_context *ctx, const unsigned char *key, unsigned int keysize)
CAMELLIA key schedule (decryption)
void camellia_init(camellia_context *ctx)
Initialize CAMELLIA context.
void camellia_free(camellia_context *ctx)
Clear CAMELLIA context.
int camellia_crypt_ctr(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)
CAMELLIA-CTR buffer encryption/decryption.
Counter with CBC-MAC (CCM) for 128-bit block ciphers.
void ccm_free(ccm_context *ctx)
Free a CCM context and underlying cipher sub-context.
int ccm_init(ccm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
CCM initialization (encryption and decryption)
@ POLARSSL_KEY_LENGTH_DES
Key length, in bits (including parity), for DES keys.
Definition: cipher.h:164
@ POLARSSL_KEY_LENGTH_DES_EDE
Key length, in bits (including parity), for DES in two key EDE.
Definition: cipher.h:166
@ POLARSSL_KEY_LENGTH_DES_EDE3
Key length, in bits (including parity), for DES in three-key EDE.
Definition: cipher.h:168
@ POLARSSL_CIPHER_ID_ARC4
Definition: cipher.h:79
@ POLARSSL_CIPHER_ID_BLOWFISH
Definition: cipher.h:78
@ POLARSSL_CIPHER_ID_CAMELLIA
Definition: cipher.h:77
@ POLARSSL_CIPHER_ID_DES
Definition: cipher.h:75
@ POLARSSL_CIPHER_ID_AES
Definition: cipher.h:74
@ POLARSSL_CIPHER_ID_NULL
Definition: cipher.h:73
#define POLARSSL_CIPHER_VARIABLE_KEY_LEN
Cipher accepts keys of variable length.
Definition: cipher.h:65
#define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA
Bad input parameters to function.
Definition: cipher.h:58
operation_t
Definition: cipher.h:154
@ POLARSSL_CIPHER_CAMELLIA_256_GCM
Definition: cipher.h:114
@ POLARSSL_CIPHER_BLOWFISH_CTR
Definition: cipher.h:124
@ POLARSSL_CIPHER_DES_EDE_ECB
Definition: cipher.h:117
@ POLARSSL_CIPHER_DES_ECB
Definition: cipher.h:115
@ POLARSSL_CIPHER_CAMELLIA_192_CCM
Definition: cipher.h:130
@ POLARSSL_CIPHER_CAMELLIA_256_CTR
Definition: cipher.h:111
@ POLARSSL_CIPHER_CAMELLIA_192_CBC
Definition: cipher.h:104
@ POLARSSL_CIPHER_NULL
Definition: cipher.h:84
@ POLARSSL_CIPHER_AES_256_CCM
Definition: cipher.h:128
@ POLARSSL_CIPHER_CAMELLIA_128_CCM
Definition: cipher.h:129
@ POLARSSL_CIPHER_AES_128_GCM
Definition: cipher.h:97
@ POLARSSL_CIPHER_AES_256_CBC
Definition: cipher.h:90
@ POLARSSL_CIPHER_BLOWFISH_CBC
Definition: cipher.h:122
@ POLARSSL_CIPHER_AES_128_ECB
Definition: cipher.h:85
@ POLARSSL_CIPHER_CAMELLIA_128_GCM
Definition: cipher.h:112
@ POLARSSL_CIPHER_AES_256_GCM
Definition: cipher.h:99
@ POLARSSL_CIPHER_AES_192_CTR
Definition: cipher.h:95
@ POLARSSL_CIPHER_CAMELLIA_256_CFB128
Definition: cipher.h:108
@ POLARSSL_CIPHER_AES_256_CFB128
Definition: cipher.h:93
@ POLARSSL_CIPHER_AES_128_CTR
Definition: cipher.h:94
@ POLARSSL_CIPHER_CAMELLIA_128_CTR
Definition: cipher.h:109
@ POLARSSL_CIPHER_DES_EDE3_ECB
Definition: cipher.h:119
@ POLARSSL_CIPHER_AES_128_CFB128
Definition: cipher.h:91
@ POLARSSL_CIPHER_CAMELLIA_128_CBC
Definition: cipher.h:103
@ POLARSSL_CIPHER_CAMELLIA_256_CCM
Definition: cipher.h:131
@ POLARSSL_CIPHER_CAMELLIA_128_CFB128
Definition: cipher.h:106
@ POLARSSL_CIPHER_CAMELLIA_192_GCM
Definition: cipher.h:113
@ POLARSSL_CIPHER_CAMELLIA_256_ECB
Definition: cipher.h:102
@ POLARSSL_CIPHER_DES_EDE_CBC
Definition: cipher.h:118
@ POLARSSL_CIPHER_AES_128_CBC
Definition: cipher.h:88
@ POLARSSL_CIPHER_CAMELLIA_192_CTR
Definition: cipher.h:110
@ POLARSSL_CIPHER_AES_192_GCM
Definition: cipher.h:98
@ POLARSSL_CIPHER_CAMELLIA_192_ECB
Definition: cipher.h:101
@ POLARSSL_CIPHER_CAMELLIA_192_CFB128
Definition: cipher.h:107
@ POLARSSL_CIPHER_AES_192_CFB128
Definition: cipher.h:92
@ POLARSSL_CIPHER_AES_128_CCM
Definition: cipher.h:126
@ POLARSSL_CIPHER_AES_192_CCM
Definition: cipher.h:127
@ POLARSSL_CIPHER_ARC4_128
Definition: cipher.h:125
@ POLARSSL_CIPHER_AES_256_CTR
Definition: cipher.h:96
@ POLARSSL_CIPHER_CAMELLIA_256_CBC
Definition: cipher.h:105
@ POLARSSL_CIPHER_BLOWFISH_CFB64
Definition: cipher.h:123
@ POLARSSL_CIPHER_AES_256_ECB
Definition: cipher.h:87
@ POLARSSL_CIPHER_BLOWFISH_ECB
Definition: cipher.h:121
@ POLARSSL_CIPHER_AES_192_ECB
Definition: cipher.h:86
@ POLARSSL_CIPHER_AES_192_CBC
Definition: cipher.h:89
@ POLARSSL_CIPHER_DES_EDE3_CBC
Definition: cipher.h:120
@ POLARSSL_CIPHER_DES_CBC
Definition: cipher.h:116
@ POLARSSL_CIPHER_CAMELLIA_128_ECB
Definition: cipher.h:100
#define POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE
The selected feature is not available.
Definition: cipher.h:57
#define POLARSSL_CIPHER_VARIABLE_IV_LEN
Cipher accepts IVs of variable length.
Definition: cipher.h:64
@ POLARSSL_MODE_GCM
Definition: cipher.h:141
@ POLARSSL_MODE_CTR
Definition: cipher.h:140
@ POLARSSL_MODE_ECB
Definition: cipher.h:136
@ POLARSSL_MODE_CBC
Definition: cipher.h:137
@ POLARSSL_MODE_CCM
Definition: cipher.h:143
@ POLARSSL_MODE_STREAM
Definition: cipher.h:142
@ POLARSSL_MODE_CFB
Definition: cipher.h:138
Cipher wrappers.
int supported_ciphers[]
const cipher_definition_t cipher_definitions[]
Configuration options (set of defines)
DES block cipher.
int des_setkey_enc(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
void des_init(des_context *ctx)
Initialize DES context.
int des3_set2key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void des3_init(des3_context *ctx)
Initialize Triple-DES context.
int des3_set3key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
int des_crypt_cbc(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 des_crypt_ecb(des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
int des3_set3key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
void des3_free(des3_context *ctx)
Clear Triple-DES context.
int des3_set2key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int des_setkey_dec(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
int des3_crypt_cbc(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 des3_crypt_ecb(des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
void des_free(des_context *ctx)
Clear DES context.
Galois/Counter mode for 128-bit block ciphers.
void gcm_free(gcm_context *ctx)
Free a GCM context and underlying cipher sub-context.
int gcm_init(gcm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
GCM initialization (encryption)
PolarSSL Platform abstraction layer.
AES context structure.
Definition: aes.h:69
ARC4 context structure.
Definition: arc4.h:50
Blowfish context structure.
Definition: blowfish.h:67
CAMELLIA context structure.
Definition: camellia.h:63
CCM context structure.
Definition: ccm.h:42
Base cipher information.
Definition: cipher.h:179
Cipher information.
Definition: cipher.h:226
Triple-DES context structure.
Definition: des.h:74
DES context structure.
Definition: des.h:64
GCM context structure.
Definition: gcm.h:53
#define polarssl_malloc
#define polarssl_free