⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bc_tfish.h

📁 加密解密,安全工具!很有意思的代码
💻 H
字号:
#ifndef __BC_TWOFISH
#define __BC_TWOFISH

#include "bc_types.h"#define SERVICE_NAME	"BC_TFISH"
#define DISPLAY_NAME	"TWOFISH"
#define BLOCK_LENGTH	16#define ALGORITHM_ID	0xA0

#define DRIVER_MAJOR_VERSION	0
#define DRIVER_MINOR_VERSION	1

/* define LittleEndian for x86 platform */
#define LittleEndian 1

/* Twofish definitions */

#define		TF_BLOCK_SIZE		128	/* number of bits per block */
#define		MAX_ROUNDS		16
#define		MAX_KEY_BITS	256	/* max number of bits of key */

#define		INPUT_WHITEN	(TF_BLOCK_SIZE/32)
#define		OUTPUT_WHITEN	(TF_BLOCK_SIZE/32)
#define		ROUND_SUBKEYS	(INPUT_WHITEN + OUTPUT_WHITEN)
#define		TOTAL_SUBKEYS	(ROUND_SUBKEYS + 2*MAX_ROUNDS)

typedef struct KeyInstance_
{
	DWORD sboxKeys[MAX_KEY_BITS/64];/* key bits used for S-boxes */
	DWORD subKeys[TOTAL_SUBKEYS];	/* round subkeys, input/output whitening bits */
	DWORD sBox8x32[4][256];			/* fully expanded S-box */
} KeyInstance;


// Key length in bits - required for external definitions of 
// BestCrypt Algorithm modules
#define KEY_LENGTH          (MAX_KEY_BITS)
// We need to reserve space both for encryption and decryption keys (the data is in bits)
#define KEY_LENGTH_EXTENDED (sizeof(KeyInstance)*8)


/******* Exported functions *********/

#define IN

BOOL
KeyExtend( PUCHAR KeySource,
           PDWORD KeyDestination );

/* 
   Encryption and decryption in Cipher Block Chaining (CBC) mode
*/

VOID
Encrypt( DWORD *IVector, 
         DWORD *KeyAdress,
         DWORD *SrcBuffer,
         DWORD *DstBuffer,
         DWORD Length );    // in bytes

VOID
Decrypt( DWORD *IVector, 
         DWORD *KeyAdress,
         DWORD *SrcBuffer,
         DWORD *DstBuffer,
         DWORD Length );    // in bytes

/* 
   Declare Twofish encrypt and decrypt functions in Electronic 
   Code Book (ECB) mode for testing the implementation - not for using
   in the BestCrypt Encryption Algorithm Module
 */

BOOL
blockEncrypt( DWORD       *Block,
              KeyInstance *key );

BOOL
blockDecrypt( DWORD       *Block,
              KeyInstance *key );


/* 
   Encryption and decryption in 32-bit Cipher-Feedback (CFB) mode
*/
VOID
encrypt_CFB( DWORD *IVector, 
             DWORD *KeyAddress,
             DWORD *SrcBuffer,
             DWORD *DstBuffer,
             DWORD Length );    /* in bytes */

VOID
decrypt_CFB( DWORD *IVector, 
             DWORD *KeyAddress,
             DWORD *SrcBuffer,
             DWORD *DstBuffer,
             DWORD Length );    /* in bytes */

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -