summaryrefslogtreecommitdiffstats
path: root/lib/libmd
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-07-12 09:13:49 +0000
committerphk <phk@FreeBSD.org>1995-07-12 09:13:49 +0000
commitd7d558428400f0ecc5856f6fcf4f56543aa841f8 (patch)
tree8b1350a696f17c97664a31181c2510c3e018115d /lib/libmd
parent0a7cf84cf326542a379591308b02b89e7a365ad6 (diff)
downloadFreeBSD-src-d7d558428400f0ecc5856f6fcf4f56543aa841f8.zip
FreeBSD-src-d7d558428400f0ecc5856f6fcf4f56543aa841f8.tar.gz
Change this to do what it should have done from the start.
Add argument for buffer for output. Fix manuals.
Diffstat (limited to 'lib/libmd')
-rw-r--r--lib/libmd/Makefile18
-rw-r--r--lib/libmd/md2.h6
-rw-r--r--lib/libmd/md4.h6
-rw-r--r--lib/libmd/md5.h6
-rw-r--r--lib/libmd/mdX.335
-rw-r--r--lib/libmd/mdXhl.c25
-rw-r--r--lib/libmd/mddriver.c4
7 files changed, 59 insertions, 41 deletions
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
index 3ec58cc..d543dd5 100644
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -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}
diff --git a/lib/libmd/md2.h b/lib/libmd/md2.h
index 0b81de6..5c343c4 100644
--- a/lib/libmd/md2.h
+++ b/lib/libmd/md2.h
@@ -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_ */
diff --git a/lib/libmd/md4.h b/lib/libmd/md4.h
index 1c73a5d..22f7c06 100644
--- a/lib/libmd/md4.h
+++ b/lib/libmd/md4.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_ */
diff --git a/lib/libmd/md5.h b/lib/libmd/md5.h
index 7a1484c..f5208c5 100644
--- a/lib/libmd/md5.h
+++ b/lib/libmd/md5.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_ */
diff --git a/lib/libmd/mdX.3 b/lib/libmd/mdX.3
index 41c0efb..1c0794b 100644
--- a/lib/libmd/mdX.3
+++ b/lib/libmd/mdX.3
@@ -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
diff --git a/lib/libmd/mdXhl.c b/lib/libmd/mdXhl.c
index d99fb43..817c551 100644
--- a/lib/libmd/mdXhl.c
+++ b/lib/libmd/mdXhl.c
@@ -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);
}
diff --git a/lib/libmd/mddriver.c b/lib/libmd/mddriver.c
index b99e558..fc65156 100644
--- a/lib/libmd/mddriver.c
+++ b/lib/libmd/mddriver.c
@@ -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.
OpenPOWER on IntegriCloud