TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tomcrypt_cipher.h
Go to the documentation of this file.
1 /* ---- SYMMETRIC KEY STUFF -----
2  *
3  * We put each of the ciphers scheduled keys in their own structs then we put all of
4  * the key formats in one union. This makes the function prototypes easier to use.
5  */
6 #ifdef LTC_BLOWFISH
7 struct blowfish_key {
8  ulong32 S[4][256];
9  ulong32 K[18];
10 };
11 #endif
12 
13 #ifdef LTC_RC5
14 struct rc5_key {
15  int rounds;
16  ulong32 K[50];
17 };
18 #endif
19 
20 #ifdef LTC_RC6
21 struct rc6_key {
22  ulong32 K[44];
23 };
24 #endif
25 
26 #ifdef LTC_SAFERP
27 struct saferp_key {
28  unsigned char K[33][16];
29  long rounds;
30 };
31 #endif
32 
33 #ifdef LTC_RIJNDAEL
34 struct rijndael_key {
35  ulong32 eK[60], dK[60];
36  int Nr;
37 };
38 #endif
39 
40 #ifdef LTC_KSEED
41 struct kseed_key {
42  ulong32 K[32], dK[32];
43 };
44 #endif
45 
46 #ifdef LTC_KASUMI
47 struct kasumi_key {
48  ulong32 KLi1[8], KLi2[8],
49  KOi1[8], KOi2[8], KOi3[8],
50  KIi1[8], KIi2[8], KIi3[8];
51 };
52 #endif
53 
54 #ifdef LTC_XTEA
55 struct xtea_key {
56  unsigned long A[32], B[32];
57 };
58 #endif
59 
60 #ifdef LTC_TWOFISH
61 #ifndef LTC_TWOFISH_SMALL
62  struct twofish_key {
63  ulong32 S[4][256], K[40];
64  };
65 #else
66  struct twofish_key {
67  ulong32 K[40];
68  unsigned char S[32], start;
69  };
70 #endif
71 #endif
72 
73 #ifdef LTC_SAFER
74 #define LTC_SAFER_K64_DEFAULT_NOF_ROUNDS 6
75 #define LTC_SAFER_K128_DEFAULT_NOF_ROUNDS 10
76 #define LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS 8
77 #define LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS 10
78 #define LTC_SAFER_MAX_NOF_ROUNDS 13
79 #define LTC_SAFER_BLOCK_LEN 8
80 #define LTC_SAFER_KEY_LEN (1 + LTC_SAFER_BLOCK_LEN * (1 + 2 * LTC_SAFER_MAX_NOF_ROUNDS))
81 typedef unsigned char safer_block_t[LTC_SAFER_BLOCK_LEN];
82 typedef unsigned char safer_key_t[LTC_SAFER_KEY_LEN];
83 struct safer_key { safer_key_t key; };
84 #endif
85 
86 #ifdef LTC_RC2
87 struct rc2_key { unsigned xkey[64]; };
88 #endif
89 
90 #ifdef LTC_DES
91 struct des_key {
92  ulong32 ek[32], dk[32];
93 };
94 
95 struct des3_key {
96  ulong32 ek[3][32], dk[3][32];
97 };
98 #endif
99 
100 #ifdef LTC_CAST5
101 struct cast5_key {
102  ulong32 K[32], keylen;
103 };
104 #endif
105 
106 #ifdef LTC_NOEKEON
107 struct noekeon_key {
108  ulong32 K[4], dK[4];
109 };
110 #endif
111 
112 #ifdef LTC_SKIPJACK
113 struct skipjack_key {
114  unsigned char key[10];
115 };
116 #endif
117 
118 #ifdef LTC_KHAZAD
119 struct khazad_key {
120  ulong64 roundKeyEnc[8 + 1];
121  ulong64 roundKeyDec[8 + 1];
122 };
123 #endif
124 
125 #ifdef LTC_ANUBIS
126 struct anubis_key {
127  int keyBits;
128  int R;
129  ulong32 roundKeyEnc[18 + 1][4];
130  ulong32 roundKeyDec[18 + 1][4];
131 };
132 #endif
133 
134 #ifdef LTC_MULTI2
135 struct multi2_key {
136  int N;
137  ulong32 uk[8];
138 };
139 #endif
140 
141 typedef union Symmetric_key {
142 #ifdef LTC_DES
143  struct des_key des;
144  struct des3_key des3;
145 #endif
146 #ifdef LTC_RC2
147  struct rc2_key rc2;
148 #endif
149 #ifdef LTC_SAFER
150  struct safer_key safer;
151 #endif
152 #ifdef LTC_TWOFISH
153  struct twofish_key twofish;
154 #endif
155 #ifdef LTC_BLOWFISH
156  struct blowfish_key blowfish;
157 #endif
158 #ifdef LTC_RC5
159  struct rc5_key rc5;
160 #endif
161 #ifdef LTC_RC6
162  struct rc6_key rc6;
163 #endif
164 #ifdef LTC_SAFERP
165  struct saferp_key saferp;
166 #endif
167 #ifdef LTC_RIJNDAEL
168  struct rijndael_key rijndael;
169 #endif
170 #ifdef LTC_XTEA
171  struct xtea_key xtea;
172 #endif
173 #ifdef LTC_CAST5
174  struct cast5_key cast5;
175 #endif
176 #ifdef LTC_NOEKEON
177  struct noekeon_key noekeon;
178 #endif
179 #ifdef LTC_SKIPJACK
180  struct skipjack_key skipjack;
181 #endif
182 #ifdef LTC_KHAZAD
183  struct khazad_key khazad;
184 #endif
185 #ifdef LTC_ANUBIS
186  struct anubis_key anubis;
187 #endif
188 #ifdef LTC_KSEED
189  struct kseed_key kseed;
190 #endif
191 #ifdef LTC_KASUMI
192  struct kasumi_key kasumi;
193 #endif
194 #ifdef LTC_MULTI2
195  struct multi2_key multi2;
196 #endif
197  void *data;
198 } symmetric_key;
199 
200 #ifdef LTC_ECB_MODE
201 
202 typedef struct {
204  int cipher,
206  blocklen;
208  symmetric_key key;
209 } symmetric_ECB;
210 #endif
211 
212 #ifdef LTC_CFB_MODE
213 
214 typedef struct {
216  int cipher,
218  blocklen,
220  padlen;
222  unsigned char IV[MAXBLOCKSIZE],
224  pad[MAXBLOCKSIZE];
226  symmetric_key key;
227 } symmetric_CFB;
228 #endif
229 
230 #ifdef LTC_OFB_MODE
231 
232 typedef struct {
234  int cipher,
236  blocklen,
238  padlen;
240  unsigned char IV[MAXBLOCKSIZE];
242  symmetric_key key;
243 } symmetric_OFB;
244 #endif
245 
246 #ifdef LTC_CBC_MODE
247 
248 typedef struct {
250  int cipher,
252  blocklen;
254  unsigned char IV[MAXBLOCKSIZE];
256  symmetric_key key;
257 } symmetric_CBC;
258 #endif
259 
260 
261 #ifdef LTC_CTR_MODE
262 
263 typedef struct {
265  int cipher,
267  blocklen,
269  padlen,
271  mode,
273  ctrlen;
274 
276  unsigned char ctr[MAXBLOCKSIZE],
278  pad[MAXBLOCKSIZE];
280  symmetric_key key;
281 } symmetric_CTR;
282 #endif
283 
284 
285 #ifdef LTC_LRW_MODE
286 
287 typedef struct {
289  int cipher;
290 
292  unsigned char IV[16],
293 
295  tweak[16],
296 
298  pad[16];
299 
301  symmetric_key key;
302 
303 #ifdef LRW_TABLES
304 
305  unsigned char PC[16][256][16];
306 #endif
307 } symmetric_LRW;
308 #endif
309 
310 #ifdef LTC_F8_MODE
311 
312 typedef struct {
314  int cipher,
316  blocklen,
318  padlen;
320  unsigned char IV[MAXBLOCKSIZE],
321  MIV[MAXBLOCKSIZE];
323  ulong32 blockcnt;
325  symmetric_key key;
326 } symmetric_F8;
327 #endif
328 
329 
331 extern struct ltc_cipher_descriptor {
333  char *name;
335  unsigned char ID;
341  block_length,
351  int (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
358  int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
365  int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
369  int (*test)(void);
370 
374  void (*done)(symmetric_key *skey);
375 
380  int (*keysize)(int *keysize);
381 
390  int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
391 
399  int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
400 
409  int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
410 
419  int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
420 
430  int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
431 
441  int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
442 
452  int (*accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
453 
471  const unsigned char *key, unsigned long keylen,
472  symmetric_key *uskey,
473  const unsigned char *nonce, unsigned long noncelen,
474  const unsigned char *header, unsigned long headerlen,
475  unsigned char *pt, unsigned long ptlen,
476  unsigned char *ct,
477  unsigned char *tag, unsigned long *taglen,
478  int direction);
479 
496  const unsigned char *key, unsigned long keylen,
497  const unsigned char *IV, unsigned long IVlen,
498  const unsigned char *adata, unsigned long adatalen,
499  unsigned char *pt, unsigned long ptlen,
500  unsigned char *ct,
501  unsigned char *tag, unsigned long *taglen,
502  int direction);
503 
513  int (*omac_memory)(
514  const unsigned char *key, unsigned long keylen,
515  const unsigned char *in, unsigned long inlen,
516  unsigned char *out, unsigned long *outlen);
517 
527  int (*xcbc_memory)(
528  const unsigned char *key, unsigned long keylen,
529  const unsigned char *in, unsigned long inlen,
530  unsigned char *out, unsigned long *outlen);
531 
542  int (*f9_memory)(
543  const unsigned char *key, unsigned long keylen,
544  const unsigned char *in, unsigned long inlen,
545  unsigned char *out, unsigned long *outlen);
547 
548 #ifdef LTC_BLOWFISH
549 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
550 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
551 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
552 int blowfish_test(void);
553 void blowfish_done(symmetric_key *skey);
554 int blowfish_keysize(int *keysize);
555 extern const struct ltc_cipher_descriptor blowfish_desc;
556 #endif
557 
558 #ifdef LTC_RC5
559 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
560 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
561 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
562 int rc5_test(void);
563 void rc5_done(symmetric_key *skey);
564 int rc5_keysize(int *keysize);
565 extern const struct ltc_cipher_descriptor rc5_desc;
566 #endif
567 
568 #ifdef LTC_RC6
569 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
570 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
571 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
572 int rc6_test(void);
573 void rc6_done(symmetric_key *skey);
574 int rc6_keysize(int *keysize);
575 extern const struct ltc_cipher_descriptor rc6_desc;
576 #endif
577 
578 #ifdef LTC_RC2
579 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
580 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
581 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
582 int rc2_test(void);
583 void rc2_done(symmetric_key *skey);
584 int rc2_keysize(int *keysize);
585 extern const struct ltc_cipher_descriptor rc2_desc;
586 #endif
587 
588 #ifdef LTC_SAFERP
589 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
590 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
591 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
592 int saferp_test(void);
593 void saferp_done(symmetric_key *skey);
594 int saferp_keysize(int *keysize);
595 extern const struct ltc_cipher_descriptor saferp_desc;
596 #endif
597 
598 #ifdef LTC_SAFER
599 int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
600 int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
601 int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
602 int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
603 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
604 int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
605 int safer_k64_test(void);
606 int safer_sk64_test(void);
607 int safer_sk128_test(void);
608 void safer_done(symmetric_key *skey);
609 int safer_64_keysize(int *keysize);
610 int safer_128_keysize(int *keysize);
611 extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;
612 #endif
613 
614 #ifdef LTC_RIJNDAEL
615 
616 /* make aes an alias */
617 #define aes_setup rijndael_setup
618 #define aes_ecb_encrypt rijndael_ecb_encrypt
619 #define aes_ecb_decrypt rijndael_ecb_decrypt
620 #define aes_test rijndael_test
621 #define aes_done rijndael_done
622 #define aes_keysize rijndael_keysize
623 
624 #define aes_enc_setup rijndael_enc_setup
625 #define aes_enc_ecb_encrypt rijndael_enc_ecb_encrypt
626 #define aes_enc_keysize rijndael_enc_keysize
627 
628 int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
629 int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
630 int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
631 int rijndael_test(void);
632 void rijndael_done(symmetric_key *skey);
633 int rijndael_keysize(int *keysize);
634 int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
635 int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
636 void rijndael_enc_done(symmetric_key *skey);
637 int rijndael_enc_keysize(int *keysize);
638 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
639 extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
640 #endif
641 
642 #ifdef LTC_XTEA
643 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
644 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
645 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
646 int xtea_test(void);
647 void xtea_done(symmetric_key *skey);
648 int xtea_keysize(int *keysize);
649 extern const struct ltc_cipher_descriptor xtea_desc;
650 #endif
651 
652 #ifdef LTC_TWOFISH
653 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
654 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
655 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
656 int twofish_test(void);
657 void twofish_done(symmetric_key *skey);
658 int twofish_keysize(int *keysize);
659 extern const struct ltc_cipher_descriptor twofish_desc;
660 #endif
661 
662 #ifdef LTC_DES
663 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
664 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
665 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
666 int des_test(void);
667 void des_done(symmetric_key *skey);
668 int des_keysize(int *keysize);
669 int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
670 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
671 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
672 int des3_test(void);
673 void des3_done(symmetric_key *skey);
674 int des3_keysize(int *keysize);
675 extern const struct ltc_cipher_descriptor des_desc, des3_desc;
676 #endif
677 
678 #ifdef LTC_CAST5
679 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
680 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
681 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
682 int cast5_test(void);
683 void cast5_done(symmetric_key *skey);
684 int cast5_keysize(int *keysize);
685 extern const struct ltc_cipher_descriptor cast5_desc;
686 #endif
687 
688 #ifdef LTC_NOEKEON
689 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
690 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
691 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
692 int noekeon_test(void);
693 void noekeon_done(symmetric_key *skey);
694 int noekeon_keysize(int *keysize);
695 extern const struct ltc_cipher_descriptor noekeon_desc;
696 #endif
697 
698 #ifdef LTC_SKIPJACK
699 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
700 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
701 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
702 int skipjack_test(void);
703 void skipjack_done(symmetric_key *skey);
704 int skipjack_keysize(int *keysize);
705 extern const struct ltc_cipher_descriptor skipjack_desc;
706 #endif
707 
708 #ifdef LTC_KHAZAD
709 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
710 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
711 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
712 int khazad_test(void);
713 void khazad_done(symmetric_key *skey);
714 int khazad_keysize(int *keysize);
715 extern const struct ltc_cipher_descriptor khazad_desc;
716 #endif
717 
718 #ifdef LTC_ANUBIS
719 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
720 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
721 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
722 int anubis_test(void);
723 void anubis_done(symmetric_key *skey);
724 int anubis_keysize(int *keysize);
725 extern const struct ltc_cipher_descriptor anubis_desc;
726 #endif
727 
728 #ifdef LTC_KSEED
729 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
730 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
731 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
732 int kseed_test(void);
733 void kseed_done(symmetric_key *skey);
734 int kseed_keysize(int *keysize);
735 extern const struct ltc_cipher_descriptor kseed_desc;
736 #endif
737 
738 #ifdef LTC_KASUMI
739 int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
740 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
741 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
742 int kasumi_test(void);
743 void kasumi_done(symmetric_key *skey);
744 int kasumi_keysize(int *keysize);
745 extern const struct ltc_cipher_descriptor kasumi_desc;
746 #endif
747 
748 
749 #ifdef LTC_MULTI2
750 int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
751 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
752 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
753 int multi2_test(void);
754 void multi2_done(symmetric_key *skey);
755 int multi2_keysize(int *keysize);
756 extern const struct ltc_cipher_descriptor multi2_desc;
757 #endif
758 
759 #ifdef LTC_ECB_MODE
760 int ecb_start(int cipher, const unsigned char *key,
761  int keylen, int num_rounds, symmetric_ECB *ecb);
762 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
763 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
764 int ecb_done(symmetric_ECB *ecb);
765 #endif
766 
767 #ifdef LTC_CFB_MODE
768 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
769  int keylen, int num_rounds, symmetric_CFB *cfb);
770 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
771 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
772 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
773 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
774 int cfb_done(symmetric_CFB *cfb);
775 #endif
776 
777 #ifdef LTC_OFB_MODE
778 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
779  int keylen, int num_rounds, symmetric_OFB *ofb);
780 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
781 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
782 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
783 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
784 int ofb_done(symmetric_OFB *ofb);
785 #endif
786 
787 #ifdef LTC_CBC_MODE
788 int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
789  int keylen, int num_rounds, symmetric_CBC *cbc);
790 int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
791 int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
792 int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
793 int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
794 int cbc_done(symmetric_CBC *cbc);
795 #endif
796 
797 #ifdef LTC_CTR_MODE
798 
799 #define CTR_COUNTER_LITTLE_ENDIAN 0x0000
800 #define CTR_COUNTER_BIG_ENDIAN 0x1000
801 #define LTC_CTR_RFC3686 0x2000
802 
803 int ctr_start( int cipher,
804  const unsigned char *IV,
805  const unsigned char *key, int keylen,
806  int num_rounds, int ctr_mode,
807  symmetric_CTR *ctr);
808 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
809 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
810 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
811 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
812 int ctr_done(symmetric_CTR *ctr);
813 int ctr_test(void);
814 #endif
815 
816 #ifdef LTC_LRW_MODE
817 
818 #define LRW_ENCRYPT 0
819 #define LRW_DECRYPT 1
820 
821 int lrw_start( int cipher,
822  const unsigned char *IV,
823  const unsigned char *key, int keylen,
824  const unsigned char *tweak,
825  int num_rounds,
826  symmetric_LRW *lrw);
827 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
828 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
829 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);
830 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);
831 int lrw_done(symmetric_LRW *lrw);
832 int lrw_test(void);
833 
834 /* don't call */
835 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
836 #endif
837 
838 #ifdef LTC_F8_MODE
839 int f8_start( int cipher, const unsigned char *IV,
840  const unsigned char *key, int keylen,
841  const unsigned char *salt_key, int skeylen,
842  int num_rounds, symmetric_F8 *f8);
843 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
844 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
845 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
846 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
847 int f8_done(symmetric_F8 *f8);
848 int f8_test_mode(void);
849 #endif
850 
851 #ifdef LTC_XTS_MODE
852 typedef struct {
853  symmetric_key key1, key2;
854  int cipher;
855 } symmetric_xts;
856 
857 int xts_start( int cipher,
858  const unsigned char *key1,
859  const unsigned char *key2,
860  unsigned long keylen,
861  int num_rounds,
862  symmetric_xts *xts);
863 
864 int xts_encrypt(
865  const unsigned char *pt, unsigned long ptlen,
866  unsigned char *ct,
867  const unsigned char *tweak,
868  symmetric_xts *xts);
869 int xts_decrypt(
870  const unsigned char *ct, unsigned long ptlen,
871  unsigned char *pt,
872  const unsigned char *tweak,
873  symmetric_xts *xts);
874 
875 void xts_done(symmetric_xts *xts);
876 int xts_test(void);
877 void xts_mult_x(unsigned char *I);
878 #endif
879 
880 int find_cipher(const char *name);
881 int find_cipher_any(const char *name, int blocklen, int keylen);
882 int find_cipher_id(unsigned char ID);
883 int register_cipher(const struct ltc_cipher_descriptor *cipher);
884 int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
885 int cipher_is_valid(int idx);
886 
887 LTC_MUTEX_PROTO(ltc_cipher_mutex)
888 
889 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cipher.h,v $ */
890 /* $Revision: 1.54 $ */
891 /* $Date: 2007/05/12 14:37:41 $ */
int(* accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey)
Definition: tomcrypt_cipher.h:441
int(* accel_gcm_memory)(const unsigned char *key, unsigned long keylen, const unsigned char *IV, unsigned long IVlen, const unsigned char *adata, unsigned long adatalen, unsigned char *pt, unsigned long ptlen, unsigned char *ct, unsigned char *tag, unsigned long *taglen, int direction)
Definition: tomcrypt_cipher.h:495
struct ltc_cipher_descriptor cipher_descriptor[]
#define I(x, y, z)
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
int(* setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
Definition: tomcrypt_cipher.h:351
int(* accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey)
Definition: tomcrypt_cipher.h:419
#define LTC_MUTEX_PROTO(x)
Definition: tomcrypt_custom.h:405
int register_cipher(const struct ltc_cipher_descriptor *cipher)
#define MAXBLOCKSIZE
Definition: tomcrypt.h:23
int(* accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey)
Definition: tomcrypt_cipher.h:430
int(* accel_ccm_memory)(const unsigned char *key, unsigned long keylen, symmetric_key *uskey, const unsigned char *nonce, unsigned long noncelen, const unsigned char *header, unsigned long headerlen, unsigned char *pt, unsigned long ptlen, unsigned char *ct, unsigned char *tag, unsigned long *taglen, int direction)
Definition: tomcrypt_cipher.h:470
int(* accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey)
Definition: tomcrypt_cipher.h:390
unsigned long ulong32
Definition: tomcrypt_macros.h:16
int find_cipher(const char *name)
unsigned long long ulong64
Definition: tomcrypt_macros.h:7
int(* accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey)
Definition: tomcrypt_cipher.h:399
void * data
Definition: tomcrypt_cipher.h:197
int default_rounds
Definition: tomcrypt_cipher.h:337
int(* xcbc_memory)(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
Definition: tomcrypt_cipher.h:527
int unregister_cipher(const struct ltc_cipher_descriptor *cipher)
int(* ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
Definition: tomcrypt_cipher.h:358
unsigned char ID
Definition: tomcrypt_cipher.h:335
Definition: tomcrypt_cipher.h:331
int max_key_length
Definition: tomcrypt_cipher.h:337
char * name
Definition: tomcrypt_cipher.h:333
int find_cipher_any(const char *name, int blocklen, int keylen)
int find_cipher_id(unsigned char ID)
union Symmetric_key symmetric_key
int(* accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey)
Definition: tomcrypt_cipher.h:452
int(* ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
Definition: tomcrypt_cipher.h:365
int min_key_length
Definition: tomcrypt_cipher.h:337
Definition: tomcrypt_cipher.h:141
int block_length
Definition: tomcrypt_cipher.h:337
int(* f9_memory)(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
Definition: tomcrypt_cipher.h:542
int(* keysize)(int *keysize)
Definition: tomcrypt_cipher.h:380
int cipher_is_valid(int idx)
int(* omac_memory)(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
Definition: tomcrypt_cipher.h:513
void(* done)(symmetric_key *skey)
Definition: tomcrypt_cipher.h:374
int(* test)(void)
Definition: tomcrypt_cipher.h:369
int(* accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey)
Definition: tomcrypt_cipher.h:409