PolarSSL v1.3.1
cipher_wrap.c
Go to the documentation of this file.
1 
30 #include "polarssl/config.h"
31 
32 #if defined(POLARSSL_CIPHER_C)
33 
34 #include "polarssl/cipher_wrap.h"
35 
36 #if defined(POLARSSL_AES_C)
37 #include "polarssl/aes.h"
38 #endif
39 
40 #if defined(POLARSSL_ARC4_C)
41 #include "polarssl/arc4.h"
42 #endif
43 
44 #if defined(POLARSSL_CAMELLIA_C)
45 #include "polarssl/camellia.h"
46 #endif
47 
48 #if defined(POLARSSL_DES_C)
49 #include "polarssl/des.h"
50 #endif
51 
52 #if defined(POLARSSL_BLOWFISH_C)
53 #include "polarssl/blowfish.h"
54 #endif
55 
56 #if defined(POLARSSL_GCM_C)
57 #include "polarssl/gcm.h"
58 #endif
59 
60 #if defined(POLARSSL_MEMORY_C)
61 #include "polarssl/memory.h"
62 #else
63 #define polarssl_malloc malloc
64 #define polarssl_free free
65 #endif
66 
67 #include <stdlib.h>
68 
69 #if defined(POLARSSL_AES_C)
70 
71 static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
72  const unsigned char *input, unsigned char *output )
73 {
74  return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
75 }
76 
77 static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
78  unsigned char *iv, const unsigned char *input, unsigned char *output )
79 {
80 #if defined(POLARSSL_CIPHER_MODE_CBC)
81  return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
82 #else
83  ((void) ctx);
84  ((void) operation);
85  ((void) length);
86  ((void) iv);
87  ((void) input);
88  ((void) output);
89 
91 #endif /* POLARSSL_CIPHER_MODE_CBC */
92 }
93 
94 static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
95  size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
96 {
97 #if defined(POLARSSL_CIPHER_MODE_CFB)
98  return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output );
99 #else
100  ((void) ctx);
101  ((void) operation);
102  ((void) length);
103  ((void) iv_off);
104  ((void) iv);
105  ((void) input);
106  ((void) output);
107 
109 #endif
110 }
111 
112 static int aes_crypt_ctr_wrap( void *ctx, size_t length,
113  size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
114  const unsigned char *input, unsigned char *output )
115 {
116 #if defined(POLARSSL_CIPHER_MODE_CTR)
117  return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
118  stream_block, input, output );
119 #else
120  ((void) ctx);
121  ((void) length);
122  ((void) nc_off);
123  ((void) nonce_counter);
124  ((void) stream_block);
125  ((void) input);
126  ((void) output);
127 
129 #endif
130 }
131 
132 static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
133 {
134  return aes_setkey_dec( (aes_context *) ctx, key, key_length );
135 }
136 
137 static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
138 {
139  return aes_setkey_enc( (aes_context *) ctx, key, key_length );
140 }
141 
142 static void * aes_ctx_alloc( void )
143 {
144  return polarssl_malloc( sizeof( aes_context ) );
145 }
146 
147 static void aes_ctx_free( void *ctx )
148 {
149  polarssl_free( ctx );
150 }
151 
152 const cipher_base_t aes_info = {
154  aes_crypt_ecb_wrap,
155  aes_crypt_cbc_wrap,
156  aes_crypt_cfb128_wrap,
157  aes_crypt_ctr_wrap,
158  NULL,
159  aes_setkey_enc_wrap,
160  aes_setkey_dec_wrap,
161  aes_ctx_alloc,
162  aes_ctx_free
163 };
164 
165 const cipher_info_t aes_128_ecb_info = {
168  128,
169  "AES-128-ECB",
170  16,
171  0,
172  16,
173  &aes_info
174 };
175 
176 const cipher_info_t aes_192_ecb_info = {
179  192,
180  "AES-192-ECB",
181  16,
182  0,
183  16,
184  &aes_info
185 };
186 
187 const cipher_info_t aes_256_ecb_info = {
190  256,
191  "AES-256-ECB",
192  16,
193  0,
194  16,
195  &aes_info
196 };
197 
198 #if defined(POLARSSL_CIPHER_MODE_CBC)
199 const cipher_info_t aes_128_cbc_info = {
202  128,
203  "AES-128-CBC",
204  16,
205  0,
206  16,
207  &aes_info
208 };
209 
210 const cipher_info_t aes_192_cbc_info = {
213  192,
214  "AES-192-CBC",
215  16,
216  0,
217  16,
218  &aes_info
219 };
220 
221 const cipher_info_t aes_256_cbc_info = {
224  256,
225  "AES-256-CBC",
226  16,
227  0,
228  16,
229  &aes_info
230 };
231 #endif /* POLARSSL_CIPHER_MODE_CBC */
232 
233 #if defined(POLARSSL_CIPHER_MODE_CFB)
234 const cipher_info_t aes_128_cfb128_info = {
237  128,
238  "AES-128-CFB128",
239  16,
240  0,
241  16,
242  &aes_info
243 };
244 
245 const cipher_info_t aes_192_cfb128_info = {
248  192,
249  "AES-192-CFB128",
250  16,
251  0,
252  16,
253  &aes_info
254 };
255 
256 const cipher_info_t aes_256_cfb128_info = {
259  256,
260  "AES-256-CFB128",
261  16,
262  0,
263  16,
264  &aes_info
265 };
266 #endif /* POLARSSL_CIPHER_MODE_CFB */
267 
268 #if defined(POLARSSL_CIPHER_MODE_CTR)
269 const cipher_info_t aes_128_ctr_info = {
272  128,
273  "AES-128-CTR",
274  16,
275  0,
276  16,
277  &aes_info
278 };
279 
280 const cipher_info_t aes_192_ctr_info = {
283  192,
284  "AES-192-CTR",
285  16,
286  0,
287  16,
288  &aes_info
289 };
290 
291 const cipher_info_t aes_256_ctr_info = {
294  256,
295  "AES-256-CTR",
296  16,
297  0,
298  16,
299  &aes_info
300 };
301 #endif /* POLARSSL_CIPHER_MODE_CTR */
302 
303 #if defined(POLARSSL_GCM_C)
304 static void *gcm_ctx_alloc( void )
305 {
306  return polarssl_malloc( sizeof( gcm_context ) );
307 }
308 
309 static void gcm_ctx_free( void *ctx )
310 {
311  gcm_free( ctx );
312  polarssl_free( ctx );
313 }
314 
315 static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
316 {
318  key, key_length );
319 }
320 
321 const cipher_base_t gcm_aes_info = {
323  NULL,
324  NULL,
325  NULL,
326  NULL,
327  NULL,
328  gcm_aes_setkey_wrap,
329  gcm_aes_setkey_wrap,
330  gcm_ctx_alloc,
331  gcm_ctx_free,
332 };
333 
334 const cipher_info_t aes_128_gcm_info = {
337  128,
338  "AES-128-GCM",
339  12,
340  1,
341  16,
342  &gcm_aes_info
343 };
344 
345 const cipher_info_t aes_192_gcm_info = {
348  192,
349  "AES-192-GCM",
350  12,
351  1,
352  16,
353  &gcm_aes_info
354 };
355 
356 const cipher_info_t aes_256_gcm_info = {
359  256,
360  "AES-256-GCM",
361  12,
362  1,
363  16,
364  &gcm_aes_info
365 };
366 #endif /* POLARSSL_GCM_C */
367 
368 #endif
369 
370 #if defined(POLARSSL_CAMELLIA_C)
371 
372 static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
373  const unsigned char *input, unsigned char *output )
374 {
375  return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
376 }
377 
378 static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
379  unsigned char *iv, const unsigned char *input, unsigned char *output )
380 {
381 #if defined(POLARSSL_CIPHER_MODE_CBC)
382  return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
383 #else
384  ((void) ctx);
385  ((void) operation);
386  ((void) length);
387  ((void) iv);
388  ((void) input);
389  ((void) output);
390 
392 #endif /* POLARSSL_CIPHER_MODE_CBC */
393 }
394 
395 static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
396  size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
397 {
398 #if defined(POLARSSL_CIPHER_MODE_CFB)
399  return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
400 #else
401  ((void) ctx);
402  ((void) operation);
403  ((void) length);
404  ((void) iv_off);
405  ((void) iv);
406  ((void) input);
407  ((void) output);
408 
410 #endif
411 }
412 
413 static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
414  size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
415  const unsigned char *input, unsigned char *output )
416 {
417 #if defined(POLARSSL_CIPHER_MODE_CTR)
418  return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
419  stream_block, input, output );
420 #else
421  ((void) ctx);
422  ((void) length);
423  ((void) nc_off);
424  ((void) nonce_counter);
425  ((void) stream_block);
426  ((void) input);
427  ((void) output);
428 
430 #endif
431 }
432 
433 static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
434 {
435  return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
436 }
437 
438 static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
439 {
440  return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
441 }
442 
443 static void * camellia_ctx_alloc( void )
444 {
445  return polarssl_malloc( sizeof( camellia_context ) );
446 }
447 
448 static void camellia_ctx_free( void *ctx )
449 {
450  polarssl_free( ctx );
451 }
452 
453 const cipher_base_t camellia_info = {
455  camellia_crypt_ecb_wrap,
456  camellia_crypt_cbc_wrap,
457  camellia_crypt_cfb128_wrap,
458  camellia_crypt_ctr_wrap,
459  NULL,
460  camellia_setkey_enc_wrap,
461  camellia_setkey_dec_wrap,
462  camellia_ctx_alloc,
463  camellia_ctx_free
464 };
465 
466 const cipher_info_t camellia_128_ecb_info = {
469  128,
470  "CAMELLIA-128-ECB",
471  16,
472  0,
473  16,
474  &camellia_info
475 };
476 
477 const cipher_info_t camellia_192_ecb_info = {
480  192,
481  "CAMELLIA-192-ECB",
482  16,
483  0,
484  16,
485  &camellia_info
486 };
487 
488 const cipher_info_t camellia_256_ecb_info = {
491  256,
492  "CAMELLIA-256-ECB",
493  16,
494  0,
495  16,
496  &camellia_info
497 };
498 
499 #if defined(POLARSSL_CIPHER_MODE_CBC)
500 const cipher_info_t camellia_128_cbc_info = {
503  128,
504  "CAMELLIA-128-CBC",
505  16,
506  0,
507  16,
508  &camellia_info
509 };
510 
511 const cipher_info_t camellia_192_cbc_info = {
514  192,
515  "CAMELLIA-192-CBC",
516  16,
517  0,
518  16,
519  &camellia_info
520 };
521 
522 const cipher_info_t camellia_256_cbc_info = {
525  256,
526  "CAMELLIA-256-CBC",
527  16,
528  0,
529  16,
530  &camellia_info
531 };
532 #endif /* POLARSSL_CIPHER_MODE_CBC */
533 
534 #if defined(POLARSSL_CIPHER_MODE_CFB)
535 const cipher_info_t camellia_128_cfb128_info = {
538  128,
539  "CAMELLIA-128-CFB128",
540  16,
541  0,
542  16,
543  &camellia_info
544 };
545 
546 const cipher_info_t camellia_192_cfb128_info = {
549  192,
550  "CAMELLIA-192-CFB128",
551  16,
552  0,
553  16,
554  &camellia_info
555 };
556 
557 const cipher_info_t camellia_256_cfb128_info = {
560  256,
561  "CAMELLIA-256-CFB128",
562  16,
563  0,
564  16,
565  &camellia_info
566 };
567 #endif /* POLARSSL_CIPHER_MODE_CFB */
568 
569 #if defined(POLARSSL_CIPHER_MODE_CTR)
570 const cipher_info_t camellia_128_ctr_info = {
573  128,
574  "CAMELLIA-128-CTR",
575  16,
576  0,
577  16,
578  &camellia_info
579 };
580 
581 const cipher_info_t camellia_192_ctr_info = {
584  192,
585  "CAMELLIA-192-CTR",
586  16,
587  0,
588  16,
589  &camellia_info
590 };
591 
592 const cipher_info_t camellia_256_ctr_info = {
595  256,
596  "CAMELLIA-256-CTR",
597  16,
598  0,
599  16,
600  &camellia_info
601 };
602 #endif /* POLARSSL_CIPHER_MODE_CTR */
603 
604 #endif
605 
606 #if defined(POLARSSL_DES_C)
607 
608 static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
609  const unsigned char *input, unsigned char *output )
610 {
611  ((void) operation);
612  return des_crypt_ecb( (des_context *) ctx, input, output );
613 }
614 
615 static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
616  const unsigned char *input, unsigned char *output )
617 {
618  ((void) operation);
619  return des3_crypt_ecb( (des3_context *) ctx, input, output );
620 }
621 
622 static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
623  unsigned char *iv, const unsigned char *input, unsigned char *output )
624 {
625 #if defined(POLARSSL_CIPHER_MODE_CBC)
626  return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
627 #else
628  ((void) ctx);
629  ((void) operation);
630  ((void) length);
631  ((void) iv);
632  ((void) input);
633  ((void) output);
634 
636 #endif /* POLARSSL_CIPHER_MODE_CBC */
637 }
638 
639 static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
640  unsigned char *iv, const unsigned char *input, unsigned char *output )
641 {
642 #if defined(POLARSSL_CIPHER_MODE_CBC)
643  return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
644 #else
645  ((void) ctx);
646  ((void) operation);
647  ((void) length);
648  ((void) iv);
649  ((void) input);
650  ((void) output);
651 
653 #endif /* POLARSSL_CIPHER_MODE_CBC */
654 }
655 
656 static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
657  size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
658 {
659  ((void) ctx);
660  ((void) operation);
661  ((void) length);
662  ((void) iv_off);
663  ((void) iv);
664  ((void) input);
665  ((void) output);
666 
668 }
669 
670 static int des_crypt_ctr_wrap( void *ctx, size_t length,
671  size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
672  const unsigned char *input, unsigned char *output )
673 {
674  ((void) ctx);
675  ((void) length);
676  ((void) nc_off);
677  ((void) nonce_counter);
678  ((void) stream_block);
679  ((void) input);
680  ((void) output);
681 
683 }
684 
685 static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
686 {
687  ((void) key_length);
688 
689  return des_setkey_dec( (des_context *) ctx, key );
690 }
691 
692 static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
693 {
694  ((void) key_length);
695 
696  return des_setkey_enc( (des_context *) ctx, key );
697 }
698 
699 static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
700 {
701  ((void) key_length);
702 
703  return des3_set2key_dec( (des3_context *) ctx, key );
704 }
705 
706 static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
707 {
708  ((void) key_length);
709 
710  return des3_set2key_enc( (des3_context *) ctx, key );
711 }
712 
713 static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
714 {
715  ((void) key_length);
716 
717  return des3_set3key_dec( (des3_context *) ctx, key );
718 }
719 
720 static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
721 {
722  ((void) key_length);
723 
724  return des3_set3key_enc( (des3_context *) ctx, key );
725 }
726 
727 static void * des_ctx_alloc( void )
728 {
729  return polarssl_malloc( sizeof( des_context ) );
730 }
731 
732 static void * des3_ctx_alloc( void )
733 {
734  return polarssl_malloc( sizeof( des3_context ) );
735 }
736 
737 static void des_ctx_free( void *ctx )
738 {
739  polarssl_free( ctx );
740 }
741 
742 const cipher_base_t des_info = {
744  des_crypt_ecb_wrap,
745  des_crypt_cbc_wrap,
746  des_crypt_cfb128_wrap,
747  des_crypt_ctr_wrap,
748  NULL,
749  des_setkey_enc_wrap,
750  des_setkey_dec_wrap,
751  des_ctx_alloc,
752  des_ctx_free
753 };
754 
755 const cipher_info_t des_ecb_info = {
759  "DES-ECB",
760  8,
761  0,
762  8,
763  &des_info
764 };
765 
766 #if defined(POLARSSL_CIPHER_MODE_CBC)
767 const cipher_info_t des_cbc_info = {
771  "DES-CBC",
772  8,
773  0,
774  8,
775  &des_info
776 };
777 #endif /* POLARSSL_CIPHER_MODE_CBC */
778 
779 const cipher_base_t des_ede_info = {
781  des3_crypt_ecb_wrap,
782  des3_crypt_cbc_wrap,
783  des_crypt_cfb128_wrap,
784  des_crypt_ctr_wrap,
785  NULL,
786  des3_set2key_enc_wrap,
787  des3_set2key_dec_wrap,
788  des3_ctx_alloc,
789  des_ctx_free
790 };
791 
792 const cipher_info_t des_ede_ecb_info = {
796  "DES-EDE-ECB",
797  8,
798  0,
799  8,
800  &des_ede_info
801 };
802 
803 #if defined(POLARSSL_CIPHER_MODE_CBC)
804 const cipher_info_t des_ede_cbc_info = {
808  "DES-EDE-CBC",
809  8,
810  0,
811  8,
812  &des_ede_info
813 };
814 #endif /* POLARSSL_CIPHER_MODE_CBC */
815 
816 const cipher_base_t des_ede3_info = {
818  des3_crypt_ecb_wrap,
819  des3_crypt_cbc_wrap,
820  des_crypt_cfb128_wrap,
821  des_crypt_ctr_wrap,
822  NULL,
823  des3_set3key_enc_wrap,
824  des3_set3key_dec_wrap,
825  des3_ctx_alloc,
826  des_ctx_free
827 };
828 
829 const cipher_info_t des_ede3_ecb_info = {
833  "DES-EDE3-ECB",
834  8,
835  0,
836  8,
837  &des_ede3_info
838 };
839 #if defined(POLARSSL_CIPHER_MODE_CBC)
840 const cipher_info_t des_ede3_cbc_info = {
844  "DES-EDE3-CBC",
845  8,
846  0,
847  8,
848  &des_ede3_info
849 };
850 #endif /* POLARSSL_CIPHER_MODE_CBC */
851 #endif
852 
853 #if defined(POLARSSL_BLOWFISH_C)
854 
855 static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
856  const unsigned char *input, unsigned char *output )
857 {
858  return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
859 }
860 
861 static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
862  unsigned char *iv, const unsigned char *input, unsigned char *output )
863 {
864 #if defined(POLARSSL_CIPHER_MODE_CBC)
865  return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, 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 
878 static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
879  size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
880 {
881 #if defined(POLARSSL_CIPHER_MODE_CFB)
882  return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
883 #else
884  ((void) ctx);
885  ((void) operation);
886  ((void) length);
887  ((void) iv_off);
888  ((void) iv);
889  ((void) input);
890  ((void) output);
891 
893 #endif
894 }
895 
896 static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
897  size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
898  const unsigned char *input, unsigned char *output )
899 {
900 #if defined(POLARSSL_CIPHER_MODE_CTR)
901  return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
902  stream_block, input, output );
903 #else
904  ((void) ctx);
905  ((void) length);
906  ((void) nc_off);
907  ((void) nonce_counter);
908  ((void) stream_block);
909  ((void) input);
910  ((void) output);
911 
913 #endif
914 }
915 
916 static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
917 {
918  return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
919 }
920 
921 static void * blowfish_ctx_alloc( void )
922 {
923  return polarssl_malloc( sizeof( blowfish_context ) );
924 }
925 
926 static void blowfish_ctx_free( void *ctx )
927 {
928  polarssl_free( ctx );
929 }
930 
931 const cipher_base_t blowfish_info = {
933  blowfish_crypt_ecb_wrap,
934  blowfish_crypt_cbc_wrap,
935  blowfish_crypt_cfb64_wrap,
936  blowfish_crypt_ctr_wrap,
937  NULL,
938  blowfish_setkey_wrap,
939  blowfish_setkey_wrap,
940  blowfish_ctx_alloc,
941  blowfish_ctx_free
942 };
943 
944 const cipher_info_t blowfish_ecb_info = {
947  128,
948  "BLOWFISH-ECB",
949  8,
950  0,
951  8,
952  &blowfish_info
953 };
954 
955 #if defined(POLARSSL_CIPHER_MODE_CBC)
956 const cipher_info_t blowfish_cbc_info = {
959  128,
960  "BLOWFISH-CBC",
961  8,
962  0,
963  8,
964  &blowfish_info
965 };
966 #endif /* POLARSSL_CIPHER_MODE_CBC */
967 
968 #if defined(POLARSSL_CIPHER_MODE_CFB)
969 const cipher_info_t blowfish_cfb64_info = {
972  128,
973  "BLOWFISH-CFB64",
974  8,
975  0,
976  8,
977  &blowfish_info
978 };
979 #endif /* POLARSSL_CIPHER_MODE_CFB */
980 
981 #if defined(POLARSSL_CIPHER_MODE_CTR)
982 const cipher_info_t blowfish_ctr_info = {
985  128,
986  "BLOWFISH-CTR",
987  8,
988  0,
989  8,
990  &blowfish_info
991 };
992 #endif /* POLARSSL_CIPHER_MODE_CTR */
993 #endif /* POLARSSL_BLOWFISH_C */
994 
995 #if defined(POLARSSL_ARC4_C)
996 static int arc4_crypt_stream_wrap( void *ctx, size_t length,
997  const unsigned char *input,
998  unsigned char *output )
999 {
1000  return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
1001 }
1002 
1003 static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1004  unsigned int key_length )
1005 {
1006  /* we get key_length in bits, arc4 expects it in bytes */
1007  if( key_length % 8 != 0)
1009 
1010  arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
1011  return( 0 );
1012 }
1013 
1014 static void * arc4_ctx_alloc( void )
1015 {
1016  return polarssl_malloc( sizeof( arc4_context ) );
1017 }
1018 
1019 static void arc4_ctx_free( void *ctx )
1020 {
1021  polarssl_free( ctx );
1022 }
1023 
1024 const cipher_base_t arc4_base_info = {
1026  NULL,
1027  NULL,
1028  NULL,
1029  NULL,
1030  arc4_crypt_stream_wrap,
1031  arc4_setkey_wrap,
1032  arc4_setkey_wrap,
1033  arc4_ctx_alloc,
1034  arc4_ctx_free
1035 };
1036 
1037 const cipher_info_t arc4_128_info = {
1040  128,
1041  "ARC4-128",
1042  0,
1043  0,
1044  1,
1045  &arc4_base_info
1046 };
1047 #endif /* POLARSSL_ARC4_C */
1048 
1049 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1050 static int null_crypt_stream( void *ctx, size_t length,
1051  const unsigned char *input,
1052  unsigned char *output )
1053 {
1054  ((void) ctx);
1055  memmove( output, input, length );
1056  return( 0 );
1057 }
1058 
1059 static int null_setkey( void *ctx, const unsigned char *key,
1060  unsigned int key_length )
1061 {
1062  ((void) ctx);
1063  ((void) key);
1064  ((void) key_length);
1065 
1066  return( 0 );
1067 }
1068 
1069 static void * null_ctx_alloc( void )
1070 {
1071  return (void *) 1;
1072 }
1073 
1074 static void null_ctx_free( void *ctx )
1075 {
1076  ((void) ctx);
1077 }
1078 
1079 const cipher_base_t null_base_info = {
1081  NULL,
1082  NULL,
1083  NULL,
1084  NULL,
1085  null_crypt_stream,
1086  null_setkey,
1087  null_setkey,
1088  null_ctx_alloc,
1089  null_ctx_free
1090 };
1091 
1092 const cipher_info_t null_cipher_info = {
1095  0,
1096  "NULL",
1097  0,
1098  0,
1099  1,
1100  &null_base_info
1101 };
1102 #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1103 
1105 {
1106 #if defined(POLARSSL_AES_C)
1107  { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1108  { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1109  { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1110 #if defined(POLARSSL_CIPHER_MODE_CBC)
1111  { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1112  { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1113  { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1114 #endif
1115 #if defined(POLARSSL_CIPHER_MODE_CFB)
1116  { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1117  { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1118  { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1119 #endif
1120 #if defined(POLARSSL_CIPHER_MODE_CTR)
1121  { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1122  { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1123  { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1124 #endif
1125 #if defined(POLARSSL_GCM_C)
1126  { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1127  { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1128  { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1129 #endif
1130 #endif /* POLARSSL_AES_C */
1131 
1132 #if defined(POLARSSL_ARC4_C)
1133  { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1134 #endif
1135 
1136 #if defined(POLARSSL_BLOWFISH_C)
1137  { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1138 #if defined(POLARSSL_CIPHER_MODE_CBC)
1139  { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1140 #endif
1141 #if defined(POLARSSL_CIPHER_MODE_CFB)
1142  { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1143 #endif
1144 #if defined(POLARSSL_CIPHER_MODE_CTR)
1145  { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1146 #endif
1147 #endif /* POLARSSL_BLOWFISH_C */
1148 
1149 #if defined(POLARSSL_CAMELLIA_C)
1150  { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1151  { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1152 #if defined(POLARSSL_CIPHER_MODE_CBC)
1153  { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1154  { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1155  { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1156 #endif
1157 #if defined(POLARSSL_CIPHER_MODE_CFB)
1158  { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1159  { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1160  { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1161 #endif
1162 #if defined(POLARSSL_CIPHER_MODE_CTR)
1163  { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1164  { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1165  { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1166 #endif
1167 #endif /* POLARSSL_CAMELLIA_C */
1168 
1169 #if defined(POLARSSL_DES_C)
1170  { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1171  { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1172  { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1173 #if defined(POLARSSL_CIPHER_MODE_CBC)
1174  { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1175  { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1176  { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1177 #endif
1178 #endif /* POLARSSL_DES_C */
1179 
1180 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1181  { POLARSSL_CIPHER_NULL, &null_cipher_info },
1182 #endif /* POLARSSL_CIPHER_NULL_CIPHER */
1183 
1184  { 0, NULL }
1185 };
1186 
1187 #define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1188 int supported_ciphers[NUM_CIPHERS];
1189 
1190 #endif