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

📄 cryptlib.h

📁 lots Elliptic curve cryptography codes. Use Visual c++ to compile
💻 H
📖 第 1 页 / 共 5 页
字号:
		{if (stored != retrieving) throw ValueTypeMismatch(name, stored, retrieving);}	template <class T>	void GetRequiredParameter(const char *className, const char *name, T &value) const	{		if (!GetValue(name, value))			throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");	}	CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const	{		if (!GetIntValue(name, value))			throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");	}	//! to be implemented by derived classes, users should use one of the above functions instead	CRYPTOPP_DLL virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0;};//! namespace containing value name definitions/*!	value names, types and semantics:	ThisObject:ClassName (ClassName, copy of this object or a subobject)	ThisPointer:ClassName (const ClassName *, pointer to this object or a subobject)*/DOCUMENTED_NAMESPACE_BEGIN(Name)// more names defined in argnames.hDOCUMENTED_NAMESPACE_END//! empty set of name-value pairsclass CRYPTOPP_DLL NullNameValuePairs : public NameValuePairs{public:	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {return false;}};//! _extern CRYPTOPP_DLL const NullNameValuePairs g_nullNameValuePairs;// ********************************************************//! interface for cloning objects, this is not implemented by most classes yetclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Clonable{public:	virtual ~Clonable() {}	//! this is not implemented by most classes yet	virtual Clonable* Clone() const {throw NotImplemented("Clone() is not implemented yet.");}	// TODO: make this =0};//! interface for all crypto algorithmsclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Algorithm : public Clonable{public:	/*! When FIPS 140-2 compliance is enabled and checkSelfTestStatus == true,		this constructor throws SelfTestFailure if the self test hasn't been run or fails. */	Algorithm(bool checkSelfTestStatus = true);	//! returns name of this algorithm, not universally implemented yet	virtual std::string AlgorithmName() const {return "unknown";}};//! keying interface for crypto algorithms that take byte strings as keysclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyingInterface{public:	virtual ~SimpleKeyingInterface() {}	//! returns smallest valid key length in bytes */	virtual size_t MinKeyLength() const =0;	//! returns largest valid key length in bytes */	virtual size_t MaxKeyLength() const =0;	//! returns default (recommended) key length in bytes */	virtual size_t DefaultKeyLength() const =0;	//! returns the smallest valid key length in bytes that is >= min(n, GetMaxKeyLength())	virtual size_t GetValidKeyLength(size_t n) const =0;	//! returns whether n is a valid key length	virtual bool IsValidKeyLength(size_t n) const		{return n == GetValidKeyLength(n);}	//! set or reset the key of this object	/*! \param params is used to specify Rounds, BlockSize, etc. */	virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs);	//! calls SetKey() with an NameValuePairs object that just specifies "Rounds"	void SetKeyWithRounds(const byte *key, size_t length, int rounds);	//! calls SetKey() with an NameValuePairs object that just specifies "IV"	void SetKeyWithIV(const byte *key, size_t length, const byte *iv, size_t ivLength);	//! calls SetKey() with an NameValuePairs object that just specifies "IV"	void SetKeyWithIV(const byte *key, size_t length, const byte *iv)		{SetKeyWithIV(key, length, iv, IVSize());}	enum IV_Requirement {UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE};	//! returns the minimal requirement for secure IVs	virtual IV_Requirement IVRequirement() const =0;	//! returns whether this object can be resynchronized (i.e. supports initialization vectors)	/*! If this function returns true, and no IV is passed to SetKey() and CanUseStructuredIVs()==true, an IV of all 0's will be assumed. */	bool IsResynchronizable() const {return IVRequirement() < NOT_RESYNCHRONIZABLE;}	//! returns whether this object can use random IVs (in addition to ones returned by GetNextIV)	bool CanUseRandomIVs() const {return IVRequirement() <= UNPREDICTABLE_RANDOM_IV;}	//! returns whether this object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV)	bool CanUsePredictableIVs() const {return IVRequirement() <= RANDOM_IV;}	//! returns whether this object can use structured IVs, for example a counter (in addition to ones returned by GetNextIV)	bool CanUseStructuredIVs() const {return IVRequirement() <= UNIQUE_IV;}	virtual unsigned int IVSize() const {throw NotImplemented(GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");}	//! returns default length of IVs accepted by this object	unsigned int DefaultIVLength() const {return IVSize();}	//! returns minimal length of IVs accepted by this object	virtual unsigned int MinIVLength() const {return IVSize();}	//! returns maximal length of IVs accepted by this object	virtual unsigned int MaxIVLength() const {return IVSize();}	//! resynchronize with an IV. ivLength=-1 means use IVSize()	virtual void Resynchronize(const byte *iv, int ivLength=-1) {throw NotImplemented(GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");}	//! get a secure IV for the next message	/*! This method should be called after you finish encrypting one message and are ready to start the next one.		After calling it, you must call SetKey() or Resynchronize() before using this object again. 		This method is not implemented on decryption objects. */	virtual void GetNextIV(RandomNumberGenerator &rng, byte *IV);protected:	virtual const Algorithm & GetAlgorithm() const =0;	virtual void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params) =0;	void ThrowIfInvalidKeyLength(size_t length);	void ThrowIfResynchronizable();			// to be called when no IV is passed	void ThrowIfInvalidIV(const byte *iv);	// check for NULL IV if it can't be used	size_t ThrowIfInvalidIVLength(int size);	const byte * GetIVAndThrowIfInvalid(const NameValuePairs &params, size_t &size);	inline void AssertValidKeyLength(size_t length) const		{assert(IsValidKeyLength(length));}};//! interface for the data processing part of block ciphers/*! Classes derived from BlockTransformation are block ciphers	in ECB mode (for example the DES::Encryption class), which are stateless.	These classes should not be used directly, but only in combination with	a mode class (see CipherModeDocumentation in modes.h).*/class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm{public:	//! encrypt or decrypt inBlock, xor with xorBlock, and write to outBlock	virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0;	//! encrypt or decrypt one block	/*! \pre size of inBlock and outBlock == BlockSize() */	void ProcessBlock(const byte *inBlock, byte *outBlock) const		{ProcessAndXorBlock(inBlock, NULL, outBlock);}	//! encrypt or decrypt one block in place	void ProcessBlock(byte *inoutBlock) const		{ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}	//! block size of the cipher in bytes	virtual unsigned int BlockSize() const =0;	//! returns how inputs and outputs should be aligned for optimal performance	virtual unsigned int OptimalDataAlignment() const;	//! returns true if this is a permutation (i.e. there is an inverse transformation)	virtual bool IsPermutation() const {return true;}	//! returns true if this is an encryption object	virtual bool IsForwardTransformation() const =0;	//! return number of blocks that can be processed in parallel, for bit-slicing implementations	virtual unsigned int OptimalNumberOfParallelBlocks() const {return 1;}	enum {BT_InBlockIsCounter=1, BT_DontIncrementInOutPointers=2, BT_XorInput=4, BT_ReverseDirection=8} FlagsForAdvancedProcessBlocks;	//! encrypt and xor blocks according to flags (see FlagsForAdvancedProcessBlocks)	/*! /note If BT_InBlockIsCounter is set, last byte of inBlocks may be modified. */	virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const;	inline CipherDir GetCipherDirection() const {return IsForwardTransformation() ? ENCRYPTION : DECRYPTION;}};//! interface for the data processing part of stream ciphersclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE StreamTransformation : public Algorithm{public:	//! return a reference to this object, 	/*! This function is useful for passing a temporary StreamTransformation object to a 		function that takes a non-const reference. */	StreamTransformation& Ref() {return *this;}	//! returns block size, if input must be processed in blocks, otherwise 1	virtual unsigned int MandatoryBlockSize() const {return 1;}	//! returns the input block size that is most efficient for this cipher	/*! \note optimal input length is n * OptimalBlockSize() - GetOptimalBlockSizeUsed() for any n > 0 */	virtual unsigned int OptimalBlockSize() const {return MandatoryBlockSize();}	//! returns how much of the current block is used up	virtual unsigned int GetOptimalBlockSizeUsed() const {return 0;}	//! returns how input should be aligned for optimal performance	virtual unsigned int OptimalDataAlignment() const;	//! encrypt or decrypt an array of bytes of specified length	/*! \note either inString == outString, or they don't overlap */	virtual void ProcessData(byte *outString, const byte *inString, size_t length) =0;	//! for ciphers where the last block of data is special, encrypt or decrypt the last block of data	/*! For now the only use of this function is for CBC-CTS mode. */	virtual void ProcessLastBlock(byte *outString, const byte *inString, size_t length);	//! returns the minimum size of the last block, 0 indicating the last block is not special	virtual unsigned int MinLastBlockSize() const {return 0;}	//! same as ProcessData(inoutString, inoutString, length)	inline void ProcessString(byte *inoutString, size_t length)		{ProcessData(inoutString, inoutString, length);}	//! same as ProcessData(outString, inString, length)	inline void ProcessString(byte *outString, const byte *inString, size_t length)		{ProcessData(outString, inString, length);}	//! implemented as {ProcessData(&input, &input, 1); return input;}	inline byte ProcessByte(byte input)		{ProcessData(&input, &input, 1); return input;}	//! returns whether this cipher supports random access	virtual bool IsRandomAccess() const =0;	//! for random access ciphers, seek to an absolute position	virtual void Seek(lword n)	{		assert(!IsRandomAccess());		throw NotImplemented("StreamTransformation: this object doesn't support random access");	}	//! returns whether this transformation is self-inverting (e.g. xor with a keystream)	virtual bool IsSelfInverting() const =0;	//! returns whether this is an encryption object	virtual bool IsForwardTransformation() const =0;};//! interface for hash functions and data processing part of MACs/*! HashTransformation objects are stateful.  They are created in an initial state,	change state as Update() is called, and return to the initial	state when Final() is called.  This interface allows a large message to	be hashed in pieces by calling Update() on each piece followed by	calling Final().*/class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HashTransformation : public Algorithm{public:	//! return a reference to this object, 	/*! This function is useful for passing a temporary HashTransformation object to a 		function that takes a non-const reference. */	HashTransformation& Ref() {return *this;}	//! process more input	virtual void Update(const byte *input, size_t length) =0;	//! request space to write input into	virtual byte * CreateUpdateSpace(size_t &size) {size=0; return NULL;}	//! compute hash for current message, then restart for a new message	/*!	\pre size of digest == DigestSize(). */	virtual void Final(byte *digest)		{TruncatedFinal(digest, DigestSize());}	//! discard the current state, and restart with a new message	virtual void Restart()		{TruncatedFinal(NULL, 0);}	//! size of the hash/digest/MAC returned by Final()	virtual unsigned int DigestSize() const =0;	//! same as DigestSize()	unsigned int TagSize() const {return DigestSize();}	//! block size of underlying compression function, or 0 if not block based	virtual unsigned int BlockSize() const {return 0;}	//! input to Update() should have length a multiple of this for optimal speed	virtual unsigned int OptimalBlockSize() const {return 1;}	//! returns how input should be aligned for optimal performance	virtual unsigned int OptimalDataAlignment() const;	//! use this if your input is in one piece and you don't want to call Update() and Final() separately	virtual void CalculateDigest(byte *digest, const byte *input, size_t length)

⌨️ 快捷键说明

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