|
|
|
|
@ -57,13 +57,11 @@ documentation and/or software.
|
|
|
|
|
#define S43 15
|
|
|
|
|
#define S44 21
|
|
|
|
|
|
|
|
|
|
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_memset PROTO_LIST ((POINTER, int, unsigned int));
|
|
|
|
|
static void MD5Transform(UINT4 [4], unsigned char [64]);
|
|
|
|
|
static void Encode(unsigned char *, UINT4 *, unsigned int);
|
|
|
|
|
static void Decode(UINT4 *, unsigned char *, unsigned int);
|
|
|
|
|
static void MD5_memcpy(POINTER, POINTER, unsigned int);
|
|
|
|
|
static void MD5_memset(POINTER, int, unsigned int);
|
|
|
|
|
|
|
|
|
|
static unsigned char PADDING[64] = {
|
|
|
|
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
@ -108,8 +106,7 @@ Rotation is separate from addition to prevent recomputation.
|
|
|
|
|
|
|
|
|
|
/* MD5 initialization. Begins an MD5 operation, writing a new context.
|
|
|
|
|
*/
|
|
|
|
|
void MD5Init (context)
|
|
|
|
|
MD5_CTX *context; /* context */
|
|
|
|
|
void MD5Init (MD5_CTX *context)
|
|
|
|
|
{
|
|
|
|
|
context->count[0] = context->count[1] = 0;
|
|
|
|
|
/* Load magic initialization constants.
|
|
|
|
|
@ -124,10 +121,10 @@ MD5_CTX *context; /* 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 */
|
|
|
|
|
void MD5Update (MD5_CTX *context, /* context */
|
|
|
|
|
unsigned char *input, /* input block */
|
|
|
|
|
unsigned int inputLen /* length of input block */
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, index, partLen;
|
|
|
|
|
|
|
|
|
|
@ -167,9 +164,7 @@ unsigned int inputLen; /* length of input block */
|
|
|
|
|
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
|
|
|
|
|
the message digest and zeroizing the context.
|
|
|
|
|
*/
|
|
|
|
|
void MD5Final (digest, context)
|
|
|
|
|
unsigned char digest[16]; /* message digest */
|
|
|
|
|
MD5_CTX *context; /* context */
|
|
|
|
|
void MD5Final (unsigned char digest[16], MD5_CTX *context)
|
|
|
|
|
{
|
|
|
|
|
unsigned char bits[8];
|
|
|
|
|
unsigned int index, padLen;
|
|
|
|
|
@ -196,9 +191,7 @@ MD5_CTX *context; /* context */
|
|
|
|
|
|
|
|
|
|
/* MD5 basic transformation. Transforms state based on block.
|
|
|
|
|
*/
|
|
|
|
|
static void MD5Transform (state, block)
|
|
|
|
|
UINT4 state[4];
|
|
|
|
|
unsigned char block[64];
|
|
|
|
|
static void MD5Transform (UINT4 state[4], unsigned char block[64])
|
|
|
|
|
{
|
|
|
|
|
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
|
|
|
|
|
|
|
|
|
@ -289,10 +282,7 @@ unsigned char block[64];
|
|
|
|
|
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
|
|
|
|
|
a multiple of 4.
|
|
|
|
|
*/
|
|
|
|
|
static void Encode (output, input, len)
|
|
|
|
|
unsigned char *output;
|
|
|
|
|
UINT4 *input;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
|
|
@ -307,10 +297,7 @@ unsigned int len;
|
|
|
|
|
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
|
|
|
|
|
a multiple of 4.
|
|
|
|
|
*/
|
|
|
|
|
static void Decode (output, input, len)
|
|
|
|
|
UINT4 *output;
|
|
|
|
|
unsigned char *input;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
|
|
@ -322,36 +309,30 @@ unsigned int len;
|
|
|
|
|
/* Note: Replace "for loop" with standard memcpy if possible.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void MD5_memcpy (output, input, len)
|
|
|
|
|
POINTER output;
|
|
|
|
|
POINTER input;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
static void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#ifndef USE_MEM
|
|
|
|
|
unsigned int i;
|
|
|
|
|
// #ifndef USE_MEM
|
|
|
|
|
// unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
|
output[i] = input[i];
|
|
|
|
|
#else
|
|
|
|
|
// for (i = 0; i < len; i++)
|
|
|
|
|
// output[i] = input[i];
|
|
|
|
|
// #else
|
|
|
|
|
memcpy( output, input, len );
|
|
|
|
|
#endif
|
|
|
|
|
// #endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Note: Replace "for loop" with standard memset if possible.
|
|
|
|
|
*/
|
|
|
|
|
static void MD5_memset (output, value, len)
|
|
|
|
|
POINTER output;
|
|
|
|
|
int value;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
static void MD5_memset (POINTER output, int value, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#ifndef USE_MEM
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
|
((char *)output)[i] = (char)value;
|
|
|
|
|
#else
|
|
|
|
|
// #ifndef USE_MEM
|
|
|
|
|
// unsigned int i;
|
|
|
|
|
// for (i = 0; i < len; i++)
|
|
|
|
|
// ((char *)output)[i] = (char)value;
|
|
|
|
|
// #else
|
|
|
|
|
memset( output, value, len );
|
|
|
|
|
#endif
|
|
|
|
|
// #endif
|
|
|
|
|
}
|
|
|
|
|
|