retdec
crc32.h
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////
2 // crc32.h
3 // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
4 // see http://create.stephan-brumme.com/disclaimer.html
5 //
6 
7 // !!!
8 // The source code was slightly modified in order to fix compilation warnings
9 // and conform to the coding standards of the RetDec project.
10 // !!!
11 
12 #ifndef RETDEC_UTILS_CRC32_H
13 #define RETDEC_UTILS_CRC32_H
14 
15 //#include "hash.h"
16 #include <string>
17 
18 // define fixed size integer types
19 #ifdef _MSC_VER
20 // Windows
21 using uint8_t = unsigned __int8;
22 using uint32_t = unsigned __int32;
23 #else
24 // GCC
25 #include <cstdint>
26 #endif
27 
28 namespace retdec {
29 namespace utils {
30 
32 
49 class CRC32 //: public Hash
50 {
51 public:
53  enum { HashBytes = 4 };
54 
56  CRC32();
57 
59  std::string operator()(const void* data, size_t numBytes);
61  std::string operator()(const std::string& text);
62 
64  void add(const void* data, size_t numBytes);
65 
67  std::string getHash();
69  void getHash(unsigned char buffer[CRC32::HashBytes]);
70 
72  void reset();
73 
74 private:
76  uint32_t m_hash;
77 };
78 
79 } // namespace utils
80 } // namespace retdec
81 
82 #endif
compute CRC32 hash, based on Intel's Slicing-by-8 algorithm
Definition: crc32.h:50
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition: crc32.cpp:340
uint32_t m_hash
hash
Definition: crc32.h:76
void reset()
restart
Definition: crc32.cpp:24
CRC32()
same as reset()
Definition: crc32.cpp:18
std::string operator()(const void *data, size_t numBytes)
compute CRC32 of a memory block
Definition: crc32.cpp:415
@ HashBytes
Definition: crc32.h:53
std::string getHash()
return latest hash as 8 hex characters
Definition: crc32.cpp:383
Definition: archive_wrapper.h:19