From 4db0fa09db895f439a5a91029e7625e329fda730 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 27 Mar 1998 10:23:00 +0000 Subject: Split the padding out into a separate function. Synchronize the kernel and libmd versions of md5c.c PR: misc/6127 Reviewed by: phk Submitted by: Ari Suutari --- lib/libmd/md2.h | 3 ++- lib/libmd/md2c.c | 19 ++++++++++++++----- lib/libmd/md4.h | 3 ++- lib/libmd/md4c.c | 21 +++++++++++++++------ lib/libmd/md5c.c | 27 +++++++++++++++++++-------- lib/libmd/mdX.3 | 11 ++++++++++- 6 files changed, 62 insertions(+), 22 deletions(-) (limited to 'lib/libmd') diff --git a/lib/libmd/md2.h b/lib/libmd/md2.h index 73e8b5a..9c1ac5d 100644 --- a/lib/libmd/md2.h +++ b/lib/libmd/md2.h @@ -1,5 +1,5 @@ /* MD2.H - header file for MD2C.C - * $Id: md2.h,v 1.5 1997/02/22 15:07:12 peter Exp $ + * $Id: md2.h,v 1.6 1997/08/25 05:24:24 joerg Exp $ */ /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All @@ -35,6 +35,7 @@ typedef struct MD2Context { __BEGIN_DECLS void MD2Init(MD2_CTX *); void MD2Update(MD2_CTX *, const unsigned char *, unsigned int); +void MD2Pad(MD2_CTX *); void MD2Final(unsigned char [16], MD2_CTX *); char * MD2End(MD2_CTX *, char *); char * MD2File(const char *, char *); diff --git a/lib/libmd/md2c.c b/lib/libmd/md2c.c index ebf9edc..561337a 100644 --- a/lib/libmd/md2c.c +++ b/lib/libmd/md2c.c @@ -1,5 +1,5 @@ /* MD2C.C - RSA Data Security, Inc., MD2 message-digest algorithm - * $Id$ + * $Id: md2c.c,v 1.5 1997/02/22 15:07:15 peter Exp $ */ /* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All @@ -131,11 +131,9 @@ unsigned int inputLen; /* length of input block */ inputLen-i); } -/* MD2 finalization. Ends an MD2 message-digest operation, writing the - message digest and zeroizing the context. +/* MD2 padding. */ -void MD2Final (digest, context) -unsigned char digest[16]; /* message digest */ +void MD2Pad (context) MD2_CTX *context; /* context */ { unsigned int index, padLen; @@ -148,6 +146,17 @@ MD2_CTX *context; /* context */ /* Extend with checksum */ MD2Update (context, context->checksum, 16); +} + +/* 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 */ +{ + /* Do padding */ + MD2Pad (context); /* Store state in digest */ memcpy ((POINTER)digest, (POINTER)context->state, 16); diff --git a/lib/libmd/md4.h b/lib/libmd/md4.h index 10058a8..cee0e4a 100644 --- a/lib/libmd/md4.h +++ b/lib/libmd/md4.h @@ -1,5 +1,5 @@ /* MD4.H - header file for MD4C.C - * $Id: md4.h,v 1.6 1997/02/22 15:07:17 peter Exp $ + * $Id: md4.h,v 1.7 1997/08/25 05:24:24 joerg Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -37,6 +37,7 @@ typedef struct MD4Context { __BEGIN_DECLS void MD4Init(MD4_CTX *); void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); +void MD4Pad(MD4_CTX *); void MD4Final(unsigned char [16], MD4_CTX *); char * MD4End(MD4_CTX *, char *); char * MD4File(const char *, char *); diff --git a/lib/libmd/md4c.c b/lib/libmd/md4c.c index a0eba4d..71c3af7 100644 --- a/lib/libmd/md4c.c +++ b/lib/libmd/md4c.c @@ -1,5 +1,5 @@ /* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm - * $Id$ + * $Id: md4c.c,v 1.5 1997/02/22 15:07:19 peter Exp $ */ /* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. @@ -141,11 +141,8 @@ unsigned int inputLen; /* length of input block */ inputLen-i); } -/* MD4 finalization. Ends an MD4 message-digest operation, writing the - the message digest and zeroizing the context. - */ -void MD4Final (digest, context) -unsigned char digest[16]; /* message digest */ +/* MD4 padding. */ +void MD4Pad (context) MD4_CTX *context; /* context */ { unsigned char bits[8]; @@ -162,6 +159,18 @@ MD4_CTX *context; /* context */ /* Append length (before padding) */ MD4Update (context, bits, 8); +} + +/* MD4 finalization. Ends an MD4 message-digest operation, writing the + the message digest and zeroizing the context. + */ +void MD4Final (digest, context) +unsigned char digest[16]; /* message digest */ +MD4_CTX *context; /* context */ +{ + /* Do padding */ + MD4Pad (context); + /* Store state in digest */ Encode (digest, context->state, 16); diff --git a/lib/libmd/md5c.c b/lib/libmd/md5c.c index 583d009..c1fdc6d 100644 --- a/lib/libmd/md5c.c +++ b/lib/libmd/md5c.c @@ -22,7 +22,7 @@ * These notices must be retained in any copies of any part of this * documentation and/or software. * - * $Id$ + * $Id: md5c.c,v 1.10 1997/10/21 13:28:36 phk Exp $ * * This code is the same as the code published by RSA Inc. It has been * edited for clarity and style only. @@ -31,7 +31,6 @@ #include #ifdef KERNEL -#include #include #else #include @@ -174,7 +173,7 @@ MD5Update (context, input, inputLen) /* Transform as many times as possible. */ if (inputLen >= partLen) { - memcpy((void *)&context->buffer[index], (void *)input, + memcpy((void *)&context->buffer[index], (const void *)input, partLen); MD5Transform (context->state, context->buffer); @@ -187,18 +186,16 @@ MD5Update (context, input, inputLen) i = 0; /* Buffer remaining input */ - memcpy ((void *)&context->buffer[index], (void *)&input[i], + memcpy ((void *)&context->buffer[index], (const void *)&input[i], inputLen-i); } /* - * MD5 finalization. Ends an MD5 message-digest operation, writing the - * the message digest and zeroizing the context. + * MD5 padding. Adds padding followed by original length. */ void -MD5Final (digest, context) - unsigned char digest[16]; +MD5Pad (context) MD5_CTX *context; { unsigned char bits[8]; @@ -214,6 +211,20 @@ MD5Final (digest, context) /* Append length (before padding) */ MD5Update (context, bits, 8); +} + +/* + * 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]; + MD5_CTX *context; +{ + /* Do padding. */ + MD5Pad (context); /* Store state in digest */ Encode (digest, context->state, 16); diff --git a/lib/libmd/mdX.3 b/lib/libmd/mdX.3 index 7174f7d..21e4d45 100644 --- a/lib/libmd/mdX.3 +++ b/lib/libmd/mdX.3 @@ -6,7 +6,7 @@ .\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp .\" ---------------------------------------------------------------------------- .\" -.\" $Id: mdX.3,v 1.11 1997/08/25 05:24:25 joerg Exp $ +.\" $Id: mdX.3,v 1.12 1998/03/19 07:34:12 charnier Exp $ .\" .Dd October 9, 1996 .Dt MDX 3 @@ -14,6 +14,7 @@ .Sh NAME .Nm MDXInit , .Nm MDXUpdate , +.Nm MDXPad , .Nm MDXFinal , .Nm MDXEnd , .Nm MDXFile , @@ -27,6 +28,8 @@ .Ft void .Fn MDXUpdate "MDX_CTX *context" "const unsigned char *data" "unsigned int len" .Ft void +.Fn MDXPad "MDX_CTX *context" +.Ft void .Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" .Ft "char *" .Fn MDXEnd "MDX_CTX *context" "char *buf" @@ -59,6 +62,12 @@ run over the data with and finally extract the result using .Fn MDXFinal . .Pp +.Fn MDXPad +can be used to pad message data in same way +as done by +.Fn MDXFinal +without terminating calculation. +.Pp .Fn MDXEnd is a wrapper for .Fn MDXFinal -- cgit v1.1