HxMD5.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __HxMD5H__
  2. #define __HxMD5H__
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  4. # pragma once
  5. #endif
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <string>
  10. using namespace std;
  11. #ifndef MD5EX_CRCBIN_LEN
  12. #define MD5EX_CRCBIN_LEN 16
  13. #define MD5EX_CRCSTR_LEN 32
  14. #endif
  15. #ifndef uint32
  16. #ifdef __alpha
  17. typedef unsigned int uint32;
  18. #else
  19. typedef unsigned int uint32;
  20. #endif
  21. #endif
  22. class MD5_CTX {
  23. public:
  24. MD5_CTX();
  25. virtual ~MD5_CTX();
  26. void update(const char *value, unsigned len);
  27. void final(unsigned char digest[16]);
  28. uint32 state[4];
  29. uint32 count[2];
  30. unsigned char in[64];
  31. };
  32. /* The four core functions - F1 is optimized somewhat */
  33. //#define F1(x, y, z) (x & y | ~x & z)
  34. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  35. #define F2(x, y, z) F1(z, x, y)
  36. #define F3(x, y, z) (x ^ y ^ z)
  37. #define F4(x, y, z) (y ^ (x | ~z))
  38. /* This is the central step in the MD5 algorithm. */
  39. #define MD5STEP(f, w, x, y, z, data, s) \
  40. ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
  41. namespace HxMD5 {
  42. void md5(const string& what, string& md5 );
  43. void MD5Transform(uint32 buf[4], uint32 in[16]);
  44. void CRCToString(unsigned char pcCrc[MD5EX_CRCSTR_LEN], string& dest);
  45. }
  46. #endif