yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #ifndef MD5_H |
| 2 | #define MD5_H |
| 3 | |
| 4 | typedef struct |
| 5 | { |
| 6 | unsigned int count[2]; |
| 7 | unsigned int state[4]; |
| 8 | unsigned char buffer[64]; |
| 9 | }MD5_CTX; |
| 10 | |
| 11 | |
| 12 | #define F(x,y,z) ((x & y) | (~x & z)) |
| 13 | #define G(x,y,z) ((x & z) | (y & ~z)) |
| 14 | #define H(x,y,z) (x^y^z) |
| 15 | #define I(x,y,z) (y ^ (x | ~z)) |
| 16 | #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) |
| 17 | #define FF(a,b,c,d,x,s,ac) \ |
| 18 | { \ |
| 19 | a += F(b,c,d) + x + ac; \ |
| 20 | a = ROTATE_LEFT(a,s); \ |
| 21 | a += b; \ |
| 22 | } |
| 23 | #define GG(a,b,c,d,x,s,ac) \ |
| 24 | { \ |
| 25 | a += G(b,c,d) + x + ac; \ |
| 26 | a = ROTATE_LEFT(a,s); \ |
| 27 | a += b; \ |
| 28 | } |
| 29 | #define HH(a,b,c,d,x,s,ac) \ |
| 30 | { \ |
| 31 | a += H(b,c,d) + x + ac; \ |
| 32 | a = ROTATE_LEFT(a,s); \ |
| 33 | a += b; \ |
| 34 | } |
| 35 | #define II(a,b,c,d,x,s,ac) \ |
| 36 | { \ |
| 37 | a += I(b,c,d) + x + ac; \ |
| 38 | a = ROTATE_LEFT(a,s); \ |
| 39 | a += b; \ |
| 40 | } |
| 41 | |
| 42 | //int get_md5_32(unsigned char *data, int len, unsigned char *digest); |
| 43 | |
| 44 | void MD5Init(MD5_CTX *context); |
| 45 | void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen); |
| 46 | void MD5Final(MD5_CTX *context,unsigned char digest[16]); |
| 47 | void MD5Transform(unsigned int state[4],unsigned char block[64]); |
| 48 | void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len); |
| 49 | void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len); |
| 50 | |
| 51 | |
| 52 | #endif |