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

📄 cryptlib.h

📁 伯克利做的SFTP安全文件传输协议
💻 H
📖 第 1 页 / 共 2 页
字号:
		virtual void TransferTo(BufferedTransformation &target);		/// same as above but only transfer up to transferMax bytes		virtual unsigned int TransferTo(BufferedTransformation &target, unsigned int transferMax);		/// peek at the next byte without removing it from the output buffer		virtual unsigned int Peek(byte &outByte) const =0;		/// discard some bytes from the output buffer		unsigned int Skip(unsigned int skipMax);	//@}	//@Man: ATTACHMENT	//@{		/** Some BufferedTransformation objects (e.g. \Ref{Filter} objects)			allow other BufferedTransformation objects to be attached.  When			this is done, the first object instead of buffering its output,			sents that output to the attached object as input.  See the			documentation for the \Ref{Filter} class for the details.		*/		///		virtual bool Attachable() {return false;}		///		virtual void Detach(BufferedTransformation *p = 0) {}	// NULL is undefined at this point		///		virtual void Attach(BufferedTransformation *) {}		/// call InputFinished() for all attached objects		virtual void Close() {InputFinished();}	//@}};/// abstract base class for public-key encryptors and decryptors/** This class provides an interface common to encryptors and decryptors	for querying their plaintext and ciphertext lengths.*/class PK_CryptoSystem{public:	///	virtual ~PK_CryptoSystem() {}	/// maximum length of plaintext for a given ciphertext length	// * This function returns 0 if cipherTextLength is not valid (too long or too short).	virtual unsigned int MaxPlainTextLength(unsigned int cipherTextLength) const =0;	/// calculate length of ciphertext given length of plaintext	// * This function returns 0 if plainTextLength is not valid (too long).	virtual unsigned int CipherTextLength(unsigned int plainTextLength) const =0;};///	abstract base class for public-key encryptors/** An encryptor is also a public encryption key.  It contains both the	key and the algorithm to perform the encryption.*/class PK_Encryptor : public virtual PK_CryptoSystem{public:	/// encrypt a byte string	/** Preconditions:			\begin{itemize} 			\item CipherTextLength(plainTextLength) != 0 (i.e., plainText isn't too long)			\item size of cipherText == CipherTextLength(plainTextLength)			\end{itemize}	*/	virtual void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) =0;};///	abstract base class for public-key decryptors/** An decryptor is also a private decryption key.  It contains both the	key and the algorithm to perform the decryption.*/class PK_Decryptor : public virtual PK_CryptoSystem{public:	/// decrypt a byte string, and return the length of plaintext	/** Precondition: size of plainText == MaxPlainTextLength(cipherTextLength)		bytes.  				The function returns the actual length of the plaintext, or 0		if decryption fails.	*/	virtual unsigned int Decrypt(const byte *cipherText, unsigned int cipherTextLength, byte *plainText) =0;};/// abstract base class for encryptors and decryptors with fixed length ciphertext/** A simplified interface (as embodied in this	class and its subclasses) is provided for crypto systems (such	as RSA) whose ciphertext depend only on the key, not on the length	of the plaintext.  The maximum plaintext length also depend only on	the key.*/class PK_FixedLengthCryptoSystem : public virtual PK_CryptoSystem{public:	///	virtual unsigned int MaxPlainTextLength() const =0;	///	virtual unsigned int CipherTextLength() const =0;	unsigned int MaxPlainTextLength(unsigned int cipherTextLength) const;	unsigned int CipherTextLength(unsigned int plainTextLength) const;};/// abstract base class for encryptors with fixed length ciphertextclass PK_FixedLengthEncryptor : public virtual PK_Encryptor, public virtual PK_FixedLengthCryptoSystem{};/// abstract base class for decryptors with fixed length ciphertextclass PK_FixedLengthDecryptor : public virtual PK_Decryptor, public virtual PK_FixedLengthCryptoSystem{public:	/// decrypt a byte string, and return the length of plaintext	/** Preconditions:			\begin{itemize} 			\item length of cipherText == CipherTextLength()			\item size of plainText == MaxPlainTextLength()			\end{itemize}				The function returns the actual length of the plaintext, or 0		if decryption fails.	*/	virtual unsigned int Decrypt(const byte *cipherText, byte *plainText) =0;	unsigned int Decrypt(const byte *cipherText, unsigned int cipherTextLength, byte *plainText);};/// abstract base class for public-key signers and verifiers/** This class provides an interface common to signers and verifiers	for querying their signature lengths and maximum message lengths.	The maximum message length is typically very low (less than 1000)	because it is intended that only message digests (see \Ref{HashModule})	should be signed.*/class PK_SignatureSystem{public:	///	virtual ~PK_SignatureSystem() {};	/// maximum length of a message that can be signed or verified	virtual unsigned int MaxMessageLength() const =0;	/// signature length support by this object (as either input or output)	virtual unsigned int SignatureLength() const =0;};/// abstract base class for public-key signers/** A signer is also a private signature key.  It contains both the	key and the algorithm to perform the signature.*/class PK_Signer : public virtual PK_SignatureSystem{public:	/// sign a message	/** Preconditions:			\begin{itemize} 			\item messageLen <= MaxMessageLength()			\item size of signature == SignatureLength()			\end{itemize}	*/	virtual void Sign(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature) =0;};/// abstract base class for public-key verifiers/** A verifier is also a public verification key.  It contains both the	key and the algorithm to perform the verification.*/class PK_Verifier : public virtual PK_SignatureSystem{public:	/// check whether sig is a valid signature for message	/** Preconditions:			\begin{itemize} 			\item messageLen <= MaxMessageLength()			\item length of signature == SignatureLength()			\end{itemize}	*/	virtual bool Verify(const byte *message, unsigned int messageLen, const byte *sig) =0;};/// abstract base class for public-key verifiers with recovery/** In a signature scheme with recovery, a verifier is able to extract	a message from its valid signature.  This saves space since	you don't need to store the message seperately.*/class PK_VerifierWithRecovery : public PK_Verifier{public:	/// recover a message from its signature, return length of message, or 0 if signature is invalid	/** Preconditions:			\begin{itemize} 			\item length of signature == SignatureLength()			\item size of recoveredMessage == MaxMessageLength()			\end{itemize}	*/	virtual unsigned int Recover(const byte *signature, byte *recoveredMessage) =0;	bool Verify(const byte *message, unsigned int messageLen, const byte *signature);};/// abstract base class for key agreement protocols/** This class defines the interface for symmetric 2-pass key agreement	protocols.  It isn't very general and only basic Diffie-Hellman	protocols fit the abstraction, so possibly a more general interface	is needed.	To use a KeyAgreementProtocol class, the two parties create matching	KeyAgreementProtocol objects, call Setup() on these objects,	and send each other the public values produced.  The objects are	responsible for remembering the corresponding secret values, and	will produce a shared secret value when Agree() is called with the	other party's public value.*/class KeyAgreementProtocol{public:	///	virtual ~KeyAgreementProtocol() {}	///	virtual unsigned int PublicValueLength() const =0;	///	virtual unsigned int AgreedKeyLength() const =0;	/// produce public value	// * Precondition: size of publicValue == PublicValueLength()	virtual void Setup(RandomNumberGenerator &rng, byte *publicValue) =0;	/// calculate agreed key given other party's public value	/** Precondition:			\begin{itemize} 			\item Setup() was called previously on this object			\item size of agreedKey == AgreedKeyLength()			\end{itemize}	*/	virtual void Agree(const byte *otherPublicValue, byte *agreedKey) const =0;};/// abstract base class for all objects that support precomputation/** The class defines a common interface for doing precomputation,	and loading and saving precomputation.*/class PK_Precomputation{public:	///	virtual ~PK_Precomputation() {}	///	/** The exact semantics of Precompute() is varies, but		typically it means calculate a table of n objects		that can be used later to speed up computation.	*/	virtual void Precompute(unsigned int n) =0;	/// retrieve previously saved precomputation	virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation) =0;	/// save precomputation for later use	virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const =0;};///template <class T> class PK_WithPrecomputation : public T, public virtual PK_Precomputation{};#endif

⌨️ 快捷键说明

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