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

📄 cryptlib.h

📁 lots Elliptic curve cryptography codes. Use Visual c++ to compile
💻 H
📖 第 1 页 / 共 5 页
字号:
		{Update(input, length); Final(digest);}	//! verify that digest is a valid digest for the current message, then reinitialize the object	/*! Default implementation is to call Final() and do a bitwise comparison		between its output and digest. */	virtual bool Verify(const byte *digest)		{return TruncatedVerify(digest, DigestSize());}	//! use this if your input is in one piece and you don't want to call Update() and Verify() separately	virtual bool VerifyDigest(const byte *digest, const byte *input, size_t length)		{Update(input, length); return Verify(digest);}	//! truncated version of Final()	virtual void TruncatedFinal(byte *digest, size_t digestSize) =0;	//! truncated version of CalculateDigest()	virtual void CalculateTruncatedDigest(byte *digest, size_t digestSize, const byte *input, size_t length)		{Update(input, length); TruncatedFinal(digest, digestSize);}	//! truncated version of Verify()	virtual bool TruncatedVerify(const byte *digest, size_t digestLength);	//! truncated version of VerifyDigest()	virtual bool VerifyTruncatedDigest(const byte *digest, size_t digestLength, const byte *input, size_t length)		{Update(input, length); return TruncatedVerify(digest, digestLength);}protected:	void ThrowIfInvalidTruncatedSize(size_t size) const;};typedef HashTransformation HashFunction;//! interface for one direction (encryption or decryption) of a block cipher/*! \note These objects usually should not be used directly. See BlockTransformation for more details. */class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockCipher : public SimpleKeyingInterface, public BlockTransformation{protected:	const Algorithm & GetAlgorithm() const {return *this;}};//! interface for one direction (encryption or decryption) of a stream cipher or cipher modeclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SymmetricCipher : public SimpleKeyingInterface, public StreamTransformation{protected:	const Algorithm & GetAlgorithm() const {return *this;}};//! interface for message authentication codesclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE MessageAuthenticationCode : public SimpleKeyingInterface, public HashTransformation{protected:	const Algorithm & GetAlgorithm() const {return *this;}};//! interface for for one direction (encryption or decryption) of a stream cipher or block cipher mode with authentication/*! The StreamTransformation part of this interface is used to encrypt/decrypt the data, and the MessageAuthenticationCode part of this	interface is used to input additional authenticated data (AAD, which is MAC'ed but not encrypted), and to generate/verify the MAC. */class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipher : public MessageAuthenticationCode, public StreamTransformation{public:	//! this indicates that a member function was called in the wrong state, for example trying to encrypt a message before having set the key or IV	class BadState : public Exception	{	public:		explicit BadState(const std::string &name, const char *message) : Exception(OTHER_ERROR, name + ": " + message) {}		explicit BadState(const std::string &name, const char *function, const char *state) : Exception(OTHER_ERROR, name + ": " + function + " was called before " + state) {}	};	//! the maximum length of AAD that can be input before the encrypted data	virtual lword MaxHeaderLength() const =0;	//! the maximum length of encrypted data	virtual lword MaxMessageLength() const =0;	//! the maximum length of AAD that can be input after the encrypted data	virtual lword MaxFooterLength() const {return 0;}	//! if this function returns true, SpecifyDataLengths() must be called before attempting to input data	/*! This is the case for some schemes, such as CCM. */	virtual bool NeedsPrespecifiedDataLengths() const {return false;}	//! this function only needs to be called if NeedsPrespecifiedDataLengths() returns true	void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);	//! encrypt and generate MAC in one call. will truncate MAC if macSize < TagSize()	virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength);	//! decrypt and verify MAC in one call, returning true iff MAC is valid. will assume MAC is truncated if macLength < TagSize()	virtual bool DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength);	// redeclare this to avoid compiler ambiguity errors	virtual std::string AlgorithmName() const =0;protected:	const Algorithm & GetAlgorithm() const {return *static_cast<const MessageAuthenticationCode *>(this);}	virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) {}};#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITYtypedef SymmetricCipher StreamCipher;#endif//! interface for random number generators/*! All return values are uniformly distributed over the range specified.*/class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE RandomNumberGenerator : public Algorithm{public:	//! update RNG state with additional unpredictable values	virtual void IncorporateEntropy(const byte *input, size_t length) {throw NotImplemented("RandomNumberGenerator: IncorporateEntropy not implemented");}	//! returns true if IncorporateEntropy is implemented	virtual bool CanIncorporateEntropy() const {return false;}	//! generate new random byte and return it	virtual byte GenerateByte();	//! generate new random bit and return it	/*! Default implementation is to call GenerateByte() and return its lowest bit. */	virtual unsigned int GenerateBit();	//! generate a random 32 bit word in the range min to max, inclusive	virtual word32 GenerateWord32(word32 a=0, word32 b=0xffffffffL);	//! generate random array of bytes	virtual void GenerateBlock(byte *output, size_t size);	//! generate and discard n bytes	virtual void DiscardBytes(size_t n);	//! generate random bytes as input to a BufferedTransformation	virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length);	//! randomly shuffle the specified array, resulting permutation is uniformly distributed	template <class IT> void Shuffle(IT begin, IT end)	{		for (; begin != end; ++begin)			std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));	}#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY	byte GetByte() {return GenerateByte();}	unsigned int GetBit() {return GenerateBit();}	word32 GetLong(word32 a=0, word32 b=0xffffffffL) {return GenerateWord32(a, b);}	word16 GetShort(word16 a=0, word16 b=0xffff) {return (word16)GenerateWord32(a, b);}	void GetBlock(byte *output, size_t size) {GenerateBlock(output, size);}#endif};//! returns a reference that can be passed to functions that ask for a RNG but doesn't actually use itCRYPTOPP_DLL RandomNumberGenerator & CRYPTOPP_API NullRNG();class WaitObjectContainer;class CallStack;//! interface for objects that you can wait forclass CRYPTOPP_NO_VTABLE Waitable{public:	virtual ~Waitable() {}	//! maximum number of wait objects that this object can return	virtual unsigned int GetMaxWaitObjectCount() const =0;	//! put wait objects into container	/*! \param callStack is used for tracing no wait loops, example:	             something.GetWaitObjects(c, CallStack("my func after X", 0));			   - or in an outer GetWaitObjects() method that itself takes a callStack parameter:			     innerThing.GetWaitObjects(c, CallStack("MyClass::GetWaitObjects at X", &callStack)); */	virtual void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) =0;	//! wait on this object	/*! same as creating an empty container, calling GetWaitObjects(), and calling Wait() on the container */	bool Wait(unsigned long milliseconds, CallStack const& callStack);};//! the default channel for BufferedTransformation, equal to the empty stringextern CRYPTOPP_DLL const std::string DEFAULT_CHANNEL;//! channel for additional authenticated data, equal to "AAD"extern CRYPTOPP_DLL const std::string AAD_CHANNEL;//! interface for buffered transformations/*! BufferedTransformation is a generalization of BlockTransformation,	StreamTransformation, and HashTransformation.	A buffered transformation is an object that takes a stream of bytes	as input (this may be done in stages), does some computation on them, and	then places the result into an internal buffer for later retrieval.  Any	partial result already in the output buffer is not modified by further	input.	If a method takes a "blocking" parameter, and you	pass "false" for it, the method will return before all input has been processed if	the input cannot be processed without waiting (for network buffers to become available, for example).	In this case the method will return true	or a non-zero integer value. When this happens you must continue to call the method with the same	parameters until it returns false or zero, before calling any other method on it or	attached BufferedTransformation. The integer return value in this case is approximately	the number of bytes left to be processed, and can be used to implement a progress bar.	For functions that take a "propagation" parameter, propagation != 0 means pass on the signal to attached	BufferedTransformation objects, with propagation decremented at each step until it reaches 0.	-1 means unlimited propagation.	\nosubgrouping*/class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, public Waitable{public:	// placed up here for CW8	static const std::string &NULL_CHANNEL;	// same as DEFAULT_CHANNEL, for backwards compatibility	BufferedTransformation() : Algorithm(false) {}	//! return a reference to this object	/*! This function is useful for passing a temporary BufferedTransformation object to a 		function that takes a non-const reference. */	BufferedTransformation& Ref() {return *this;}	//!	\name INPUT	//@{		//! input a byte for processing		size_t Put(byte inByte, bool blocking=true)			{return Put(&inByte, 1, blocking);}		//! input multiple bytes		size_t Put(const byte *inString, size_t length, bool blocking=true)			{return Put2(inString, length, 0, blocking);}		//! input a 16-bit word		size_t PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);		//! input a 32-bit word		size_t PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);		//! request space which can be written into by the caller, and then used as input to Put()		/*! \param size is requested size (as a hint) for input, and size of the returned space for output */		/*! \note The purpose of this method is to help avoid doing extra memory allocations. */		virtual byte * CreatePutSpace(size_t &size) {size=0; return NULL;}		virtual bool CanModifyInput() const {return false;}		//! input multiple bytes that may be modified by callee		size_t PutModifiable(byte *inString, size_t length, bool blocking=true)			{return PutModifiable2(inString, length, 0, blocking);}		bool MessageEnd(int propagation=-1, bool blocking=true)			{return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}		size_t PutMessageEnd(const byte *inString, size_t length, int propagation=-1, bool blocking=true)			{return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}		//! input multiple bytes for blocking or non-blocking processing		/*! \param messageEnd means how many filters to signal MessageEnd to, including this one */		virtual size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking) =0;		//! input multiple bytes that may be modified by callee for blocking or non-blocking processing		/*! \param messageEnd means how many filters to signal MessageEnd to, including this one */		virtual size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)			{return Put2(inString, length, messageEnd, blocking);}		//! thrown by objects that have not implemented nonblocking input processing		struct BlockingInputOnly : public NotImplemented			{BlockingInputOnly(const std::string &s) : NotImplemented(s + ": Nonblocking input is not implemented by this object.") {}};	//@}	//!	\name WAITING	//@{		unsigned int GetMaxWaitObjectCount() const;		void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack);	//@}	//!	\name SIGNALS	//@{		virtual void IsolatedInitialize(const NameValuePairs &parameters) {throw NotImplemented("BufferedTransformation: this object can't be reinitialized");}		virtual bool IsolatedFlush(bool hardFlush, bool blocking) =0;		virtual bool IsolatedMessageSeriesEnd(bool blocking) {return false;}		//! initialize or reinitialize this object		virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1);		//! flush buffered input and/or output		/*! \param hardFlush is used to indicate whether all data should be flushed			\note Hard flushes must be used with care. It means try to process and output everything, even if			there may not be enough data to complete the action. For example, hard flushing a HexDecoder would			cause an error if you do it after inputing an odd number of hex encoded characters.			For some types of filters, for example ZlibDecompressor, hard flushes can only			be done at "synchronization points". These synchronization points are positions in the data			stream that are created by hard flushes on the corresponding reverse filters, in this			example ZlibCompressor. This is useful when zlib compressed data is moved across a			network in packets and compression state is preserved across packets, as in the ssh2 protocol.		*/		virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true);		//! mark end of a series of messages		/*! There should be a MessageEnd immediately before MessageSeriesEnd. */		virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true);		//! set propagation of automatically generated and transferred signals		/*! propagation == 0 means do not automaticly generate signals */		virtual void SetAutoSignalPropagation(int propagation) {}

⌨️ 快捷键说明

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