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 
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;
55  uint8_t m_hash[16];
56 };
57 
58 #endif
MD5_HASH()
Definition: md5_hash.cpp:32
uint32_t bitlen[2]
Definition: md5_hash.h:44
bool operator!=(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:87
void md5_final(MD5_CTX *ctx, uint8_t hash[])
Definition: md5_hash.cpp:236
void Hash(uint8_t *data, uint32_t length)
Definition: md5_hash.cpp:65
void md5_init(MD5_CTX *ctx)
Definition: md5_hash.cpp:210
bool m_valid
Definition: md5_hash.h:53
uint32_t state[4]
Definition: md5_hash.h:45
void md5_update(MD5_CTX *ctx, uint8_t data[], uint32_t len)
Definition: md5_hash.cpp:221
uint32_t datalen
Definition: md5_hash.h:43
void md5_transform(MD5_CTX *ctx, uint8_t data[])
Definition: md5_hash.cpp:121
uint8_t m_hash[16]
Definition: md5_hash.h:55
uint8_t data[64]
Definition: md5_hash.h:42
bool operator==(const MD5_HASH &aOther) const
Definition: md5_hash.cpp:82
std::string Format(bool aCompactForm=false)
Definition: md5_hash.cpp:93
void Init()
Definition: md5_hash.cpp:59
void Finalize()
Definition: md5_hash.cpp:75
bool IsValid() const
Definition: md5_hash.h:24
MD5_CTX m_ctx
Definition: md5_hash.h:54
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