Crypto++  5.6.3
Free C++ class library of cryptographic schemes
crc.h
Go to the documentation of this file.
1 // crc.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile crc.h
5 //! \brief Classes for CRC-32 checksum algorithm
6 
7 #ifndef CRYPTOPP_CRC32_H
8 #define CRYPTOPP_CRC32_H
9 
10 #include "cryptlib.h"
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 const word32 CRC32_NEGL = 0xffffffffL;
15 
16 #ifdef IS_LITTLE_ENDIAN
17 #define CRC32_INDEX(c) (c & 0xff)
18 #define CRC32_SHIFTED(c) (c >> 8)
19 #else
20 #define CRC32_INDEX(c) (c >> 24)
21 #define CRC32_SHIFTED(c) (c << 8)
22 #endif
23 
24 //! CRC Checksum Calculation
25 class CRC32 : public HashTransformation
26 {
27 public:
28  CRYPTOPP_CONSTANT(DIGESTSIZE = 4)
29  CRC32();
30  void Update(const byte *input, size_t length);
31  void TruncatedFinal(byte *hash, size_t size);
32  unsigned int DigestSize() const {return DIGESTSIZE;}
33  static const char * StaticAlgorithmName() {return "CRC32";}
34  std::string AlgorithmName() const {return StaticAlgorithmName();}
35 
36  void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
37  byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
38 
39 private:
40  void Reset() {m_crc = CRC32_NEGL;}
41 
42  static const word32 m_tab[256];
43  word32 m_crc;
44 };
45 
46 NAMESPACE_END
47 
48 #endif
Abstract base classes that provide a uniform interface to this library.
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: crc.h:32
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
Definition: crc.cpp:150
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: crc.h:34
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: crc.cpp:125
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:912
Crypto++ library namespace.
CRC Checksum Calculation.
Definition: crc.h:25