Crypto++
crc.h
1 #ifndef CRYPTOPP_CRC32_H
2 #define CRYPTOPP_CRC32_H
3 
4 #include "cryptlib.h"
5 
6 NAMESPACE_BEGIN(CryptoPP)
7 
8 const word32 CRC32_NEGL = 0xffffffffL;
9 
10 #ifdef IS_LITTLE_ENDIAN
11 #define CRC32_INDEX(c) (c & 0xff)
12 #define CRC32_SHIFTED(c) (c >> 8)
13 #else
14 #define CRC32_INDEX(c) (c >> 24)
15 #define CRC32_SHIFTED(c) (c << 8)
16 #endif
17 
18 //! CRC Checksum Calculation
19 class CRC32 : public HashTransformation
20 {
21 public:
22  CRYPTOPP_CONSTANT(DIGESTSIZE = 4)
23  CRC32();
24  void Update(const byte *input, size_t length);
25  void TruncatedFinal(byte *hash, size_t size);
26  unsigned int DigestSize() const {return DIGESTSIZE;}
27  static const char * StaticAlgorithmName() {return "CRC32";}
28  std::string AlgorithmName() const {return StaticAlgorithmName();}
29 
30  void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
31  byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
32 
33 private:
34  void Reset() {m_crc = CRC32_NEGL;}
35 
36  static const word32 m_tab[256];
37  word32 m_crc;
38 };
39 
40 NAMESPACE_END
41 
42 #endif
unsigned int DigestSize() const
size of the hash/digest/MAC returned by Final()
Definition: crc.h:26
void TruncatedFinal(byte *hash, size_t size)
truncated version of Final()
std::string AlgorithmName() const
returns name of this algorithm, not universally implemented yet
Definition: crc.h:28
void Update(const byte *input, size_t length)
process more input
interface for hash functions and data processing part of MACs
Definition: cryptlib.h:530
CRC Checksum Calculation.
Definition: crc.h:19