File indexing completed on 2025-01-18 09:54:55
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_CRC32_H
0007 #define CRYPTOPP_CRC32_H
0008
0009 #include "cryptlib.h"
0010
0011 NAMESPACE_BEGIN(CryptoPP)
0012
0013 const word32 CRC32_NEGL = 0xffffffffL;
0014
0015 #if (CRYPTOPP_LITTLE_ENDIAN)
0016 #define CRC32_INDEX(c) (c & 0xff)
0017 #define CRC32_SHIFTED(c) (c >> 8)
0018 #else
0019 #define CRC32_INDEX(c) (c >> 24)
0020 #define CRC32_SHIFTED(c) (c << 8)
0021 #endif
0022
0023
0024
0025 class CRC32 : public HashTransformation
0026 {
0027 public:
0028 CRYPTOPP_CONSTANT(DIGESTSIZE = 4);
0029 CRC32();
0030 void Update(const byte *input, size_t length);
0031 void TruncatedFinal(byte *hash, size_t size);
0032 unsigned int DigestSize() const {return DIGESTSIZE;}
0033 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CRC32";}
0034 std::string AlgorithmName() const {return StaticAlgorithmName();}
0035
0036
0037
0038 void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
0039
0040
0041
0042
0043 byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
0044
0045 std::string AlgorithmProvider() const;
0046
0047 protected:
0048 void Reset() {m_crc = CRC32_NEGL;}
0049
0050 private:
0051 static const word32 m_tab[256];
0052 word32 m_crc;
0053 };
0054
0055
0056
0057
0058 class CRC32C : public HashTransformation
0059 {
0060 public:
0061 CRYPTOPP_CONSTANT(DIGESTSIZE = 4);
0062 CRC32C();
0063 void Update(const byte *input, size_t length);
0064 void TruncatedFinal(byte *hash, size_t size);
0065 unsigned int DigestSize() const {return DIGESTSIZE;}
0066 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "CRC32C";}
0067 std::string AlgorithmName() const {return StaticAlgorithmName();}
0068
0069
0070
0071 void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
0072
0073
0074
0075
0076 byte GetCrcByte(size_t i) const {return reinterpret_cast<const byte *>(&m_crc)[i];}
0077
0078 std::string AlgorithmProvider() const;
0079
0080 protected:
0081 void Reset() {m_crc = CRC32_NEGL;}
0082
0083 private:
0084 static const word32 m_tab[256];
0085 word32 m_crc;
0086 };
0087
0088 NAMESPACE_END
0089
0090 #endif