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

📄 cryptlib.h

📁 hashish-1.1b加密算法库c++
💻 H
📖 第 1 页 / 共 5 页
字号:
// cryptlib.h - written and placed in the public domain by Wei Dai/*! \file 	This file contains the declarations for the abstract base	classes that provide a uniform interface to this library.*//*!	\mainpage <a href="http://www.cryptopp.com">Crypto++</a><sup><small>TM</small></sup> Library 5.1 Reference Manual<dl><dt>Abstract Base Classes<dd>	cryptlib.h<dt>Symmetric Ciphers<dd>	SymmetricCipherDocumentation<dt>Hash Functions<dd>	HAVAL, MD2, MD4, MD5, PanamaHash, RIPEMD160, SHA, SHA256, SHA384, SHA512, Tiger<dt>Non-Cryptographic Checksums<dd>	CRC32, Adler32<dt>Message Authentication Codes<dd>	#MD5MAC, XMACC, HMAC, CBC_MAC, DMAC, PanamaMAC<dt>Random Number Generators<dd>	NullRNG(), LC_RNG, RandomPool, BlockingRng, NonblockingRng, AutoSeededRandomPool, AutoSeededX917RNG<dt>Public Key Cryptosystems<dd>	DLIES, ECIES, LUCES, RSAES, RabinES, LUC_IES<dt>Public Key Signature Schemes<dd>	DSA, GDSA, ECDSA, NR, ECNR, LUCSS, RSASS, RabinSS, RWSS, ESIGN<dt>Key Agreement<dd>	#DH, DH2, #MQV, ECDH, ECMQV, XTR_DH<dt>Algebraic Structures<dd>	Integer, PolynomialMod2, PolynomialOver, RingOfPolynomialsOver,	ModularArithmetic, MontgomeryRepresentation, GFP2_ONB,	GF2NP, GF256, GF2_32, EC2N, ECP<dt>Secret Sharing and Information Dispersal<dd>	SecretSharing, SecretRecovery, InformationDispersal, InformationRecovery<dt>Compression<dd>	Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor<dt>Input Source Classes<dd>	StringSource, FileSource, SocketSource, WindowsPipeSource, RandomNumberSource<dt>Output Sink Classes<dd>	StringSinkTemplate, ArraySink, FileSink, SocketSink, WindowsPipeSink<dt>Filter Wrappers<dd>	StreamTransformationFilter, HashFilter, HashVerificationFilter, SignerFilter, SignatureVerificationFilter<dt>Binary to Text Encoders and Decoders<dd>	HexEncoder, HexDecoder, Base64Encoder, Base64Decoder<dt>Wrappers for OS features<dd>	Timer, Socket, WindowsHandle, ThreadLocalStorage<dt>FIPS 140 related<dd>	fips140.h</dl><p>This reference manual is a work in progress. Some classes are still lacking detailed descriptions.<p>Click <a href="CryptoPPRef.zip">here</a> to download a zip archive containing this manual.<p>Thanks to Ryan Phillips for providing the Doxygen configuration fileand getting me started with this manual.*/#ifndef CRYPTOPP_CRYPTLIB_H#define CRYPTOPP_CRYPTLIB_H#include "config.h"#include <limits.h>#include <exception>#include <string>#include <typeinfo>#include <assert.h>NAMESPACE_BEGIN(CryptoPP)// forward declarationsclass Integer;//! used to specify a direction for a cipher to operate in (encrypt or decrypt)enum CipherDir {ENCRYPTION,	DECRYPTION};//! used to represent infinite timeconst unsigned long INFINITE_TIME = ULONG_MAX;// VC60 workaround: using enums as template parameters causes problemstemplate <typename ENUM_TYPE, int VALUE>struct EnumToType{	static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}};enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1};typedef EnumToType<ByteOrder, LITTLE_ENDIAN_ORDER> LittleEndian;typedef EnumToType<ByteOrder, BIG_ENDIAN_ORDER> BigEndian;//! base class for all exceptions thrown by Crypto++class Exception : public std::exception{public:	//! error types	enum ErrorType {		//! a method is not implemented		NOT_IMPLEMENTED,		//! invalid function argument		INVALID_ARGUMENT,		//! BufferedTransformation received a Flush(true) signal but can't flush buffers		CANNOT_FLUSH,		//! data integerity check (such as CRC or MAC) failed		DATA_INTEGRITY_CHECK_FAILED,		//! received input data that doesn't conform to expected format		INVALID_DATA_FORMAT,		//! error reading from input device or writing to output device		IO_ERROR,		//! some error not belong to any of the above categories		OTHER_ERROR	};	explicit Exception(ErrorType errorType, const std::string &s) : m_errorType(errorType), m_what(s) {}	virtual ~Exception() throw() {}	const char *what() const throw() {return (m_what.c_str());}	const std::string &GetWhat() const {return m_what;}	void SetWhat(const std::string &s) {m_what = s;}	ErrorType GetErrorType() const {return m_errorType;}	void SetErrorType(ErrorType errorType) {m_errorType = errorType;}private:	ErrorType m_errorType;	std::string m_what;};//! exception thrown when an invalid argument is detectedclass InvalidArgument : public Exception{public:	explicit InvalidArgument(const std::string &s) : Exception(INVALID_ARGUMENT, s) {}};//! exception thrown by decryption filters when trying to decrypt an invalid ciphertextclass InvalidDataFormat : public Exception{public:	explicit InvalidDataFormat(const std::string &s) : Exception(INVALID_DATA_FORMAT, s) {}};//! exception thrown by decryption filters when trying to decrypt an invalid ciphertextclass InvalidCiphertext : public InvalidDataFormat{public:	explicit InvalidCiphertext(const std::string &s) : InvalidDataFormat(s) {}};//! exception thrown by a class if a non-implemented method is calledclass NotImplemented : public Exception{public:	explicit NotImplemented(const std::string &s) : Exception(NOT_IMPLEMENTED, s) {}};//! exception thrown by a class when Flush(true) is called but it can't completely flush its buffersclass CannotFlush : public Exception{public:	explicit CannotFlush(const std::string &s) : Exception(CANNOT_FLUSH, s) {}};//! error reported by the operating systemclass OS_Error : public Exception{public:	OS_Error(ErrorType errorType, const std::string s, const std::string& operation, int errorCode)		: Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}	~OS_Error() throw() {}	// the operating system API that reported the error	const std::string & GetOperation() const {return m_operation;}	// the error code return by the operating system	int GetErrorCode() const {return m_errorCode;}protected:	std::string m_operation;	int m_errorCode;};//! used to return decoding resultsstruct DecodingResult{	explicit DecodingResult() : isValidCoding(false), messageLength(0) {}	explicit DecodingResult(unsigned int len) : isValidCoding(true), messageLength(len) {}	bool operator==(const DecodingResult &rhs) const {return isValidCoding == rhs.isValidCoding && messageLength == rhs.messageLength;}	bool operator!=(const DecodingResult &rhs) const {return !operator==(rhs);}	bool isValidCoding;	unsigned int messageLength;#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY	operator unsigned int() const {return isValidCoding ? messageLength : 0;}#endif};//! interface for retrieving values given their names/*! This class is used to safely pass a variable number of arbitrarily typed arguments to functions	and to read values from keys and crypto parameters.	To get a value, you need to know the name and the type of the value. 	Call GetValueNames() on a NameValuePairs object to obtain a list of value names that it supports.	Then look at the Name namespace documentation to see what the type of each value is, or	alternatively, call GetIntValue() with the value name, and if the type is not int, a	ValueTypeMismatch exception will be thrown and you can get the actual type from the exception object.*/class NameValuePairs{public:	virtual ~NameValuePairs() {}	//! exception thrown when trying to retrieve a value using a different type than expected	class ValueTypeMismatch : public InvalidArgument	{	public:		ValueTypeMismatch(std::string name, const std::type_info &stored, const std::type_info &retrieving)			: InvalidArgument("NameValuePairs: type mismatch for '" + name + "', stored '" + stored.name() + "', trying to retrieve '" + retrieving.name() + "'")			, m_stored(stored), m_retrieving(retrieving) {}		const std::type_info & GetStoredTypeInfo() const {return m_stored;}		const std::type_info & GetRetrievingTypeInfo() const {return m_retrieving;}	private:		const std::type_info &m_stored;		const std::type_info &m_retrieving;	};	//! get a copy of this object or a subobject of it	template <class T>	bool GetThisObject(T &object) const	{		return GetValue((std::string("ThisObject:")+typeid(T).name()).c_str(), object);	}	//! get a pointer to this object, as a pointer to T	template <class T>	bool GetThisPointer(T *&p) const	{		return GetValue((std::string("ThisPointer:")+typeid(T).name()).c_str(), p);	}	//! get a named value, returns true if the name exists	template <class T>	bool GetValue(const char *name, T &value) const	{		return GetVoidValue(name, typeid(T), &value);	}	//! get a named value, returns the default if the name doesn't exist	template <class T>	T GetValueWithDefault(const char *name, T defaultValue) const	{		GetValue(name, defaultValue);		return defaultValue;	}	//! get a list of value names that can be retrieved	std::string GetValueNames() const		{std::string result; GetValue("ValueNames", result); return result;}	//! get a named value with type int	/*! used to ensure we don't accidentally try to get an unsigned int		or some other type when we mean int (which is the most common case) */	bool GetIntValue(const char *name, int &value) const		{return GetValue(name, value);}	//! get a named value with type int, with default	int GetIntValueWithDefault(const char *name, int defaultValue) const		{return GetValueWithDefault(name, defaultValue);}	//! used by derived classes to check for type mismatch	static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)		{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 + "'");	}	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	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//! .class NullNameValuePairs : public NameValuePairs{public:	bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {return false;}};//! .extern const NullNameValuePairs g_nullNameValuePairs;

⌨️ 快捷键说明

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