OpenM++ runtime library (libopenm)
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
15typedef unsigned __int8 uint8_t;
16typedef unsigned __int32 uint32_t;
17typedef unsigned __int64 uint64_t;
18#else
19// GCC
20#include <stdint.h>
21#endif
22
23
25
37class MD5 //: public Hash
38{
39public:
41 enum { BlockSize = 512 / 8, HashBytes = 16 };
42
44 MD5();
45
47 std::string operator()(const void* data, size_t numBytes);
49 std::string operator()(const std::string& text);
50
52 void add(const void* data, size_t numBytes);
53
55 std::string getHash();
57 void getHash(unsigned char buffer[HashBytes]);
58
60 void reset();
61
62private:
64 void processBlock(const void* data);
66 void processBuffer();
67
69 uint64_t m_numBytes;
71 size_t m_bufferSize;
73 uint8_t m_buffer[BlockSize];
74
75 enum { HashValues = HashBytes / 4 };
77 uint32_t m_hash[HashValues];
78};
compute MD5 hash
Definition: md5.h:38
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
std::string operator()(const void *data, size_t numBytes)
compute MD5 of a memory block
Definition: md5.cpp:370
std::string getHash()
return latest hash as 32 hex characters
Definition: md5.cpp:324
void reset()
restart
Definition: md5.cpp:26
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
Definition: md5.cpp:214
MD5()
same as reset()
Definition: md5.cpp:19