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

📄 bc_cast.h

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


#define SERVICE_NAME	"BC_CAST"
#define DISPLAY_NAME    "CAST"
#define ALGORITHM_ID     0xE0

#define DRIVER_MAJOR_VERSION	0
#define DRIVER_MINOR_VERSION	1

//#define BLOCK_SIZE 8
#define BLOCK_LENGTH 8
/* The CAST algorithm allows to define a variable key size.
   The following key sizes (in bytes) are possible:
   5,6,7,8,9,10,11,12,13,14,15,16
 */
#define CAST_DEFAULT_KEYSIZE_BYTES   16

#define CAST_MINIMUM_KEYSIZE_BYTES   5
#define CAST_MAXIMUM_KEYSIZE_BYTES   16

#define CAST_MAXIMUM_KEYSIZE_DWORD (CAST_MAXIMUM_KEYSIZE_BYTES / sizeof(DWORD))

/* The CAST algorithm uses 12 or 16 rounds depending on the key size used */
#define CAST_MAX_NUMBER_OF_ROUNDS    16

/* 1) For key sizes up to and including 10 bytes (i.e., 5, 6, 7, 8,
      9, and 10 bytes), the algorithm is exactly as specified in the 
	  algorithm description, but uses 12 rounds instead of 16;

   2) For key sizes greater than 10 bytes, the algorithm uses the full 16
      rounds;

   The following KEYSIZE values are in bytes.
*/
#define MAX_KEYSIZE_FOR_12_ROUNDS    10
#define MIN_KEYSIZE_FOR_16_ROUNDS    11

/* CastData structure describes a place in memory for expanded CAST key.
   The make16rounds field is necessary to define a correct number of rounds
   (12 or 16) during encrypt/decrypt operations.
 */
typedef struct CastData_ {
    DWORD subKeys[CAST_MAX_NUMBER_OF_ROUNDS*2];
    BOOL make16rounds;
} CastData;


// Key length in bites - required for external definitions of 
// BestCrypt Algorithm modules
#define KEY_LENGTH          (CAST_MAXIMUM_KEYSIZE_BYTES * 8)

// We need to reserve space for extended key
#define KEY_LENGTH_EXTENDED (sizeof(CastData) * 8)


// Exported functions

BOOL
KeyExtend(  BYTE  *KeySource,         // 8-bit  uchars
            DWORD *KeyDestination );  // 32-bit dwords

//	CastECB() does encrypting (encrypt==TRUE) or
//	decrypting (encrypt==FALSE) for a block of data the size of
//	cipher block (BLOCK_SIZE, given in bytes).
BOOL 
CastECB( BYTE  *InBlock, 
         BYTE  *OutBlock,
         DWORD *ExtKey,
         BOOL  Encrypt);

/* Encryption and decryption in CBC mode */

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

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


#endif /* __CAST_H__ */

⌨️ 快捷键说明

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