crc.h
Go to the documentation of this file.
// crc.h - originally written and placed in the public domain by Wei Dai
/// \file crc.h
/// \brief Classes for CRC-32 and CRC-32C checksum algorithm
#ifndef CRYPTOPP_CRC32_H
#define CRYPTOPP_CRC32_H
#include "cryptlib.h"
NAMESPACE_BEGIN(CryptoPP)
const word32 CRC32_NEGL = 0xffffffffL;
#if (CRYPTOPP_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
/// \brief CRC-32 Checksum Calculation
/// \details Uses CRC polynomial 0xEDB88320
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;}
CRYPTOPP_STATIC_CONSTEXPR 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 reinterpret_cast<const byte *>(&m_crc)[i];}
std::string AlgorithmProvider() const;
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
/// \since Crypto++ 5.6.4
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;}
CRYPTOPP_STATIC_CONSTEXPR 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 reinterpret_cast<const byte *>(&m_crc)[i];}
std::string AlgorithmProvider() const;
protected:
void Reset() {m_crc = CRC32_NEGL;}
private:
static const word32 m_tab[256];
word32 m_crc;
};
NAMESPACE_END
#endif
CRC32C
CRC-32C Checksum Calculation.
Definition: crc.h:53
CRC32C::TruncatedFinal
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
Definition: crc.cpp:356
CRC32C::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: crc.h:61
CRC32C::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: crc.h:59
CRC32C::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: crc.cpp:319
CRC32C::AlgorithmProvider
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: crc.cpp:301
CRC32
CRC-32 Checksum Calculation.
Definition: crc.h:26
CRC32::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: crc.h:32
CRC32::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: crc.h:34
CRC32::TruncatedFinal
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
Definition: crc.cpp:178
CRC32::Update
void Update(const byte *input, size_t length)
Updates a hash with additional input.
Definition: crc.cpp:147
CRC32::AlgorithmProvider
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: crc.cpp:133
HashTransformation
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1113
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
CryptoPP
Crypto++ library namespace.