NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
md5.h
1 // //////////////////////////////////////////////////////////
2 // md5.h
3 // Copyright (c) 2014 Stephan Brumme. All rights reserved.
4 // see http://create.stephan-brumme.com/disclaimer.html
5 //
6 
7 #pragma once
8 
9 //#include "hash.h"
10 #include <string>
11 
12 // define fixed size integer types
13 #ifdef _MSC_VER
14 // Windows
15 typedef unsigned __int8 uint8_t;
16 typedef unsigned __int32 uint32_t;
17 typedef unsigned __int64 uint64_t;
18 #else
19 // GCC
20 #include <stdint.h>
21 #endif
22 
23 namespace hash_lib
24 {
25 
27 
39 class MD5 //: public Hash
40 {
41 public:
43  enum { BlockSize = 512 / 8, HashBytes = 16 };
44 
46  MD5();
47 
49  std::string operator()(const void* data, size_t numBytes);
51  std::string operator()(const std::string& text);
52 
54  void add(const void* data, size_t numBytes);
55 
57  std::string getHash();
59  void getHash(unsigned char buffer[MD5::HashBytes]);
60 
62  void reset();
63 
64 private:
66  void processBlock(const void* data);
68  void processBuffer();
69 
71  uint64_t m_numBytes;
73  size_t m_bufferSize;
75  uint8_t m_buffer[BlockSize];
76 
77  enum { HashValues = HashBytes / 4 };
79  uint32_t m_hash[HashValues];
80 };
81 
82 }
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition: md5.cpp:212
MD5()
same as reset()
Definition: md5.cpp:17
std::string getHash()
return latest hash as 32 hex characters
Definition: md5.cpp:322
compute MD5 hash
Definition: md5.h:39
std::string operator()(const void *data, size_t numBytes)
compute MD5 of a memory block
Definition: md5.cpp:368
void reset()
restart
Definition: md5.cpp:24