xref: /netbsd-src/lib/libc/md/mdX.3 (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1.\"	$NetBSD: mdX.3,v 1.7 2002/02/07 07:00:20 ross Exp $
2.\"
3.\" ----------------------------------------------------------------------------
4.\" "THE BEER-WARE LICENSE" (Revision 42):
5.\" <phk@login.dkuug.dk> wrote this file.  As long as you retain this notice you
6.\" can do whatever you want with this stuff. If we meet some day, and you think
7.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
8.\" ----------------------------------------------------------------------------
9.\"
10.\"	from FreeBSD Id: mdX.3,v 1.7 1996/10/22 16:28:56 phk Exp
11.\"
12.Dd October 9, 1996
13.Dt MDX 3
14.Os
15.Sh NAME
16.Nm MDXInit ,
17.Nm MDXUpdate ,
18.Nm MDXFinal ,
19.Nm MDXEnd ,
20.Nm MDXFile ,
21.Nm MDXData
22.Nd calculate the RSA Data Security, Inc.,
23.Dq MDX
24message digest
25.Sh LIBRARY
26.Lb libc
27.Sh SYNOPSIS
28.Fd #include \*[Lt]sys/types.h\*[Gt]
29.Fd #include \*[Lt]mdX.h\*[Gt]
30.Ft void
31.Fn MDXInit "MDX_CTX *context"
32.Ft void
33.Fn MDXUpdate "MDX_CTX *context" "unsigned char *data" "unsigned int len"
34.Ft void
35.Fn MDXFinal "unsigned char digest[16]" "MDX_CTX *context"
36.Ft "char *"
37.Fn MDXEnd "MDX_CTX *context" "char *buf"
38.Ft "char *"
39.Fn MDXFile "char *filename" "char *buf"
40.Ft "char *"
41.Fn MDXData "unsigned char *data" "unsigned int len" "char *buf"
42.Sh DESCRIPTION
43The MDX functions calculate a 128-bit cryptographic checksum (digest)
44for any number of input bytes.  A cryptographic checksum is a one-way
45hash-function, that is, you cannot find (except by exhaustive search)
46the input corresponding to a particular output.  This net result is
47a ``fingerprint'' of the input-data, which doesn't disclose the actual
48input.
49.Pp
50MD2 is the slowest, MD4 is the fastest and MD5 is somewhere in the middle.
51MD2 can only be used for Privacy-Enhanced Mail.
52MD4 has been criticized for being too weak, so MD5 was developed in
53response as ``MD4 with safety-belts''.  When in doubt, use MD5.
54.Pp
55The
56.Fn MDXInit ,
57.Fn MDXUpdate ,
58and
59.Fn MDXFinal
60functions are the core functions.  Allocate an MDX_CTX, initialize it with
61.Fn MDXInit ,
62run over the data with
63.Fn MDXUpdate ,
64and finally extract the result using
65.Fn MDXFinal .
66.Pp
67.Fn MDXEnd
68is a wrapper for
69.Fn MDXFinal
70which converts the return value to a 33-character
71(including the terminating '\e0')
72.Tn ASCII
73string which represents the 128 bits in hexadecimal.
74.Pp
75.Fn MDXFile
76calculates the digest of a file, and uses
77.Fn MDXEnd
78to return the result.
79If the file cannot be opened, a null pointer is returned.
80.Fn MDXData
81calculates the digest of a chunk of data in memory, and uses
82.Fn MDXEnd
83to return the result.
84.Pp
85When using
86.Fn MDXEnd ,
87.Fn MDXFile ,
88or
89.Fn MDXData ,
90the
91.Ar buf
92argument can be a null pointer, in which case the returned string
93is allocated with
94.Xr malloc 3
95and subsequently must be explicitly deallocated using
96.Xr free 3
97after use.
98If the
99.Ar buf
100argument is non-null it must point to at least 33 characters of buffer space.
101.Sh SEE ALSO
102.Xr md2 3 ,
103.Xr md4 3 ,
104.Xr md5 3
105.Rs
106.%A B. Kaliski
107.%T The MD2 Message-Digest Algorithm
108.%O RFC 1319
109.Re
110.Rs
111.%A R. Rivest
112.%T The MD4 Message-Digest Algorithm
113.%O RFC 1186
114.Re
115.Rs
116.%A R. Rivest
117.%T The MD5 Message-Digest Algorithm
118.%O RFC 1321
119.Re
120.Rs
121.%A RSA Laboratories
122.%T Frequently Asked Questions About today's Cryptography
123.Re
124.Sh HISTORY
125These functions appeared in
126.Nx 1.3 .
127.Sh AUTHORS
128The original MDX routines were developed by
129.Tn RSA
130Data Security, Inc., and published in the above references.
131This code is derived directly from these implementations by Poul-Henning Kamp
132.Aq Li phk@login.dkuug.dk
133.Pp
134Phk ristede runen.
135.Sh BUGS
136No method is known to exist which finds two files having the same hash value,
137nor to find a file with a specific hash value.
138There is on the other hand no guarantee that such a method doesn't exist.
139.Sh COPYRIGHT
140