1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ 2 /* SPDX-License-Identifier: Unlicense */ 3 4 /* ---- SYMMETRIC KEY STUFF ----- 5 * 6 * We put each of the ciphers scheduled keys in their own structs then we put all of 7 * the key formats in one union. This makes the function prototypes easier to use. 8 */ 9 #ifdef LTC_BLOWFISH 10 struct blowfish_key { 11 ulong32 S[4][256]; 12 ulong32 K[18]; 13 }; 14 #endif 15 16 #ifdef LTC_RC5 17 struct rc5_key { 18 int rounds; 19 ulong32 K[50]; 20 }; 21 #endif 22 23 #ifdef LTC_RC6 24 struct rc6_key { 25 ulong32 K[44]; 26 }; 27 #endif 28 29 #ifdef LTC_SAFERP 30 struct saferp_key { 31 unsigned char K[33][16]; 32 long rounds; 33 }; 34 #endif 35 36 #ifdef LTC_RIJNDAEL 37 struct rijndael_key { 38 ulong32 eK[60], dK[60]; 39 int Nr; 40 }; 41 #endif 42 43 #ifdef LTC_KSEED 44 struct kseed_key { 45 ulong32 K[32], dK[32]; 46 }; 47 #endif 48 49 #ifdef LTC_KASUMI 50 struct kasumi_key { 51 ulong32 KLi1[8], KLi2[8], 52 KOi1[8], KOi2[8], KOi3[8], 53 KIi1[8], KIi2[8], KIi3[8]; 54 }; 55 #endif 56 57 #ifdef LTC_XTEA 58 struct xtea_key { 59 unsigned long A[32], B[32]; 60 }; 61 #endif 62 63 #ifdef LTC_TWOFISH 64 #ifndef LTC_TWOFISH_SMALL 65 struct twofish_key { 66 ulong32 S[4][256], K[40]; 67 }; 68 #else 69 struct twofish_key { 70 ulong32 K[40]; 71 unsigned char S[32], start; 72 }; 73 #endif 74 #endif 75 76 #ifdef LTC_SAFER 77 #define LTC_SAFER_K64_DEFAULT_NOF_ROUNDS 6 78 #define LTC_SAFER_K128_DEFAULT_NOF_ROUNDS 10 79 #define LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS 8 80 #define LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS 10 81 #define LTC_SAFER_MAX_NOF_ROUNDS 13 82 #define LTC_SAFER_BLOCK_LEN 8 83 #define LTC_SAFER_KEY_LEN (1 + LTC_SAFER_BLOCK_LEN * (1 + 2 * LTC_SAFER_MAX_NOF_ROUNDS)) 84 typedef unsigned char safer_block_t[LTC_SAFER_BLOCK_LEN]; 85 typedef unsigned char safer_key_t[LTC_SAFER_KEY_LEN]; 86 struct safer_key { safer_key_t key; }; 87 #endif 88 89 #ifdef LTC_RC2 90 struct rc2_key { unsigned xkey[64]; }; 91 #endif 92 93 #ifdef LTC_DES 94 struct des_key { 95 ulong32 ek[32], dk[32]; 96 }; 97 98 struct des3_key { 99 ulong32 ek[3][32], dk[3][32]; 100 }; 101 #endif 102 103 #ifdef LTC_CAST5 104 struct cast5_key { 105 ulong32 K[32], keylen; 106 }; 107 #endif 108 109 #ifdef LTC_NOEKEON 110 struct noekeon_key { 111 ulong32 K[4], dK[4]; 112 }; 113 #endif 114 115 #ifdef LTC_SKIPJACK 116 struct skipjack_key { 117 unsigned char key[10]; 118 }; 119 #endif 120 121 #ifdef LTC_KHAZAD 122 struct khazad_key { 123 ulong64 roundKeyEnc[8 + 1]; 124 ulong64 roundKeyDec[8 + 1]; 125 }; 126 #endif 127 128 #ifdef LTC_ANUBIS 129 struct anubis_key { 130 int keyBits; 131 int R; 132 ulong32 roundKeyEnc[18 + 1][4]; 133 ulong32 roundKeyDec[18 + 1][4]; 134 }; 135 #endif 136 137 #ifdef LTC_MULTI2 138 struct multi2_key { 139 int N; 140 ulong32 uk[8]; 141 }; 142 #endif 143 144 #ifdef LTC_CAMELLIA 145 struct camellia_key { 146 int R; 147 ulong64 kw[4], k[24], kl[6]; 148 }; 149 #endif 150 151 #ifdef LTC_IDEA 152 /* rounds */ 153 #define LTC_IDEA_ROUNDS 8 154 /* key schedule length in # of unsigned shorts */ 155 #define LTC_IDEA_KEYLEN 6*LTC_IDEA_ROUNDS+4 156 struct idea_key { 157 unsigned short int ek[LTC_IDEA_KEYLEN]; /* enc key */ 158 unsigned short int dk[LTC_IDEA_KEYLEN]; /* dec key */ 159 }; 160 #endif 161 162 #ifdef LTC_SERPENT 163 struct serpent_key { 164 ulong32 k[33*4]; 165 }; 166 #endif 167 168 #ifdef LTC_TEA 169 struct tea_key { 170 ulong32 k[4]; 171 }; 172 #endif 173 174 typedef union Symmetric_key { 175 #ifdef LTC_DES 176 struct des_key des; 177 struct des3_key des3; 178 #endif 179 #ifdef LTC_RC2 180 struct rc2_key rc2; 181 #endif 182 #ifdef LTC_SAFER 183 struct safer_key safer; 184 #endif 185 #ifdef LTC_TWOFISH 186 struct twofish_key twofish; 187 #endif 188 #ifdef LTC_BLOWFISH 189 struct blowfish_key blowfish; 190 #endif 191 #ifdef LTC_RC5 192 struct rc5_key rc5; 193 #endif 194 #ifdef LTC_RC6 195 struct rc6_key rc6; 196 #endif 197 #ifdef LTC_SAFERP 198 struct saferp_key saferp; 199 #endif 200 #ifdef LTC_RIJNDAEL 201 struct rijndael_key rijndael; 202 #endif 203 #ifdef LTC_XTEA 204 struct xtea_key xtea; 205 #endif 206 #ifdef LTC_CAST5 207 struct cast5_key cast5; 208 #endif 209 #ifdef LTC_NOEKEON 210 struct noekeon_key noekeon; 211 #endif 212 #ifdef LTC_SKIPJACK 213 struct skipjack_key skipjack; 214 #endif 215 #ifdef LTC_KHAZAD 216 struct khazad_key khazad; 217 #endif 218 #ifdef LTC_ANUBIS 219 struct anubis_key anubis; 220 #endif 221 #ifdef LTC_KSEED 222 struct kseed_key kseed; 223 #endif 224 #ifdef LTC_KASUMI 225 struct kasumi_key kasumi; 226 #endif 227 #ifdef LTC_MULTI2 228 struct multi2_key multi2; 229 #endif 230 #ifdef LTC_CAMELLIA 231 struct camellia_key camellia; 232 #endif 233 #ifdef LTC_IDEA 234 struct idea_key idea; 235 #endif 236 #ifdef LTC_SERPENT 237 struct serpent_key serpent; 238 #endif 239 #ifdef LTC_TEA 240 struct tea_key tea; 241 #endif 242 void *data; 243 } symmetric_key; 244 245 #ifdef LTC_ECB_MODE 246 /** A block cipher ECB structure */ 247 typedef struct { 248 /** The index of the cipher chosen */ 249 int cipher, 250 /** The block size of the given cipher */ 251 blocklen; 252 /** The scheduled key */ 253 symmetric_key key; 254 } symmetric_ECB; 255 #endif 256 257 #ifdef LTC_CFB_MODE 258 /** A block cipher CFB structure */ 259 typedef struct { 260 /** The index of the cipher chosen */ 261 int cipher, 262 /** The block size of the given cipher */ 263 blocklen, 264 /** The padding offset */ 265 padlen; 266 /** The current IV */ 267 unsigned char IV[MAXBLOCKSIZE], 268 /** The pad used to encrypt/decrypt */ 269 pad[MAXBLOCKSIZE]; 270 /** The scheduled key */ 271 symmetric_key key; 272 } symmetric_CFB; 273 #endif 274 275 #ifdef LTC_OFB_MODE 276 /** A block cipher OFB structure */ 277 typedef struct { 278 /** The index of the cipher chosen */ 279 int cipher, 280 /** The block size of the given cipher */ 281 blocklen, 282 /** The padding offset */ 283 padlen; 284 /** The current IV */ 285 unsigned char IV[MAXBLOCKSIZE]; 286 /** The scheduled key */ 287 symmetric_key key; 288 } symmetric_OFB; 289 #endif 290 291 #ifdef LTC_CBC_MODE 292 /** A block cipher CBC structure */ 293 typedef struct { 294 /** The index of the cipher chosen */ 295 int cipher, 296 /** The block size of the given cipher */ 297 blocklen; 298 /** The current IV */ 299 unsigned char IV[MAXBLOCKSIZE]; 300 /** The scheduled key */ 301 symmetric_key key; 302 } symmetric_CBC; 303 #endif 304 305 306 #ifdef LTC_CTR_MODE 307 /** A block cipher CTR structure */ 308 typedef struct { 309 /** The index of the cipher chosen */ 310 int cipher, 311 /** The block size of the given cipher */ 312 blocklen, 313 /** The padding offset */ 314 padlen, 315 /** The mode (endianess) of the CTR, 0==little, 1==big */ 316 mode, 317 /** counter width */ 318 ctrlen; 319 320 /** The counter */ 321 unsigned char ctr[MAXBLOCKSIZE]; 322 /** The pad used to encrypt/decrypt */ 323 unsigned char pad[MAXBLOCKSIZE] LTC_ALIGN(16); 324 /** The scheduled key */ 325 symmetric_key key; 326 } symmetric_CTR; 327 #endif 328 329 330 #ifdef LTC_LRW_MODE 331 /** A LRW structure */ 332 typedef struct { 333 /** The index of the cipher chosen (must be a 128-bit block cipher) */ 334 int cipher; 335 336 /** The current IV */ 337 unsigned char IV[16], 338 339 /** the tweak key */ 340 tweak[16], 341 342 /** The current pad, it's the product of the first 15 bytes against the tweak key */ 343 pad[16]; 344 345 /** The scheduled symmetric key */ 346 symmetric_key key; 347 348 #ifdef LTC_LRW_TABLES 349 /** The pre-computed multiplication table */ 350 unsigned char PC[16][256][16]; 351 #endif 352 } symmetric_LRW; 353 #endif 354 355 #ifdef LTC_F8_MODE 356 /** A block cipher F8 structure */ 357 typedef struct { 358 /** The index of the cipher chosen */ 359 int cipher, 360 /** The block size of the given cipher */ 361 blocklen, 362 /** The padding offset */ 363 padlen; 364 /** The current IV */ 365 unsigned char IV[MAXBLOCKSIZE], 366 MIV[MAXBLOCKSIZE]; 367 /** Current block count */ 368 ulong32 blockcnt; 369 /** The scheduled key */ 370 symmetric_key key; 371 } symmetric_F8; 372 #endif 373 374 375 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */ 376 extern const struct ltc_cipher_descriptor { 377 /** name of cipher */ 378 const char *name; 379 /** internal ID */ 380 unsigned char ID; 381 /** min keysize (octets) */ 382 int min_key_length, 383 /** max keysize (octets) */ 384 max_key_length, 385 /** block size (octets) */ 386 block_length, 387 /** default number of rounds */ 388 default_rounds; 389 /** Setup the cipher 390 @param key The input symmetric key 391 @param keylen The length of the input key (octets) 392 @param num_rounds The requested number of rounds (0==default) 393 @param skey [out] The destination of the scheduled key 394 @return CRYPT_OK if successful 395 */ 396 int (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 397 /** Encrypt a block 398 @param pt The plaintext 399 @param ct [out] The ciphertext 400 @param skey The scheduled key 401 @return CRYPT_OK if successful 402 */ 403 int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 404 /** Decrypt a block 405 @param ct The ciphertext 406 @param pt [out] The plaintext 407 @param skey The scheduled key 408 @return CRYPT_OK if successful 409 */ 410 int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 411 /** Test the block cipher 412 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled 413 */ 414 int (*test)(void); 415 416 /** Terminate the context 417 @param skey The scheduled key 418 */ 419 void (*done)(symmetric_key *skey); 420 421 /** Determine a key size 422 @param keysize [in/out] The size of the key desired and the suggested size 423 @return CRYPT_OK if successful 424 */ 425 int (*keysize)(int *keysize); 426 427 /** Accelerators **/ 428 /** Accelerated ECB encryption 429 @param pt Plaintext 430 @param ct Ciphertext 431 @param blocks The number of complete blocks to process 432 @param skey The scheduled key context 433 @return CRYPT_OK if successful 434 */ 435 int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, const symmetric_key *skey); 436 437 /** Accelerated ECB decryption 438 @param pt Plaintext 439 @param ct Ciphertext 440 @param blocks The number of complete blocks to process 441 @param skey The scheduled key context 442 @return CRYPT_OK if successful 443 */ 444 int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, const symmetric_key *skey); 445 446 /** Accelerated CBC encryption 447 @param pt Plaintext 448 @param ct Ciphertext 449 @param blocks The number of complete blocks to process 450 @param IV The initial value (input/output) 451 @param skey The scheduled key context 452 @return CRYPT_OK if successful 453 */ 454 int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey); 455 456 /** Accelerated CBC decryption 457 @param pt Plaintext 458 @param ct Ciphertext 459 @param blocks The number of complete blocks to process 460 @param IV The initial value (input/output) 461 @param skey The scheduled key context 462 @return CRYPT_OK if successful 463 */ 464 int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey); 465 466 /** Accelerated CTR encryption 467 @param pt Plaintext 468 @param ct Ciphertext 469 @param blocks The number of complete blocks to process 470 @param IV The initial value (input/output) 471 @param mode little or big endian counter (mode=0 or mode=1) 472 @param skey The scheduled key context 473 @return CRYPT_OK if successful 474 */ 475 int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey); 476 477 /** Accelerated LRW 478 @param pt Plaintext 479 @param ct Ciphertext 480 @param blocks The number of complete blocks to process 481 @param IV The initial value (input/output) 482 @param tweak The LRW tweak 483 @param skey The scheduled key context 484 @return CRYPT_OK if successful 485 */ 486 int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey); 487 488 /** Accelerated LRW 489 @param ct Ciphertext 490 @param pt Plaintext 491 @param blocks The number of complete blocks to process 492 @param IV The initial value (input/output) 493 @param tweak The LRW tweak 494 @param skey The scheduled key context 495 @return CRYPT_OK if successful 496 */ 497 int (*accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey); 498 499 /** Accelerated CCM packet (one-shot) 500 @param key The secret key to use 501 @param keylen The length of the secret key (octets) 502 @param uskey A previously scheduled key [optional can be NULL] 503 @param nonce The session nonce [use once] 504 @param noncelen The length of the nonce 505 @param header The header for the session 506 @param headerlen The length of the header (octets) 507 @param pt [out] The plaintext 508 @param ptlen The length of the plaintext (octets) 509 @param ct [out] The ciphertext 510 @param tag [out] The destination tag 511 @param taglen [in/out] The max size and resulting size of the authentication tag 512 @param direction Encrypt or Decrypt direction (0 or 1) 513 @return CRYPT_OK if successful 514 */ 515 int (*accel_ccm_memory)( 516 const unsigned char *key, unsigned long keylen, 517 symmetric_key *uskey, 518 const unsigned char *nonce, unsigned long noncelen, 519 const unsigned char *header, unsigned long headerlen, 520 unsigned char *pt, unsigned long ptlen, 521 unsigned char *ct, 522 unsigned char *tag, unsigned long *taglen, 523 int direction); 524 525 /** Accelerated GCM packet (one shot) 526 @param key The secret key 527 @param keylen The length of the secret key 528 @param IV The initialization vector 529 @param IVlen The length of the initialization vector 530 @param adata The additional authentication data (header) 531 @param adatalen The length of the adata 532 @param pt The plaintext 533 @param ptlen The length of the plaintext (ciphertext length is the same) 534 @param ct The ciphertext 535 @param tag [out] The MAC tag 536 @param taglen [in/out] The MAC tag length 537 @param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT) 538 @return CRYPT_OK on success 539 */ 540 int (*accel_gcm_memory)( 541 const unsigned char *key, unsigned long keylen, 542 const unsigned char *IV, unsigned long IVlen, 543 const unsigned char *adata, unsigned long adatalen, 544 unsigned char *pt, unsigned long ptlen, 545 unsigned char *ct, 546 unsigned char *tag, unsigned long *taglen, 547 int direction); 548 549 /** Accelerated one shot LTC_OMAC 550 @param key The secret key 551 @param keylen The key length (octets) 552 @param in The message 553 @param inlen Length of message (octets) 554 @param out [out] Destination for tag 555 @param outlen [in/out] Initial and final size of out 556 @return CRYPT_OK on success 557 */ 558 int (*omac_memory)( 559 const unsigned char *key, unsigned long keylen, 560 const unsigned char *in, unsigned long inlen, 561 unsigned char *out, unsigned long *outlen); 562 563 /** Accelerated one shot XCBC 564 @param key The secret key 565 @param keylen The key length (octets) 566 @param in The message 567 @param inlen Length of message (octets) 568 @param out [out] Destination for tag 569 @param outlen [in/out] Initial and final size of out 570 @return CRYPT_OK on success 571 */ 572 int (*xcbc_memory)( 573 const unsigned char *key, unsigned long keylen, 574 const unsigned char *in, unsigned long inlen, 575 unsigned char *out, unsigned long *outlen); 576 577 /** Accelerated one shot F9 578 @param key The secret key 579 @param keylen The key length (octets) 580 @param in The message 581 @param inlen Length of message (octets) 582 @param out [out] Destination for tag 583 @param outlen [in/out] Initial and final size of out 584 @return CRYPT_OK on success 585 @remark Requires manual padding 586 */ 587 int (*f9_memory)( 588 const unsigned char *key, unsigned long keylen, 589 const unsigned char *in, unsigned long inlen, 590 unsigned char *out, unsigned long *outlen); 591 592 /** Accelerated XTS encryption 593 @param pt Plaintext 594 @param ct Ciphertext 595 @param blocks The number of complete blocks to process 596 @param tweak The 128-bit encryption tweak (input/output). 597 The tweak should not be encrypted on input, but 598 next tweak will be copied encrypted on output. 599 @param skey1 The first scheduled key context 600 @param skey2 The second scheduled key context 601 @return CRYPT_OK if successful 602 */ 603 int (*accel_xts_encrypt)(const unsigned char *pt, unsigned char *ct, 604 unsigned long blocks, unsigned char *tweak, 605 const symmetric_key *skey1, const symmetric_key *skey2); 606 607 /** Accelerated XTS decryption 608 @param ct Ciphertext 609 @param pt Plaintext 610 @param blocks The number of complete blocks to process 611 @param tweak The 128-bit encryption tweak (input/output). 612 The tweak should not be encrypted on input, but 613 next tweak will be copied encrypted on output. 614 @param skey1 The first scheduled key context 615 @param skey2 The second scheduled key context 616 @return CRYPT_OK if successful 617 */ 618 int (*accel_xts_decrypt)(const unsigned char *ct, unsigned char *pt, 619 unsigned long blocks, unsigned char *tweak, 620 const symmetric_key *skey1, const symmetric_key *skey2); 621 } *cipher_descriptor[]; 622 623 #ifdef LTC_BLOWFISH 624 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 625 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 626 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 627 int blowfish_test(void); 628 void blowfish_done(symmetric_key *skey); 629 int blowfish_keysize(int *keysize); 630 extern const struct ltc_cipher_descriptor blowfish_desc; 631 #endif 632 633 #ifdef LTC_RC5 634 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 635 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 636 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 637 int rc5_test(void); 638 void rc5_done(symmetric_key *skey); 639 int rc5_keysize(int *keysize); 640 extern const struct ltc_cipher_descriptor rc5_desc; 641 #endif 642 643 #ifdef LTC_RC6 644 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 645 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 646 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 647 int rc6_test(void); 648 void rc6_done(symmetric_key *skey); 649 int rc6_keysize(int *keysize); 650 extern const struct ltc_cipher_descriptor rc6_desc; 651 #endif 652 653 #ifdef LTC_RC2 654 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 655 int rc2_setup_ex(const unsigned char *key, int keylen, int bits, int num_rounds, symmetric_key *skey); 656 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 657 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 658 int rc2_test(void); 659 void rc2_done(symmetric_key *skey); 660 int rc2_keysize(int *keysize); 661 extern const struct ltc_cipher_descriptor rc2_desc; 662 #endif 663 664 #ifdef LTC_SAFERP 665 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 666 int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 667 int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 668 int saferp_test(void); 669 void saferp_done(symmetric_key *skey); 670 int saferp_keysize(int *keysize); 671 extern const struct ltc_cipher_descriptor saferp_desc; 672 #endif 673 674 #ifdef LTC_SAFER 675 int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 676 int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 677 int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 678 int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 679 int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 680 int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 681 int safer_k64_test(void); 682 int safer_sk64_test(void); 683 int safer_sk128_test(void); 684 void safer_done(symmetric_key *skey); 685 int safer_64_keysize(int *keysize); 686 int safer_128_keysize(int *keysize); 687 extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc; 688 #endif 689 690 #ifdef LTC_RIJNDAEL 691 692 /* make aes an alias */ 693 #define aes_setup rijndael_setup 694 #define aes_ecb_encrypt rijndael_ecb_encrypt 695 #define aes_ecb_decrypt rijndael_ecb_decrypt 696 #define aes_test rijndael_test 697 #define aes_done rijndael_done 698 #define aes_keysize rijndael_keysize 699 700 #define aes_enc_setup rijndael_enc_setup 701 #define aes_enc_ecb_encrypt rijndael_enc_ecb_encrypt 702 #define aes_enc_keysize rijndael_enc_keysize 703 704 int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 705 int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 706 int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 707 int rijndael_test(void); 708 void rijndael_done(symmetric_key *skey); 709 int rijndael_keysize(int *keysize); 710 int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 711 int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 712 void rijndael_enc_done(symmetric_key *skey); 713 int rijndael_enc_keysize(int *keysize); 714 extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc; 715 extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc; 716 #endif 717 718 #ifdef LTC_XTEA 719 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 720 int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 721 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 722 int xtea_test(void); 723 void xtea_done(symmetric_key *skey); 724 int xtea_keysize(int *keysize); 725 extern const struct ltc_cipher_descriptor xtea_desc; 726 #endif 727 728 #ifdef LTC_TWOFISH 729 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 730 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 731 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 732 int twofish_test(void); 733 void twofish_done(symmetric_key *skey); 734 int twofish_keysize(int *keysize); 735 extern const struct ltc_cipher_descriptor twofish_desc; 736 #endif 737 738 #ifdef LTC_DES 739 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 740 int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 741 int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 742 int des_test(void); 743 void des_done(symmetric_key *skey); 744 int des_keysize(int *keysize); 745 int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 746 int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 747 int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 748 int des3_test(void); 749 void des3_done(symmetric_key *skey); 750 int des3_keysize(int *keysize); 751 extern const struct ltc_cipher_descriptor des_desc, des3_desc; 752 #endif 753 754 #ifdef LTC_CAST5 755 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 756 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 757 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 758 int cast5_test(void); 759 void cast5_done(symmetric_key *skey); 760 int cast5_keysize(int *keysize); 761 extern const struct ltc_cipher_descriptor cast5_desc; 762 #endif 763 764 #ifdef LTC_NOEKEON 765 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 766 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 767 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 768 int noekeon_test(void); 769 void noekeon_done(symmetric_key *skey); 770 int noekeon_keysize(int *keysize); 771 extern const struct ltc_cipher_descriptor noekeon_desc; 772 #endif 773 774 #ifdef LTC_SKIPJACK 775 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 776 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 777 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 778 int skipjack_test(void); 779 void skipjack_done(symmetric_key *skey); 780 int skipjack_keysize(int *keysize); 781 extern const struct ltc_cipher_descriptor skipjack_desc; 782 #endif 783 784 #ifdef LTC_KHAZAD 785 int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 786 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 787 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 788 int khazad_test(void); 789 void khazad_done(symmetric_key *skey); 790 int khazad_keysize(int *keysize); 791 extern const struct ltc_cipher_descriptor khazad_desc; 792 #endif 793 794 #ifdef LTC_ANUBIS 795 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 796 int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 797 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 798 int anubis_test(void); 799 void anubis_done(symmetric_key *skey); 800 int anubis_keysize(int *keysize); 801 extern const struct ltc_cipher_descriptor anubis_desc; 802 #endif 803 804 #ifdef LTC_KSEED 805 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 806 int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 807 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 808 int kseed_test(void); 809 void kseed_done(symmetric_key *skey); 810 int kseed_keysize(int *keysize); 811 extern const struct ltc_cipher_descriptor kseed_desc; 812 #endif 813 814 #ifdef LTC_KASUMI 815 int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 816 int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 817 int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 818 int kasumi_test(void); 819 void kasumi_done(symmetric_key *skey); 820 int kasumi_keysize(int *keysize); 821 extern const struct ltc_cipher_descriptor kasumi_desc; 822 #endif 823 824 825 #ifdef LTC_MULTI2 826 int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 827 int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 828 int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 829 int multi2_test(void); 830 void multi2_done(symmetric_key *skey); 831 int multi2_keysize(int *keysize); 832 extern const struct ltc_cipher_descriptor multi2_desc; 833 #endif 834 835 #ifdef LTC_CAMELLIA 836 int camellia_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 837 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 838 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 839 int camellia_test(void); 840 void camellia_done(symmetric_key *skey); 841 int camellia_keysize(int *keysize); 842 extern const struct ltc_cipher_descriptor camellia_desc; 843 #endif 844 845 #ifdef LTC_IDEA 846 int idea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 847 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 848 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 849 int idea_test(void); 850 void idea_done(symmetric_key *skey); 851 int idea_keysize(int *keysize); 852 extern const struct ltc_cipher_descriptor idea_desc; 853 #endif 854 855 #ifdef LTC_SERPENT 856 int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 857 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 858 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 859 int serpent_test(void); 860 void serpent_done(symmetric_key *skey); 861 int serpent_keysize(int *keysize); 862 extern const struct ltc_cipher_descriptor serpent_desc; 863 #endif 864 865 #ifdef LTC_TEA 866 int tea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); 867 int tea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey); 868 int tea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey); 869 int tea_test(void); 870 void tea_done(symmetric_key *skey); 871 int tea_keysize(int *keysize); 872 extern const struct ltc_cipher_descriptor tea_desc; 873 #endif 874 875 #ifdef LTC_ECB_MODE 876 int ecb_start(int cipher, const unsigned char *key, 877 int keylen, int num_rounds, symmetric_ECB *ecb); 878 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb); 879 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb); 880 int ecb_done(symmetric_ECB *ecb); 881 #endif 882 883 #ifdef LTC_CFB_MODE 884 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 885 int keylen, int num_rounds, symmetric_CFB *cfb); 886 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb); 887 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb); 888 int cfb_getiv(unsigned char *IV, unsigned long *len, const symmetric_CFB *cfb); 889 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb); 890 int cfb_done(symmetric_CFB *cfb); 891 #endif 892 893 #ifdef LTC_OFB_MODE 894 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 895 int keylen, int num_rounds, symmetric_OFB *ofb); 896 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb); 897 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb); 898 int ofb_getiv(unsigned char *IV, unsigned long *len, const symmetric_OFB *ofb); 899 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb); 900 int ofb_done(symmetric_OFB *ofb); 901 #endif 902 903 #ifdef LTC_CBC_MODE 904 int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key, 905 int keylen, int num_rounds, symmetric_CBC *cbc); 906 int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc); 907 int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc); 908 int cbc_getiv(unsigned char *IV, unsigned long *len, const symmetric_CBC *cbc); 909 int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc); 910 int cbc_done(symmetric_CBC *cbc); 911 #endif 912 913 #ifdef LTC_CTR_MODE 914 915 #define CTR_COUNTER_LITTLE_ENDIAN 0x0000 916 #define CTR_COUNTER_BIG_ENDIAN 0x1000 917 #define LTC_CTR_RFC3686 0x2000 918 919 int ctr_start( int cipher, 920 const unsigned char *IV, 921 const unsigned char *key, int keylen, 922 int num_rounds, int ctr_mode, 923 symmetric_CTR *ctr); 924 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr); 925 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr); 926 int ctr_getiv(unsigned char *IV, unsigned long *len, const symmetric_CTR *ctr); 927 int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr); 928 int ctr_done(symmetric_CTR *ctr); 929 int ctr_test(void); 930 #endif 931 932 #ifdef LTC_LRW_MODE 933 934 #define LRW_ENCRYPT LTC_ENCRYPT 935 #define LRW_DECRYPT LTC_DECRYPT 936 937 int lrw_start( int cipher, 938 const unsigned char *IV, 939 const unsigned char *key, int keylen, 940 const unsigned char *tweak, 941 int num_rounds, 942 symmetric_LRW *lrw); 943 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw); 944 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw); 945 int lrw_getiv(unsigned char *IV, unsigned long *len, const symmetric_LRW *lrw); 946 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw); 947 int lrw_done(symmetric_LRW *lrw); 948 int lrw_test(void); 949 950 /* don't call */ 951 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw); 952 #endif 953 954 #ifdef LTC_F8_MODE 955 int f8_start( int cipher, const unsigned char *IV, 956 const unsigned char *key, int keylen, 957 const unsigned char *salt_key, int skeylen, 958 int num_rounds, symmetric_F8 *f8); 959 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8); 960 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8); 961 int f8_getiv(unsigned char *IV, unsigned long *len, const symmetric_F8 *f8); 962 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8); 963 int f8_done(symmetric_F8 *f8); 964 int f8_test_mode(void); 965 #endif 966 967 #ifdef LTC_XTS_MODE 968 typedef struct { 969 symmetric_key key1, key2; 970 int cipher; 971 } symmetric_xts; 972 973 int xts_start( int cipher, 974 const unsigned char *key1, 975 const unsigned char *key2, 976 unsigned long keylen, 977 int num_rounds, 978 symmetric_xts *xts); 979 980 int xts_encrypt( 981 const unsigned char *pt, unsigned long ptlen, 982 unsigned char *ct, 983 unsigned char *tweak, 984 const symmetric_xts *xts); 985 int xts_decrypt( 986 const unsigned char *ct, unsigned long ptlen, 987 unsigned char *pt, 988 unsigned char *tweak, 989 const symmetric_xts *xts); 990 991 void xts_done(symmetric_xts *xts); 992 int xts_test(void); 993 void xts_mult_x(unsigned char *I); 994 #endif 995 996 int find_cipher(const char *name); 997 int find_cipher_any(const char *name, int blocklen, int keylen); 998 int find_cipher_id(unsigned char ID); 999 int register_cipher(const struct ltc_cipher_descriptor *cipher); 1000 int unregister_cipher(const struct ltc_cipher_descriptor *cipher); 1001 int register_all_ciphers(void); 1002 int cipher_is_valid(int idx); 1003 1004 LTC_MUTEX_PROTO(ltc_cipher_mutex) 1005 1006 /* ---- stream ciphers ---- */ 1007 1008 #ifdef LTC_CHACHA 1009 1010 typedef struct { 1011 ulong32 input[16]; 1012 unsigned char kstream[64]; 1013 unsigned long ksleft; 1014 unsigned long ivlen; 1015 int rounds; 1016 } chacha_state; 1017 1018 int chacha_setup(chacha_state *st, const unsigned char *key, unsigned long keylen, int rounds); 1019 int chacha_ivctr32(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong32 counter); 1020 int chacha_ivctr64(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter); 1021 int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1022 int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen); 1023 int chacha_done(chacha_state *st); 1024 int chacha_test(void); 1025 int chacha_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds, 1026 const unsigned char *iv, unsigned long ivlen, ulong64 counter, 1027 const unsigned char *datain, unsigned long datalen, unsigned char *dataout); 1028 1029 #endif /* LTC_CHACHA */ 1030 1031 #ifdef LTC_SALSA20 1032 1033 typedef struct { 1034 ulong32 input[16]; 1035 unsigned char kstream[64]; 1036 unsigned long ksleft; 1037 unsigned long ivlen; 1038 int rounds; 1039 } salsa20_state; 1040 1041 int salsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long keylen, int rounds); 1042 int salsa20_ivctr64(salsa20_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter); 1043 int salsa20_crypt(salsa20_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1044 int salsa20_keystream(salsa20_state *st, unsigned char *out, unsigned long outlen); 1045 int salsa20_done(salsa20_state *st); 1046 int salsa20_test(void); 1047 int salsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds, 1048 const unsigned char *iv, unsigned long ivlen, ulong64 counter, 1049 const unsigned char *datain, unsigned long datalen, unsigned char *dataout); 1050 1051 #endif /* LTC_SALSA20 */ 1052 1053 #ifdef LTC_XSALSA20 1054 1055 int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long keylen, 1056 const unsigned char *nonce, unsigned long noncelen, 1057 int rounds); 1058 int xsalsa20_test(void); 1059 int xsalsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds, 1060 const unsigned char *nonce, unsigned long noncelen, 1061 const unsigned char *datain, unsigned long datalen, unsigned char *dataout); 1062 1063 #endif /* LTC_XSALSA20 */ 1064 1065 #ifdef LTC_SOSEMANUK 1066 1067 typedef struct { 1068 ulong32 kc[100]; /* key_context */ 1069 ulong32 s00, s01, s02, s03, s04, s05, s06, s07, s08, s09; 1070 ulong32 r1, r2; 1071 /* 1072 * Buffering: the stream cipher produces output data by 1073 * blocks of 640 bits. buf[] contains such a block, and 1074 * "ptr" is the index of the next output byte. 1075 */ 1076 unsigned char buf[80]; 1077 unsigned ptr; 1078 } sosemanuk_state; 1079 1080 int sosemanuk_setup(sosemanuk_state *st, const unsigned char *key, unsigned long keylen); 1081 int sosemanuk_setiv(sosemanuk_state *st, const unsigned char *iv, unsigned long ivlen); 1082 int sosemanuk_crypt(sosemanuk_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1083 int sosemanuk_keystream(sosemanuk_state *st, unsigned char *out, unsigned long outlen); 1084 int sosemanuk_done(sosemanuk_state *st); 1085 int sosemanuk_test(void); 1086 int sosemanuk_memory(const unsigned char *key, unsigned long keylen, 1087 const unsigned char *iv, unsigned long ivlen, 1088 const unsigned char *datain, unsigned long datalen, 1089 unsigned char *dataout); 1090 1091 #endif /* LTC_SOSEMANUK */ 1092 1093 #ifdef LTC_RABBIT 1094 1095 typedef struct { 1096 ulong32 x[8]; 1097 ulong32 c[8]; 1098 ulong32 carry; 1099 } rabbit_ctx; 1100 1101 typedef struct { 1102 rabbit_ctx master_ctx; 1103 rabbit_ctx work_ctx; 1104 unsigned char block[16]; /* last keystream block containing unused bytes */ 1105 ulong32 unused; /* count fm right */ 1106 } rabbit_state; 1107 1108 int rabbit_setup(rabbit_state* st, const unsigned char *key, unsigned long keylen); 1109 int rabbit_setiv(rabbit_state* st, const unsigned char *iv, unsigned long ivlen); 1110 int rabbit_crypt(rabbit_state* st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1111 int rabbit_keystream(rabbit_state* st, unsigned char *out, unsigned long outlen); 1112 int rabbit_done(rabbit_state *st); 1113 int rabbit_test(void); 1114 int rabbit_memory(const unsigned char *key, unsigned long keylen, 1115 const unsigned char *iv, unsigned long ivlen, 1116 const unsigned char *datain, unsigned long datalen, 1117 unsigned char *dataout); 1118 1119 #endif /* LTC_RABBIT */ 1120 1121 #ifdef LTC_RC4_STREAM 1122 1123 typedef struct { 1124 unsigned int x, y; 1125 unsigned char buf[256]; 1126 } rc4_state; 1127 1128 int rc4_stream_setup(rc4_state *st, const unsigned char *key, unsigned long keylen); 1129 int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1130 int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen); 1131 int rc4_stream_done(rc4_state *st); 1132 int rc4_stream_test(void); 1133 int rc4_stream_memory(const unsigned char *key, unsigned long keylen, 1134 const unsigned char *datain, unsigned long datalen, 1135 unsigned char *dataout); 1136 1137 #endif /* LTC_RC4_STREAM */ 1138 1139 #ifdef LTC_SOBER128_STREAM 1140 1141 typedef struct { 1142 ulong32 R[17], /* Working storage for the shift register */ 1143 initR[17], /* saved register contents */ 1144 konst, /* key dependent constant */ 1145 sbuf; /* partial word encryption buffer */ 1146 int nbuf; /* number of part-word stream bits buffered */ 1147 } sober128_state; 1148 1149 int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned long keylen); 1150 int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen); 1151 int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); 1152 int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen); 1153 int sober128_stream_done(sober128_state *st); 1154 int sober128_stream_test(void); 1155 int sober128_stream_memory(const unsigned char *key, unsigned long keylen, 1156 const unsigned char *iv, unsigned long ivlen, 1157 const unsigned char *datain, unsigned long datalen, 1158 unsigned char *dataout); 1159 1160 #endif /* LTC_SOBER128_STREAM */ 1161