KiCad PCB EDA Suite
md5_hash.h
Go to the documentation of this file.
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 
36  std::string Format();
37 
38 private:
39  struct MD5_CTX {
40  uint8_t data[64];
41  uint32_t datalen;
42  uint32_t bitlen[2];
43  uint32_t state[4];
44  };
45 
46  void md5_transform(MD5_CTX *ctx, uint8_t data[]);
47  void md5_init(MD5_CTX *ctx);
48  void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len);
49  void md5_final(MD5_CTX *ctx, uint8_t hash[]);
50 
51  bool m_valid;
53  uint8_t m_hash[16];
54 };
55 
56 #endif
MD5_HASH()
Definition: md5_hash.cpp:32
uint32_t bitlen[2]
Definition: md5_hash.h:42
bool operator!=(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:89
void md5_final(MD5_CTX *ctx, uint8_t hash[])
Definition: md5_hash.cpp:236
std::string Format()
Definition: md5_hash.cpp:95
void Hash(uint8_t *data, uint32_t length)
Definition: md5_hash.cpp:66
void md5_init(MD5_CTX *ctx)
Definition: md5_hash.cpp:210
bool m_valid
Definition: md5_hash.h:51
uint32_t state[4]
Definition: md5_hash.h:43
void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len)
Definition: md5_hash.cpp:221
uint32_t datalen
Definition: md5_hash.h:41
void md5_transform(MD5_CTX *ctx, uint8_t data[])
Definition: md5_hash.cpp:121
uint8_t m_hash[16]
Definition: md5_hash.h:53
uint8_t data[64]
Definition: md5_hash.h:40
bool operator==(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:84
void Init()
Definition: md5_hash.cpp:59
void Finalize()
Definition: md5_hash.cpp:76
bool IsValid() const
Definition: md5_hash.h:24
MD5_CTX m_ctx
Definition: md5_hash.h:52
void SetValid(bool aValid)
Definition: md5_hash.h:26
MD5_HASH & operator=(const MD5_HASH &aOther)
Definition: md5_hash.cpp:49
~MD5_HASH()
Definition: md5_hash.cpp:44