blowfish.h

来自「C++实现的数字签名DSA算法」· C头文件 代码 · 共 50 行

H
50
字号
#ifndef CRYPTOPP_BLOWFISH_H
#define CRYPTOPP_BLOWFISH_H

/** \file */

#include "cryptlib.h"
#include "misc.h"

NAMESPACE_BEGIN(CryptoPP)

/// base class, do not use directly
class Blowfish : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 72>
{
public:
	Blowfish(const byte *key_string, unsigned int keylength, CipherDir direction);

	void ProcessBlock(byte * inoutBlock) const
		{Blowfish::ProcessBlock(inoutBlock, inoutBlock);}
	void ProcessBlock(const byte *inBlock, byte *outBlock) const;

	enum {ROUNDS=16};

private:
	void crypt_block(const word32 in[2], word32 out[2]) const;

	static const word32 p_init[ROUNDS+2];
	static const word32 s_init[4*256];
	SecBlock<word32> pbox, sbox;
};

/// <a href="http://www.weidai.com/scan-mirror/cs.html#Blowfish">Blowfish</a>
class BlowfishEncryption : public Blowfish
{
public:
	BlowfishEncryption(const byte *key_string, unsigned int keylength=DEFAULT_KEYLENGTH)
		: Blowfish(key_string, keylength, ENCRYPTION) {}
};

/// <a href="http://www.weidai.com/scan-mirror/cs.html#Blowfish">Blowfish</a>
class BlowfishDecryption : public Blowfish
{
public:
	BlowfishDecryption(const byte *key_string, unsigned int keylength=DEFAULT_KEYLENGTH)
		: Blowfish(key_string, keylength, DECRYPTION) {}
};

NAMESPACE_END

#endif

⌨️ 快捷键说明

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