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

📄 ctwofishcipher.h

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 H
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CTwofishCipher.h,v 1.4 2002/08/06 20:10:19 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CTwofishCipher_h	// [
#define Included_CTwofishCipher_h

#include "CCipher.h"
#include "CSecureObject.h"

extern "C"
{
	#undef CONST
	#include "TwofishAES.h"
}

_PGP_BEGIN

// Class CTwofishCipher

class CTwofishCipher : public CCipher
{
public:
	enum 
	{
		kNumKeyBits			= 256, 
		kNumKeyBytes		= kNumKeyBits / 8, 
		kNumEncryptBytes	= 16, 
		kNumDecryptBytes	= 16, 
		kNumSaltBytes		= 16, 
		kNumIvsNeeded		= 8
	};

private:
	enum
	{
		ValidationCRC	= 0x193AFD79
	};

	struct KeyInfo
	{
		Crypto::SymmetricKey	key;
		Crypto::PassphraseSalt	salt;

		keyInstance	keyInstance;
	};

	struct ExportedCipher
	{
		Crypto::SymmetricKey	key;
		Crypto::PassphraseSalt	salt;
	};

public:
	CTwofishCipher(PGPdiskEncryptionAlgorithm algorithm);
	~CTwofishCipher() { }

	PGPBoolean	IsKeyAttached() const {return mIsKeyAttached;}

	const Crypto::SymmetricKey&		Key() const {return mPCurKeyInfo->key;}
	const Crypto::PassphraseSalt&	Salt() const {return mPCurKeyInfo->salt;}

	PGPUInt32	SizeExportedCipher() const {return sizeof(ExportedCipher);}
	PGPUInt16	NumKeyBits() const {return kNumKeyBits;}
	PGPUInt16	NumKeyBytes() const {return kNumKeyBytes;}
	PGPUInt16	NumEncryptBytes() const {return kNumEncryptBytes;}
	PGPUInt16	NumDecryptBytes() const {return kNumDecryptBytes;}
	PGPUInt16	NumSaltBytes() const {return kNumSaltBytes;}
	PGPUInt16	NumIvsNeeded() const {return kNumIvsNeeded;}

	SMART_ERROR	Validate() const;

	void	AttachKey(const Crypto::SymmetricKey& key, 
		const Crypto::PassphraseSalt& salt);
	void	FlipKeyBytes();

	void	Encrypt(const void *in, void *out, PGPUInt32 numBlocks = 1) const;
	void	Decrypt(const void *in, void *out, PGPUInt32 numBlocks = 1) const;

	void	EncryptCFBdbl(PGPUInt32 ivs[], const PGPUInt32 *src, 
		PGPUInt32 *dest, PGPUInt32 len) const;
	void	DecryptCFBdbl(PGPUInt32 ivs[], const PGPUInt32 *src, 
		PGPUInt32 *dest, PGPUInt32 len) const;

	SMART_ERROR	ExportCipher(void *buffer, PGPUInt32 sizeBuffer) const;
	SMART_ERROR	ImportCipher(const void *buffer, PGPUInt32 sizeBuffer);

private:
	PGPBoolean	mIsKeyAttached;
	PGPBoolean	mTrueIfUsingKey1;

	KeyInfo	*mPCurKeyInfo;

	CSecureObject<KeyInfo>	mKeyInfo1;
	CSecureObject<KeyInfo>	mKeyInfo2;
};

_PGP_END

#endif	// ] Included_CTwofishCipher_h

⌨️ 快捷键说明

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