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