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

📄 ccast5cipher.h

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

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

#ifndef Included_CCast5Cipher_h	// [
#define Included_CCast5Cipher_h

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

_PGP_BEGIN

// Class CCast5Cipher

class CCast5Cipher : public CCipher
{
public:
	enum 
	{
		kNumKeyBits			= 128, 
		kNumKeyBytes		= kNumKeyBits / 8, 
		kNumEncryptBytes	= 8, 
		kNumDecryptBytes	= 8, 
		kNumSaltBytes		= 8, 
		kNumIvsNeeded		= 4
	};

private:
	enum
	{
		ValidationCRC	= 0xD8D4C8D7
	};

	union ExpandedKey
	{
		PGPUInt8	bytes[128];
		PGPUInt32	dwords[128/sizeof(PGPUInt32)];
	};
	
	struct KeyInfo
	{
		Crypto::SymmetricKey	key;
		Crypto::PassphraseSalt	salt;

		ExpandedKey		expandedKey;
		ExpandedKey		expandedKeyCFB;
	};

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

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

	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	mUseOldMethod;
	PGPBoolean	mTrueIfUsingKey1;

	KeyInfo	*mPCurKeyInfo;

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

_PGP_END

#endif	// ] Included_CCast5Cipher_h

⌨️ 快捷键说明

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