MD5 and HMAC-MD5 class
Spaniakos - MD5 and HMAC-MD5 class for arduino and Raspberry Pi
MD5.h
1 #ifndef MD5_h
2 #define MD5_h
3 
10 #include "MD5_config.h"
11 /*
12  * This is an OpenSSL-compatible implementation of the RSA Data Security,
13  * Inc. MD5 Message-Digest Algorithm (RFC 1321).
14  *
15  * Written by Solar Designer <solar at openwall.com> in 2001, and placed
16  * in the public domain. There's absolutely no warranty.
17  *
18  * This differs from Colin Plumb's older public domain implementation in
19  * that no 32-bit integer data type is required, there's no compile-time
20  * endianness configuration, and the function prototypes match OpenSSL's.
21  * The primary goals are portability and ease of use.
22  *
23  * This implementation is meant to be fast, but not as fast as possible.
24  * Some known optimizations are not included to reduce source code size
25  * and avoid compile-time configuration.
26  */
27 
28 /*
29  * Updated by Scott MacVicar for arduino
30  * <scott@macvicar.net>
31  */
32 
33 typedef unsigned long MD5_u32plus;
34 
35 typedef struct {
36  MD5_u32plus lo, hi;
37  MD5_u32plus a, b, c, d;
38  unsigned char buffer[64];
39  MD5_u32plus block[16];
40 } MD5_CTX;
42 class MD5
43 {
44 public:
49  MD5();
50 
60  unsigned char* make_hash(const void *arg);
61 
70  char* make_digest(const unsigned char *digest, int len);
71 
79  char* md5(const void *arg);
80 
93  void hmac_md5(const void *text, int text_len,void *key, int key_len, unsigned char *digest);
94 
104  char* hmac_md5(const void *text, int text_len,void *key, int key_len);
105 
113  static const void *body(void *ctxBuf, const void *data, size_t size);
114 
120  static void MD5Init(void *ctxBuf);
121 
122 
129  static void MD5Final(unsigned char *result, void *ctxBuf);
130 
139  static void MD5Update(void *ctxBuf, const void *data, size_t size);
140  #if defined(MD5_LINUX)
141 
146  double millis();
147  #endif
148 private:
149  #if defined(MD5_LINUX)
150  timeval tv;
151  #endif
152 };
153 extern MD5 hashMD5;
154 #endif
155 
static void MD5Update(void *ctxBuf, const void *data, size_t size)
Definition: MD5.cpp:194
unsigned char * make_hash(const void *arg)
Definition: MD5.cpp:281
double millis()
Definition: MD5.cpp:381
static const void * body(void *ctxBuf, const void *data, size_t size)
Definition: MD5.cpp:72
static void MD5Final(unsigned char *result, void *ctxBuf)
Definition: MD5.cpp:230
MD5_u32plus lo
Definition: MD5.h:36
Definition: MD5.h:42
char * make_digest(const unsigned char *digest, int len)
Definition: MD5.cpp:9
MD5_u32plus d
Definition: MD5.h:37
char * md5(const void *arg)
Definition: MD5.cpp:291
timeval tv
Definition: MD5.h:150
static void MD5Init(void *ctxBuf)
Definition: MD5.cpp:182
MD5()
Definition: MD5.cpp:3
void hmac_md5(const void *text, int text_len, void *key, int key_len, unsigned char *digest)
Definition: MD5.cpp:295
Definition: MD5.h:35