00001 #ifndef __HxMD5H__
00002 #define __HxMD5H__
00003
00004 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00005 # pragma once
00006 #endif
00007
00008
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <string>
00013
00014 using namespace std;
00015
00016 #ifndef MD5EX_CRCBIN_LEN
00017 #define MD5EX_CRCBIN_LEN 16
00018 #define MD5EX_CRCSTR_LEN 32
00019 #endif
00020
00021
00022 #ifndef uint32
00023 #ifdef __alpha
00024 typedef unsigned int uint32;
00025 #else
00026 typedef unsigned int uint32;
00027 #endif
00028 #endif
00029
00030 class MD5_CTX {
00031 public:
00032 MD5_CTX();
00033 virtual ~MD5_CTX();
00034
00035 void update(const char *value, unsigned len);
00036 void final(unsigned char digest[16]);
00037
00038 uint32 state[4];
00039 uint32 count[2];
00040 unsigned char in[64];
00041 };
00042
00043
00044
00045
00046
00047 #define F1(x, y, z) (z ^ (x & (y ^ z)))
00048 #define F2(x, y, z) F1(z, x, y)
00049 #define F3(x, y, z) (x ^ y ^ z)
00050 #define F4(x, y, z) (y ^ (x | ~z))
00051
00052
00053 #define MD5STEP(f, w, x, y, z, data, s) \
00054 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
00055
00056
00057 namespace HxMD5 {
00058 void md5(const string& what, string& md5 );
00059 void MD5Transform(uint32 buf[4], uint32 in[16]);
00060 void CRCToString(unsigned char pcCrc[MD5EX_CRCSTR_LEN], string& dest);
00061 }
00062
00063 #endif