diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-06-03 22:20:45 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-06-03 22:20:45 +0000 |
commit | d82cbad05922b34f5dacce3ffc4e8e5cec7a9fca (patch) | |
tree | f23b9a0bfcc15a8bdaebb103d4d2507c2139da7d /lib | |
parent | 922fa08b4ed7e47e63768a64bf4432302b3ffd83 (diff) |
Add md[245] routines in libc/md, remove md5 from libc/crypt. Add $OpenBSD$
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/Makefile | 3 | ||||
-rw-r--r-- | lib/libc/crypt/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/crypt/crypt.3 | 4 | ||||
-rw-r--r-- | lib/libc/crypt/crypt.c | 2 | ||||
-rw-r--r-- | lib/libc/crypt/md5crypt.c | 6 | ||||
-rw-r--r-- | lib/libc/crypt/morecrypt.c | 2 | ||||
-rw-r--r-- | lib/libc/md/Makefile.inc | 39 | ||||
-rw-r--r-- | lib/libc/md/md4.copyright | 20 | ||||
-rw-r--r-- | lib/libc/md/md4c.c | 278 | ||||
-rw-r--r-- | lib/libc/md/md5.copyright (renamed from lib/libc/crypt/md5.h) | 25 | ||||
-rw-r--r-- | lib/libc/md/md5c.c (renamed from lib/libc/crypt/md5c.c) | 4 | ||||
-rw-r--r-- | lib/libc/md/mdX.3 | 125 | ||||
-rw-r--r-- | lib/libc/md/mdXhl.c | 71 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 |
14 files changed, 549 insertions, 36 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile index e1aad2a8ce5..792a68fc397 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -1,5 +1,5 @@ +# $OpenBSD: Makefile,v 1.5 1996/06/03 22:20:31 niklas Exp $ # $NetBSD: Makefile,v 1.47 1995/11/23 02:20:59 jtc Exp $ -# @(#)Makefile 8.2 (Berkeley) 2/3/94 # # All library objects contain sccsid strings by default; they may be # excluded as a space-saving measure. To produce a library that does @@ -35,6 +35,7 @@ CLEANFILES+=tags .include "${.CURDIR}/crypt/Makefile.inc" .include "${.CURDIR}/gmon/Makefile.inc" .include "${.CURDIR}/locale/Makefile.inc" +.include "${.CURDIR}/md/Makefile.inc" .include "${.CURDIR}/net/Makefile.inc" .include "${.CURDIR}/nls/Makefile.inc" .if (${MACHINE_ARCH} != "alpha") diff --git a/lib/libc/crypt/Makefile.inc b/lib/libc/crypt/Makefile.inc index 39ef7486283..7b576e9e19e 100644 --- a/lib/libc/crypt/Makefile.inc +++ b/lib/libc/crypt/Makefile.inc @@ -1,8 +1,8 @@ -# $Id: Makefile.inc,v 1.3 1996/05/30 02:36:32 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1996/06/03 22:20:33 niklas Exp $ .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/crypt ${.CURDIR}/crypt -SRCS+= crypt.c morecrypt.c md5crypt.c md5c.c +SRCS+= crypt.c morecrypt.c md5crypt.c MAN+= crypt.3 MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 diff --git a/lib/libc/crypt/crypt.3 b/lib/libc/crypt/crypt.3 index 78a54b18a2d..e08f6595e2e 100644 --- a/lib/libc/crypt/crypt.3 +++ b/lib/libc/crypt/crypt.3 @@ -1,3 +1,5 @@ +.\" $OpenBSD: crypt.3,v 1.2 1996/06/03 22:20:34 niklas Exp $ +.\" .\" FreeSec: libcrypt .\" .\" Copyright (c) 1994 David Burren @@ -27,8 +29,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: crypt.3,v 1.1 1995/12/16 12:55:29 deraadt Exp $ -.\" .\" Manual page, using -mandoc macros .\" .Dd March 9, 1994 diff --git a/lib/libc/crypt/crypt.c b/lib/libc/crypt/crypt.c index 521b6385422..38b690d8665 100644 --- a/lib/libc/crypt/crypt.c +++ b/lib/libc/crypt/crypt.c @@ -1,4 +1,4 @@ -/* $Id: crypt.c,v 1.3 1996/03/25 22:31:45 tholo Exp $ */ +/* $OpenBSD: crypt.c,v 1.4 1996/06/03 22:20:35 niklas Exp $ */ /* * FreeSec: libcrypt diff --git a/lib/libc/crypt/md5crypt.c b/lib/libc/crypt/md5crypt.c index 7872c368597..f17a8d374cb 100644 --- a/lib/libc/crypt/md5crypt.c +++ b/lib/libc/crypt/md5crypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md5crypt.c,v 1.1 1996/05/30 02:36:33 deraadt Exp $ */ +/* $OpenBSD: md5crypt.c,v 1.2 1996/06/03 22:20:37 niklas Exp $ */ /* * ---------------------------------------------------------------------------- @@ -11,12 +11,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.1 1996/05/30 02:36:33 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.2 1996/06/03 22:20:37 niklas Exp $"; #endif /* LIBC_SCCS and not lint */ #include <unistd.h> #include <stdio.h> -#include "md5.h" +#include <md5.h> static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; diff --git a/lib/libc/crypt/morecrypt.c b/lib/libc/crypt/morecrypt.c index 4b36ac793bd..f68e2fccacd 100644 --- a/lib/libc/crypt/morecrypt.c +++ b/lib/libc/crypt/morecrypt.c @@ -1,4 +1,4 @@ -/* $Id: morecrypt.c,v 1.4 1996/03/25 22:31:46 tholo Exp $ */ +/* $OpenBSD: morecrypt.c,v 1.5 1996/06/03 22:20:37 niklas Exp $ */ /* * FreeSec: libcrypt diff --git a/lib/libc/md/Makefile.inc b/lib/libc/md/Makefile.inc new file mode 100644 index 00000000000..21c4419e817 --- /dev/null +++ b/lib/libc/md/Makefile.inc @@ -0,0 +1,39 @@ +# $OpenBSD: Makefile.inc,v 1.1 1996/06/03 22:20:39 niklas Exp $ + +.PATH: ${.CURDIR}/md + +SRCS+= md2c.c md4c.c md5c.c md2hl.c md4hl.c md5hl.c + +MAN+= md2.3 md4.3 md5.3 +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].3 + +all: md2.3 md4.3 md5.3 + +md2hl.c: mdXhl.c + sed -e 's/mdX/md2/g' -e 's/MDX/MD2/g' $> > $@ + +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' $> > $@ + +md2.3: mdX.3 + sed -e 's/mdX/md2/g' -e 's/MDX/MD2/g' $> > $@ + cat ${>:H}/md2.copyright >> $@ + +md4.3: mdX.3 + sed -e 's/mdX/md4/g' -e 's/MDX/MD4/g' $> > $@ + cat ${>:H}/md4.copyright >> $@ + +md5.3: mdX.3 + sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' $> > $@ + cat ${>:H}/md5.copyright >> $@ + +beforedepend: md2hl.c md4hl.c md5hl.c diff --git a/lib/libc/md/md4.copyright b/lib/libc/md/md4.copyright new file mode 100644 index 00000000000..3d0af815ecd --- /dev/null +++ b/lib/libc/md/md4.copyright @@ -0,0 +1,20 @@ +.\" $OpenBSD: md4.copyright,v 1.1 1996/06/03 22:20:41 niklas Exp $ +Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD4 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD4 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. diff --git a/lib/libc/md/md4c.c b/lib/libc/md/md4c.c new file mode 100644 index 00000000000..f5d6772ad92 --- /dev/null +++ b/lib/libc/md/md4c.c @@ -0,0 +1,278 @@ +/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm + * $OpenBSD: md4c.c,v 1.1 1996/06/03 22:20:41 niklas Exp $ + */ + +/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD4 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD4 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#include <md4.h> +#include <string.h> + +typedef unsigned char *POINTER; +typedef unsigned short int UINT2; +typedef unsigned long int UINT4; + +#define PROTO_LIST(list) list + +/* Constants for MD4Transform routine. + */ +#define S11 3 +#define S12 7 +#define S13 11 +#define S14 19 +#define S21 3 +#define S22 5 +#define S23 9 +#define S24 13 +#define S31 3 +#define S32 9 +#define S33 11 +#define S34 15 + +static void MD4Transform PROTO_LIST ((UINT4 [4], const unsigned char [64])); +static void Encode PROTO_LIST + ((unsigned char *, UINT4 *, unsigned int)); +static void Decode PROTO_LIST + ((UINT4 *, const unsigned char *, unsigned int)); + +static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G and H are basic MD4 functions. + */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) + +/* ROTATE_LEFT rotates x left n bits. + */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* FF, GG and HH are transformations for rounds 1, 2 and 3 */ +/* Rotation is separate from addition to prevent recomputation */ +#define FF(a, b, c, d, x, s) { \ + (a) += F ((b), (c), (d)) + (x); \ + (a) = ROTATE_LEFT ((a), (s)); \ + } +#define GG(a, b, c, d, x, s) { \ + (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \ + (a) = ROTATE_LEFT ((a), (s)); \ + } +#define HH(a, b, c, d, x, s) { \ + (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \ + (a) = ROTATE_LEFT ((a), (s)); \ + } + +/* MD4 initialization. Begins an MD4 operation, writing a new context. + */ +void MD4Init (context) +MD4_CTX *context; /* context */ +{ + context->count[0] = context->count[1] = 0; + + /* Load magic initialization constants. + */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* MD4 block update operation. Continues an MD4 message-digest + operation, processing another message block, and updating the + context. + */ +void MD4Update (context, input, inputLen) +MD4_CTX *context; /* context */ +const unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + /* Update number of bits */ + if ((context->count[0] += ((UINT4)inputLen << 3)) + < ((UINT4)inputLen << 3)) + context->count[1]++; + context->count[1] += ((UINT4)inputLen >> 29); + + partLen = 64 - index; + /* Transform as many times as possible. + */ + if (inputLen >= partLen) { + memcpy + ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD4Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD4Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + + /* Buffer remaining input */ + memcpy + ((POINTER)&context->buffer[index], (POINTER)&input[i], + 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_CTX *context; /* context */ +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + Encode (bits, context->count, 8); + + /* Pad out to 56 mod 64. + */ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD4Update (context, PADDING, padLen); + + /* Append length (before padding) */ + MD4Update (context, bits, 8); + /* Store state in digest */ + Encode (digest, context->state, 16); + + /* Zeroize sensitive information. + */ + memset ((POINTER)context, 0, sizeof (*context)); +} + +/* MD4 basic transformation. Transforms state based on block. + */ +static void MD4Transform (state, block) +UINT4 state[4]; +const unsigned char block[64]; +{ + UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode (x, block, 64); + + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11); /* 1 */ + FF (d, a, b, c, x[ 1], S12); /* 2 */ + FF (c, d, a, b, x[ 2], S13); /* 3 */ + FF (b, c, d, a, x[ 3], S14); /* 4 */ + FF (a, b, c, d, x[ 4], S11); /* 5 */ + FF (d, a, b, c, x[ 5], S12); /* 6 */ + FF (c, d, a, b, x[ 6], S13); /* 7 */ + FF (b, c, d, a, x[ 7], S14); /* 8 */ + FF (a, b, c, d, x[ 8], S11); /* 9 */ + FF (d, a, b, c, x[ 9], S12); /* 10 */ + FF (c, d, a, b, x[10], S13); /* 11 */ + FF (b, c, d, a, x[11], S14); /* 12 */ + FF (a, b, c, d, x[12], S11); /* 13 */ + FF (d, a, b, c, x[13], S12); /* 14 */ + FF (c, d, a, b, x[14], S13); /* 15 */ + FF (b, c, d, a, x[15], S14); /* 16 */ + + /* Round 2 */ + GG (a, b, c, d, x[ 0], S21); /* 17 */ + GG (d, a, b, c, x[ 4], S22); /* 18 */ + GG (c, d, a, b, x[ 8], S23); /* 19 */ + GG (b, c, d, a, x[12], S24); /* 20 */ + GG (a, b, c, d, x[ 1], S21); /* 21 */ + GG (d, a, b, c, x[ 5], S22); /* 22 */ + GG (c, d, a, b, x[ 9], S23); /* 23 */ + GG (b, c, d, a, x[13], S24); /* 24 */ + GG (a, b, c, d, x[ 2], S21); /* 25 */ + GG (d, a, b, c, x[ 6], S22); /* 26 */ + GG (c, d, a, b, x[10], S23); /* 27 */ + GG (b, c, d, a, x[14], S24); /* 28 */ + GG (a, b, c, d, x[ 3], S21); /* 29 */ + GG (d, a, b, c, x[ 7], S22); /* 30 */ + GG (c, d, a, b, x[11], S23); /* 31 */ + GG (b, c, d, a, x[15], S24); /* 32 */ + + /* Round 3 */ + HH (a, b, c, d, x[ 0], S31); /* 33 */ + HH (d, a, b, c, x[ 8], S32); /* 34 */ + HH (c, d, a, b, x[ 4], S33); /* 35 */ + HH (b, c, d, a, x[12], S34); /* 36 */ + HH (a, b, c, d, x[ 2], S31); /* 37 */ + HH (d, a, b, c, x[10], S32); /* 38 */ + HH (c, d, a, b, x[ 6], S33); /* 39 */ + HH (b, c, d, a, x[14], S34); /* 40 */ + HH (a, b, c, d, x[ 1], S31); /* 41 */ + HH (d, a, b, c, x[ 9], S32); /* 42 */ + HH (c, d, a, b, x[ 5], S33); /* 43 */ + HH (b, c, d, a, x[13], S34); /* 44 */ + HH (a, b, c, d, x[ 3], S31); /* 45 */ + HH (d, a, b, c, x[11], S32); /* 46 */ + HH (c, d, a, b, x[ 7], S33); /* 47 */ + HH (b, c, d, a, x[15], S34); /* 48 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. + */ + memset ((POINTER)x, 0, sizeof (x)); +} + +/* Encodes input (UINT4) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void Encode (output, input, len) +unsigned char *output; +UINT4 *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (UINT4). Assumes len is + a multiple of 4. + */ +static void Decode (output, input, len) + +UINT4 *output; +const unsigned char *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); +} diff --git a/lib/libc/crypt/md5.h b/lib/libc/md/md5.copyright index da0c116c2e0..b892ff0b707 100644 --- a/lib/libc/crypt/md5.h +++ b/lib/libc/md/md5.copyright @@ -1,8 +1,5 @@ -/* MD5.H - header file for MD5C.C - * $FreeBSD$ - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +.\" $OpenBSD: md5.copyright,v 1.1 1996/06/03 22:20:42 niklas Exp $ +Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it @@ -22,21 +19,3 @@ without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. - */ - -#ifndef _MD5_H_ -#define _MD5_H_ -/* MD5 context. */ -typedef struct MD5Context { - unsigned long state[4]; /* state (ABCD) */ - unsigned long count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} MD5_CTX; - -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 *); -char * MD5File(char *, char *); -char * MD5Data(const unsigned char *, unsigned int, char *); -#endif /* _MD5_H_ */ diff --git a/lib/libc/crypt/md5c.c b/lib/libc/md/md5c.c index 5c35b5b58d0..9e96c3a70ad 100644 --- a/lib/libc/crypt/md5c.c +++ b/lib/libc/md/md5c.c @@ -1,5 +1,5 @@ /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - * $FreeBSD$ + * $OpenBSD: md5c.c,v 1.1 1996/06/03 22:20:43 niklas Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -24,7 +24,7 @@ These notices must be retained in any copies of any part of this documentation and/or software. */ -#include "md5.h" +#include <md5.h> #include <string.h> typedef unsigned char *POINTER; diff --git a/lib/libc/md/mdX.3 b/lib/libc/md/mdX.3 new file mode 100644 index 00000000000..6afb2d8ac9e --- /dev/null +++ b/lib/libc/md/mdX.3 @@ -0,0 +1,125 @@ +.\" +.\" ---------------------------------------------------------------------------- +.\" "THE BEER-WARE LICENSE" (Revision 42): +.\" <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you +.\" can do whatever you want with this stuff. If we meet some day, and you think +.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp +.\" ---------------------------------------------------------------------------- +.\" +.\" $OpenBSD: mdX.3,v 1.1 1996/06/03 22:20:43 niklas Exp $ +.\" +.Dd July 14, 1994 +.Dt MDX 3 +.Os FreeBSD 2 +.Sh NAME +.Nm MDXInit , +.Nm MDXUpdate , +.Nm MDXFinal , +.Nm MDXEnd , +.Nm MDXFile , +.Nm MDXData +.Nd calculate ``MDX'' cryptographic checksum +.Sh SYNOPSIS +.Fd #include <mdX.h> +.Ft void +.Fn MDXInit "MDX_CTX *context" +.Ft void +.Fn MDXUpdate "MDX_CTX *context" "unsigned char *data" "unsigned int len" +.Ft void +.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context" +.Ft "char *" +.Fn MDXEnd "MDX_CTX *context" "char *buf" +.Ft "char *" +.Fn MDXFile "char *filename" "char *buf" +.Ft "char *" +.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 +hash-function, that is, you cannot find (except by exhaustive search) +the input corresponding to a particular output. This net result is +a ``fingerprint'' of the input-data, which doesn't disclose the actual +input. + +MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle. +MD2 can only be used for Privacy-Enhanced Mail. +MD4 has been critizised for being to weak, and MD5 was developed as a +response to this as ``MD4 with safety-belts''. If in doubt, use MD5. + +The +.Fn MDXInit , +.Fn MDXUpdate +and +.Fn MDXFinal +functions are the core functions. Allocate a MDX_CTX, initialize it with +.Fn MDXInit +run over the data with +.Fn MDXUpdate +and finally extract the result using +.Fn MDXFinal . + +.Fn MDXEnd +is a wrapper for +.Fn MDXFinal , +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 uses +.Fn MDXEnd +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 uses +.Fn MDXEnd +to return the result. + +When using +.Fn MDXEnd , +.Fn MDXFile +or +.Fn MDXData , +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 , +.Xr md5 3 +.Pp +ISOC +Internet Request For Comments +.%T RFC1319 , +.%T RFC1320 +and +.%T RFC1321 . +.Pp +RSA Laboratories +.%T Frequently Asked Questions About today's Cryptography . +.Sh AUTHOR +The MD2, MD4 and MD5 is designed and written by Ron Rivest and published in +the above RFC's, including a reference implementation of each algorithm. + +This code is derived directly from these implementations by Poul-Henning Kamp +<phk@login.dkuug.dk> + +Phk ristede runen. +.Sh HISTORY +These functions appeared in +.Em FreeBSD-2.0 +.Sh BUGS +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 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/libc/md/mdXhl.c b/lib/libc/md/mdXhl.c new file mode 100644 index 00000000000..87cfa8d6f57 --- /dev/null +++ b/lib/libc/md/mdXhl.c @@ -0,0 +1,71 @@ +/* mdXhl.c + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $OpenBSD: mdXhl.c,v 1.1 1996/06/03 22:20:44 niklas Exp $ + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include "mdX.h" +#include <sys/file.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <unistd.h> + +char * +MDXEnd(MDX_CTX *ctx, char *buf) +{ + int i; + char *p = malloc(33); + unsigned char digest[16]; + static const char hex[]="0123456789abcdef"; + + if (!p) + p = malloc(33); + if (!p) + return 0; + MDXFinal(digest,ctx); + for (i=0;i<16;i++) { + p[i+i] = hex[digest[i] >> 4]; + p[i+i+1] = hex[digest[i] & 0x0f]; + } + p[i+i] = '\0'; + return p; +} + +char * +MDXFile (char *filename, char *buf) +{ + unsigned char buffer[BUFSIZ]; + MDX_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); +} + +char * +MDXData (const unsigned char *data, unsigned int len, char *buf) +{ + MDX_CTX ctx; + + MDXInit(&ctx); + MDXUpdate(&ctx,data,len); + return MDXEnd(&ctx, buf); +} diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index d7d79c18fcb..0602d9953e9 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,2 +1,2 @@ major=12 -minor=5 +minor=6 |