1、#define PROTO_LIST(list) ()/* F, G, H and I are basic MD5 functions.*/#define F(x, y, z) (x) & (y) | (x) & (z)#define G(x, y, z) (x) & (z) | (y) & (z)#define H(x, y, z) (x) (y) (z)#define I(x, y, z) (y) (x) | (z)/* ROTATE_LEFT rotates x left n bits.*/ #define ROTATE_LEFT(x, n) (x) (32-(n)/* FF, GG,
2、HH, and II transformations for rounds 1, 2, 3, and 4.Rotation is separate from addition to prevent recomputation.*/#define FF(a, b, c, d, x, s, ac) (a) += F (b), (c), (d) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT (a), (s); (a) += (b);#define GG(a, b, c, d, x, s, ac) (a) += G (b), (c), (d) + (x) + (UINT
3、4)(ac);#define HH(a, b, c, d, x, s, ac) (a) += H (b), (c), (d) + (x) + (UINT4)(ac); #define II(a, b, c, d, x, s, ac) (a) += I (b), (c), (d) + (x) + (UINT4)(ac);#define MD_CTX MD5_CTX#define MDInit MD5Init#define MD5Update MD5Update#define MDFinal MD5Final/* Length of test block, number of test block
4、s.*/#define TEST_BLOCK_LEN 10000#define TEST_BLOCK_COUNT 10000/* POINTER defines a generic pointer type */typedef unsigned char *POINTER;/* UINT2 defines a two byte word */typedef unsigned short int UINT2;/* UINT4 defines a four byte word */typedef unsigned long int UINT4;/* MD5 context. */typedef s
5、truct UINT4 state4; /* state (ABCD) */ UINT4 count2; /* number of bits, modulo 264 (lsb first) */ unsigned char buffer64; /* input buffer */ MD5_CTX;void MD5Init PROTO_LIST (MD5_CTX *);void MD5Update PROTO_LIST(MD5_CTX *, unsigned char *, unsigned int);void MD5Final PROTO_LIST (unsigned char 16, MD5
6、_CTX *);static void MD5Transform PROTO_LIST (UINT4 4, unsigned char 64);static void Encode PROTO_LIST(unsigned char *, UINT4 *, unsigned int);static void Decode PROTO_LIST(UINT4 *, unsigned char *, unsigned int);static void MD5_memcpy PROTO_LIST (POINTER, POINTER, unsigned int);static void MD5_memse
7、t PROTO_LIST (POINTER, int, unsigned int);static unsigned char PADDING64 = 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;/* MD5 initialization. Begins a
8、n MD5 operation, writing a new context.*/void MD5Init (MD5_CTX *context) /* context */ context-count0 = context-count1 = 0; /* Load magic initialization constants.*/state0 = 0x67452301;state1 = 0xefcdab89;state2 = 0x98badcfe;state3 = 0x10325476;/* Note: Replace for loop with standard memcpy if possi
9、ble.*/static void MD5_memcpy (POINTER output, POINTER input,unsigned int len) unsigned int i; for (i = 0; i len; i+) outputi = inputi; with standard memset if possible.*/static void MD5_memset (POINTER output,int value,unsigned int len) (char *)output)i = (char)value;/* Decodes input (unsigned char)
10、 into output (UINT4). Assumes len isa multiple of 4.*/static void Decode (UINT4 *output, unsigned char *input, unsigned int len) unsigned int i, j; for (i = 0, j = 0; j i+, j += 4) outputi = (UINT4)inputj) | (UINT4)inputj+1) 8) | (UINT4)inputj+2) 16) | (UINT4)inputj+3) count0 3) & 0x3F); /* Update n
11、umber of bits */ if (context-count0 += (UINT4)inputLen 3) (UINT4)inputLen count1+;count1 += (UINT4)inputLen 29); partLen = 64 - index; /* Transform as many times as possible.*/ if (inputLen = partLen) MD5_memcpy(POINTER)&context-bufferindex, (POINTER)input, partLen); MD5Transform (context-state, con
12、text-buffer); for (i = partLen; i + 63 state, &inputi); index = 0; else i = 0; /* Buffer remaining input */ MD5_memcpy(POINTER)&bufferindex, (POINTER)&inputi,inputLen-i);/* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4.*/static void Encode (unsigned char *output,
13、UINT4 *input,unsigned int len) i+, j += 4) outputj = (unsigned char)(inputi & 0xff); outputj+1 = (unsigned char)(inputi 8) & outputj+2 = (unsigned char)(inputi 16) & outputj+3 = (unsigned char)(inputi 24) &/* MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context.*/void MD5Final (unsigned char digest16, MD5_CTX *context) unsigned char bits8; unsigned int index, padLen; /* Save number of bits */ Encode (bits, context-count, 8); /* Pad out to 56 mod 64.*/ 0x3f); padLen = (index 56) ? (56 - index) : (120 - index); MD5Update (c
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1