xref: /freebsd/sbin/md5/md5.1 (revision 9768746b)
1.\" $FreeBSD$
2.Dd February 6, 2023
3.Dt MD5 1
4.Os
5.Sh NAME
6.Nm md5 , sha1 , sha224 , sha256 , sha384 ,
7.Nm sha512 , sha512t224 , sha512t256 ,
8.Nm rmd160 , skein256 , skein512 , skein1024 ,
9.Nm md5sum , sha1sum , sha224sum , sha256sum , sha384sum ,
10.Nm sha512sum , sha512t224sum , sha512t256sum ,
11.Nm rmd160sum , skein256sum , skein512sum , skein1024sum
12.Nd calculate a message-digest fingerprint (checksum) for a file
13.Sh SYNOPSIS
14.Nm
15.Op Fl pqrtx
16.Op Fl c Ar string
17.Op Fl s Ar string
18.Op Ar
19.Pp
20.Nm md5sum
21.Op Fl pqrtx
22.Op Fl c Ar file
23.Op Fl s Ar string
24.Op Ar
25.Pp
26(All other hashes have the same options and usage.)
27.Sh DESCRIPTION
28The
29.Nm md5 , sha1 , sha224 , sha256 , sha384 , sha512 , sha512t224 , sha512t256 ,
30.Nm rmd160 , skein256 , skein512 ,
31and
32.Nm skein1024
33utilities take as input a message of arbitrary length and produce as
34output a
35.Dq fingerprint
36or
37.Dq message digest
38of the input.
39The
40.Nm md5sum , sha1sum , sha224sum , sha256sum , sha384sum , sha512sum ,
41.Nm sha512t224sum , sha512t256sum , rmd160sum , skein256sum , skein512sum ,
42and
43.Nm skein1024sum
44utilities do the same, but default to the reversed format of
45the
46.Fl r
47flag.
48It is conjectured that it is computationally infeasible to
49produce two messages having the same message digest, or to produce any
50message having a given prespecified target message digest.
51The SHA-224 , SHA-256 , SHA-384 , SHA-512, RIPEMD-160,
52and SKEIN
53algorithms are intended for digital signature applications, where a
54large file must be
55.Dq compressed
56in a secure manner before being encrypted with a private
57(secret)
58key under a public-key cryptosystem such as RSA.
59.Pp
60The MD5 and SHA-1 algorithms have been proven to be vulnerable to practical
61collision attacks and should not be relied upon to produce unique outputs,
62.Em nor should they be used as part of a cryptographic signature scheme.
63As of 2017-03-02, there is no publicly known method to
64.Em reverse
65either algorithm, i.e., to find an input that produces a specific
66output.
67.Pp
68SHA-512t256 is a version of SHA-512 truncated to only 256 bits.
69On 64-bit hardware, this algorithm is approximately 50% faster than SHA-256 but
70with the same level of security.
71The hashes are not interchangeable.
72.Pp
73SHA-512t224 is identical to SHA-512t256, but with the digest truncated
74to 224 bits.
75.Pp
76It is recommended that all new applications use SHA-512 or SKEIN-512
77instead of one of the other hash functions.
78.Pp
79The following options may be used in any combination and must
80precede any files named on the command line.
81The hexadecimal checksum of each file listed on the command line is printed
82after the options are processed.
83.Bl -tag -width indent
84.It Fl b
85Make the
86.Nm -sum
87programs separate hash and digest with a blank followed by an asterisk instead
88of by 2 blank characters for full compatibility with the output generated by the
89coreutils versions of these programs.
90.It Fl c Ar string
91If the program was called with a name that does not end in
92.Nm sum ,
93compare the digest of the file against this string.
94If combined with the
95.Fl q
96option, the calculated digest is printed in addition to the exit status being set.
97.Pq Note that this option is not yet useful if multiple files are specified.
98.It Fl c Ar file
99If the program was called with a name that does end in
100.Nm sum ,
101the file passed as argument must contain digest lines generated by the same
102digest algorithm with or without the
103.Fl r
104option
105.Pq i.e., in either classical BSD format or in GNU coreutils format .
106A line with the file name followed by a colon
107.Dq ":"
108and either OK or FAILED is written for each well-formed line in the digest file.
109If applicable, the number of failed comparisons and the number of lines that were
110skipped since they were not well-formed are printed at the end.
111The
112.Fl q
113option can be used to quiesce the output unless there are mismatched entries in
114the digest.
115.Pp
116.It Fl s Ar string
117Print a checksum of the given
118.Ar string .
119.It Fl p
120Echo stdin to stdout and append the checksum to stdout.
121.It Fl q
122Quiet mode \(em only the checksum is printed out.
123Overrides the
124.Fl r
125option.
126.It Fl r
127Reverses the format of the output.
128This helps with visual diffs.
129Does nothing
130when combined with the
131.Fl ptx
132options.
133.It Fl t
134Run a built-in time trial.
135For the
136.Nm -sum
137versions, this is a nop for compatibility with coreutils.
138.It Fl x
139Run a built-in test script.
140.El
141.Sh EXIT STATUS
142The
143.Nm md5 , sha1 , sha224 , sha256 , sha512 , sha512t256 , rmd160 ,
144.Nm skein256 , skein512 ,
145and
146.Nm skein1024
147utilities exit 0 on success,
1481 if at least one of the input files could not be read,
149and 2 if at least one file does not have the same hash as the
150.Fl c
151option.
152.Sh EXAMPLES
153Calculate the MD5 checksum of the string
154.Dq Hello .
155.Bd -literal -offset indent
156$ md5 -s Hello
157MD5 ("Hello") = 8b1a9953c4611296a827abf8c47804d7
158.Ed
159.Pp
160Same as above, but note the absence of the newline character in the input
161string:
162.Bd -literal -offset indent
163$ echo -n Hello | md5
1648b1a9953c4611296a827abf8c47804d7
165.Ed
166.Pp
167Calculate the checksum of multiple files reversing the output:
168.Bd -literal -offset indent
169$ md5 -r /boot/loader.conf /etc/rc.conf
170ada5f60f23af88ff95b8091d6d67bef6 /boot/loader.conf
171d80bf36c332dc0fdc479366ec3fa44cd /etc/rc.conf
172.Pd
173The
174.Nm -sum
175variants put 2 blank characters between hash and file name for full compatibility
176with the coreutils versions of these commands.
177.Ed
178.Pp
179Write the digest for
180.Pa /boot/loader.conf
181in a file named
182.Pa digest .
183Then calculate the checksum again and validate it against the checksum string
184extracted from the
185.Pa digest
186file:
187.Bd -literal -offset indent
188$ md5 /boot/loader.conf > digest && md5 -c $(cut -f2 -d= digest) /boot/loader.conf
189MD5 (/boot/loader.conf) = ada5f60f23af88ff95b8091d6d67bef6
190.Ed
191.Pp
192Same as above but comparing the digest against an invalid string
193.Pq Dq randomstring ,
194which results in a failure.
195.Bd -literal -offset indent
196$ md5 -c randomstring /boot/loader.conf
197MD5 (/boot/loader.conf) = ada5f60f23af88ff95b8091d6d67bef6 [ Failed ]
198.Ed
199.Pp
200If invoked with a name ending in
201.Nm -sum
202the
203.Fl c
204option does not compare against a hash string passed as parameter.
205Instead, it expects a digest file, as created under the name
206.Pa digest
207for
208.Pa /boot/loader.conf
209in the example above.
210.Bd -literal -offset indent
211$ md5 -c digest /boot/loader.conf
212/boot/loader.conf: OK
213.Ed
214.Pp
215The digest file may contain any number of lines in the format generated with or without the
216.Fl r
217option
218.Pq i.e., in either classical BSD format or in GNU coreutils format .
219If a hash value does not match the file, FAILED is printed instead of OK.
220.Sh SEE ALSO
221.Xr cksum 1 ,
222.Xr md5 3 ,
223.Xr ripemd 3 ,
224.Xr sha 3 ,
225.Xr sha256 3 ,
226.Xr sha384 3 ,
227.Xr sha512 3 ,
228.Xr skein 3
229.Rs
230.%A R. Rivest
231.%T The MD5 Message-Digest Algorithm
232.%O RFC1321
233.Re
234.Rs
235.%A J. Burrows
236.%T The Secure Hash Standard
237.%O FIPS PUB 180-2
238.Re
239.Rs
240.%A D. Eastlake and P. Jones
241.%T US Secure Hash Algorithm 1
242.%O RFC 3174
243.Re
244.Pp
245RIPEMD-160 is part of the ISO draft standard
246.Qq ISO/IEC DIS 10118-3
247on dedicated hash functions.
248.Pp
249Secure Hash Standard (SHS):
250.Pa https://www.nist.gov/publications/secure-hash-standard-shs
251.Pp
252The RIPEMD-160 page:
253.Pa https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
254.Sh BUGS
255All of the utilities that end in
256.Sq sum
257are intended to be compatible with the GNU coreutils programs.
258However, the long option functionality is not provided.
259.Sh ACKNOWLEDGMENTS
260This program is placed in the public domain for free general use by
261RSA Data Security.
262.Pp
263Support for SHA-1 and RIPEMD-160 has been added by
264.An Oliver Eikemeier Aq Mt eik@FreeBSD.org .
265