📄 cryptlib.h
字号:
//! virtual int GetAutoSignalPropagation() const {return 0;}public:#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY void Close() {MessageEnd();}#endif //@} //! \name RETRIEVAL OF ONE MESSAGE //@{ //! returns number of bytes that is currently ready for retrieval /*! All retrieval functions return the actual number of bytes retrieved, which is the lesser of the request number and MaxRetrievable(). */ virtual lword MaxRetrievable() const; //! returns whether any bytes are currently ready for retrieval virtual bool AnyRetrievable() const; //! try to retrieve a single byte virtual size_t Get(byte &outByte); //! try to retrieve multiple bytes virtual size_t Get(byte *outString, size_t getMax); //! peek at the next byte without removing it from the output buffer virtual size_t Peek(byte &outByte) const; //! peek at multiple bytes without removing them from the output buffer virtual size_t Peek(byte *outString, size_t peekMax) const; //! try to retrieve a 16-bit word size_t GetWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER); //! try to retrieve a 32-bit word size_t GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER); //! try to peek at a 16-bit word size_t PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; //! try to peek at a 32-bit word size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const; //! move transferMax bytes of the buffered output to target as input lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) {TransferTo2(target, transferMax, channel); return transferMax;} //! discard skipMax bytes from the output buffer virtual lword Skip(lword skipMax=LWORD_MAX); //! copy copyMax bytes of the buffered output to target as input lword CopyTo(BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const {return CopyRangeTo(target, 0, copyMax, channel);} //! copy copyMax bytes of the buffered output, starting at position (relative to current position), to target as input lword CopyRangeTo(BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel); return i-position;}#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY unsigned long MaxRetrieveable() const {return MaxRetrievable();}#endif //@} //! \name RETRIEVAL OF MULTIPLE MESSAGES //@{ //! virtual lword TotalBytesRetrievable() const; //! number of times MessageEnd() has been received minus messages retrieved or skipped virtual unsigned int NumberOfMessages() const; //! returns true if NumberOfMessages() > 0 virtual bool AnyMessages() const; //! start retrieving the next message /*! Returns false if no more messages exist or this message is not completely retrieved. */ virtual bool GetNextMessage(); //! skip count number of messages virtual unsigned int SkipMessages(unsigned int count=UINT_MAX); //! unsigned int TransferMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) {TransferMessagesTo2(target, count, channel); return count;} //! unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const; //! virtual void SkipAll(); //! void TransferAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) {TransferAllTo2(target, channel);} //! void CopyAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const; virtual bool GetNextMessageSeries() {return false;} virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();} virtual unsigned int NumberOfMessageSeries() const {return 0;} //@} //! \name NON-BLOCKING TRANSFER OF OUTPUT //@{ //! upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block virtual size_t TransferTo2(BufferedTransformation &target, lword &byteCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) =0; //! upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block virtual size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const =0; //! upon return, messageCount contains number of messages that have finished being transfered, and returns the number of bytes left in the current transfer block size_t TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); //! returns the number of bytes left in the current transfer block size_t TransferAllTo2(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true); //@} //! \name CHANNELS //@{ struct NoChannelSupport : public NotImplemented {NoChannelSupport(const std::string &name) : NotImplemented(name + ": this object doesn't support multiple channels") {}}; struct InvalidChannelName : public InvalidArgument {InvalidChannelName(const std::string &name, const std::string &channel) : InvalidArgument(name + ": unexpected channel name \"" + channel + "\"") {}}; size_t ChannelPut(const std::string &channel, byte inByte, bool blocking=true) {return ChannelPut(channel, &inByte, 1, blocking);} size_t ChannelPut(const std::string &channel, const byte *inString, size_t length, bool blocking=true) {return ChannelPut2(channel, inString, length, 0, blocking);} size_t ChannelPutModifiable(const std::string &channel, byte *inString, size_t length, bool blocking=true) {return ChannelPutModifiable2(channel, inString, length, 0, blocking);} size_t ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); size_t ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true); bool ChannelMessageEnd(const std::string &channel, int propagation=-1, bool blocking=true) {return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);} size_t ChannelPutMessageEnd(const std::string &channel, const byte *inString, size_t length, int propagation=-1, bool blocking=true) {return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);} virtual byte * ChannelCreatePutSpace(const std::string &channel, size_t &size); virtual size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking); virtual size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking); virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true); virtual bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); virtual void SetRetrievalChannel(const std::string &channel); //@} //! \name ATTACHMENT /*! Some BufferedTransformation objects (e.g. 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. The entire attachment chain is deleted when the anchor object is destructed. */ //@{ //! returns whether this object allows attachment virtual bool Attachable() {return false;} //! returns the object immediately attached to this object or NULL for no attachment virtual BufferedTransformation *AttachedTransformation() {assert(!Attachable()); return 0;} //! virtual const BufferedTransformation *AttachedTransformation() const {return const_cast<BufferedTransformation *>(this)->AttachedTransformation();} //! delete the current attachment chain and replace it with newAttachment virtual void Detach(BufferedTransformation *newAttachment = 0) {assert(!Attachable()); throw NotImplemented("BufferedTransformation: this object is not attachable");} //! add newAttachment to the end of attachment chain virtual void Attach(BufferedTransformation *newAttachment); //@}protected: static int DecrementPropagation(int propagation) {return propagation != 0 ? propagation - 1 : 0;}private: byte m_buf[4]; // for ChannelPutWord16 and ChannelPutWord32, to ensure buffer isn't deallocated before non-blocking operation completes};//! returns a reference to a BufferedTransformation object that discards all inputBufferedTransformation & TheBitBucket();//! interface for crypto material, such as public and private keys, and crypto parametersclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoMaterial : public NameValuePairs{public: //! exception thrown when invalid crypto material is detected class CRYPTOPP_DLL InvalidMaterial : public InvalidDataFormat { public: explicit InvalidMaterial(const std::string &s) : InvalidDataFormat(s) {} }; //! assign values from source to this object /*! \note This function can be used to create a public key from a private key. */ virtual void AssignFrom(const NameValuePairs &source) =0; //! check this object for errors /*! \param level denotes the level of thoroughness: 0 - using this object won't cause a crash or exception (rng is ignored) 1 - this object will probably function (encrypt, sign, etc.) correctly (but may not check for weak keys and such) 2 - make sure this object will function correctly, and do reasonable security checks 3 - do checks that may take a long time \return true if the tests pass */ virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0; //! throws InvalidMaterial if this object fails Validate() test virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const {if (!Validate(rng, level)) throw InvalidMaterial("CryptoMaterial: this object contains invalid values");}// virtual std::vector<std::string> GetSupportedFormats(bool includeSaveOnly=false, bool includeLoadOnly=false); //! save key into a BufferedTransformation virtual void Save(BufferedTransformation &bt) const {throw NotImplemented("CryptoMaterial: this object does not support saving");} //! load key from a BufferedTransformation /*! \throws KeyingErr if decode fails \note Generally does not check that the key is valid. Call ValidateKey() or ThrowIfInvalidKey() to check that. */ virtual void Load(BufferedTransformation &bt) {throw NotImplemented("CryptoMaterial: this object does not support loading");} //! \return whether this object supports precomputation virtual bool SupportsPrecomputation() const {return false;} //! do 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) {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} //! retrieve previously saved precomputation virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation) {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} //! save precomputation for later use virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");} // for internal library use void DoQuickSanityCheck() const {ThrowIfInvalid(NullRNG(), 0);}#if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) // Sun Studio 11/CC 5.8 workaround: it generates incorrect code when casting to an empty virtual base class char m_sunCCworkaround;#endif};//! interface for generatable crypto material, such as private keys and crypto parametersclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GeneratableCryptoMaterial : virtual public CryptoMaterial{public: //! generate a random key or crypto parameters /*! \throws KeyingErr if algorithm parameters are invalid, or if a key can't be generated (e.g., if this is a public key object) */ virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs) {throw NotImplemented("GeneratableCryptoMaterial: this object does not support key/parameter generation");} //! calls the above function with a NameValuePairs object that just specifies "KeySize" void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize);};//! interface for public keysclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKey : virtual public CryptoMaterial{};//! interface for private keysclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKey : public GeneratableCryptoMaterial{};//! interface for crypto prametersclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CryptoParameters : public GeneratableCryptoMaterial{};//! interface for asymmetric algorithmsclass CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AsymmetricAlgorithm : public Algorithm{public: //! returns a reference to the crypto material used by this object virtual CryptoMaterial & AccessMaterial() =0; //! returns a const reference to the crypto material used by this object virtual const CryptoMaterial & GetMaterial() const =0; //! for backwards compatibility, calls AccessMaterial().Load(bt) void BERDecode(BufferedTransformation &bt) {AccessMaterial().Load(bt);} //! for backwards compatibility, calls GetMaterial().Save(bt) void DEREncode(BufferedTransformation &bt) const {GetMaterial().Save(bt);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -