- Liberal application of suggestions in /usr/share/misc/style.
- Don't use sed(1) to generate these files. The C preprocessor is your friend.
This commit is contained in:
parent
754137acc9
commit
30e6b470fc
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile.inc,v 1.1 1997/01/30 01:01:39 thorpej Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.2 1997/04/30 00:40:44 thorpej Exp $
|
||||
|
||||
# MD4/MD5 sources
|
||||
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/md ${.CURDIR}/md
|
||||
|
@ -14,12 +14,6 @@ MLINKS+=md5.3 MD5End.3 md5.3 MD5File.3 md5.3 MD5Data.3
|
|||
|
||||
CLEANFILES+= md[45]hl.c md[45].3
|
||||
|
||||
md4hl.c: mdXhl.c
|
||||
sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' $> > $@
|
||||
|
||||
md5hl.c: mdXhl.c
|
||||
sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' $> > $@
|
||||
|
||||
.if !defined(NOMAN)
|
||||
md4.3: mdX.3
|
||||
sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' $> > $@
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/* $NetBSD: md4hl.c,v 1.1 1997/04/30 00:40:45 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Jason R. Thorpe <thorpej@netbsd.org>, April 29, 1997.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#define MDALGORITHM MD4
|
||||
|
||||
#include <md4.h>
|
||||
|
||||
#include "mdXhl.c"
|
|
@ -0,0 +1,12 @@
|
|||
/* $NetBSD: md5hl.c,v 1.1 1997/04/30 00:40:46 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Jason R. Thorpe <thorpej@netbsd.org>, April 29, 1997.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#define MDALGORITHM MD5
|
||||
|
||||
#include <md5.h>
|
||||
|
||||
#include "mdXhl.c"
|
|
@ -1,6 +1,6 @@
|
|||
/* $NetBSD: mdXhl.c,v 1.1 1997/01/30 01:01:44 thorpej Exp $ */
|
||||
/* $NetBSD: mdXhl.c,v 1.2 1997/04/30 00:40:47 thorpej Exp $ */
|
||||
|
||||
/* mdXhl.c
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
|
@ -9,7 +9,10 @@
|
|||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* from FreeBSD Id: mdXhl.c,v 1.8 1996/10/25 06:48:12 bde Exp
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modifed April 29, 1997 by Jason R. Thorpe <thorpej@netbsd.org>
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -20,54 +23,70 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mdX.h"
|
||||
#define CONCAT(x,y) __CONCAT(x,y)
|
||||
#define MDNAME(x) CONCAT(MDALGORITHM,x)
|
||||
|
||||
char *
|
||||
MDXEnd(MDX_CTX *ctx, char *buf)
|
||||
MDNAME(End)(ctx, buf)
|
||||
MDNAME(_CTX) *ctx;
|
||||
char *buf;
|
||||
{
|
||||
int i;
|
||||
unsigned char digest[16];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
int i;
|
||||
unsigned char digest[16];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
if (!buf)
|
||||
buf = malloc(33);
|
||||
if (!buf)
|
||||
return 0;
|
||||
MDXFinal(digest,ctx);
|
||||
for (i=0;i<16;i++) {
|
||||
buf[i+i] = hex[digest[i] >> 4];
|
||||
buf[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
buf[i+i] = '\0';
|
||||
return buf;
|
||||
if (buf == NULL)
|
||||
buf = malloc(33);
|
||||
if (buf == NULL)
|
||||
return (NULL);
|
||||
|
||||
MDNAME(Final)(digest, ctx);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
buf[i+i] = hex[digest[i] >> 4];
|
||||
buf[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
|
||||
buf[i+i] = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
char *
|
||||
MDXFile (char *filename, char *buf)
|
||||
MDNAME(File)(filename, buf)
|
||||
const char *filename;
|
||||
char *buf;
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MDX_CTX ctx;
|
||||
int f,i,j;
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MDNAME(_CTX) ctx;
|
||||
int f, i, j;
|
||||
|
||||
MDXInit(&ctx);
|
||||
f = open(filename,O_RDONLY);
|
||||
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, buf);
|
||||
MDNAME(Init)(&ctx);
|
||||
f = open(filename, O_RDONLY, 0666);
|
||||
if (f < 0)
|
||||
return NULL;
|
||||
|
||||
while ((i = read(f, buffer, sizeof(buffer))) > 0)
|
||||
MDNAME(Update)(&ctx, buffer, i);
|
||||
|
||||
j = errno;
|
||||
close(f);
|
||||
errno = j;
|
||||
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
MDXData (const unsigned char *data, unsigned int len, char *buf)
|
||||
MDNAME(Data)(data, len, buf)
|
||||
const unsigned char *data;
|
||||
unsigned int len;
|
||||
char *buf;
|
||||
{
|
||||
MDX_CTX ctx;
|
||||
MDNAME(_CTX) ctx;
|
||||
|
||||
MDXInit(&ctx);
|
||||
MDXUpdate(&ctx,data,len);
|
||||
return MDXEnd(&ctx, buf);
|
||||
MDNAME(Init)(&ctx);
|
||||
MDNAME(Update)(&ctx, data, len);
|
||||
return (MDNAME(End)(&ctx, buf));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue