Sweep over our manual pages and remove .Pp before a .Bd or .Bl without
[dragonfly.git] / usr.bin / cksum / cksum.1
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)cksum.1     8.2 (Berkeley) 4/28/95
36 .\" $FreeBSD: src/usr.bin/cksum/cksum.1,v 1.10.2.7 2001/08/16 13:16:43 ru Exp $
37 .\" $DragonFly: src/usr.bin/cksum/cksum.1,v 1.4 2008/05/02 02:05:07 swildner Exp $
38 .\"
39 .Dd April 28, 1995
40 .Dt CKSUM 1
41 .Os
42 .Sh NAME
43 .Nm cksum ,
44 .Nm sum
45 .Nd display file checksums and block counts
46 .Sh SYNOPSIS
47 .Nm
48 .Op Fl o Ar 1 | 2 | 3
49 .Op Ar
50 .Nm sum
51 .Op Ar
52 .Sh DESCRIPTION
53 The
54 .Nm
55 utility writes to the standard output three whitespace separated
56 fields for each input file.
57 These fields are a checksum
58 .Tn CRC ,
59 the total number of octets in the file and the file name.
60 If no file name is specified, the standard input is used and no file name
61 is written.
62 .Pp
63 The
64 .Nm sum
65 utility is identical to the
66 .Nm
67 utility, except that it defaults to using historic algorithm 1, as
68 described below.
69 It is provided for compatibility only.
70 .Pp
71 The options are as follows:
72 .Bl -tag -width indent
73 .It Fl o
74 Use historic algorithms instead of the (superior) default one.
75 .Pp
76 Algorithm 1 is the algorithm used by historic
77 .Bx
78 systems as the
79 .Xr sum 1
80 algorithm and by historic
81 .At V
82 systems as the
83 .Xr sum 1
84 algorithm when using the
85 .Fl r
86 option.
87 This is a 16-bit checksum, with a right rotation before each addition;
88 overflow is discarded.
89 .Pp
90 Algorithm 2 is the algorithm used by historic
91 .At V
92 systems as the
93 default
94 .Xr sum 1
95 algorithm.
96 This is a 32-bit checksum, and is defined as follows:
97 .Bd -unfilled -offset indent
98 s = sum of all bytes;
99 r = s % 2^16 + (s % 2^32) / 2^16;
100 cksum = (r % 2^16) + r / 2^16;
101 .Ed
102 .Pp
103 Algorithm 3 is what is commonly called the
104 .Ql 32bit CRC
105 algorithm.
106 This is a 32-bit checksum.
107 .Pp
108 Both algorithm 1 and 2 write to the standard output the same fields as
109 the default algorithm except that the size of the file in bytes is
110 replaced with the size of the file in blocks.
111 For historic reasons, the block size is 1024 for algorithm 1 and 512
112 for algorithm 2.
113 Partial blocks are rounded up.
114 .El
115 .Pp
116 The default
117 .Tn CRC
118 used is based on the polynomial used for
119 .Tn CRC
120 error checking
121 in the networking standard
122 .St -iso8802-3 .
123 The
124 .Tn CRC
125 checksum encoding is defined by the generating polynomial:
126 .Bd -unfilled -offset indent
127 G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 +
128      x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
129 .Ed
130 .Pp
131 Mathematically, the
132 .Tn CRC
133 value corresponding to a given file is defined by
134 the following procedure:
135 .Bd -ragged -offset indent
136 The
137 .Ar n
138 bits to be evaluated are considered to be the coefficients of a mod 2
139 polynomial M(x) of degree
140 .Ar n Ns \-1 .
141 These
142 .Ar n
143 bits are the bits from the file, with the most significant bit being the most
144 significant bit of the first octet of the file and the last bit being the least
145 significant bit of the last octet, padded with zero bits (if necessary) to
146 achieve an integral number of octets, followed by one or more octets
147 representing the length of the file as a binary value, least significant octet
148 first.
149 The smallest number of octets capable of representing this integer are used.
150 .Pp
151 M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by
152 G(x) using mod 2 division, producing a remainder R(x) of degree \(<= 31.
153 .Pp
154 The coefficients of R(x) are considered to be a 32-bit sequence.
155 .Pp
156 The bit sequence is complemented and the result is the CRC.
157 .Ed
158 .Sh DIAGNOSTICS
159 .Ex -std cksum sum
160 .Sh SEE ALSO
161 .Xr md5 1
162 .Pp
163 The default calculation is identical to that given in pseudo-code
164 in the following
165 .Tn ACM
166 article.
167 .Rs
168 .%T "Computation of Cyclic Redundancy Checks Via Table Lookup"
169 .%A Dilip V. Sarwate
170 .%J "Communications of the" Tn ACM
171 .%D "August 1988"
172 .Re
173 .Sh STANDARDS
174 The
175 .Nm
176 utility is expected to conform to
177 .St -p1003.2-92 .
178 .Sh HISTORY
179 The
180 .Nm
181 utility appeared in
182 .Bx 4.4 .