• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BLOWFISH
7 struct blowfish_key {
8    ulong32 S[4][256];
9    ulong32 K[18];
10 };
11 #endif
12 
13 #ifdef RC5
14 struct rc5_key {
15    int rounds;
16    ulong32 K[50];
17 };
18 #endif
19 
20 #ifdef RC6
21 struct rc6_key {
22    ulong32 K[44];
23 };
24 #endif
25 
26 #ifdef SAFERP
27 struct saferp_key {
28    unsigned char K[33][16];
29    long rounds;
30 };
31 #endif
32 
33 #ifdef RIJNDAEL
34 struct rijndael_key {
35    ulong32 eK[60], dK[60];
36    int Nr;
37 };
38 #endif
39 
40 #ifdef 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 XTEA
55 struct xtea_key {
56    unsigned long A[32], B[32];
57 };
58 #endif
59 
60 #ifdef TWOFISH
61 #ifndef 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 SAFER
74 #define SAFER_K64_DEFAULT_NOF_ROUNDS     6
75 #define SAFER_K128_DEFAULT_NOF_ROUNDS   10
76 #define SAFER_SK64_DEFAULT_NOF_ROUNDS    8
77 #define SAFER_SK128_DEFAULT_NOF_ROUNDS  10
78 #define SAFER_MAX_NOF_ROUNDS            13
79 #define SAFER_BLOCK_LEN                  8
80 #define SAFER_KEY_LEN     (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS))
81 typedef unsigned char safer_block_t[SAFER_BLOCK_LEN];
82 typedef unsigned char safer_key_t[SAFER_KEY_LEN];
83 struct safer_key { safer_key_t key; };
84 #endif
85 
86 #ifdef RC2
87 struct rc2_key { unsigned xkey[64]; };
88 #endif
89 
90 #ifdef 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 CAST5
101 struct cast5_key {
102     ulong32 K[32], keylen;
103 };
104 #endif
105 
106 #ifdef NOEKEON
107 struct noekeon_key {
108     ulong32 K[4], dK[4];
109 };
110 #endif
111 
112 #ifdef SKIPJACK
113 struct skipjack_key {
114     unsigned char key[10];
115 };
116 #endif
117 
118 #ifdef KHAZAD
119 struct khazad_key {
120    ulong64 roundKeyEnc[8 + 1];
121    ulong64 roundKeyDec[8 + 1];
122 };
123 #endif
124 
125 #ifdef 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 typedef union Symmetric_key {
135 #ifdef DES
136    struct des_key des;
137    struct des3_key des3;
138 #endif
139 #ifdef RC2
140    struct rc2_key rc2;
141 #endif
142 #ifdef SAFER
143    struct safer_key safer;
144 #endif
145 #ifdef TWOFISH
146    struct twofish_key  twofish;
147 #endif
148 #ifdef BLOWFISH
149    struct blowfish_key blowfish;
150 #endif
151 #ifdef RC5
152    struct rc5_key      rc5;
153 #endif
154 #ifdef RC6
155    struct rc6_key      rc6;
156 #endif
157 #ifdef SAFERP
158    struct saferp_key   saferp;
159 #endif
160 #ifdef RIJNDAEL
161    struct rijndael_key rijndael;
162 #endif
163 #ifdef XTEA
164    struct xtea_key     xtea;
165 #endif
166 #ifdef CAST5
167    struct cast5_key    cast5;
168 #endif
169 #ifdef NOEKEON
170    struct noekeon_key  noekeon;
171 #endif
172 #ifdef SKIPJACK
173    struct skipjack_key skipjack;
174 #endif
175 #ifdef KHAZAD
176    struct khazad_key   khazad;
177 #endif
178 #ifdef ANUBIS
179    struct anubis_key   anubis;
180 #endif
181 #ifdef KSEED
182    struct kseed_key    kseed;
183 #endif
184 #ifdef LTC_KASUMI
185    struct kasumi_key   kasumi;
186 #endif
187    void   *data;
188 } symmetric_key;
189 
190 #ifdef LTC_ECB_MODE
191 /** A block cipher ECB structure */
192 typedef struct {
193    /** The index of the cipher chosen */
194    int                 cipher,
195    /** The block size of the given cipher */
196                        blocklen;
197    /** The scheduled key */
198    symmetric_key       key;
199 } symmetric_ECB;
200 #endif
201 
202 #ifdef LTC_CFB_MODE
203 /** A block cipher CFB structure */
204 typedef struct {
205    /** The index of the cipher chosen */
206    int                 cipher,
207    /** The block size of the given cipher */
208                        blocklen,
209    /** The padding offset */
210                        padlen;
211    /** The current IV */
212    unsigned char       IV[MAXBLOCKSIZE],
213    /** The pad used to encrypt/decrypt */
214                        pad[MAXBLOCKSIZE];
215    /** The scheduled key */
216    symmetric_key       key;
217 } symmetric_CFB;
218 #endif
219 
220 #ifdef LTC_OFB_MODE
221 /** A block cipher OFB structure */
222 typedef struct {
223    /** The index of the cipher chosen */
224    int                 cipher,
225    /** The block size of the given cipher */
226                        blocklen,
227    /** The padding offset */
228                        padlen;
229    /** The current IV */
230    unsigned char       IV[MAXBLOCKSIZE];
231    /** The scheduled key */
232    symmetric_key       key;
233 } symmetric_OFB;
234 #endif
235 
236 #ifdef LTC_CBC_MODE
237 /** A block cipher CBC structure */
238 typedef struct {
239    /** The index of the cipher chosen */
240    int                 cipher,
241    /** The block size of the given cipher */
242                        blocklen;
243    /** The current IV */
244    unsigned char       IV[MAXBLOCKSIZE];
245    /** The scheduled key */
246    symmetric_key       key;
247 } symmetric_CBC;
248 #endif
249 
250 
251 #ifdef LTC_CTR_MODE
252 /** A block cipher CTR structure */
253 typedef struct {
254    /** The index of the cipher chosen */
255    int                 cipher,
256    /** The block size of the given cipher */
257                        blocklen,
258    /** The padding offset */
259                        padlen,
260    /** The mode (endianess) of the CTR, 0==little, 1==big */
261                        mode;
262    /** The counter */
263    unsigned char       ctr[MAXBLOCKSIZE],
264    /** The pad used to encrypt/decrypt */
265                        pad[MAXBLOCKSIZE];
266    /** The scheduled key */
267    symmetric_key       key;
268 } symmetric_CTR;
269 #endif
270 
271 
272 #ifdef LTC_LRW_MODE
273 /** A LRW structure */
274 typedef struct {
275     /** The index of the cipher chosen (must be a 128-bit block cipher) */
276     int               cipher;
277 
278     /** The current IV */
279     unsigned char     IV[16],
280 
281     /** the tweak key */
282                       tweak[16],
283 
284     /** The current pad, it's the product of the first 15 bytes against the tweak key */
285                       pad[16];
286 
287     /** The scheduled symmetric key */
288     symmetric_key     key;
289 
290 #ifdef LRW_TABLES
291     /** The pre-computed multiplication table */
292     unsigned char     PC[16][256][16];
293 #endif
294 } symmetric_LRW;
295 #endif
296 
297 #ifdef LTC_F8_MODE
298 /** A block cipher F8 structure */
299 typedef struct {
300    /** The index of the cipher chosen */
301    int                 cipher,
302    /** The block size of the given cipher */
303                        blocklen,
304    /** The padding offset */
305                        padlen;
306    /** The current IV */
307    unsigned char       IV[MAXBLOCKSIZE],
308                        MIV[MAXBLOCKSIZE];
309    /** Current block count */
310    ulong32             blockcnt;
311    /** The scheduled key */
312    symmetric_key       key;
313 } symmetric_F8;
314 #endif
315 
316 
317 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */
318 extern struct ltc_cipher_descriptor {
319    /** name of cipher */
320    char *name;
321    /** internal ID */
322    unsigned char ID;
323    /** min keysize (octets) */
324    int  min_key_length,
325    /** max keysize (octets) */
326         max_key_length,
327    /** block size (octets) */
328         block_length,
329    /** default number of rounds */
330         default_rounds;
331    /** Setup the cipher
332       @param key         The input symmetric key
333       @param keylen      The length of the input key (octets)
334       @param num_rounds  The requested number of rounds (0==default)
335       @param skey        [out] The destination of the scheduled key
336       @return CRYPT_OK if successful
337    */
338    int  (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
339    /** Encrypt a block
340       @param pt      The plaintext
341       @param ct      [out] The ciphertext
342       @param skey    The scheduled key
343       @return CRYPT_OK if successful
344    */
345    int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
346    /** Decrypt a block
347       @param ct      The ciphertext
348       @param pt      [out] The plaintext
349       @param skey    The scheduled key
350       @return CRYPT_OK if successful
351    */
352    int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
353    /** Test the block cipher
354        @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
355    */
356    int (*test)(void);
357 
358    /** Terminate the context
359       @param skey    The scheduled key
360    */
361    void (*done)(symmetric_key *skey);
362 
363    /** Determine a key size
364        @param keysize    [in/out] The size of the key desired and the suggested size
365        @return CRYPT_OK if successful
366    */
367    int  (*keysize)(int *keysize);
368 
369 /** Accelerators **/
370    /** Accelerated ECB encryption
371        @param pt      Plaintext
372        @param ct      Ciphertext
373        @param blocks  The number of complete blocks to process
374        @param skey    The scheduled key context
375        @return CRYPT_OK if successful
376    */
377    int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
378 
379    /** Accelerated ECB decryption
380        @param pt      Plaintext
381        @param ct      Ciphertext
382        @param blocks  The number of complete blocks to process
383        @param skey    The scheduled key context
384        @return CRYPT_OK if successful
385    */
386    int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
387 
388    /** Accelerated CBC encryption
389        @param pt      Plaintext
390        @param ct      Ciphertext
391        @param blocks  The number of complete blocks to process
392        @param IV      The initial value (input/output)
393        @param skey    The scheduled key context
394        @return CRYPT_OK if successful
395    */
396    int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
397 
398    /** Accelerated CBC decryption
399        @param pt      Plaintext
400        @param ct      Ciphertext
401        @param blocks  The number of complete blocks to process
402        @param IV      The initial value (input/output)
403        @param skey    The scheduled key context
404        @return CRYPT_OK if successful
405    */
406    int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
407 
408    /** Accelerated CTR encryption
409        @param pt      Plaintext
410        @param ct      Ciphertext
411        @param blocks  The number of complete blocks to process
412        @param IV      The initial value (input/output)
413        @param mode    little or big endian counter (mode=0 or mode=1)
414        @param skey    The scheduled key context
415        @return CRYPT_OK if successful
416    */
417    int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
418 
419    /** Accelerated LRW
420        @param pt      Plaintext
421        @param ct      Ciphertext
422        @param blocks  The number of complete blocks to process
423        @param IV      The initial value (input/output)
424        @param tweak   The LRW tweak
425        @param skey    The scheduled key context
426        @return CRYPT_OK if successful
427    */
428    int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
429 
430    /** Accelerated LRW
431        @param ct      Ciphertext
432        @param pt      Plaintext
433        @param blocks  The number of complete blocks to process
434        @param IV      The initial value (input/output)
435        @param tweak   The LRW tweak
436        @param skey    The scheduled key context
437        @return CRYPT_OK if successful
438    */
439    int (*accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
440 
441    /** Accelerated CCM packet (one-shot)
442        @param key        The secret key to use
443        @param keylen     The length of the secret key (octets)
444        @param uskey      A previously scheduled key [optional can be NULL]
445        @param nonce      The session nonce [use once]
446        @param noncelen   The length of the nonce
447        @param header     The header for the session
448        @param headerlen  The length of the header (octets)
449        @param pt         [out] The plaintext
450        @param ptlen      The length of the plaintext (octets)
451        @param ct         [out] The ciphertext
452        @param tag        [out] The destination tag
453        @param taglen     [in/out] The max size and resulting size of the authentication tag
454        @param direction  Encrypt or Decrypt direction (0 or 1)
455        @return CRYPT_OK if successful
456    */
457    int (*accel_ccm_memory)(
458        const unsigned char *key,    unsigned long keylen,
459        symmetric_key       *uskey,
460        const unsigned char *nonce,  unsigned long noncelen,
461        const unsigned char *header, unsigned long headerlen,
462              unsigned char *pt,     unsigned long ptlen,
463              unsigned char *ct,
464              unsigned char *tag,    unsigned long *taglen,
465                        int  direction);
466 
467    /** Accelerated GCM packet (one shot)
468        @param key        The secret key
469        @param keylen     The length of the secret key
470        @param IV         The initial vector
471        @param IVlen      The length of the initial vector
472        @param adata      The additional authentication data (header)
473        @param adatalen   The length of the adata
474        @param pt         The plaintext
475        @param ptlen      The length of the plaintext (ciphertext length is the same)
476        @param ct         The ciphertext
477        @param tag        [out] The MAC tag
478        @param taglen     [in/out] The MAC tag length
479        @param direction  Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
480        @return CRYPT_OK on success
481    */
482    int (*accel_gcm_memory)(
483        const unsigned char *key,    unsigned long keylen,
484        const unsigned char *IV,     unsigned long IVlen,
485        const unsigned char *adata,  unsigned long adatalen,
486              unsigned char *pt,     unsigned long ptlen,
487              unsigned char *ct,
488              unsigned char *tag,    unsigned long *taglen,
489                        int direction);
490 
491    /** Accelerated one shot OMAC
492        @param key            The secret key
493        @param keylen         The key length (octets)
494        @param in             The message
495        @param inlen          Length of message (octets)
496        @param out            [out] Destination for tag
497        @param outlen         [in/out] Initial and final size of out
498        @return CRYPT_OK on success
499    */
500    int (*omac_memory)(
501        const unsigned char *key, unsigned long keylen,
502        const unsigned char *in,  unsigned long inlen,
503              unsigned char *out, unsigned long *outlen);
504 
505    /** Accelerated one shot XCBC
506        @param key            The secret key
507        @param keylen         The key length (octets)
508        @param in             The message
509        @param inlen          Length of message (octets)
510        @param out            [out] Destination for tag
511        @param outlen         [in/out] Initial and final size of out
512        @return CRYPT_OK on success
513    */
514    int (*xcbc_memory)(
515        const unsigned char *key, unsigned long keylen,
516        const unsigned char *in,  unsigned long inlen,
517              unsigned char *out, unsigned long *outlen);
518 
519    /** Accelerated one shot F9
520        @param key            The secret key
521        @param keylen         The key length (octets)
522        @param in             The message
523        @param inlen          Length of message (octets)
524        @param out            [out] Destination for tag
525        @param outlen         [in/out] Initial and final size of out
526        @return CRYPT_OK on success
527        @remark Requires manual padding
528    */
529    int (*f9_memory)(
530        const unsigned char *key, unsigned long keylen,
531        const unsigned char *in,  unsigned long inlen,
532              unsigned char *out, unsigned long *outlen);
533 } cipher_descriptor[];
534 
535 #ifdef BLOWFISH
536 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);
538 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
539 int blowfish_test(void);
540 void blowfish_done(symmetric_key *skey);
541 int blowfish_keysize(int *keysize);
542 extern const struct ltc_cipher_descriptor blowfish_desc;
543 #endif
544 
545 #ifdef RC5
546 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);
548 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
549 int rc5_test(void);
550 void rc5_done(symmetric_key *skey);
551 int rc5_keysize(int *keysize);
552 extern const struct ltc_cipher_descriptor rc5_desc;
553 #endif
554 
555 #ifdef RC6
556 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);
558 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
559 int rc6_test(void);
560 void rc6_done(symmetric_key *skey);
561 int rc6_keysize(int *keysize);
562 extern const struct ltc_cipher_descriptor rc6_desc;
563 #endif
564 
565 #ifdef RC2
566 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);
568 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
569 int rc2_test(void);
570 void rc2_done(symmetric_key *skey);
571 int rc2_keysize(int *keysize);
572 extern const struct ltc_cipher_descriptor rc2_desc;
573 #endif
574 
575 #ifdef SAFERP
576 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);
578 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
579 int saferp_test(void);
580 void saferp_done(symmetric_key *skey);
581 int saferp_keysize(int *keysize);
582 extern const struct ltc_cipher_descriptor saferp_desc;
583 #endif
584 
585 #ifdef SAFER
586 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);
588 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);
590 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
591 int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
592 int safer_k64_test(void);
593 int safer_sk64_test(void);
594 int safer_sk128_test(void);
595 void safer_done(symmetric_key *skey);
596 int safer_64_keysize(int *keysize);
597 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;
599 #endif
600 
601 #ifdef RIJNDAEL
602 
603 /* make aes an alias */
604 #define aes_setup           rijndael_setup
605 #define aes_ecb_encrypt     rijndael_ecb_encrypt
606 #define aes_ecb_decrypt     rijndael_ecb_decrypt
607 #define aes_test            rijndael_test
608 #define aes_done            rijndael_done
609 #define aes_keysize         rijndael_keysize
610 
611 #define aes_enc_setup           rijndael_enc_setup
612 #define aes_enc_ecb_encrypt     rijndael_enc_ecb_encrypt
613 #define aes_enc_keysize         rijndael_enc_keysize
614 
615 int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
616 int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
617 int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
618 int rijndael_test(void);
619 void rijndael_done(symmetric_key *skey);
620 int rijndael_keysize(int *keysize);
621 int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
622 int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
623 void rijndael_enc_done(symmetric_key *skey);
624 int rijndael_enc_keysize(int *keysize);
625 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
626 extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
627 #endif
628 
629 #ifdef XTEA
630 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);
632 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
633 int xtea_test(void);
634 void xtea_done(symmetric_key *skey);
635 int xtea_keysize(int *keysize);
636 extern const struct ltc_cipher_descriptor xtea_desc;
637 #endif
638 
639 #ifdef TWOFISH
640 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);
642 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
643 int twofish_test(void);
644 void twofish_done(symmetric_key *skey);
645 int twofish_keysize(int *keysize);
646 extern const struct ltc_cipher_descriptor twofish_desc;
647 #endif
648 
649 #ifdef DES
650 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);
652 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
653 int des_test(void);
654 void des_done(symmetric_key *skey);
655 int des_keysize(int *keysize);
656 int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
657 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
658 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
659 int des3_test(void);
660 void des3_done(symmetric_key *skey);
661 int des3_keysize(int *keysize);
662 extern const struct ltc_cipher_descriptor des_desc, des3_desc;
663 #endif
664 
665 #ifdef CAST5
666 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);
668 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
669 int cast5_test(void);
670 void cast5_done(symmetric_key *skey);
671 int cast5_keysize(int *keysize);
672 extern const struct ltc_cipher_descriptor cast5_desc;
673 #endif
674 
675 #ifdef NOEKEON
676 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);
678 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
679 int noekeon_test(void);
680 void noekeon_done(symmetric_key *skey);
681 int noekeon_keysize(int *keysize);
682 extern const struct ltc_cipher_descriptor noekeon_desc;
683 #endif
684 
685 #ifdef SKIPJACK
686 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);
688 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
689 int skipjack_test(void);
690 void skipjack_done(symmetric_key *skey);
691 int skipjack_keysize(int *keysize);
692 extern const struct ltc_cipher_descriptor skipjack_desc;
693 #endif
694 
695 #ifdef KHAZAD
696 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);
698 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
699 int khazad_test(void);
700 void khazad_done(symmetric_key *skey);
701 int khazad_keysize(int *keysize);
702 extern const struct ltc_cipher_descriptor khazad_desc;
703 #endif
704 
705 #ifdef ANUBIS
706 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);
708 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
709 int anubis_test(void);
710 void anubis_done(symmetric_key *skey);
711 int anubis_keysize(int *keysize);
712 extern const struct ltc_cipher_descriptor anubis_desc;
713 #endif
714 
715 #ifdef KSEED
716 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);
718 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
719 int kseed_test(void);
720 void kseed_done(symmetric_key *skey);
721 int kseed_keysize(int *keysize);
722 extern const struct ltc_cipher_descriptor kseed_desc;
723 #endif
724 
725 #ifdef LTC_KASUMI
726 int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
727 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
728 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
729 int kasumi_test(void);
730 void kasumi_done(symmetric_key *skey);
731 int kasumi_keysize(int *keysize);
732 extern const struct ltc_cipher_descriptor kasumi_desc;
733 #endif
734 
735 #ifdef LTC_ECB_MODE
736 int ecb_start(int cipher, const unsigned char *key,
737               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);
739 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
740 int ecb_done(symmetric_ECB *ecb);
741 #endif
742 
743 #ifdef LTC_CFB_MODE
744 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
745               int keylen, int num_rounds, symmetric_CFB *cfb);
746 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
747 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
748 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
749 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
750 int cfb_done(symmetric_CFB *cfb);
751 #endif
752 
753 #ifdef LTC_OFB_MODE
754 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
755               int keylen, int num_rounds, symmetric_OFB *ofb);
756 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
757 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
758 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
759 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
760 int ofb_done(symmetric_OFB *ofb);
761 #endif
762 
763 #ifdef LTC_CBC_MODE
764 int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
765                int keylen, int num_rounds, symmetric_CBC *cbc);
766 int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
767 int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
768 int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
769 int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
770 int cbc_done(symmetric_CBC *cbc);
771 #endif
772 
773 #ifdef LTC_CTR_MODE
774 
775 #define CTR_COUNTER_LITTLE_ENDIAN    0
776 #define CTR_COUNTER_BIG_ENDIAN       1
777 #define LTC_CTR_RFC3686              2
778 
779 int ctr_start(               int   cipher,
780               const unsigned char *IV,
781               const unsigned char *key,       int keylen,
782                              int  num_rounds, int ctr_mode,
783                    symmetric_CTR *ctr);
784 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
785 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
786 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
787 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
788 int ctr_done(symmetric_CTR *ctr);
789 int ctr_test(void);
790 #endif
791 
792 #ifdef LTC_LRW_MODE
793 
794 #define LRW_ENCRYPT 0
795 #define LRW_DECRYPT 1
796 
797 int lrw_start(               int   cipher,
798               const unsigned char *IV,
799               const unsigned char *key,       int keylen,
800               const unsigned char *tweak,
801                              int  num_rounds,
802                    symmetric_LRW *lrw);
803 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
804 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
805 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);
806 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);
807 int lrw_done(symmetric_LRW *lrw);
808 int lrw_test(void);
809 
810 /* don't call */
811 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
812 #endif
813 
814 #ifdef LTC_F8_MODE
815 int f8_start(                int  cipher, const unsigned char *IV,
816              const unsigned char *key,                    int  keylen,
817              const unsigned char *salt_key,               int  skeylen,
818                              int  num_rounds,   symmetric_F8  *f8);
819 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
820 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
821 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
822 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
823 int f8_done(symmetric_F8 *f8);
824 int f8_test_mode(void);
825 #endif
826 
827 
828 int find_cipher(const char *name);
829 int find_cipher_any(const char *name, int blocklen, int keylen);
830 int find_cipher_id(unsigned char ID);
831 int register_cipher(const struct ltc_cipher_descriptor *cipher);
832 int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
833 int cipher_is_valid(int idx);
834 
835 LTC_MUTEX_PROTO(ltc_cipher_mutex)
836 
837 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cipher.h,v $ */
838 /* $Revision: 1.46 $ */
839 /* $Date: 2006/11/13 23:09:38 $ */
840