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 <ari@suutari.iki.fi>
This commit is contained in:
Poul-Henning Kamp 1998-03-27 10:23:00 +00:00
parent f9be84912c
commit c6bcf724da
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=34909
8 changed files with 81 additions and 28 deletions

View File

@ -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 *);

View File

@ -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);

View File

@ -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 *);

View File

@ -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);

View File

@ -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 <sys/types.h>
#ifdef KERNEL
#include <sys/param.h>
#include <sys/systm.h>
#else
#include <string.h>
@ -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);

View File

@ -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

View File

@ -22,7 +22,7 @@
* These notices must be retained in any copies of any part of this
* documentation and/or software.
*
* $Id: md5c.c,v 1.9 1997/08/02 14:31:35 bde Exp $
* $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.
@ -191,13 +191,11 @@ MD5Update (context, input, inputLen)
}
/*
* 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];
@ -213,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);

View File

@ -1,5 +1,5 @@
/* MD5.H - header file for MD5C.C
* $Id: md5.h,v 1.8 1997/02/22 09:45:33 peter Exp $
* $Id: md5.h,v 1.9 1997/08/25 05:24:31 joerg Exp $
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
@ -38,6 +38,7 @@ typedef struct MD5Context {
__BEGIN_DECLS
void MD5Init (MD5_CTX *);
void MD5Update (MD5_CTX *, const unsigned char *, unsigned int);
void MD5Pad (MD5_CTX *);
void MD5Final (unsigned char [16], MD5_CTX *);
char * MD5End(MD5_CTX *, char *);
char * MD5File(const char *, char *);