📄 cryptlib.h
字号:
\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 creating message
accumulators.
*/
class PK_SignatureSystem
{
public:
//!
virtual ~PK_SignatureSystem() {};
//! signature length support by this object (as either input or output)
virtual unsigned int SignatureLength() const =0;
//! create a new HashModule to accumulate the message to be signed or verified
virtual HashModule * NewMessageAccumulator() 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:
//! key too short exception, may be thrown by Sign() or SignMessage()
class KeyTooShort : public Exception
{
public:
KeyTooShort() : Exception("PK_Signer: key too short") {}
};
//! sign and delete messageAccumulator
/*! Preconditions:
\begin{itemize}
\item messageAccumulator was obtained by calling NewMessageAccumulator()
\item HashModule::Final() has not been called on messageAccumulator
\item size of signature == SignatureLength()
\end{itemize}
*/
virtual void Sign(RandomNumberGenerator &rng, HashModule *messageAccumulator, byte *signature) const =0;
//! sign a message
/*! Precondition: size of signature == SignatureLength() */
virtual void SignMessage(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature) const;
};
//! 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 messageAccumulator, and delete messageAccumulator
/*! Preconditions:
\begin{itemize}
\item messageAccumulator was obtained by calling NewMessageAccumulator()
\item HashModule::Final() has not been called on messageAccumulator
\item length of signature == SignatureLength()
\end{itemize}
*/
virtual bool Verify(HashModule *messageAccumulator, const byte *sig) const =0;
//! check whether sig is a valid signature for message
/*! Precondition: size of signature == SignatureLength() */
virtual bool VerifyMessage(const byte *message, unsigned int messageLen, const byte *sig) const;
};
//! abstract base class for public-key signers and verifiers with recovery
/*! In a signature scheme with recovery, a verifier is able to extract
a message from its valid signature.
*/
class PK_SignatureSystemWithRecovery : public virtual PK_SignatureSystem
{
public:
//! length of longest message that can be fully recovered
virtual unsigned int MaximumRecoverableLength() const =0;
//! whether or not messages longer than MaximumRecoverableLength() can be signed
/*! If this function returns false, any message longer than
MaximumRecoverableLength() will be truncated for signature
and will fail verification.
*/
virtual bool AllowLeftoverMessage() const =0;
};
//! abstract base class for public-key signers with recovery
class PK_SignerWithRecovery : public virtual PK_SignatureSystemWithRecovery, public PK_Signer
{
};
//! abstract base class for public-key verifiers with recovery
/*! A PK_VerifierWithRecovery can also be used the same way as a PK_Verifier,
where the signature and the entire message is given to Verify() or
VerifyMessage() as input.
*/
class PK_VerifierWithRecovery : public virtual PK_SignatureSystemWithRecovery, public PK_Verifier
{
public:
//! create a new HashModule to accumulate leftover message
virtual HashModule * NewLeftoverMessageAccumulator(const byte *signature) const =0;
//! partially recover a message from its signature, return length of recoverd message, or 0 if signature is invalid
/*! Preconditions:
\begin{itemize}
\item leftoverMessageAccumulator was obtained by calling NewLeftoverMessageAccumulator(signature)
\item HashModule::Final() has not been called on leftoverMessageAccumulator
\item length of signature == SignatureLength()
\item size of recoveredMessage == MaximumRecoverableLength()
\end{itemize}
*/
virtual unsigned int PartialRecover(HashModule *leftoverMessageAccumulator, byte *recoveredMessage) const =0;
//! recover a message from its signature, return length of message, or 0 if signature is invalid
/*! This function should be equivalent to PartialRecover(NewLeftoverMessageAccumulator(signature), recoveredMessage).
Preconditions:
\begin{itemize}
\item length of signature == SignatureLength()
\item size of recoveredMessage == MaximumRecoverableLength()
\end{itemize}
*/
virtual unsigned int Recover(const byte *signature, byte *recoveredMessage) const =0;
};
//! abstract base class for domains of simple key agreement protocols
/*! A key agreement domain is a set of parameters that must be shared
by two parties in a key agreement protocol, along with the algorithms
for generating key pairs and deriving agreed values.
*/
class PK_SimpleKeyAgreementDomain
{
public:
virtual ~PK_SimpleKeyAgreementDomain() {}
//! return whether the domain parameters stored in this object are valid
virtual bool ValidateDomainParameters(RandomNumberGenerator &rng) const =0;
//! return length of agreed value produced
virtual unsigned int AgreedValueLength() const =0;
//! return length of private keys in this domain
virtual unsigned int PrivateKeyLength() const =0;
//! return length of public keys in this domain
virtual unsigned int PublicKeyLength() const =0;
//! generate private/public key pair
/*! Preconditions:
\begin{itemize}
\item size of privateKey == PrivateKeyLength()
\item size of publicKey == PublicKeyLength()
\end{itemize}
*/
virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const =0;
//! derive agreed value from your private key and couterparty's public key, return false in case of failure
/*! Note: If you have previously validated the public key, use validateOtherPublicKey=false to save time.
/*! Preconditions:
\begin{itemize}
\item size of agreedValue == AgreedValueLength()
\item length of privateKey == PrivateKeyLength()
\item length of otherPublicKey == PublicKeyLength()
\end{itemize}
*/
virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0;
};
//! abstract base class for domains of authenticated key agreement protocols
/*! In an authenticated key agreement protocol, each party has two
key pairs. The long-lived key pair is called the static key pair,
and the short-lived key pair is called the ephemeral key pair.
*/
class PK_AuthenticatedKeyAgreementDomain
{
public:
virtual ~PK_AuthenticatedKeyAgreementDomain() {}
//! return whether the domain parameters stored in this object are valid
virtual bool ValidateDomainParameters(RandomNumberGenerator &rng) const =0;
//! return length of agreed value produced
virtual unsigned int AgreedValueLength() const =0;
//! return length of static private keys in this domain
virtual unsigned int StaticPrivateKeyLength() const =0;
//! return length of static public keys in this domain
virtual unsigned int StaticPublicKeyLength() const =0;
//! generate static private/public key pair
/*! Preconditions:
\begin{itemize}
\item size of privateKey == StaticPrivateKeyLength()
\item size of publicKey == StaticPublicKeyLength()
\end{itemize}
*/
virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const =0;
//! return length of ephemeral private keys in this domain
virtual unsigned int EphemeralPrivateKeyLength() const =0;
//! return length of ephemeral public keys in this domain
virtual unsigned int EphemeralPublicKeyLength() const =0;
//! generate ephemeral private/public key pair
/*! Preconditions:
\begin{itemize}
\item size of privateKey == EphemeralPrivateKeyLength()
\item size of publicKey == EphemeralPublicKeyLength()
\end{itemize}
*/
virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const =0;
//! derive agreed value from your private keys and couterparty's public keys, return false in case of failure
/*! Note: The ephemeral public key will always be validated.
If you have previously validated the static public key, use validateStaticOtherPublicKey=false to save time.
Preconditions:
\begin{itemize}
\item size of agreedValue == AgreedValueLength()
\item length of staticPrivateKey == StaticPrivateKeyLength()
\item length of ephemeralPrivateKey == EphemeralPrivateKeyLength()
\item length of staticOtherPublicKey == StaticPublicKeyLength()
\item length of ephemeralOtherPublicKey == EphemeralPublicKeyLength()
\end{itemize}
*/
virtual bool Agree(byte *agreedValue,
const byte *staticPrivateKey, const byte *ephemeralPrivateKey,
const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
bool validateStaticOtherPublicKey=true) 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 virtual T, public virtual PK_Precomputation
{
};
NAMESPACE_END
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -