retdec
Public Types | Public Member Functions | Private Attributes | List of all members
retdec::utils::CRC32 Class Reference

compute CRC32 hash, based on Intel's Slicing-by-8 algorithm More...

#include <crc32.h>

Collaboration diagram for retdec::utils::CRC32:
Collaboration graph
[legend]

Public Types

enum  { HashBytes = 4 }
 hash is 4 bytes long More...
 

Public Member Functions

 CRC32 ()
 same as reset() More...
 
std::string operator() (const void *data, size_t numBytes)
 compute CRC32 of a memory block More...
 
std::string operator() (const std::string &text)
 compute CRC32 of a string, excluding final zero More...
 
void add (const void *data, size_t numBytes)
 add arbitrary number of bytes More...
 
std::string getHash ()
 return latest hash as 8 hex characters More...
 
void getHash (unsigned char buffer[CRC32::HashBytes])
 return latest hash as bytes More...
 
void reset ()
 restart More...
 

Private Attributes

uint32_t m_hash
 hash More...
 

Detailed Description

compute CRC32 hash, based on Intel's Slicing-by-8 algorithm

Usage: CRC32 crc32; std::string myHash = crc32("Hello World"); // std::string std::string myHash2 = crc32("How are you", 11); // arbitrary data, 11 bytes

or in a streaming fashion:

CRC32 crc32;
while (more data available)
  crc32.add(pointer to fresh data, number of new bytes);
std::string myHash3 = crc32.getHash();

Note:
You can find code for the faster Slicing-by-16 algorithm on my website, too:
http://create.stephan-brumme.com/crc32/
Its unrolled version is about twice as fast but its look-up table doubled in size as well.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

hash is 4 bytes long

Enumerator
HashBytes 

Constructor & Destructor Documentation

◆ CRC32()

retdec::utils::CRC32::CRC32 ( )

same as reset()

Member Function Documentation

◆ add()

void retdec::utils::CRC32::add ( const void *  data,
size_t  numBytes 
)

add arbitrary number of bytes

◆ getHash() [1/2]

std::string retdec::utils::CRC32::getHash ( )

return latest hash as 8 hex characters

◆ getHash() [2/2]

void retdec::utils::CRC32::getHash ( unsigned char  buffer[CRC32::HashBytes])

return latest hash as bytes

◆ operator()() [1/2]

std::string retdec::utils::CRC32::operator() ( const std::string &  text)

compute CRC32 of a string, excluding final zero

◆ operator()() [2/2]

std::string retdec::utils::CRC32::operator() ( const void *  data,
size_t  numBytes 
)

compute CRC32 of a memory block

◆ reset()

void retdec::utils::CRC32::reset ( )

restart

Member Data Documentation

◆ m_hash

uint32_t retdec::utils::CRC32::m_hash
private

hash


The documentation for this class was generated from the following files: