📄 tomcrypt_cipher.h
字号:
/* ---- SYMMETRIC KEY STUFF ----- * * We put each of the ciphers scheduled keys in their own structs then we put all of * the key formats in one union. This makes the function prototypes easier to use. */#ifdef BLOWFISHstruct blowfish_key { ulong32 S[4][256]; ulong32 K[18];};#endif#ifdef RC5struct rc5_key { int rounds; ulong32 K[50];};#endif#ifdef RC6struct rc6_key { ulong32 K[44];};#endif#ifdef SAFERPstruct saferp_key { unsigned char K[33][16]; long rounds;};#endif#ifdef RIJNDAELstruct rijndael_key { ulong32 eK[60], dK[60]; int Nr;};#endif#ifdef XTEAstruct xtea_key { unsigned long A[32], B[32];};#endif#ifdef TWOFISH#ifndef TWOFISH_SMALL struct twofish_key { ulong32 S[4][256], K[40]; };#else struct twofish_key { ulong32 K[40]; unsigned char S[32], start; };#endif#endif#ifdef SAFER#define SAFER_K64_DEFAULT_NOF_ROUNDS 6#define SAFER_K128_DEFAULT_NOF_ROUNDS 10#define SAFER_SK64_DEFAULT_NOF_ROUNDS 8#define SAFER_SK128_DEFAULT_NOF_ROUNDS 10#define SAFER_MAX_NOF_ROUNDS 13#define SAFER_BLOCK_LEN 8#define SAFER_KEY_LEN (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS))typedef unsigned char safer_block_t[SAFER_BLOCK_LEN];typedef unsigned char safer_key_t[SAFER_KEY_LEN];struct safer_key { safer_key_t key; };#endif#ifdef RC2struct rc2_key { unsigned xkey[64]; };#endif#ifdef DESstruct des_key { ulong32 ek[32], dk[32];};struct des3_key { ulong32 ek[3][32], dk[3][32];};#endif#ifdef CAST5struct cast5_key { ulong32 K[32], keylen;};#endif#ifdef NOEKEONstruct noekeon_key { ulong32 K[4], dK[4];};#endif#ifdef SKIPJACK struct skipjack_key { unsigned char key[10];};#endif#ifdef KHAZADstruct khazad_key { ulong64 roundKeyEnc[8 + 1]; ulong64 roundKeyDec[8 + 1]; };#endif#ifdef ANUBISstruct anubis_key { int keyBits; int R; ulong32 roundKeyEnc[18 + 1][4]; ulong32 roundKeyDec[18 + 1][4]; }; #endiftypedef union Symmetric_key {#ifdef DES struct des_key des; struct des3_key des3;#endif#ifdef RC2 struct rc2_key rc2;#endif#ifdef SAFER struct safer_key safer;#endif#ifdef TWOFISH struct twofish_key twofish;#endif#ifdef BLOWFISH struct blowfish_key blowfish;#endif#ifdef RC5 struct rc5_key rc5;#endif#ifdef RC6 struct rc6_key rc6;#endif#ifdef SAFERP struct saferp_key saferp;#endif#ifdef RIJNDAEL struct rijndael_key rijndael;#endif#ifdef XTEA struct xtea_key xtea;#endif#ifdef CAST5 struct cast5_key cast5;#endif#ifdef NOEKEON struct noekeon_key noekeon;#endif #ifdef SKIPJACK struct skipjack_key skipjack;#endif#ifdef KHAZAD struct khazad_key khazad;#endif#ifdef ANUBIS struct anubis_key anubis;#endif void *data;} symmetric_key;/* A block cipher ECB structure */typedef struct { /** The index of the cipher chosen */ int cipher, /** The block size of the given cipher */ blocklen; /** The scheduled key */ symmetric_key key;} symmetric_ECB;/* A block cipher CFB structure */typedef struct { /** The index of the cipher chosen */ int cipher, /** The block size of the given cipher */ blocklen, /** The padding offset */ padlen; /** The current IV */ unsigned char IV[MAXBLOCKSIZE], /** The pad used to encrypt/decrypt */ pad[MAXBLOCKSIZE]; /** The scheduled key */ symmetric_key key;} symmetric_CFB;/* A block cipher OFB structure */typedef struct { /** The index of the cipher chosen */ int cipher, /** The block size of the given cipher */ blocklen, /** The padding offset */ padlen; /** The current IV */ unsigned char IV[MAXBLOCKSIZE]; /** The scheduled key */ symmetric_key key;} symmetric_OFB;/* A block cipher CBC structure */typedef struct { /** The index of the cipher chosen */ int cipher, /** The block size of the given cipher */ blocklen; /** The current IV */ unsigned char IV[MAXBLOCKSIZE]; /** The scheduled key */ symmetric_key key;} symmetric_CBC;/* A block cipher CTR structure */typedef struct { /** The index of the cipher chosen */ int cipher, /** The block size of the given cipher */ blocklen, /** The padding offset */ padlen, /** The mode (endianess) of the CTR, 0==little, 1==big */ mode; /** The counter */ unsigned char ctr[MAXBLOCKSIZE], /** The pad used to encrypt/decrypt */ pad[MAXBLOCKSIZE]; /** The scheduled key */ symmetric_key key;} symmetric_CTR;/* cipher descriptor table, last entry has "name == NULL" to mark the end of table */extern struct ltc_cipher_descriptor { /** name of cipher */ char *name; /** internal ID */ unsigned char ID; /** min keysize (octets) */ int min_key_length, /** max keysize (octets) */ max_key_length, /** block size (octets) */ block_length, /** default number of rounds */ default_rounds; /** Setup the cipher @param key The input symmetric key @param keylen The length of the input key (octets) @param num_rounds The requested number of rounds (0==default) @param skey [out] The destination of the scheduled key @return CRYPT_OK if successful */ int (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); /** Encrypt a block @param pt The plaintext @param ct [out] The ciphertext @param skey The scheduled key */ void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); /** Decrypt a block @param ct The ciphertext @param pt [out] The plaintext @param skey The scheduled key */ void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); /** Test the block cipher @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled */ int (*test)(void); /** Terminate the context @param skey The scheduled key */ void (*done)(symmetric_key *skey); /** Determine a key size @param keysize [in/out] The size of the key desired and the suggested size @return CRYPT_OK if successful */ int (*keysize)(int *keysize);/** Accelerators **/ /** Accelerated ECB encryption @param pt Plaintext @param ct Ciphertext @param blocks The number of complete blocks to process @param skey The scheduled key context */ void (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey); /** Accelerated ECB decryption @param pt Plaintext @param ct Ciphertext @param blocks The number of complete blocks to process @param skey The scheduled key context */ void (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey); /** Accelerated CBC encryption @param pt Plaintext @param ct Ciphertext @param blocks The number of complete blocks to process @param IV The initial value (input/output) @param skey The scheduled key context */ void (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -