--- rsaref/source/md2c.c 2018/04/24 16:37:52 1.1 +++ rsaref/source/md2c.c 2018/04/24 16:38:17 1.1.1.2 @@ -1,7 +1,8 @@ /* MD2C.C - RSA Data Security, Inc., MD2 message-digest algorithm */ -/* Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. +/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All + rights reserved. License to copy and use this software is granted for non-commercial Internet Privacy-Enhanced Mail provided that it is @@ -51,8 +52,11 @@ static unsigned char PI_SUBST[256] = { }; static unsigned char *PADDING[] = { - (unsigned char *)"", (unsigned char *)"\001", (unsigned char *)"\002\002", - (unsigned char *)"\003\003\003", (unsigned char *)"\004\004\004\004", + (unsigned char *)"", + (unsigned char *)"\001", + (unsigned char *)"\002\002", + (unsigned char *)"\003\003\003", + (unsigned char *)"\004\004\004\004", (unsigned char *)"\005\005\005\005\005", (unsigned char *)"\006\006\006\006\006\006", (unsigned char *)"\007\007\007\007\007\007\007", @@ -61,8 +65,10 @@ static unsigned char *PADDING[] = { (unsigned char *)"\012\012\012\012\012\012\012\012\012\012", (unsigned char *)"\013\013\013\013\013\013\013\013\013\013\013", (unsigned char *)"\014\014\014\014\014\014\014\014\014\014\014\014", - (unsigned char *)"\015\015\015\015\015\015\015\015\015\015\015\015\015", - (unsigned char *)"\016\016\016\016\016\016\016\016\016\016\016\016\016\016", + (unsigned char *) + "\015\015\015\015\015\015\015\015\015\015\015\015\015", + (unsigned char *) + "\016\016\016\016\016\016\016\016\016\016\016\016\016\016", (unsigned char *) "\017\017\017\017\017\017\017\017\017\017\017\017\017\017\017", (unsigned char *) @@ -72,20 +78,22 @@ static unsigned char *PADDING[] = { /* MD2 initialization. Begins an MD2 operation, writing a new context. */ void MD2Init (context) -MD2_CTX *context; /* context */ +MD2_CTX *context; /* context */ { context->count = 0; MD2_memset ((POINTER)context->state, 0, sizeof (context->state)); - MD2_memset ((POINTER)context->checksum, 0, sizeof (context->checksum)); + MD2_memset + ((POINTER)context->checksum, 0, sizeof (context->checksum)); } -/* MD2 block update operation. Continues an MD2 message-digest operation, - processing another message block, and updating the context. +/* MD2 block update operation. Continues an MD2 message-digest + operation, processing another message block, and updating the + context. */ void MD2Update (context, input, inputLen) -MD2_CTX *context; /* context */ -unsigned char *input; /* input block */ -unsigned int inputLen; /* length of input block */ +MD2_CTX *context; /* context */ +unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ { unsigned int i, index, partLen; @@ -98,7 +106,8 @@ unsigned int inputLen; /* Transform as many times as possible. */ if (inputLen >= partLen) { - MD2_memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD2_memcpy + ((POINTER)&context->buffer[index], (POINTER)input, partLen); MD2Transform (context->state, context->checksum, context->buffer); for (i = partLen; i + 15 < inputLen; i += 16) @@ -111,15 +120,16 @@ unsigned int inputLen; /* Buffer remaining input */ MD2_memcpy - ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); + ((POINTER)&context->buffer[index], (POINTER)&input[i], + inputLen-i); } /* MD2 finalization. Ends an MD2 message-digest operation, writing the message digest and zeroizing the context. */ void MD2Final (digest, context) -unsigned char digest[16]; /* message digest */ -MD2_CTX *context; /* context */ +unsigned char digest[16]; /* message digest */ +MD2_CTX *context; /* context */ { unsigned int index, padLen; @@ -153,11 +163,10 @@ unsigned char block[16]; /* Form encryption block from state, block, state ^ block. */ - for (i = 0; i < 16; i++) { - x[i] = state[i]; - x[i+16] = block[i]; + MD2_memcpy ((POINTER)x, (POINTER)state, 16); + MD2_memcpy ((POINTER)x+16, (POINTER)block, 16); + for (i = 0; i < 16; i++) x[i+32] = state[i] ^ block[i]; - } /* Encrypt block (18 rounds). */ @@ -169,8 +178,7 @@ unsigned char block[16]; } /* Save new state */ - for (i = 0; i < 16; i++) - state[i] = x[i]; + MD2_memcpy ((POINTER)state, (POINTER)x, 16); /* Update checksum. */