Horizon
md5_hash.h
1 // Code by: B-Con (http://b-con.us)
2 // Released under the GNU GPL
3 // MD5 Hash Digest implementation (little endian byte order)
4 
5 #ifndef __MD5_HASH_H
6 #define __MD5_HASH_H
7 
8 #include <cstdint>
9 #include <string>
10 
11 class MD5_HASH
12 {
13 
14 public:
15  MD5_HASH();
16  MD5_HASH( const MD5_HASH& aOther );
17 
18  ~MD5_HASH();
19 
20  void Init();
21  void Hash ( uint8_t *data, uint32_t length );
22  void Hash ( int value );
23  void Finalize();
24  bool IsValid() const { return m_valid; };
25 
26  void SetValid( bool aValid ) { m_valid = aValid; }
27 
28  MD5_HASH& operator=( const MD5_HASH& aOther );
29 
30  bool operator==( const MD5_HASH& aOther ) const;
31  bool operator!=( const MD5_HASH& aOther ) const;
32 
38  std::string Format( bool aCompactForm = false );
39 
40 private:
41  struct MD5_CTX {
42  uint8_t data[64];
43  uint32_t datalen;
44  uint32_t bitlen[2];
45  uint32_t state[4];
46  };
47 
48  void md5_transform(MD5_CTX *ctx, uint8_t data[]);
49  void md5_init(MD5_CTX *ctx);
50  void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len);
51  void md5_final(MD5_CTX *ctx, uint8_t hash[]);
52 
53  bool m_valid;
54  MD5_CTX m_ctx;
55  uint8_t m_hash[16];
56 };
57 
58 #endif
Definition: md5_hash.h:12
std::string Format(bool aCompactForm=false)
Definition: md5_hash.cpp:97