summaryrefslogtreecommitdiff
path: root/crc.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2016-04-24 13:24:45 -0400
committerJeffrey Walton <noloader@gmail.com>2016-04-24 13:24:45 -0400
commitbf22c4575bae3bc158e3070bd0dae9aab40bfde3 (patch)
tree0a0704dd59e86d99b30a0ab077a49edd3e0b49e4 /crc.h
parent87d81372a9dfaca6dca4472cca4df61a3f4fd02b (diff)
downloadcryptopp-git-bf22c4575bae3bc158e3070bd0dae9aab40bfde3.tar.gz
Add CRC-32C using CXX and SSE4 (Issue 160)
Diffstat (limited to 'crc.h')
-rw-r--r--crc.h32
1 files changed, 29 insertions, 3 deletions
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;
};