www.pudn.com > IPMSNv2.06.rar > BLOWFISH.H, change:2008-02-22,size:1932b


// blowfish.h    gaoguangtao 2008-2050 interface file for blowfish.cpp 
/* ======================================================================== 
	Project  Name			: IP Messenger for Win32 
	Module Name				: blowfish 
	Create					: 2008-02-20(Sat) 
    Update					: 2008-02-14(Wed) 
	Copyright				: gaoguangtao 
	Reference				:  
	======================================================================== */ 
#define MAXKEYBYTES		56		// 448 bits max 
#define NPASS			16		// SBox passes 
 
#define DWORD	unsigned long 
#define WORD	unsigned short 
#define BYTE	unsigned char 
 
#define BF_ECB		0x0001 
#define BF_CBC		0x0002 
//#define BF_OFB		0x0004 
//#define BF_CFB		0x0008 
//#define BF_PKCS2	0x0010 
#define BF_PKCS5	0x0020 
#define BF_BLKSIZE	8 
 
#define ALIGN_SIZE(size, align_size) ((((size) + (align_size) -1) / (align_size)) * (align_size)) 
 
class CBlowFish 
{ 
private: 
	DWORD	*PArray; 
	DWORD	(*SBoxes)[256]; 
	void	Blowfish_encipher(DWORD *xl, DWORD *xr); 
	void	Blowfish_decipher(DWORD *xl, DWORD *xr); 
 
public: 
			CBlowFish(const BYTE *key=NULL, int keybytes=0); 
			~CBlowFish(); 
	void	Initialize(const BYTE *key, int keybytes); 
	DWORD	GetOutputLength(DWORD lInputLong, int mode); 
	DWORD	Encrypt(const BYTE *pInput, BYTE *pOutput, DWORD lSize, int mode=BF_CBC|BF_PKCS5, _int64 IV=0); 
	DWORD	Decrypt(const BYTE *pInput, BYTE *pOutput, DWORD lSize, int mode=BF_CBC|BF_PKCS5, _int64 IV=0); 
}; 
 
// choose a byte order for your hardware 
#define ORDER_DCBA	// chosing Intel in this case 
 
union aword { 
	DWORD	dword; 
	BYTE	byte[4]; 
	struct { 
#ifdef ORDER_ABCD  	// ABCD - big endian - motorola 
		BYTE byte0; 
		BYTE byte1; 
		BYTE byte2; 
		BYTE byte3; 
#endif 
#ifdef ORDER_DCBA  	// DCBA - little endian - intel 
		BYTE byte3; 
		BYTE byte2; 
		BYTE byte1; 
		BYTE byte0; 
#endif 
#ifdef ORDER_BADC  	// BADC - vax 
		BYTE byte1; 
		BYTE byte0; 
		BYTE byte3; 
		BYTE byte2; 
#endif 
	} w; 
};