1 .\" $NetBSD: cksum.1,v 1.44 2012/06/25 02:32:12 riastradh Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the Institute of Electrical and Electronics Engineers, Inc.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" @(#)cksum.1 8.2 (Berkeley) 4/28/95
46 .Nd display file checksums and block counts
50 .Op Fl a Ar algorithm Oo Fl ptx Oc Oo Fl s Ar string Oc
51 .Op Fl o Ar 1 Ns | Ns Ar 2
52 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
55 .Op Fl a Ar algorithm Oo Fl ptx Oc Oo Fl s Ar string Oc
56 .Op Fl o Ar 1 Ns | Ns Ar 2
57 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
61 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
65 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
69 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
73 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
77 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
81 utility writes to the standard output three whitespace separated
82 fields for each input file.
83 These fields are a checksum
85 the total number of octets in the file and the file name.
86 If no file name is specified, the standard input is used and no file name
91 utility is identical to the
93 utility, except that it defaults to using historic algorithm 1, as
95 It is provided for compatibility only.
104 utilities compute cryptographic hash functions, and write to standard
105 output the hexadecimal representation of the hash of their input.
107 The options are as follows:
108 .Bl -tag -width indent
109 .It Fl a Ar algorithm
114 Valid algorithms are:
115 .Bl -column -offset indent ".Sy Algorithm" ".Sy Bits" ".Sy Description"
116 .It Sy Algorithm Ta Sy Bits Ta Sy Description
117 .It Li CRC Ta 32 Ta Default CRC algorithm
118 .It Li MD2 Ta 128 Ta MD2, per Li RFC1319
119 .It Li MD4 Ta 128 Ta MD4, per Li RFC1320
120 .It Li MD5 Ta 128 Ta MD5, per Li RFC1321
121 .It Li RMD160 Ta 160 Ta RIPEMD-160
122 .It Li SHA1 Ta 160 Ta SHA-1, per Li FIPS PUB 180-1
123 .It Li SHA256 Ta 256 Ta SHA-2
124 .It Li SHA384 Ta 384 Ta SHA-2
125 .It Li SHA512 Ta 512 Ta SHA-2
126 .It Li old1 Ta 16 Ta Algorithm 1, per Fl o Ar 1
127 .It Li old2 Ta 16 Ta Algorithm 2, per Fl o Ar 2
129 .It Fl c Op Ar sumfile
130 Verify (check) files against a list of checksums.
131 The list is read from
133 or from stdin if no filename is given.
135 .Dl Ic md5 *.tgz \*[Gt] MD5
136 .Dl Ic sha1 *.tgz \*[Gt] SHA1
137 to generate a list of MD5 checksums in
139 then use the following command to verify them:
140 .Dl Ic cat MD5 SHA1 | cksum -c
141 If an error is found during checksum verification, an error
142 message is printed, and the program returns an error code of 1.
144 Use historic algorithms instead of the (superior) default one.
146 Algorithm 1 is the algorithm used by historic
150 algorithm and by historic
154 algorithm when using the
157 This is a 16-bit checksum, with a right rotation before each addition;
158 overflow is discarded.
160 Algorithm 2 is the algorithm used by historic
166 This is a 32-bit checksum, and is defined as follows:
167 .Bd -unfilled -offset indent
168 s = sum of all bytes;
169 r = s % 2^16 + (s % 2^32) / 2^16;
170 cksum = (r % 2^16) + r / 2^16;
173 Both algorithm 1 and 2 write to the standard output the same fields as
174 the default algorithm except that the size of the file in bytes is
175 replaced with the size of the file in blocks.
176 For historic reasons, the block size is 1024 for algorithm 1 and 512
178 Partial blocks are rounded up.
180 Print warnings about malformed checksum files when verifying
185 The following options apply only when using the one of the message
187 .Bl -tag -width indent
189 Print the hash and the filename in the normal sum output form, with
190 the hash at the left and the filename following on the right.
192 Echo input from standard input to standard output, and append the
193 selected message digest.
195 Print the hash of the given string
198 Run a built-in message digest time trial.
200 Run a built-in message digest test script.
201 The tests that are run
202 are supposed to encompass all the various tests in the suites that
203 accompany the algorithms' descriptions with the exception of the
204 last test for the SHA-1 algorithm and the RIPEMD-160 algorithm.
206 last test for these is one million copies of the lower letter a.
211 used is based on the polynomial used for
214 in the networking standard
218 checksum encoding is defined by the generating polynomial:
220 .Bd -unfilled -offset indent
221 G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 +
222 x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
227 value corresponding to a given file is defined by
228 the following procedure:
229 .Bd -filled -offset indent
232 bits to be evaluated are considered to be the coefficients of a mod 2
233 polynomial M(x) of degree
237 bits are the bits from the file, with the most significant bit being the most
238 significant bit of the first octet of the file and the last bit being the least
239 significant bit of the last octet, padded with zero bits (if necessary) to
240 achieve an integral number of octets, followed by one or more octets
241 representing the length of the file as a binary value, least significant octet
243 The smallest number of octets capable of representing this integer are used.
245 M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by
246 G(x) using mod 2 division, producing a remainder R(x) of degree \*[Le] 31.
248 The coefficients of R(x) are considered to be a 32-bit sequence.
250 The bit sequence is complemented and the result is the CRC.
257 utilities exit 0 on success, and \*[Gt]0 if an error occurs.
262 The default calculation is identical to that given in pseudo-code
267 .%T "Computation of Cyclic Redundancy Checks Via Table Lookup"
269 .%J "Communications of the \*(tNACM\*(sP"
274 .%T The MD2 Message-Digest Algorithm
279 .%T The MD4 Message-Digest Algorithm
280 .%O RFC 1186 and RFC 1320
284 .%T The MD5 Message-Digest Algorithm
289 .%T Secure Hash Standard
295 utility is expected to conform to
305 The functionality for
313 Support for the SHA-2 algorithms
322 The functionality to verify checksum stored in a file
329 .\" utility appeared in