Debian Codegraph @

src/libtom/tomcrypt_cipher.h

raw symbols SCIP
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 /** A block cipher ECB structure */
202 typedef struct {
203 /** The index of the cipher chosen */
204 int cipher,
205 /** The block size of the given cipher */
206 blocklen;
207 /** The scheduled key */
208 symmetric_key key;
209 } symmetric_ECB;
210 #endif
211
212 #ifdef LTC_CFB_MODE
213 /** A block cipher CFB structure */
214 typedef struct {
215 /** The index of the cipher chosen */
216 int cipher,
217 /** The block size of the given cipher */
218 blocklen,
219 /** The padding offset */
220 padlen;
221 /** The current IV */
222 unsigned char IV[MAXBLOCKSIZE],
223 /** The pad used to encrypt/decrypt */
224 pad[MAXBLOCKSIZE];
225 /** The scheduled key */
226 symmetric_key key;
227 } symmetric_CFB;
228 #endif
229
230 #ifdef LTC_OFB_MODE
231 /** A block cipher OFB structure */
232 typedef struct {
233 /** The index of the cipher chosen */
234 int cipher,
235 /** The block size of the given cipher */
236 blocklen,
237 /** The padding offset */
238 padlen;
239 /** The current IV */
240 unsigned char IV[MAXBLOCKSIZE];
241 /** The scheduled key */
242 symmetric_key key;
243 } symmetric_OFB;
244 #endif
245
246 #ifdef LTC_CBC_MODE
247 /** A block cipher CBC structure */
248 typedef struct {
249 /** The index of the cipher chosen */
250 int cipher,
251 /** The block size of the given cipher */
252 blocklen;
253 /** The current IV */
254 unsigned char IV[MAXBLOCKSIZE];
255 /** The scheduled key */
256 symmetric_key key;
257 } symmetric_CBC;
258 #endif
259
260
261 #ifdef LTC_CTR_MODE
262 /** A block cipher CTR structure */
263 typedef struct {
264 /** The index of the cipher chosen */
265 int cipher,
266 /** The block size of the given cipher */
267 blocklen,
268 /** The padding offset */
269 padlen,
270 /** The mode (endianess) of the CTR, 0==little, 1==big */
271 mode,
272 /** counter width */
273 ctrlen;
274
275 /** The counter */
276 unsigned char ctr[MAXBLOCKSIZE],
277 /** The pad used to encrypt/decrypt */
278 pad[MAXBLOCKSIZE];
279 /** The scheduled key */
280 symmetric_key key;
281 } symmetric_CTR;
282 #endif
283
284
285 #ifdef LTC_LRW_MODE
286 /** A LRW structure */
287 typedef struct {
288 /** The index of the cipher chosen (must be a 128-bit block cipher) */
289 int cipher;
290
291 /** The current IV */
292 unsigned char IV[16],
293
294 /** the tweak key */
295 tweak[16],
296
297 /** The current pad, it's the product of the first 15 bytes against the tweak key */
298 pad[16];
299
300 /** The scheduled symmetric key */
301 symmetric_key key;
302
303 #ifdef LRW_TABLES
304 /** The pre-computed multiplication table */
305 unsigned char PC[16][256][16];
306 #endif
307 } symmetric_LRW;
308 #endif
309
310 #ifdef LTC_F8_MODE
311 /** A block cipher F8 structure */
312 typedef struct {
313 /** The index of the cipher chosen */
314 int cipher,
315 /** The block size of the given cipher */
316 blocklen,
317 /** The padding offset */
318 padlen;
319 /** The current IV */
320 unsigned char IV[MAXBLOCKSIZE],
321 MIV[MAXBLOCKSIZE];
322 /** Current block count */
323 ulong32 blockcnt;
324 /** The scheduled key */
325 symmetric_key key;
326 } symmetric_F8;
327 #endif
328
329
330 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */
331 extern struct ltc_cipher_descriptor {
332 /** name of cipher */
333 char *name;
334 /** internal ID */
335 unsigned char ID;
336 /** min keysize (octets) */
337 int min_key_length,
338 /** max keysize (octets) */
339 max_key_length,
340 /** block size (octets) */
341 block_length,
342 /** default number of rounds */
343 default_rounds;
344 /** Setup the cipher
345 @param key The input symmetric key
346 @param keylen The length of the input key (octets)
347 @param num_rounds The requested number of rounds (0==default)
348 @param skey [out] The destination of the scheduled key
349 @return CRYPT_OK if successful
350 */
351 int (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
352 /** Encrypt a block
353 @param pt The plaintext
354 @param ct [out] The ciphertext
355 @param skey The scheduled key
356 @return CRYPT_OK if successful
357 */
358 int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
359 /** Decrypt a block
360 @param ct The ciphertext
361 @param pt [out] The plaintext
362 @param skey The scheduled key
363 @return CRYPT_OK if successful
364 */
365 int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
366 /** Test the block cipher
367 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
368 */
369 int (*test)(void);
370
371 /** Terminate the context
372 @param skey The scheduled key
373 */
374 void (*done)(symmetric_key *skey);
375
376 /** Determine a key size
377 @param keysize [in/out] The size of the key desired and the suggested size
378 @return CRYPT_OK if successful
379 */
380 int (*keysize)(int *keysize);
381
382 /** Accelerators **/
383 /** Accelerated ECB encryption
384 @param pt Plaintext
385 @param ct Ciphertext
386 @param blocks The number of complete blocks to process
387 @param skey The scheduled key context
388 @return CRYPT_OK if successful
389 */
390 int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
391
392 /** Accelerated ECB decryption
393 @param pt Plaintext
394 @param ct Ciphertext
395 @param blocks The number of complete blocks to process
396 @param skey The scheduled key context
397 @return CRYPT_OK if successful
398 */
399 int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
400
401 /** Accelerated CBC encryption
402 @param pt Plaintext
403 @param ct Ciphertext
404 @param blocks The number of complete blocks to process
405 @param IV The initial value (input/output)
406 @param skey The scheduled key context
407 @return CRYPT_OK if successful
408 */
409 int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
410
411 /** Accelerated CBC decryption
412 @param pt Plaintext
413 @param ct Ciphertext
414 @param blocks The number of complete blocks to process
415 @param IV The initial value (input/output)
416 @param skey The scheduled key context
417 @return CRYPT_OK if successful
418 */
419 int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
420
421 /** Accelerated CTR encryption
422 @param pt Plaintext
423 @param ct Ciphertext
424 @param blocks The number of complete blocks to process
425 @param IV The initial value (input/output)
426 @param mode little or big endian counter (mode=0 or mode=1)
427 @param skey The scheduled key context
428 @return CRYPT_OK if successful
429 */
430 int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
431
432 /** Accelerated LRW
433 @param pt Plaintext
434 @param ct Ciphertext
435 @param blocks The number of complete blocks to process
436 @param IV The initial value (input/output)
437 @param tweak The LRW tweak
438 @param skey The scheduled key context
439 @return CRYPT_OK if successful
440 */
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
443 /** Accelerated LRW
444 @param ct Ciphertext
445 @param pt Plaintext
446 @param blocks The number of complete blocks to process
447 @param IV The initial value (input/output)
448 @param tweak The LRW tweak
449 @param skey The scheduled key context
450 @return CRYPT_OK if successful
451 */
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
454 /** Accelerated CCM packet (one-shot)
455 @param key The secret key to use
456 @param keylen The length of the secret key (octets)
457 @param uskey A previously scheduled key [optional can be NULL]
458 @param nonce The session nonce [use once]
459 @param noncelen The length of the nonce
460 @param header The header for the session
461 @param headerlen The length of the header (octets)
462 @param pt [out] The plaintext
463 @param ptlen The length of the plaintext (octets)
464 @param ct [out] The ciphertext
465 @param tag [out] The destination tag
466 @param taglen [in/out] The max size and resulting size of the authentication tag
467 @param direction Encrypt or Decrypt direction (0 or 1)
468 @return CRYPT_OK if successful
469 */
470 int (*accel_ccm_memory)(
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
480 /** Accelerated GCM packet (one shot)
481 @param key The secret key
482 @param keylen The length of the secret key
483 @param IV The initial vector
484 @param IVlen The length of the initial vector
485 @param adata The additional authentication data (header)
486 @param adatalen The length of the adata
487 @param pt The plaintext
488 @param ptlen The length of the plaintext (ciphertext length is the same)
489 @param ct The ciphertext
490 @param tag [out] The MAC tag
491 @param taglen [in/out] The MAC tag length
492 @param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
493 @return CRYPT_OK on success
494 */
495 int (*accel_gcm_memory)(
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
504 /** Accelerated one shot LTC_OMAC
505 @param key The secret key
506 @param keylen The key length (octets)
507 @param in The message
508 @param inlen Length of message (octets)
509 @param out [out] Destination for tag
510 @param outlen [in/out] Initial and final size of out
511 @return CRYPT_OK on success
512 */
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
518 /** Accelerated one shot XCBC
519 @param key The secret key
520 @param keylen The key length (octets)
521 @param in The message
522 @param inlen Length of message (octets)
523 @param out [out] Destination for tag
524 @param outlen [in/out] Initial and final size of out
525 @return CRYPT_OK on success
526 */
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
532 /** Accelerated one shot F9
533 @param key The secret key
534 @param keylen The key length (octets)
535 @param in The message
536 @param inlen Length of message (octets)
537 @param out [out] Destination for tag
538 @param outlen [in/out] Initial and final size of out
539 @return CRYPT_OK on success
540 @remark Requires manual padding
541 */
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);
546 } cipher_descriptor[];
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 static int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
664 static int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
665 static int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
666 static int des_test(void);
667 static void des_done(symmetric_key *skey);
668 static int des_keysize(int *keysize);
669 static int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
670 static int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
671 static int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
672 static int des3_test(void);
673 static void des3_done(symmetric_key *skey);
674 static int des3_keysize(int *keysize);
675 #endif
676
677 #ifdef LTC_CAST5
678 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
679 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
680 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
681 int cast5_test(void);
682 void cast5_done(symmetric_key *skey);
683 int cast5_keysize(int *keysize);
684 extern const struct ltc_cipher_descriptor cast5_desc;
685 #endif
686
687 #ifdef LTC_NOEKEON
688 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
689 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
690 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
691 int noekeon_test(void);
692 void noekeon_done(symmetric_key *skey);
693 int noekeon_keysize(int *keysize);
694 extern const struct ltc_cipher_descriptor noekeon_desc;
695 #endif
696
697 #ifdef LTC_SKIPJACK
698 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
699 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
700 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
701 int skipjack_test(void);
702 void skipjack_done(symmetric_key *skey);
703 int skipjack_keysize(int *keysize);
704 extern const struct ltc_cipher_descriptor skipjack_desc;
705 #endif
706
707 #ifdef LTC_KHAZAD
708 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
709 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
710 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
711 int khazad_test(void);
712 void khazad_done(symmetric_key *skey);
713 int khazad_keysize(int *keysize);
714 extern const struct ltc_cipher_descriptor khazad_desc;
715 #endif
716
717 #ifdef LTC_ANUBIS
718 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
719 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
720 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
721 int anubis_test(void);
722 void anubis_done(symmetric_key *skey);
723 int anubis_keysize(int *keysize);
724 extern const struct ltc_cipher_descriptor anubis_desc;
725 #endif
726
727 #ifdef LTC_KSEED
728 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
729 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
730 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
731 int kseed_test(void);
732 void kseed_done(symmetric_key *skey);
733 int kseed_keysize(int *keysize);
734 extern const struct ltc_cipher_descriptor kseed_desc;
735 #endif
736
737 #ifdef LTC_KASUMI
738 int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
739 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
740 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
741 int kasumi_test(void);
742 void kasumi_done(symmetric_key *skey);
743 int kasumi_keysize(int *keysize);
744 extern const struct ltc_cipher_descriptor kasumi_desc;
745 #endif
746
747
748 #ifdef LTC_MULTI2
749 int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
750 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
751 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
752 int multi2_test(void);
753 void multi2_done(symmetric_key *skey);
754 int multi2_keysize(int *keysize);
755 extern const struct ltc_cipher_descriptor multi2_desc;
756 #endif
757
758 #ifdef LTC_ECB_MODE
759 int ecb_start(int cipher, const unsigned char *key,
760 int keylen, int num_rounds, symmetric_ECB *ecb);
761 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
762 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
763 int ecb_done(symmetric_ECB *ecb);
764 #endif
765
766 #ifdef LTC_CFB_MODE
767 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
768 int keylen, int num_rounds, symmetric_CFB *cfb);
769 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
770 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
771 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
772 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
773 int cfb_done(symmetric_CFB *cfb);
774 #endif
775
776 #ifdef LTC_OFB_MODE
777 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
778 int keylen, int num_rounds, symmetric_OFB *ofb);
779 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
780 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
781 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
782 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
783 int ofb_done(symmetric_OFB *ofb);
784 #endif
785
786 #ifdef LTC_CBC_MODE
787 int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
788 int keylen, int num_rounds, symmetric_CBC *cbc);
789 int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
790 int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
791 int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
792 int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
793 int cbc_done(symmetric_CBC *cbc);
794 #endif
795
796 #ifdef LTC_CTR_MODE
797
798 #define CTR_COUNTER_LITTLE_ENDIAN 0x0000
799 #define CTR_COUNTER_BIG_ENDIAN 0x1000
800 #define LTC_CTR_RFC3686 0x2000
801
802 int ctr_start( int cipher,
803 const unsigned char *IV,
804 const unsigned char *key, int keylen,
805 int num_rounds, int ctr_mode,
806 symmetric_CTR *ctr);
807 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
808 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
809 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
810 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
811 int ctr_done(symmetric_CTR *ctr);
812 int ctr_test(void);
813 #endif
814
815 #ifdef LTC_LRW_MODE
816
817 #define LRW_ENCRYPT 0
818 #define LRW_DECRYPT 1
819
820 int lrw_start( int cipher,
821 const unsigned char *IV,
822 const unsigned char *key, int keylen,
823 const unsigned char *tweak,
824 int num_rounds,
825 symmetric_LRW *lrw);
826 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
827 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
828 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);
829 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);
830 int lrw_done(symmetric_LRW *lrw);
831 int lrw_test(void);
832
833 /* don't call */
834 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
835 #endif
836
837 #ifdef LTC_F8_MODE
838 int f8_start( int cipher, const unsigned char *IV,
839 const unsigned char *key, int keylen,
840 const unsigned char *salt_key, int skeylen,
841 int num_rounds, symmetric_F8 *f8);
842 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
843 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
844 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
845 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
846 int f8_done(symmetric_F8 *f8);
847 int f8_test_mode(void);
848 #endif
849
850 #ifdef LTC_XTS_MODE
851 typedef struct {
852 symmetric_key key1, key2;
853 int cipher;
854 } symmetric_xts;
855
856 int xts_start( int cipher,
857 const unsigned char *key1,
858 const unsigned char *key2,
859 unsigned long keylen,
860 int num_rounds,
861 symmetric_xts *xts);
862
863 int xts_encrypt(
864 const unsigned char *pt, unsigned long ptlen,
865 unsigned char *ct,
866 const unsigned char *tweak,
867 symmetric_xts *xts);
868 int xts_decrypt(
869 const unsigned char *ct, unsigned long ptlen,
870 unsigned char *pt,
871 const unsigned char *tweak,
872 symmetric_xts *xts);
873
874 void xts_done(symmetric_xts *xts);
875 int xts_test(void);
876 void xts_mult_x(unsigned char *I);
877 #endif
878
879 int find_cipher(const char *name);
880 int find_cipher_any(const char *name, int blocklen, int keylen);
881 int find_cipher_id(unsigned char ID);
882 int register_cipher(const struct ltc_cipher_descriptor *cipher);
883 int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
884 int cipher_is_valid(int idx);
885
886 LTC_MUTEX_PROTO(ltc_cipher_mutex)
887
888 /* $Source$ */
889 /* $Revision$ */
890 /* $Date$ */