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 
10 class MD5_HASH
11 {
12 
13 public:
14  MD5_HASH();
15  MD5_HASH( const MD5_HASH& aOther );
16 
17  ~MD5_HASH();
18 
19  void Init();
20  void Hash ( uint8_t *data, uint32_t length );
21  void Hash ( int value );
22  void Finalize();
23  bool IsValid() const { return m_valid; };
24 
25  void SetValid( bool aValid ) { m_valid = aValid; }
26 
27  MD5_HASH& operator=( const MD5_HASH& aOther );
28 
29  bool operator==( const MD5_HASH& aOther ) const;
30  bool operator!=( const MD5_HASH& aOther ) const;
31 
32 private:
33  struct MD5_CTX {
34  uint8_t data[64];
35  uint32_t datalen;
36  uint32_t bitlen[2];
37  uint32_t state[4];
38  };
39 
40  void md5_transform(MD5_CTX *ctx, uint8_t data[]);
41  void md5_init(MD5_CTX *ctx);
42  void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len);
43  void md5_final(MD5_CTX *ctx, uint8_t hash[]);
44 
45  bool m_valid;
47  uint8_t m_hash[16];
48 };
49 
50 #endif
MD5_HASH()
Definition: md5_hash.cpp:32
uint32_t bitlen[2]
Definition: md5_hash.h:36
void md5_final(MD5_CTX *ctx, uint8_t hash[])
Definition: md5_hash.cpp:210
bool operator==(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:84
void Hash(uint8_t *data, uint32_t length)
Definition: md5_hash.cpp:66
void md5_init(MD5_CTX *ctx)
Definition: md5_hash.cpp:184
bool m_valid
Definition: md5_hash.h:45
uint32_t state[4]
Definition: md5_hash.h:37
void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len)
Definition: md5_hash.cpp:195
uint32_t datalen
Definition: md5_hash.h:35
void md5_transform(MD5_CTX *ctx, uint8_t data[])
Definition: md5_hash.cpp:95
uint8_t m_hash[16]
Definition: md5_hash.h:47
bool IsValid() const
Definition: md5_hash.h:23
void Init()
Definition: md5_hash.cpp:59
void Finalize()
Definition: md5_hash.cpp:76
bool operator!=(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:89
MD5_CTX m_ctx
Definition: md5_hash.h:46
void SetValid(bool aValid)
Definition: md5_hash.h:25
MD5_HASH & operator=(const MD5_HASH &aOther)
Definition: md5_hash.cpp:49
~MD5_HASH()
Definition: md5_hash.cpp:44