summaryrefslogtreecommitdiff
path: root/crc.h
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2002-10-04 17:31:41 +0000
committerweidai <weidai11@users.noreply.github.com>2002-10-04 17:31:41 +0000
commita3b6ece7ab341b5b14135baeccea7d5e4c086771 (patch)
tree8b045309c238226c32a563b1df6b9c30a2f0e0b3 /crc.h
downloadcryptopp-git-a3b6ece7ab341b5b14135baeccea7d5e4c086771.tar.gz
Initial revision
Diffstat (limited to 'crc.h')
-rw-r--r--crc.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/crc.h b/crc.h
new file mode 100644
index 00000000..3ba13236
--- /dev/null
+++ b/crc.h
@@ -0,0 +1,40 @@
+#ifndef CRYPTOPP_CRC32_H
+#define CRYPTOPP_CRC32_H
+
+#include "cryptlib.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+const word32 CRC32_NEGL = 0xffffffffL;
+
+#ifdef IS_LITTLE_ENDIAN
+#define CRC32_INDEX(c) (c & 0xff)
+#define CRC32_SHIFTED(c) (c >> 8)
+#else
+#define CRC32_INDEX(c) (c >> 24)
+#define CRC32_SHIFTED(c) (c << 8)
+#endif
+
+//! CRC Checksum Calculation
+class CRC32 : public HashTransformation
+{
+public:
+ enum {DIGESTSIZE = 4};
+ CRC32();
+ void Update(const byte *input, unsigned int length);
+ void TruncatedFinal(byte *hash, unsigned int size);
+ unsigned int DigestSize() const {return DIGESTSIZE;}
+
+ void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
+ byte GetCrcByte(unsigned int i) const {return ((byte *)&(m_crc))[i];}
+
+private:
+ void Reset() {m_crc = CRC32_NEGL;}
+
+ static const word32 m_tab[256];
+ word32 m_crc;
+};
+
+NAMESPACE_END
+
+#endif