diff options
author | Mattes D <github@xoft.cz> | 2013-11-27 09:23:17 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2013-11-27 09:23:17 +0100 |
commit | 49760db89d94ede5d123d927141a6cd60dbaaf07 (patch) | |
tree | 6c6cf99e4cf3128311a93cd187947b502f3732a0 /lib/cryptopp/crc.h | |
parent | cWorld::SpawnExperienceOrb() now returns the entity ID of the spawned orb. (diff) | |
parent | Fixed VC2008 compilation, normalized include paths. (diff) | |
download | cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.gz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.bz2 cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.lz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.xz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.zst cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.zip |
Diffstat (limited to 'lib/cryptopp/crc.h')
-rw-r--r-- | lib/cryptopp/crc.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/cryptopp/crc.h b/lib/cryptopp/crc.h new file mode 100644 index 000000000..f75ea384c --- /dev/null +++ b/lib/cryptopp/crc.h @@ -0,0 +1,42 @@ +#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: + CRYPTOPP_CONSTANT(DIGESTSIZE = 4) + CRC32(); + 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 "CRC32";} + 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];} + +private: + void Reset() {m_crc = CRC32_NEGL;} + + static const word32 m_tab[256]; + word32 m_crc; +}; + +NAMESPACE_END + +#endif |