md5.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef MD5_H
  2. #define MD5_H
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct
  8. {
  9. uint32_t count[2];
  10. uint32_t state[4];
  11. uint8_t buffer[64];
  12. }md5_ctx_t;
  13. #define F(x,y,z) ((x & y) | (~x & z))
  14. #define G(x,y,z) ((x & z) | (y & ~z))
  15. #define H(x,y,z) (x^y^z)
  16. #define I(x,y,z) (y ^ (x | ~z))
  17. #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
  18. #define FF(a,b,c,d,x,s,ac) \
  19. { \
  20. a += F(b, c, d) + x + ac; \
  21. a = ROTATE_LEFT(a, s); \
  22. a += b; \
  23. }
  24. #define GG(a,b,c,d,x,s,ac) \
  25. { \
  26. a += G(b, c, d) + x + ac; \
  27. a = ROTATE_LEFT(a, s); \
  28. a += b; \
  29. }
  30. #define HH(a,b,c,d,x,s,ac) \
  31. { \
  32. a += H(b, c, d) + x + ac; \
  33. a = ROTATE_LEFT(a, s); \
  34. a += b; \
  35. }
  36. #define II(a,b,c,d,x,s,ac) \
  37. { \
  38. a += I(b, c, d) + x + ac; \
  39. a = ROTATE_LEFT(a, s); \
  40. a += b; \
  41. }
  42. void md5_init(md5_ctx_t* context);
  43. void md5_update(md5_ctx_t* context, uint8_t* input, uint32_t inputlen);
  44. void md5_final(md5_ctx_t* context, uint8_t digest[16]);
  45. void md5_transform(uint32_t state[4], uint8_t block[64]);
  46. void md5_encode(uint8_t* output, uint32_t* input, uint32_t len);
  47. void md5_decode(uint32_t* output, uint8_t* input, uint32_t len);
  48. int md5_calc(void* p1, int len1, void* p2, int len2, char* md5);
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. #endif