blowfish.h

来自「关于SQL SERVER 的加密和解密包」· C头文件 代码 · 共 70 行

H
70
字号
/********** blowfish.h **********/

#ifndef ___BLOWFISH_H___
#define ___BLOWFISH_H___


#define NUM_SUBKEYS  18
#define NUM_S_BOXES  4
#define NUM_ENTRIES  256

#define MAX_STRING   256
#define MAX_PASSWD   56  // 448bits

// #define BIG_ENDIAN
#define LITTLE_ENDIAN


#ifdef BIG_ENDIAN
struct WordByte
{
	unsigned int zero:8;
	unsigned int one:8;
	unsigned int two:8;
	unsigned int three:8;
};
#endif

#ifdef LITTLE_ENDIAN
struct WordByte
{
	unsigned int three:8;
	unsigned int two:8;
	unsigned int one:8;
	unsigned int zero:8;
};
#endif

union Word
{
	unsigned int word;
	WordByte byte;
};

struct DWord
{
	Word word0;
	Word word1;
};


class Blowfish
{
private:
	unsigned int PA[NUM_SUBKEYS];
	unsigned int SB[NUM_S_BOXES][NUM_ENTRIES];

	void Gen_Subkeys(char *, unsigned long len);
	inline void BF_En(Word *,Word *);
	inline void BF_De(Word *,Word *);

public:
	Blowfish();

	void Reset();
	void Set_Passwd(char * = NULL, unsigned long len = 0);
	void Encrypt(void *,unsigned int);
	void Decrypt(void *,unsigned int);
};
#endif

⌨️ 快捷键说明

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