diff options
author | Malfurious <m@lfurio.us> | 2024-10-24 06:44:24 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2024-10-24 06:44:24 -0400 |
commit | 512aa4c77b3dc0d72db713a9215ff65a98a99ec3 (patch) | |
tree | 6db82e0109dc987b5b021f81d4e8a0926eb75ff7 /cryptopp562/zinflate.h | |
parent | 428471d39fb8c205a9fad899c88c30a2cb7df685 (diff) | |
parent | 10affea371406c0ae4c080e5a19390a8e9bd154b (diff) | |
download | compass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.tar.gz compass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.zip |
Merge branch 'mbedtls'
Replace Crypto++ 5.6.2 with Mbed TLS 3.6.0
Newer compilers are starting to show the age of the crypto library we've
been using, as it is sometimes a pain to recompile compass lately. So,
the tracked version of Crypto++ was at least due for an upgrade.
However, I plan to soon begin reimplementing compass in C. So, I'm
taking this opportunity to first just migrate the cryptography library
to a newer C alternative. This branch does so, and integrates its use
into the current C++ version of compass.
* mbedtls:
Remove unnecessary exception handler catch block
Refactor random password generation to use mbedtls entropy source
Refactor SHA256 function to use mbedtls
Refactor AES functions to use mbedtls
Add Mbedtls library
Remove Crypto++ library
Diffstat (limited to '')
-rw-r--r-- | cryptopp562/zinflate.h | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/cryptopp562/zinflate.h b/cryptopp562/zinflate.h deleted file mode 100644 index 7e1225b..0000000 --- a/cryptopp562/zinflate.h +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef CRYPTOPP_ZINFLATE_H -#define CRYPTOPP_ZINFLATE_H - -#include "filters.h" -#include <vector> - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -class LowFirstBitReader -{ -public: - LowFirstBitReader(BufferedTransformation &store) - : m_store(store), m_buffer(0), m_bitsBuffered(0) {} -// unsigned long BitsLeft() const {return m_store.MaxRetrievable() * 8 + m_bitsBuffered;} - unsigned int BitsBuffered() const {return m_bitsBuffered;} - unsigned long PeekBuffer() const {return m_buffer;} - bool FillBuffer(unsigned int length); - unsigned long PeekBits(unsigned int length); - void SkipBits(unsigned int length); - unsigned long GetBits(unsigned int length); - -private: - BufferedTransformation &m_store; - unsigned long m_buffer; - unsigned int m_bitsBuffered; -}; - -struct CodeLessThan; - -//! Huffman Decoder -class HuffmanDecoder -{ -public: - typedef unsigned int code_t; - typedef unsigned int value_t; - enum {MAX_CODE_BITS = sizeof(code_t)*8}; - - class Err : public Exception {public: Err(const std::string &what) : Exception(INVALID_DATA_FORMAT, "HuffmanDecoder: " + what) {}}; - - HuffmanDecoder() {} - HuffmanDecoder(const unsigned int *codeBitLengths, unsigned int nCodes) {Initialize(codeBitLengths, nCodes);} - - void Initialize(const unsigned int *codeBitLengths, unsigned int nCodes); - unsigned int Decode(code_t code, /* out */ value_t &value) const; - bool Decode(LowFirstBitReader &reader, value_t &value) const; - -private: - friend struct CodeLessThan; - - struct CodeInfo - { - CodeInfo(code_t code=0, unsigned int len=0, value_t value=0) : code(code), len(len), value(value) {} - inline bool operator<(const CodeInfo &rhs) const {return code < rhs.code;} - code_t code; - unsigned int len; - value_t value; - }; - - struct LookupEntry - { - unsigned int type; - union - { - value_t value; - const CodeInfo *begin; - }; - union - { - unsigned int len; - const CodeInfo *end; - }; - }; - - static code_t NormalizeCode(code_t code, unsigned int codeBits); - void FillCacheEntry(LookupEntry &entry, code_t normalizedCode) const; - - unsigned int m_maxCodeBits, m_cacheBits, m_cacheMask, m_normalizedCacheMask; - std::vector<CodeInfo, AllocatorWithCleanup<CodeInfo> > m_codeToValue; - mutable std::vector<LookupEntry, AllocatorWithCleanup<LookupEntry> > m_cache; -}; - -//! DEFLATE (RFC 1951) decompressor - -class Inflator : public AutoSignaling<Filter> -{ -public: - class Err : public Exception - { - public: - Err(ErrorType e, const std::string &s) - : Exception(e, s) {} - }; - class UnexpectedEndErr : public Err {public: UnexpectedEndErr() : Err(INVALID_DATA_FORMAT, "Inflator: unexpected end of compressed block") {}}; - class BadBlockErr : public Err {public: BadBlockErr() : Err(INVALID_DATA_FORMAT, "Inflator: error in compressed block") {}}; - - /*! \param repeat decompress multiple compressed streams in series - \param autoSignalPropagation 0 to turn off MessageEnd signal - */ - Inflator(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1); - - void IsolatedInitialize(const NameValuePairs ¶meters); - size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking); - bool IsolatedFlush(bool hardFlush, bool blocking); - - virtual unsigned int GetLog2WindowSize() const {return 15;} - -protected: - ByteQueue m_inQueue; - -private: - virtual unsigned int MaxPrestreamHeaderSize() const {return 0;} - virtual void ProcessPrestreamHeader() {} - virtual void ProcessDecompressedData(const byte *string, size_t length) - {AttachedTransformation()->Put(string, length);} - virtual unsigned int MaxPoststreamTailSize() const {return 0;} - virtual void ProcessPoststreamTail() {} - - void ProcessInput(bool flush); - void DecodeHeader(); - bool DecodeBody(); - void FlushOutput(); - void OutputByte(byte b); - void OutputString(const byte *string, size_t length); - void OutputPast(unsigned int length, unsigned int distance); - - static const HuffmanDecoder *FixedLiteralDecoder(); - static const HuffmanDecoder *FixedDistanceDecoder(); - - const HuffmanDecoder& GetLiteralDecoder() const; - const HuffmanDecoder& GetDistanceDecoder() const; - - enum State {PRE_STREAM, WAIT_HEADER, DECODING_BODY, POST_STREAM, AFTER_END}; - State m_state; - bool m_repeat, m_eof, m_wrappedAround; - byte m_blockType; - word16 m_storedLen; - enum NextDecode {LITERAL, LENGTH_BITS, DISTANCE, DISTANCE_BITS}; - NextDecode m_nextDecode; - unsigned int m_literal, m_distance; // for LENGTH_BITS or DISTANCE_BITS - HuffmanDecoder m_dynamicLiteralDecoder, m_dynamicDistanceDecoder; - LowFirstBitReader m_reader; - SecByteBlock m_window; - size_t m_current, m_lastFlush; -}; - -NAMESPACE_END - -#endif |