Change this to do what it should have done from the start.
Add argument for buffer for output. Fix manuals.
This commit is contained in:
parent
270d5e9f91
commit
05f65b296e
@ -3,13 +3,17 @@
|
||||
LIB= md
|
||||
NOPIC= true
|
||||
SRCS= md2c.c md4c.c md5c.c md2hl.c md4hl.c md5hl.c
|
||||
MAN3+= mdX.3
|
||||
MLINKS+=mdX.3 MD2Init.3 mdX.3 MD2Update.3 mdX.3 MD2Final.3
|
||||
MLINKS+=mdX.3 MD2End.3 mdX.3 MD2File.3 mdX.3 MD2Data.3
|
||||
MLINKS+=mdX.3 MD4Init.3 mdX.3 MD4Update.3 mdX.3 MD4Final.3
|
||||
MLINKS+=mdX.3 MD4End.3 mdX.3 MD4File.3 mdX.3 MD4Data.3
|
||||
MLINKS+=mdX.3 MD5Init.3 mdX.3 MD5Update.3 mdX.3 MD5Final.3
|
||||
MLINKS+=mdX.3 MD5End.3 mdX.3 MD5File.3 mdX.3 MD5Data.3
|
||||
.if exists(obj)
|
||||
MAN3+= obj/md2.3 obj/md4.3 obj/md5.3
|
||||
.else
|
||||
MAN3+= md2.3 md4.3 md5.3
|
||||
.endif
|
||||
MLINKS+=md2.3 MD2Init.3 md2.3 MD2Update.3 md2.3 MD2Final.3
|
||||
MLINKS+=md2.3 MD2End.3 md2.3 MD2File.3 md2.3 MD2Data.3
|
||||
MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3
|
||||
MLINKS+=md4.3 MD4End.3 md4.3 MD4File.3 md4.3 MD4Data.3
|
||||
MLINKS+=md5.3 MD5Init.3 md5.3 MD5Update.3 md5.3 MD5Final.3
|
||||
MLINKS+=md5.3 MD5End.3 md5.3 MD5File.3 md5.3 MD5Data.3
|
||||
CLEANFILES+= md[245]hl.c md[245].ref md[245].3 mddriver
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
|
||||
|
@ -33,8 +33,8 @@ typedef struct {
|
||||
void MD2Init(MD2_CTX *);
|
||||
void MD2Update(MD2_CTX *, const unsigned char *, unsigned int);
|
||||
void MD2Final(unsigned char [16], MD2_CTX *);
|
||||
char * MD2End(MD2_CTX *);
|
||||
char * MD2File(char *);
|
||||
char * MD2Data(const unsigned char *, unsigned int);
|
||||
char * MD2End(MD2_CTX *, char *);
|
||||
char * MD2File(char *, char *);
|
||||
char * MD2Data(const unsigned char *, unsigned int, char *);
|
||||
|
||||
#endif /* _MD2_H_ */
|
||||
|
@ -35,8 +35,8 @@ typedef struct {
|
||||
void MD4Init(MD4_CTX *);
|
||||
void MD4Update(MD4_CTX *, const unsigned char *, unsigned int);
|
||||
void MD4Final(unsigned char [16], MD4_CTX *);
|
||||
char * MD4End(MD4_CTX *);
|
||||
char * MD4File(char *);
|
||||
char * MD4Data(const unsigned char *, unsigned int);
|
||||
char * MD4End(MD4_CTX *, char *);
|
||||
char * MD4File(char *, char *);
|
||||
char * MD4Data(const unsigned char *, unsigned int, char *);
|
||||
|
||||
#endif /* _MD4_H_ */
|
||||
|
@ -36,7 +36,7 @@ typedef struct {
|
||||
void MD5Init (MD5_CTX *);
|
||||
void MD5Update (MD5_CTX *, const unsigned char *, unsigned int);
|
||||
void MD5Final (unsigned char [16], MD5_CTX *);
|
||||
char * MD5End(MD5_CTX *);
|
||||
char * MD5File(char *);
|
||||
char * MD5Data(const unsigned char *, unsigned int);
|
||||
char * MD5End(MD5_CTX *, char *);
|
||||
char * MD5File(char *, char *);
|
||||
char * MD5Data(const unsigned char *, unsigned int, char *);
|
||||
#endif /* _MD5_H_ */
|
||||
|
@ -28,11 +28,11 @@
|
||||
.Ft void
|
||||
.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context"
|
||||
.Ft "char *"
|
||||
.Fn MDXEnd "MDX_CTX *context"
|
||||
.Fn MDXEnd "MDX_CTX *context" "char *buf"
|
||||
.Ft "char *"
|
||||
.Fn MDXFile "char *filename"
|
||||
.Fn MDXFile "char *filename" "char *buf"
|
||||
.Ft "char *"
|
||||
.Fn MDXData "unsigned char *data" "unsigned int len"
|
||||
.Fn MDXData "unsigned char *data" "unsigned int len" "char *buf"
|
||||
.Sh DESCRIPTION
|
||||
The MDX functions calculate a 128-bit cryptographic checksum (digest)
|
||||
for any number of input bytes. A cryptographic checksum is a one-way
|
||||
@ -59,28 +59,37 @@ and finally extract the result using
|
||||
.Fn MDXFinal .
|
||||
|
||||
.Fn MDXEnd
|
||||
is identical to
|
||||
is a wrapper for
|
||||
.Fn MDXFinal ,
|
||||
except the return is in ASCII-HEX in a
|
||||
string allocated with
|
||||
.Xr malloc 3 .
|
||||
which converts the return value to a 33 character (incl terminating NULL)
|
||||
ascii string which represents the 128 bits in hexadecimal.
|
||||
|
||||
.Fn MDXFile
|
||||
calculates the digest of a file, and returns the ASCII-HEX result.
|
||||
calculates the digest of a file, and uses
|
||||
.Fn MDXFinal
|
||||
to return the result.
|
||||
In case the file cannot be opened, NULL is returned.
|
||||
|
||||
.Fn MDXData
|
||||
calculates the digest of a chunk of data in memory, and returns the ASCII-HEX
|
||||
result.
|
||||
calculates the digest of a chunk of data in memory, and uses
|
||||
.Fn MDXFinal
|
||||
to return the result.
|
||||
|
||||
When using
|
||||
.Fn MDXEnd ,
|
||||
.Fn MDXFile
|
||||
and
|
||||
or
|
||||
.Fn MDXData ,
|
||||
the returned string must be explicitly deallocated using
|
||||
the
|
||||
.Ar buf
|
||||
argument can be NULL, in which case the returned string is allocated with
|
||||
.Xr malloc 3
|
||||
and subsequently must be explicitly deallocated using
|
||||
.Xr free 3
|
||||
after use.
|
||||
If the
|
||||
.Ar buf
|
||||
argument isn't NULL it must point to at least 33 characters of buffer space.
|
||||
.Sh SEE ALSO
|
||||
.Xr md2 3 ,
|
||||
.Xr md4 3 ,
|
||||
@ -111,6 +120,6 @@ No method is known to exist which finds two files having the same hash value,
|
||||
nor to find a file with a specific hash value.
|
||||
There is on the other hand no guarantee that such a method doesn't exist.
|
||||
|
||||
MD2 can only be used for Privacy Enhanced Mail.
|
||||
MD2 has only been released for use in Privacy Enhanced eMail.
|
||||
Use MD4 or MD5 if that isn't what you're doing.
|
||||
.Sh COPYRIGHT
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: mdXhl.c,v 1.4 1995/04/27 16:05:51 wollman Exp $
|
||||
* $Id: mdXhl.c,v 1.5 1995/05/30 05:45:17 rgrimes Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -20,16 +20,19 @@
|
||||
#include <unistd.h>
|
||||
|
||||
char *
|
||||
MDXEnd(MDX_CTX *ctx)
|
||||
MDXEnd(MDX_CTX *ctx, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = malloc(33);
|
||||
unsigned char digest[16];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
if(!p) return 0;
|
||||
if (!p)
|
||||
p = malloc(33);
|
||||
if (!p)
|
||||
return 0;
|
||||
MDXFinal(digest,ctx);
|
||||
for(i=0;i<16;i++) {
|
||||
for (i=0;i<16;i++) {
|
||||
p[i+i] = hex[digest[i] >> 4];
|
||||
p[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
@ -38,7 +41,7 @@ MDXEnd(MDX_CTX *ctx)
|
||||
}
|
||||
|
||||
char *
|
||||
MDXFile (char *filename)
|
||||
MDXFile (char *filename, char *buf)
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MDX_CTX ctx;
|
||||
@ -46,23 +49,23 @@ MDXFile (char *filename)
|
||||
|
||||
MDXInit(&ctx);
|
||||
f = open(filename,O_RDONLY);
|
||||
if(f < 0) return 0;
|
||||
while((i = read(f,buffer,sizeof buffer)) > 0) {
|
||||
if (f < 0) return 0;
|
||||
while ((i = read(f,buffer,sizeof buffer)) > 0) {
|
||||
MDXUpdate(&ctx,buffer,i);
|
||||
}
|
||||
j = errno;
|
||||
close(f);
|
||||
errno = j;
|
||||
if(i < 0) return 0;
|
||||
return MDXEnd(&ctx);
|
||||
if (i < 0) return 0;
|
||||
return MDXEnd(&ctx, buf);
|
||||
}
|
||||
|
||||
char *
|
||||
MDXData (const unsigned char *data, unsigned int len)
|
||||
MDXData (const unsigned char *data, unsigned int len, char *buf)
|
||||
{
|
||||
MDX_CTX ctx;
|
||||
|
||||
MDXInit(&ctx);
|
||||
MDXUpdate(&ctx,data,len);
|
||||
return MDXEnd(&ctx);
|
||||
return MDXEnd(&ctx, buf);
|
||||
}
|
||||
|
@ -42,8 +42,10 @@
|
||||
static void MDString (string)
|
||||
char *string;
|
||||
{
|
||||
char buf[33];
|
||||
|
||||
printf ("MD%d (\"%s\") = %s\n", MD, string, MDData(string,strlen(string)));
|
||||
printf ("MD%d (\"%s\") = %s\n",
|
||||
MD, string, MDData(string,strlen(string),buf));
|
||||
}
|
||||
|
||||
/* Digests a reference suite of strings and prints the results.
|
||||
|
@ -36,7 +36,7 @@ typedef struct {
|
||||
void MD5Init (MD5_CTX *);
|
||||
void MD5Update (MD5_CTX *, const unsigned char *, unsigned int);
|
||||
void MD5Final (unsigned char [16], MD5_CTX *);
|
||||
char * MD5End(MD5_CTX *);
|
||||
char * MD5File(char *);
|
||||
char * MD5Data(const unsigned char *, unsigned int);
|
||||
char * MD5End(MD5_CTX *, char *);
|
||||
char * MD5File(char *, char *);
|
||||
char * MD5Data(const unsigned char *, unsigned int, char *);
|
||||
#endif /* _MD5_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user