Path: blob/master/libs/tomcrypt/src/headers/tomcrypt_cipher.h
5971 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/89/* ---- SYMMETRIC KEY STUFF -----10*11* We put each of the ciphers scheduled keys in their own structs then we put all of12* the key formats in one union. This makes the function prototypes easier to use.13*/14#ifdef LTC_BLOWFISH15struct blowfish_key {16ulong32 S[4][256];17ulong32 K[18];18};19#endif2021#ifdef LTC_RC522struct rc5_key {23int rounds;24ulong32 K[50];25};26#endif2728#ifdef LTC_RC629struct rc6_key {30ulong32 K[44];31};32#endif3334#ifdef LTC_SAFERP35struct saferp_key {36unsigned char K[33][16];37long rounds;38};39#endif4041#ifdef LTC_RIJNDAEL42struct rijndael_key {43ulong32 eK[60], dK[60];44int Nr;45};46#endif4748#ifdef LTC_KSEED49struct kseed_key {50ulong32 K[32], dK[32];51};52#endif5354#ifdef LTC_KASUMI55struct kasumi_key {56ulong32 KLi1[8], KLi2[8],57KOi1[8], KOi2[8], KOi3[8],58KIi1[8], KIi2[8], KIi3[8];59};60#endif6162#ifdef LTC_XTEA63struct xtea_key {64unsigned long A[32], B[32];65};66#endif6768#ifdef LTC_TWOFISH69#ifndef LTC_TWOFISH_SMALL70struct twofish_key {71ulong32 S[4][256], K[40];72};73#else74struct twofish_key {75ulong32 K[40];76unsigned char S[32], start;77};78#endif79#endif8081#ifdef LTC_SAFER82#define LTC_SAFER_K64_DEFAULT_NOF_ROUNDS 683#define LTC_SAFER_K128_DEFAULT_NOF_ROUNDS 1084#define LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS 885#define LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS 1086#define LTC_SAFER_MAX_NOF_ROUNDS 1387#define LTC_SAFER_BLOCK_LEN 888#define LTC_SAFER_KEY_LEN (1 + LTC_SAFER_BLOCK_LEN * (1 + 2 * LTC_SAFER_MAX_NOF_ROUNDS))89typedef unsigned char safer_block_t[LTC_SAFER_BLOCK_LEN];90typedef unsigned char safer_key_t[LTC_SAFER_KEY_LEN];91struct safer_key { safer_key_t key; };92#endif9394#ifdef LTC_RC295struct rc2_key { unsigned xkey[64]; };96#endif9798#ifdef LTC_DES99struct des_key {100ulong32 ek[32], dk[32];101};102103struct des3_key {104ulong32 ek[3][32], dk[3][32];105};106#endif107108#ifdef LTC_CAST5109struct cast5_key {110ulong32 K[32], keylen;111};112#endif113114#ifdef LTC_NOEKEON115struct noekeon_key {116ulong32 K[4], dK[4];117};118#endif119120#ifdef LTC_SKIPJACK121struct skipjack_key {122unsigned char key[10];123};124#endif125126#ifdef LTC_KHAZAD127struct khazad_key {128ulong64 roundKeyEnc[8 + 1];129ulong64 roundKeyDec[8 + 1];130};131#endif132133#ifdef LTC_ANUBIS134struct anubis_key {135int keyBits;136int R;137ulong32 roundKeyEnc[18 + 1][4];138ulong32 roundKeyDec[18 + 1][4];139};140#endif141142#ifdef LTC_MULTI2143struct multi2_key {144int N;145ulong32 uk[8];146};147#endif148149#ifdef LTC_CAMELLIA150struct camellia_key {151int R;152ulong64 kw[4], k[24], kl[6];153};154#endif155156typedef union Symmetric_key {157#ifdef LTC_DES158struct des_key des;159struct des3_key des3;160#endif161#ifdef LTC_RC2162struct rc2_key rc2;163#endif164#ifdef LTC_SAFER165struct safer_key safer;166#endif167#ifdef LTC_TWOFISH168struct twofish_key twofish;169#endif170#ifdef LTC_BLOWFISH171struct blowfish_key blowfish;172#endif173#ifdef LTC_RC5174struct rc5_key rc5;175#endif176#ifdef LTC_RC6177struct rc6_key rc6;178#endif179#ifdef LTC_SAFERP180struct saferp_key saferp;181#endif182#ifdef LTC_RIJNDAEL183struct rijndael_key rijndael;184#endif185#ifdef LTC_XTEA186struct xtea_key xtea;187#endif188#ifdef LTC_CAST5189struct cast5_key cast5;190#endif191#ifdef LTC_NOEKEON192struct noekeon_key noekeon;193#endif194#ifdef LTC_SKIPJACK195struct skipjack_key skipjack;196#endif197#ifdef LTC_KHAZAD198struct khazad_key khazad;199#endif200#ifdef LTC_ANUBIS201struct anubis_key anubis;202#endif203#ifdef LTC_KSEED204struct kseed_key kseed;205#endif206#ifdef LTC_KASUMI207struct kasumi_key kasumi;208#endif209#ifdef LTC_MULTI2210struct multi2_key multi2;211#endif212#ifdef LTC_CAMELLIA213struct camellia_key camellia;214#endif215void *data;216} symmetric_key;217218#ifdef LTC_ECB_MODE219/** A block cipher ECB structure */220typedef struct {221/** The index of the cipher chosen */222int cipher,223/** The block size of the given cipher */224blocklen;225/** The scheduled key */226symmetric_key key;227} symmetric_ECB;228#endif229230#ifdef LTC_CFB_MODE231/** A block cipher CFB structure */232typedef struct {233/** The index of the cipher chosen */234int cipher,235/** The block size of the given cipher */236blocklen,237/** The padding offset */238padlen;239/** The current IV */240unsigned char IV[MAXBLOCKSIZE],241/** The pad used to encrypt/decrypt */242pad[MAXBLOCKSIZE];243/** The scheduled key */244symmetric_key key;245} symmetric_CFB;246#endif247248#ifdef LTC_OFB_MODE249/** A block cipher OFB structure */250typedef struct {251/** The index of the cipher chosen */252int cipher,253/** The block size of the given cipher */254blocklen,255/** The padding offset */256padlen;257/** The current IV */258unsigned char IV[MAXBLOCKSIZE];259/** The scheduled key */260symmetric_key key;261} symmetric_OFB;262#endif263264#ifdef LTC_CBC_MODE265/** A block cipher CBC structure */266typedef struct {267/** The index of the cipher chosen */268int cipher,269/** The block size of the given cipher */270blocklen;271/** The current IV */272unsigned char IV[MAXBLOCKSIZE];273/** The scheduled key */274symmetric_key key;275} symmetric_CBC;276#endif277278279#ifdef LTC_CTR_MODE280/** A block cipher CTR structure */281typedef struct {282/** The index of the cipher chosen */283int cipher,284/** The block size of the given cipher */285blocklen,286/** The padding offset */287padlen,288/** The mode (endianess) of the CTR, 0==little, 1==big */289mode,290/** counter width */291ctrlen;292293/** The counter */294unsigned char ctr[MAXBLOCKSIZE],295/** The pad used to encrypt/decrypt */296pad[MAXBLOCKSIZE];297/** The scheduled key */298symmetric_key key;299} symmetric_CTR;300#endif301302303#ifdef LTC_LRW_MODE304/** A LRW structure */305typedef struct {306/** The index of the cipher chosen (must be a 128-bit block cipher) */307int cipher;308309/** The current IV */310unsigned char IV[16],311312/** the tweak key */313tweak[16],314315/** The current pad, it's the product of the first 15 bytes against the tweak key */316pad[16];317318/** The scheduled symmetric key */319symmetric_key key;320321#ifdef LTC_LRW_TABLES322/** The pre-computed multiplication table */323unsigned char PC[16][256][16];324#endif325} symmetric_LRW;326#endif327328#ifdef LTC_F8_MODE329/** A block cipher F8 structure */330typedef struct {331/** The index of the cipher chosen */332int cipher,333/** The block size of the given cipher */334blocklen,335/** The padding offset */336padlen;337/** The current IV */338unsigned char IV[MAXBLOCKSIZE],339MIV[MAXBLOCKSIZE];340/** Current block count */341ulong32 blockcnt;342/** The scheduled key */343symmetric_key key;344} symmetric_F8;345#endif346347348/** cipher descriptor table, last entry has "name == NULL" to mark the end of table */349extern struct ltc_cipher_descriptor {350/** name of cipher */351const char *name;352/** internal ID */353unsigned char ID;354/** min keysize (octets) */355int min_key_length,356/** max keysize (octets) */357max_key_length,358/** block size (octets) */359block_length,360/** default number of rounds */361default_rounds;362/** Setup the cipher363@param key The input symmetric key364@param keylen The length of the input key (octets)365@param num_rounds The requested number of rounds (0==default)366@param skey [out] The destination of the scheduled key367@return CRYPT_OK if successful368*/369int (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);370/** Encrypt a block371@param pt The plaintext372@param ct [out] The ciphertext373@param skey The scheduled key374@return CRYPT_OK if successful375*/376int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);377/** Decrypt a block378@param ct The ciphertext379@param pt [out] The plaintext380@param skey The scheduled key381@return CRYPT_OK if successful382*/383int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);384/** Test the block cipher385@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled386*/387int (*test)(void);388389/** Terminate the context390@param skey The scheduled key391*/392void (*done)(symmetric_key *skey);393394/** Determine a key size395@param keysize [in/out] The size of the key desired and the suggested size396@return CRYPT_OK if successful397*/398int (*keysize)(int *keysize);399400/** Accelerators **/401/** Accelerated ECB encryption402@param pt Plaintext403@param ct Ciphertext404@param blocks The number of complete blocks to process405@param skey The scheduled key context406@return CRYPT_OK if successful407*/408int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);409410/** Accelerated ECB decryption411@param pt Plaintext412@param ct Ciphertext413@param blocks The number of complete blocks to process414@param skey The scheduled key context415@return CRYPT_OK if successful416*/417int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);418419/** Accelerated CBC encryption420@param pt Plaintext421@param ct Ciphertext422@param blocks The number of complete blocks to process423@param IV The initial value (input/output)424@param skey The scheduled key context425@return CRYPT_OK if successful426*/427int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);428429/** Accelerated CBC decryption430@param pt Plaintext431@param ct Ciphertext432@param blocks The number of complete blocks to process433@param IV The initial value (input/output)434@param skey The scheduled key context435@return CRYPT_OK if successful436*/437int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);438439/** Accelerated CTR encryption440@param pt Plaintext441@param ct Ciphertext442@param blocks The number of complete blocks to process443@param IV The initial value (input/output)444@param mode little or big endian counter (mode=0 or mode=1)445@param skey The scheduled key context446@return CRYPT_OK if successful447*/448int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);449450/** Accelerated LRW451@param pt Plaintext452@param ct Ciphertext453@param blocks The number of complete blocks to process454@param IV The initial value (input/output)455@param tweak The LRW tweak456@param skey The scheduled key context457@return CRYPT_OK if successful458*/459int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);460461/** Accelerated LRW462@param ct Ciphertext463@param pt Plaintext464@param blocks The number of complete blocks to process465@param IV The initial value (input/output)466@param tweak The LRW tweak467@param skey The scheduled key context468@return CRYPT_OK if successful469*/470int (*accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);471472/** Accelerated CCM packet (one-shot)473@param key The secret key to use474@param keylen The length of the secret key (octets)475@param uskey A previously scheduled key [optional can be NULL]476@param nonce The session nonce [use once]477@param noncelen The length of the nonce478@param header The header for the session479@param headerlen The length of the header (octets)480@param pt [out] The plaintext481@param ptlen The length of the plaintext (octets)482@param ct [out] The ciphertext483@param tag [out] The destination tag484@param taglen [in/out] The max size and resulting size of the authentication tag485@param direction Encrypt or Decrypt direction (0 or 1)486@return CRYPT_OK if successful487*/488int (*accel_ccm_memory)(489const unsigned char *key, unsigned long keylen,490symmetric_key *uskey,491const unsigned char *nonce, unsigned long noncelen,492const unsigned char *header, unsigned long headerlen,493unsigned char *pt, unsigned long ptlen,494unsigned char *ct,495unsigned char *tag, unsigned long *taglen,496int direction);497498/** Accelerated GCM packet (one shot)499@param key The secret key500@param keylen The length of the secret key501@param IV The initialization vector502@param IVlen The length of the initialization vector503@param adata The additional authentication data (header)504@param adatalen The length of the adata505@param pt The plaintext506@param ptlen The length of the plaintext (ciphertext length is the same)507@param ct The ciphertext508@param tag [out] The MAC tag509@param taglen [in/out] The MAC tag length510@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)511@return CRYPT_OK on success512*/513int (*accel_gcm_memory)(514const unsigned char *key, unsigned long keylen,515const unsigned char *IV, unsigned long IVlen,516const unsigned char *adata, unsigned long adatalen,517unsigned char *pt, unsigned long ptlen,518unsigned char *ct,519unsigned char *tag, unsigned long *taglen,520int direction);521522/** Accelerated one shot LTC_OMAC523@param key The secret key524@param keylen The key length (octets)525@param in The message526@param inlen Length of message (octets)527@param out [out] Destination for tag528@param outlen [in/out] Initial and final size of out529@return CRYPT_OK on success530*/531int (*omac_memory)(532const unsigned char *key, unsigned long keylen,533const unsigned char *in, unsigned long inlen,534unsigned char *out, unsigned long *outlen);535536/** Accelerated one shot XCBC537@param key The secret key538@param keylen The key length (octets)539@param in The message540@param inlen Length of message (octets)541@param out [out] Destination for tag542@param outlen [in/out] Initial and final size of out543@return CRYPT_OK on success544*/545int (*xcbc_memory)(546const unsigned char *key, unsigned long keylen,547const unsigned char *in, unsigned long inlen,548unsigned char *out, unsigned long *outlen);549550/** Accelerated one shot F9551@param key The secret key552@param keylen The key length (octets)553@param in The message554@param inlen Length of message (octets)555@param out [out] Destination for tag556@param outlen [in/out] Initial and final size of out557@return CRYPT_OK on success558@remark Requires manual padding559*/560int (*f9_memory)(561const unsigned char *key, unsigned long keylen,562const unsigned char *in, unsigned long inlen,563unsigned char *out, unsigned long *outlen);564565/** Accelerated XTS encryption566@param pt Plaintext567@param ct Ciphertext568@param blocks The number of complete blocks to process569@param tweak The 128-bit encryption tweak (input/output).570The tweak should not be encrypted on input, but571next tweak will be copied encrypted on output.572@param skey1 The first scheduled key context573@param skey2 The second scheduled key context574@return CRYPT_OK if successful575*/576int (*accel_xts_encrypt)(const unsigned char *pt, unsigned char *ct,577unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,578symmetric_key *skey2);579580/** Accelerated XTS decryption581@param ct Ciphertext582@param pt Plaintext583@param blocks The number of complete blocks to process584@param tweak The 128-bit encryption tweak (input/output).585The tweak should not be encrypted on input, but586next tweak will be copied encrypted on output.587@param skey1 The first scheduled key context588@param skey2 The second scheduled key context589@return CRYPT_OK if successful590*/591int (*accel_xts_decrypt)(const unsigned char *ct, unsigned char *pt,592unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,593symmetric_key *skey2);594} cipher_descriptor[];595596#ifdef LTC_BLOWFISH597int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);598int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);599int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);600int blowfish_test(void);601void blowfish_done(symmetric_key *skey);602int blowfish_keysize(int *keysize);603extern const struct ltc_cipher_descriptor blowfish_desc;604#endif605606#ifdef LTC_RC5607int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);608int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);609int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);610int rc5_test(void);611void rc5_done(symmetric_key *skey);612int rc5_keysize(int *keysize);613extern const struct ltc_cipher_descriptor rc5_desc;614#endif615616#ifdef LTC_RC6617int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);618int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);619int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);620int rc6_test(void);621void rc6_done(symmetric_key *skey);622int rc6_keysize(int *keysize);623extern const struct ltc_cipher_descriptor rc6_desc;624#endif625626#ifdef LTC_RC2627int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);628int rc2_setup_ex(const unsigned char *key, int keylen, int bits, int num_rounds, symmetric_key *skey);629int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);630int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);631int rc2_test(void);632void rc2_done(symmetric_key *skey);633int rc2_keysize(int *keysize);634extern const struct ltc_cipher_descriptor rc2_desc;635#endif636637#ifdef LTC_SAFERP638int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);639int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);640int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);641int saferp_test(void);642void saferp_done(symmetric_key *skey);643int saferp_keysize(int *keysize);644extern const struct ltc_cipher_descriptor saferp_desc;645#endif646647#ifdef LTC_SAFER648int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);649int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);650int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);651int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);652int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);653int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);654int safer_k64_test(void);655int safer_sk64_test(void);656int safer_sk128_test(void);657void safer_done(symmetric_key *skey);658int safer_64_keysize(int *keysize);659int safer_128_keysize(int *keysize);660extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;661#endif662663#ifdef LTC_RIJNDAEL664665/* make aes an alias */666#define aes_setup rijndael_setup667#define aes_ecb_encrypt rijndael_ecb_encrypt668#define aes_ecb_decrypt rijndael_ecb_decrypt669#define aes_test rijndael_test670#define aes_done rijndael_done671#define aes_keysize rijndael_keysize672673#define aes_enc_setup rijndael_enc_setup674#define aes_enc_ecb_encrypt rijndael_enc_ecb_encrypt675#define aes_enc_keysize rijndael_enc_keysize676677int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);678int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);679int rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);680int rijndael_test(void);681void rijndael_done(symmetric_key *skey);682int rijndael_keysize(int *keysize);683int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);684int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);685void rijndael_enc_done(symmetric_key *skey);686int rijndael_enc_keysize(int *keysize);687extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;688extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;689#endif690691#ifdef LTC_XTEA692int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);693int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);694int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);695int xtea_test(void);696void xtea_done(symmetric_key *skey);697int xtea_keysize(int *keysize);698extern const struct ltc_cipher_descriptor xtea_desc;699#endif700701#ifdef LTC_TWOFISH702int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);703int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);704int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);705int twofish_test(void);706void twofish_done(symmetric_key *skey);707int twofish_keysize(int *keysize);708extern const struct ltc_cipher_descriptor twofish_desc;709#endif710711#ifdef LTC_DES712int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);713int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);714int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);715int des_test(void);716void des_done(symmetric_key *skey);717int des_keysize(int *keysize);718int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);719int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);720int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);721int des3_test(void);722void des3_done(symmetric_key *skey);723int des3_keysize(int *keysize);724extern const struct ltc_cipher_descriptor des_desc, des3_desc;725#endif726727#ifdef LTC_CAST5728int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);729int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);730int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);731int cast5_test(void);732void cast5_done(symmetric_key *skey);733int cast5_keysize(int *keysize);734extern const struct ltc_cipher_descriptor cast5_desc;735#endif736737#ifdef LTC_NOEKEON738int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);739int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);740int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);741int noekeon_test(void);742void noekeon_done(symmetric_key *skey);743int noekeon_keysize(int *keysize);744extern const struct ltc_cipher_descriptor noekeon_desc;745#endif746747#ifdef LTC_SKIPJACK748int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);749int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);750int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);751int skipjack_test(void);752void skipjack_done(symmetric_key *skey);753int skipjack_keysize(int *keysize);754extern const struct ltc_cipher_descriptor skipjack_desc;755#endif756757#ifdef LTC_KHAZAD758int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);759int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);760int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);761int khazad_test(void);762void khazad_done(symmetric_key *skey);763int khazad_keysize(int *keysize);764extern const struct ltc_cipher_descriptor khazad_desc;765#endif766767#ifdef LTC_ANUBIS768int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);769int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);770int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);771int anubis_test(void);772void anubis_done(symmetric_key *skey);773int anubis_keysize(int *keysize);774extern const struct ltc_cipher_descriptor anubis_desc;775#endif776777#ifdef LTC_KSEED778int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);779int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);780int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);781int kseed_test(void);782void kseed_done(symmetric_key *skey);783int kseed_keysize(int *keysize);784extern const struct ltc_cipher_descriptor kseed_desc;785#endif786787#ifdef LTC_KASUMI788int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);789int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);790int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);791int kasumi_test(void);792void kasumi_done(symmetric_key *skey);793int kasumi_keysize(int *keysize);794extern const struct ltc_cipher_descriptor kasumi_desc;795#endif796797798#ifdef LTC_MULTI2799int multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);800int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);801int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);802int multi2_test(void);803void multi2_done(symmetric_key *skey);804int multi2_keysize(int *keysize);805extern const struct ltc_cipher_descriptor multi2_desc;806#endif807808#ifdef LTC_CAMELLIA809int camellia_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);810int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);811int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);812int camellia_test(void);813void camellia_done(symmetric_key *skey);814int camellia_keysize(int *keysize);815extern const struct ltc_cipher_descriptor camellia_desc;816#endif817818#ifdef LTC_ECB_MODE819int ecb_start(int cipher, const unsigned char *key,820int keylen, int num_rounds, symmetric_ECB *ecb);821int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);822int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);823int ecb_done(symmetric_ECB *ecb);824#endif825826#ifdef LTC_CFB_MODE827int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,828int keylen, int num_rounds, symmetric_CFB *cfb);829int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);830int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);831int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);832int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);833int cfb_done(symmetric_CFB *cfb);834#endif835836#ifdef LTC_OFB_MODE837int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,838int keylen, int num_rounds, symmetric_OFB *ofb);839int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);840int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);841int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);842int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);843int ofb_done(symmetric_OFB *ofb);844#endif845846#ifdef LTC_CBC_MODE847int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,848int keylen, int num_rounds, symmetric_CBC *cbc);849int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);850int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);851int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);852int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);853int cbc_done(symmetric_CBC *cbc);854#endif855856#ifdef LTC_CTR_MODE857858#define CTR_COUNTER_LITTLE_ENDIAN 0x0000859#define CTR_COUNTER_BIG_ENDIAN 0x1000860#define LTC_CTR_RFC3686 0x2000861862int ctr_start( int cipher,863const unsigned char *IV,864const unsigned char *key, int keylen,865int num_rounds, int ctr_mode,866symmetric_CTR *ctr);867int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);868int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);869int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);870int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);871int ctr_done(symmetric_CTR *ctr);872int ctr_test(void);873#endif874875#ifdef LTC_LRW_MODE876877#define LRW_ENCRYPT LTC_ENCRYPT878#define LRW_DECRYPT LTC_DECRYPT879880int lrw_start( int cipher,881const unsigned char *IV,882const unsigned char *key, int keylen,883const unsigned char *tweak,884int num_rounds,885symmetric_LRW *lrw);886int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);887int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);888int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);889int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);890int lrw_done(symmetric_LRW *lrw);891int lrw_test(void);892893/* don't call */894int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);895#endif896897#ifdef LTC_F8_MODE898int f8_start( int cipher, const unsigned char *IV,899const unsigned char *key, int keylen,900const unsigned char *salt_key, int skeylen,901int num_rounds, symmetric_F8 *f8);902int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);903int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);904int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);905int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);906int f8_done(symmetric_F8 *f8);907int f8_test_mode(void);908#endif909910#ifdef LTC_XTS_MODE911typedef struct {912symmetric_key key1, key2;913int cipher;914} symmetric_xts;915916int xts_start( int cipher,917const unsigned char *key1,918const unsigned char *key2,919unsigned long keylen,920int num_rounds,921symmetric_xts *xts);922923int xts_encrypt(924const unsigned char *pt, unsigned long ptlen,925unsigned char *ct,926unsigned char *tweak,927symmetric_xts *xts);928int xts_decrypt(929const unsigned char *ct, unsigned long ptlen,930unsigned char *pt,931unsigned char *tweak,932symmetric_xts *xts);933934void xts_done(symmetric_xts *xts);935int xts_test(void);936void xts_mult_x(unsigned char *I);937#endif938939int find_cipher(const char *name);940int find_cipher_any(const char *name, int blocklen, int keylen);941int find_cipher_id(unsigned char ID);942int register_cipher(const struct ltc_cipher_descriptor *cipher);943int unregister_cipher(const struct ltc_cipher_descriptor *cipher);944int register_all_ciphers(void);945int cipher_is_valid(int idx);946947LTC_MUTEX_PROTO(ltc_cipher_mutex)948949/* ---- stream ciphers ---- */950951#ifdef LTC_CHACHA952953typedef struct {954ulong32 input[16];955unsigned char kstream[64];956unsigned long ksleft;957unsigned long ivlen;958int rounds;959} chacha_state;960961int chacha_setup(chacha_state *st, const unsigned char *key, unsigned long keylen, int rounds);962int chacha_ivctr32(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong32 counter);963int chacha_ivctr64(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter);964int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);965int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen);966int chacha_done(chacha_state *st);967int chacha_test(void);968969#endif /* LTC_CHACHA */970971#ifdef LTC_RC4_STREAM972973typedef struct {974unsigned int x, y;975unsigned char buf[256];976} rc4_state;977978int rc4_stream_setup(rc4_state *st, const unsigned char *key, unsigned long keylen);979int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);980int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen);981int rc4_stream_done(rc4_state *st);982int rc4_stream_test(void);983984#endif /* LTC_RC4_STREAM */985986#ifdef LTC_SOBER128_STREAM987988typedef struct {989ulong32 R[17], /* Working storage for the shift register */990initR[17], /* saved register contents */991konst, /* key dependent constant */992sbuf; /* partial word encryption buffer */993int nbuf; /* number of part-word stream bits buffered */994} sober128_state;995996int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned long keylen);997int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen);998int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);999int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen);1000int sober128_stream_done(sober128_state *st);1001int sober128_stream_test(void);10021003#endif /* LTC_SOBER128_STREAM */100410051006