comparison libtomcrypt/src/headers/tomcrypt_cipher.h @ 1435:f849a5ca2efc

update to libtomcrypt 1.17 (with Dropbear changes)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 17:50:50 +0800
parents 0cbe8f6dbf9e
children 6dba84798cd5
comparison
equal deleted inserted replaced
1434:27b9ddb06b09 1435:f849a5ca2efc
1 /* ---- SYMMETRIC KEY STUFF ----- 1 /* ---- SYMMETRIC KEY STUFF -----
2 * 2 *
3 * We put each of the ciphers scheduled keys in their own structs then we put all of 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. 4 * the key formats in one union. This makes the function prototypes easier to use.
5 */ 5 */
6 #ifdef BLOWFISH 6 #ifdef LTC_BLOWFISH
7 struct blowfish_key { 7 struct blowfish_key {
8 ulong32 S[4][256]; 8 ulong32 S[4][256];
9 ulong32 K[18]; 9 ulong32 K[18];
10 }; 10 };
11 #endif 11 #endif
12 12
13 #ifdef RC5 13 #ifdef LTC_RC5
14 struct rc5_key { 14 struct rc5_key {
15 int rounds; 15 int rounds;
16 ulong32 K[50]; 16 ulong32 K[50];
17 }; 17 };
18 #endif 18 #endif
19 19
20 #ifdef RC6 20 #ifdef LTC_RC6
21 struct rc6_key { 21 struct rc6_key {
22 ulong32 K[44]; 22 ulong32 K[44];
23 }; 23 };
24 #endif 24 #endif
25 25
26 #ifdef SAFERP 26 #ifdef LTC_SAFERP
27 struct saferp_key { 27 struct saferp_key {
28 unsigned char K[33][16]; 28 unsigned char K[33][16];
29 long rounds; 29 long rounds;
30 }; 30 };
31 #endif 31 #endif
32 32
33 #ifdef RIJNDAEL 33 #ifdef LTC_RIJNDAEL
34 struct rijndael_key { 34 struct rijndael_key {
35 ulong32 eK[60], dK[60]; 35 ulong32 eK[60], dK[60];
36 int Nr; 36 int Nr;
37 }; 37 };
38 #endif 38 #endif
39 39
40 #ifdef KSEED 40 #ifdef LTC_KSEED
41 struct kseed_key { 41 struct kseed_key {
42 ulong32 K[32], dK[32]; 42 ulong32 K[32], dK[32];
43 }; 43 };
44 #endif 44 #endif
45 45
49 KOi1[8], KOi2[8], KOi3[8], 49 KOi1[8], KOi2[8], KOi3[8],
50 KIi1[8], KIi2[8], KIi3[8]; 50 KIi1[8], KIi2[8], KIi3[8];
51 }; 51 };
52 #endif 52 #endif
53 53
54 #ifdef XTEA 54 #ifdef LTC_XTEA
55 struct xtea_key { 55 struct xtea_key {
56 unsigned long A[32], B[32]; 56 unsigned long A[32], B[32];
57 }; 57 };
58 #endif 58 #endif
59 59
60 #ifdef TWOFISH 60 #ifdef LTC_TWOFISH
61 #ifndef TWOFISH_SMALL 61 #ifndef LTC_TWOFISH_SMALL
62 struct twofish_key { 62 struct twofish_key {
63 ulong32 S[4][256], K[40]; 63 ulong32 S[4][256], K[40];
64 }; 64 };
65 #else 65 #else
66 struct twofish_key { 66 struct twofish_key {
68 unsigned char S[32], start; 68 unsigned char S[32], start;
69 }; 69 };
70 #endif 70 #endif
71 #endif 71 #endif
72 72
73 #ifdef SAFER 73 #ifdef LTC_SAFER
74 #define SAFER_K64_DEFAULT_NOF_ROUNDS 6 74 #define LTC_SAFER_K64_DEFAULT_NOF_ROUNDS 6
75 #define SAFER_K128_DEFAULT_NOF_ROUNDS 10 75 #define LTC_SAFER_K128_DEFAULT_NOF_ROUNDS 10
76 #define SAFER_SK64_DEFAULT_NOF_ROUNDS 8 76 #define LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS 8
77 #define SAFER_SK128_DEFAULT_NOF_ROUNDS 10 77 #define LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS 10
78 #define SAFER_MAX_NOF_ROUNDS 13 78 #define LTC_SAFER_MAX_NOF_ROUNDS 13
79 #define SAFER_BLOCK_LEN 8 79 #define LTC_SAFER_BLOCK_LEN 8
80 #define SAFER_KEY_LEN (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS)) 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[SAFER_BLOCK_LEN]; 81 typedef unsigned char safer_block_t[LTC_SAFER_BLOCK_LEN];
82 typedef unsigned char safer_key_t[SAFER_KEY_LEN]; 82 typedef unsigned char safer_key_t[LTC_SAFER_KEY_LEN];
83 struct safer_key { safer_key_t key; }; 83 struct safer_key { safer_key_t key; };
84 #endif 84 #endif
85 85
86 #ifdef RC2 86 #ifdef LTC_RC2
87 struct rc2_key { unsigned xkey[64]; }; 87 struct rc2_key { unsigned xkey[64]; };
88 #endif 88 #endif
89 89
90 #ifdef DES 90 #ifdef LTC_DES
91 struct des_key { 91 struct des_key {
92 ulong32 ek[32], dk[32]; 92 ulong32 ek[32], dk[32];
93 }; 93 };
94 94
95 struct des3_key { 95 struct des3_key {
96 ulong32 ek[3][32], dk[3][32]; 96 ulong32 ek[3][32], dk[3][32];
97 }; 97 };
98 #endif 98 #endif
99 99
100 #ifdef CAST5 100 #ifdef LTC_CAST5
101 struct cast5_key { 101 struct cast5_key {
102 ulong32 K[32], keylen; 102 ulong32 K[32], keylen;
103 }; 103 };
104 #endif 104 #endif
105 105
106 #ifdef NOEKEON 106 #ifdef LTC_NOEKEON
107 struct noekeon_key { 107 struct noekeon_key {
108 ulong32 K[4], dK[4]; 108 ulong32 K[4], dK[4];
109 }; 109 };
110 #endif 110 #endif
111 111
112 #ifdef SKIPJACK 112 #ifdef LTC_SKIPJACK
113 struct skipjack_key { 113 struct skipjack_key {
114 unsigned char key[10]; 114 unsigned char key[10];
115 }; 115 };
116 #endif 116 #endif
117 117
118 #ifdef KHAZAD 118 #ifdef LTC_KHAZAD
119 struct khazad_key { 119 struct khazad_key {
120 ulong64 roundKeyEnc[8 + 1]; 120 ulong64 roundKeyEnc[8 + 1];
121 ulong64 roundKeyDec[8 + 1]; 121 ulong64 roundKeyDec[8 + 1];
122 }; 122 };
123 #endif 123 #endif
124 124
125 #ifdef ANUBIS 125 #ifdef LTC_ANUBIS
126 struct anubis_key { 126 struct anubis_key {
127 int keyBits; 127 int keyBits;
128 int R; 128 int R;
129 ulong32 roundKeyEnc[18 + 1][4]; 129 ulong32 roundKeyEnc[18 + 1][4];
130 ulong32 roundKeyDec[18 + 1][4]; 130 ulong32 roundKeyDec[18 + 1][4];
131 }; 131 };
132 #endif 132 #endif
133 133
134 #ifdef LTC_MULTI2
135 struct multi2_key {
136 int N;
137 ulong32 uk[8];
138 };
139 #endif
140
134 typedef union Symmetric_key { 141 typedef union Symmetric_key {
135 #ifdef DES 142 #ifdef LTC_DES
136 struct des_key des; 143 struct des_key des;
137 struct des3_key des3; 144 struct des3_key des3;
138 #endif 145 #endif
139 #ifdef RC2 146 #ifdef LTC_RC2
140 struct rc2_key rc2; 147 struct rc2_key rc2;
141 #endif 148 #endif
142 #ifdef SAFER 149 #ifdef LTC_SAFER
143 struct safer_key safer; 150 struct safer_key safer;
144 #endif 151 #endif
145 #ifdef TWOFISH 152 #ifdef LTC_TWOFISH
146 struct twofish_key twofish; 153 struct twofish_key twofish;
147 #endif 154 #endif
148 #ifdef BLOWFISH 155 #ifdef LTC_BLOWFISH
149 struct blowfish_key blowfish; 156 struct blowfish_key blowfish;
150 #endif 157 #endif
151 #ifdef RC5 158 #ifdef LTC_RC5
152 struct rc5_key rc5; 159 struct rc5_key rc5;
153 #endif 160 #endif
154 #ifdef RC6 161 #ifdef LTC_RC6
155 struct rc6_key rc6; 162 struct rc6_key rc6;
156 #endif 163 #endif
157 #ifdef SAFERP 164 #ifdef LTC_SAFERP
158 struct saferp_key saferp; 165 struct saferp_key saferp;
159 #endif 166 #endif
160 #ifdef RIJNDAEL 167 #ifdef LTC_RIJNDAEL
161 struct rijndael_key rijndael; 168 struct rijndael_key rijndael;
162 #endif 169 #endif
163 #ifdef XTEA 170 #ifdef LTC_XTEA
164 struct xtea_key xtea; 171 struct xtea_key xtea;
165 #endif 172 #endif
166 #ifdef CAST5 173 #ifdef LTC_CAST5
167 struct cast5_key cast5; 174 struct cast5_key cast5;
168 #endif 175 #endif
169 #ifdef NOEKEON 176 #ifdef LTC_NOEKEON
170 struct noekeon_key noekeon; 177 struct noekeon_key noekeon;
171 #endif 178 #endif
172 #ifdef SKIPJACK 179 #ifdef LTC_SKIPJACK
173 struct skipjack_key skipjack; 180 struct skipjack_key skipjack;
174 #endif 181 #endif
175 #ifdef KHAZAD 182 #ifdef LTC_KHAZAD
176 struct khazad_key khazad; 183 struct khazad_key khazad;
177 #endif 184 #endif
178 #ifdef ANUBIS 185 #ifdef LTC_ANUBIS
179 struct anubis_key anubis; 186 struct anubis_key anubis;
180 #endif 187 #endif
181 #ifdef KSEED 188 #ifdef LTC_KSEED
182 struct kseed_key kseed; 189 struct kseed_key kseed;
183 #endif 190 #endif
184 #ifdef LTC_KASUMI 191 #ifdef LTC_KASUMI
185 struct kasumi_key kasumi; 192 struct kasumi_key kasumi;
186 #endif 193 #endif
194 #ifdef LTC_MULTI2
195 struct multi2_key multi2;
196 #endif
187 void *data; 197 void *data;
188 } symmetric_key; 198 } symmetric_key;
189 199
190 #ifdef LTC_ECB_MODE 200 #ifdef LTC_ECB_MODE
191 /** A block cipher ECB structure */ 201 /** A block cipher ECB structure */
255 int cipher, 265 int cipher,
256 /** The block size of the given cipher */ 266 /** The block size of the given cipher */
257 blocklen, 267 blocklen,
258 /** The padding offset */ 268 /** The padding offset */
259 padlen, 269 padlen,
260 /** The mode (endianess) of the CTR, 0==little, 1==big */ 270 /** The mode (endianess) of the CTR, 0==little, 1==big */
261 mode; 271 mode,
272 /** counter width */
273 ctrlen;
274
262 /** The counter */ 275 /** The counter */
263 unsigned char ctr[MAXBLOCKSIZE], 276 unsigned char ctr[MAXBLOCKSIZE],
264 /** The pad used to encrypt/decrypt */ 277 /** The pad used to encrypt/decrypt */
265 pad[MAXBLOCKSIZE]; 278 pad[MAXBLOCKSIZE];
266 /** The scheduled key */ 279 /** The scheduled key */
486 unsigned char *pt, unsigned long ptlen, 499 unsigned char *pt, unsigned long ptlen,
487 unsigned char *ct, 500 unsigned char *ct,
488 unsigned char *tag, unsigned long *taglen, 501 unsigned char *tag, unsigned long *taglen,
489 int direction); 502 int direction);
490 503
491 /** Accelerated one shot OMAC 504 /** Accelerated one shot LTC_OMAC
492 @param key The secret key 505 @param key The secret key
493 @param keylen The key length (octets) 506 @param keylen The key length (octets)
494 @param in The message 507 @param in The message
495 @param inlen Length of message (octets) 508 @param inlen Length of message (octets)
496 @param out [out] Destination for tag 509 @param out [out] Destination for tag
530 const unsigned char *key, unsigned long keylen, 543 const unsigned char *key, unsigned long keylen,
531 const unsigned char *in, unsigned long inlen, 544 const unsigned char *in, unsigned long inlen,
532 unsigned char *out, unsigned long *outlen); 545 unsigned char *out, unsigned long *outlen);
533 } cipher_descriptor[]; 546 } cipher_descriptor[];
534 547
535 #ifdef BLOWFISH 548 #ifdef LTC_BLOWFISH
536 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 549 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
537 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 550 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
538 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 551 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
539 int blowfish_test(void); 552 int blowfish_test(void);
540 void blowfish_done(symmetric_key *skey); 553 void blowfish_done(symmetric_key *skey);
541 int blowfish_keysize(int *keysize); 554 int blowfish_keysize(int *keysize);
542 extern const struct ltc_cipher_descriptor blowfish_desc; 555 extern const struct ltc_cipher_descriptor blowfish_desc;
543 #endif 556 #endif
544 557
545 #ifdef RC5 558 #ifdef LTC_RC5
546 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 559 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
547 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 560 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
548 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 561 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
549 int rc5_test(void); 562 int rc5_test(void);
550 void rc5_done(symmetric_key *skey); 563 void rc5_done(symmetric_key *skey);
551 int rc5_keysize(int *keysize); 564 int rc5_keysize(int *keysize);
552 extern const struct ltc_cipher_descriptor rc5_desc; 565 extern const struct ltc_cipher_descriptor rc5_desc;
553 #endif 566 #endif
554 567
555 #ifdef RC6 568 #ifdef LTC_RC6
556 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 569 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
557 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 570 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
558 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 571 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
559 int rc6_test(void); 572 int rc6_test(void);
560 void rc6_done(symmetric_key *skey); 573 void rc6_done(symmetric_key *skey);
561 int rc6_keysize(int *keysize); 574 int rc6_keysize(int *keysize);
562 extern const struct ltc_cipher_descriptor rc6_desc; 575 extern const struct ltc_cipher_descriptor rc6_desc;
563 #endif 576 #endif
564 577
565 #ifdef RC2 578 #ifdef LTC_RC2
566 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 579 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
567 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 580 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
568 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 581 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
569 int rc2_test(void); 582 int rc2_test(void);
570 void rc2_done(symmetric_key *skey); 583 void rc2_done(symmetric_key *skey);
571 int rc2_keysize(int *keysize); 584 int rc2_keysize(int *keysize);
572 extern const struct ltc_cipher_descriptor rc2_desc; 585 extern const struct ltc_cipher_descriptor rc2_desc;
573 #endif 586 #endif
574 587
575 #ifdef SAFERP 588 #ifdef LTC_SAFERP
576 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 589 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
577 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 590 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
578 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 591 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
579 int saferp_test(void); 592 int saferp_test(void);
580 void saferp_done(symmetric_key *skey); 593 void saferp_done(symmetric_key *skey);
581 int saferp_keysize(int *keysize); 594 int saferp_keysize(int *keysize);
582 extern const struct ltc_cipher_descriptor saferp_desc; 595 extern const struct ltc_cipher_descriptor saferp_desc;
583 #endif 596 #endif
584 597
585 #ifdef SAFER 598 #ifdef LTC_SAFER
586 int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 599 int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
587 int safer_sk64_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);
588 int safer_k128_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);
589 int safer_sk128_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);
590 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); 603 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
596 int safer_64_keysize(int *keysize); 609 int safer_64_keysize(int *keysize);
597 int safer_128_keysize(int *keysize); 610 int safer_128_keysize(int *keysize);
598 extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc; 611 extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;
599 #endif 612 #endif
600 613
601 #ifdef RIJNDAEL 614 #ifdef LTC_RIJNDAEL
602 615
603 /* make aes an alias */ 616 /* make aes an alias */
604 #define aes_setup rijndael_setup 617 #define aes_setup rijndael_setup
605 #define aes_ecb_encrypt rijndael_ecb_encrypt 618 #define aes_ecb_encrypt rijndael_ecb_encrypt
606 #define aes_ecb_decrypt rijndael_ecb_decrypt 619 #define aes_ecb_decrypt rijndael_ecb_decrypt
624 int rijndael_enc_keysize(int *keysize); 637 int rijndael_enc_keysize(int *keysize);
625 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc; 638 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
626 extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc; 639 extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
627 #endif 640 #endif
628 641
629 #ifdef XTEA 642 #ifdef LTC_XTEA
630 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 643 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
631 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 644 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
632 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 645 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
633 int xtea_test(void); 646 int xtea_test(void);
634 void xtea_done(symmetric_key *skey); 647 void xtea_done(symmetric_key *skey);
635 int xtea_keysize(int *keysize); 648 int xtea_keysize(int *keysize);
636 extern const struct ltc_cipher_descriptor xtea_desc; 649 extern const struct ltc_cipher_descriptor xtea_desc;
637 #endif 650 #endif
638 651
639 #ifdef TWOFISH 652 #ifdef LTC_TWOFISH
640 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 653 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
641 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 654 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
642 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 655 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
643 int twofish_test(void); 656 int twofish_test(void);
644 void twofish_done(symmetric_key *skey); 657 void twofish_done(symmetric_key *skey);
645 int twofish_keysize(int *keysize); 658 int twofish_keysize(int *keysize);
646 extern const struct ltc_cipher_descriptor twofish_desc; 659 extern const struct ltc_cipher_descriptor twofish_desc;
647 #endif 660 #endif
648 661
649 #ifdef DES 662 #ifdef LTC_DES
650 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 663 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
651 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 664 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
652 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 665 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
653 int des_test(void); 666 int des_test(void);
654 void des_done(symmetric_key *skey); 667 void des_done(symmetric_key *skey);
660 void des3_done(symmetric_key *skey); 673 void des3_done(symmetric_key *skey);
661 int des3_keysize(int *keysize); 674 int des3_keysize(int *keysize);
662 extern const struct ltc_cipher_descriptor des_desc, des3_desc; 675 extern const struct ltc_cipher_descriptor des_desc, des3_desc;
663 #endif 676 #endif
664 677
665 #ifdef CAST5 678 #ifdef LTC_CAST5
666 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 679 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
667 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 680 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
668 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 681 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
669 int cast5_test(void); 682 int cast5_test(void);
670 void cast5_done(symmetric_key *skey); 683 void cast5_done(symmetric_key *skey);
671 int cast5_keysize(int *keysize); 684 int cast5_keysize(int *keysize);
672 extern const struct ltc_cipher_descriptor cast5_desc; 685 extern const struct ltc_cipher_descriptor cast5_desc;
673 #endif 686 #endif
674 687
675 #ifdef NOEKEON 688 #ifdef LTC_NOEKEON
676 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 689 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
677 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 690 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
678 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 691 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
679 int noekeon_test(void); 692 int noekeon_test(void);
680 void noekeon_done(symmetric_key *skey); 693 void noekeon_done(symmetric_key *skey);
681 int noekeon_keysize(int *keysize); 694 int noekeon_keysize(int *keysize);
682 extern const struct ltc_cipher_descriptor noekeon_desc; 695 extern const struct ltc_cipher_descriptor noekeon_desc;
683 #endif 696 #endif
684 697
685 #ifdef SKIPJACK 698 #ifdef LTC_SKIPJACK
686 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 699 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
687 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 700 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
688 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 701 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
689 int skipjack_test(void); 702 int skipjack_test(void);
690 void skipjack_done(symmetric_key *skey); 703 void skipjack_done(symmetric_key *skey);
691 int skipjack_keysize(int *keysize); 704 int skipjack_keysize(int *keysize);
692 extern const struct ltc_cipher_descriptor skipjack_desc; 705 extern const struct ltc_cipher_descriptor skipjack_desc;
693 #endif 706 #endif
694 707
695 #ifdef KHAZAD 708 #ifdef LTC_KHAZAD
696 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 709 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
697 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 710 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
698 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 711 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
699 int khazad_test(void); 712 int khazad_test(void);
700 void khazad_done(symmetric_key *skey); 713 void khazad_done(symmetric_key *skey);
701 int khazad_keysize(int *keysize); 714 int khazad_keysize(int *keysize);
702 extern const struct ltc_cipher_descriptor khazad_desc; 715 extern const struct ltc_cipher_descriptor khazad_desc;
703 #endif 716 #endif
704 717
705 #ifdef ANUBIS 718 #ifdef LTC_ANUBIS
706 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 719 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
707 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 720 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
708 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 721 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
709 int anubis_test(void); 722 int anubis_test(void);
710 void anubis_done(symmetric_key *skey); 723 void anubis_done(symmetric_key *skey);
711 int anubis_keysize(int *keysize); 724 int anubis_keysize(int *keysize);
712 extern const struct ltc_cipher_descriptor anubis_desc; 725 extern const struct ltc_cipher_descriptor anubis_desc;
713 #endif 726 #endif
714 727
715 #ifdef KSEED 728 #ifdef LTC_KSEED
716 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 729 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
717 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); 730 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
718 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); 731 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
719 int kseed_test(void); 732 int kseed_test(void);
720 void kseed_done(symmetric_key *skey); 733 void kseed_done(symmetric_key *skey);
730 void kasumi_done(symmetric_key *skey); 743 void kasumi_done(symmetric_key *skey);
731 int kasumi_keysize(int *keysize); 744 int kasumi_keysize(int *keysize);
732 extern const struct ltc_cipher_descriptor kasumi_desc; 745 extern const struct ltc_cipher_descriptor kasumi_desc;
733 #endif 746 #endif
734 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
735 #ifdef LTC_ECB_MODE 759 #ifdef LTC_ECB_MODE
736 int ecb_start(int cipher, const unsigned char *key, 760 int ecb_start(int cipher, const unsigned char *key,
737 int keylen, int num_rounds, symmetric_ECB *ecb); 761 int keylen, int num_rounds, symmetric_ECB *ecb);
738 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb); 762 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
739 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb); 763 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
770 int cbc_done(symmetric_CBC *cbc); 794 int cbc_done(symmetric_CBC *cbc);
771 #endif 795 #endif
772 796
773 #ifdef LTC_CTR_MODE 797 #ifdef LTC_CTR_MODE
774 798
775 #define CTR_COUNTER_LITTLE_ENDIAN 0 799 #define CTR_COUNTER_LITTLE_ENDIAN 0x0000
776 #define CTR_COUNTER_BIG_ENDIAN 1 800 #define CTR_COUNTER_BIG_ENDIAN 0x1000
777 #define LTC_CTR_RFC3686 2 801 #define LTC_CTR_RFC3686 0x2000
778 802
779 int ctr_start( int cipher, 803 int ctr_start( int cipher,
780 const unsigned char *IV, 804 const unsigned char *IV,
781 const unsigned char *key, int keylen, 805 const unsigned char *key, int keylen,
782 int num_rounds, int ctr_mode, 806 int num_rounds, int ctr_mode,
822 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8); 846 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
823 int f8_done(symmetric_F8 *f8); 847 int f8_done(symmetric_F8 *f8);
824 int f8_test_mode(void); 848 int f8_test_mode(void);
825 #endif 849 #endif
826 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
827 879
828 int find_cipher(const char *name); 880 int find_cipher(const char *name);
829 int find_cipher_any(const char *name, int blocklen, int keylen); 881 int find_cipher_any(const char *name, int blocklen, int keylen);
830 int find_cipher_id(unsigned char ID); 882 int find_cipher_id(unsigned char ID);
831 int register_cipher(const struct ltc_cipher_descriptor *cipher); 883 int register_cipher(const struct ltc_cipher_descriptor *cipher);
832 int unregister_cipher(const struct ltc_cipher_descriptor *cipher); 884 int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
833 int cipher_is_valid(int idx); 885 int cipher_is_valid(int idx);
834 886
835 LTC_MUTEX_PROTO(ltc_cipher_mutex) 887 LTC_MUTEX_PROTO(ltc_cipher_mutex)
836 888
837 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cipher.h,v $ */ 889 /* $Source$ */
838 /* $Revision: 1.46 $ */ 890 /* $Revision$ */
839 /* $Date: 2006/11/13 23:09:38 $ */ 891 /* $Date$ */