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