X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;ds=sidebyside;f=uip%2Fmd5.c;fp=uip%2Fmd5.c;h=a40d2898c3c13415361e4952b43202e1d7ac7cbe;hb=a485ed478abbd599d8c9aab48934e7a26733ecb1;hp=5e0ab3be1420cd810d0f9adc568fddb7f0b2e3d6;hpb=f480c03187724e54e5391ee61b810827da319a6c;p=mmh diff --git a/uip/md5.c b/uip/md5.c index 5e0ab3b..a40d289 100644 --- a/uip/md5.c +++ b/uip/md5.c @@ -1,4 +1,3 @@ - /* * md5.c -- md5 message digest algorithm * taken from RFC-1321/Appendix A.3 @@ -75,37 +74,37 @@ static unsigned char PADDING[64] = { #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. -Rotation is separate from addition to prevent recomputation. + * 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); \ - } + (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) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} #define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} #define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} /* MD5 initialization. Begins an MD5 operation, writing a new context. */ void MD5Init (context) -MD5_CTX *context; /* context */ +MD5_CTX *context; /* context */ { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. -*/ + */ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; @@ -113,13 +112,13 @@ MD5_CTX *context; /* context */ } /* MD5 block update operation. Continues an MD5 message-digest - operation, processing another message block, and updating the - context. + * operation, processing another message block, and updating the + * context. */ void MD5Update (context, input, inputLen) -MD5_CTX *context; /* context */ -unsigned char *input; /* input block */ -unsigned int inputLen; /* length of input block */ +MD5_CTX *context; /* context */ +unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ { unsigned int i, index, partLen; @@ -127,25 +126,23 @@ unsigned int inputLen; /* length of input block */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += ((UINT4)inputLen << 3)) - < ((UINT4)inputLen << 3)) - context->count[1]++; + if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) + context->count[1]++; context->count[1] += ((UINT4)inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { - memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); - MD5Transform (context->state, context->buffer); + memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform (context->state, &input[i]); + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); - index = 0; - } - else - i = 0; + index = 0; + } else + i = 0; /* Buffer remaining input */ memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); @@ -156,8 +153,8 @@ unsigned int inputLen; /* length of input block */ * the message digest and zeroizing the context. */ void MD5Final (digest, context) -unsigned char digest[16]; /* message digest */ -MD5_CTX *context; /* context */ +unsigned char digest[16]; /* message digest */ +MD5_CTX *context; /* context */ { unsigned char bits[8]; unsigned int index, padLen; @@ -166,7 +163,7 @@ MD5_CTX *context; /* context */ Encode (bits, context->count, 8); /* Pad out to 56 mod 64. -*/ + */ index = (unsigned int)((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update (context, PADDING, padLen); @@ -272,7 +269,7 @@ unsigned char block[64]; } /* Encodes input (UINT4) into output (unsigned char). Assumes len is - a multiple of 4. + * a multiple of 4. */ static void Encode (output, input, len) unsigned char *output; @@ -282,15 +279,15 @@ unsigned int len; unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is - a multiple of 4. + * a multiple of 4. */ static void Decode (output, input, len) UINT4 *output; @@ -300,7 +297,6 @@ unsigned int len; unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } -