From bf22c4575bae3bc158e3070bd0dae9aab40bfde3 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 24 Apr 2016 13:24:45 -0400 Subject: Add CRC-32C using CXX and SSE4 (Issue 160) --- crc.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'crc.h') diff --git a/crc.h b/crc.h index d31555dd..89b68629 100644 --- a/crc.h +++ b/crc.h @@ -2,7 +2,7 @@ //! \file //! \headerfile crc.h -//! \brief Classes for CRC-32 checksum algorithm +//! \brief Classes for CRC-32 and CRC-32C checksum algorithm #ifndef CRYPTOPP_CRC32_H #define CRYPTOPP_CRC32_H @@ -21,7 +21,8 @@ const word32 CRC32_NEGL = 0xffffffffL; #define CRC32_SHIFTED(c) (c << 8) #endif -//! CRC Checksum Calculation +//! \brief CRC-32 Checksum Calculation +//! \details Uses CRC polynomial 0xEDB88320 class CRC32 : public HashTransformation { public: @@ -36,9 +37,34 @@ public: void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} +protected: + void Reset() {m_crc = CRC32_NEGL;} + private: + static const word32 m_tab[256]; + word32 m_crc; +}; + +//! \brief CRC-32C Checksum Calculation +//! \details Uses CRC polynomial 0x82F63B78 +class CRC32C : public HashTransformation +{ +public: + CRYPTOPP_CONSTANT(DIGESTSIZE = 4) + CRC32C(); + void Update(const byte *input, size_t length); + void TruncatedFinal(byte *hash, size_t size); + unsigned int DigestSize() const {return DIGESTSIZE;} + static const char * StaticAlgorithmName() {return "CRC32C";} + std::string AlgorithmName() const {return StaticAlgorithmName();} + + void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} + byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} + +protected: void Reset() {m_crc = CRC32_NEGL;} - + +private: static const word32 m_tab[256]; word32 m_crc; }; -- cgit v1.2.1