Commit | Line | Data |
---|---|---|
a92c7c36 WJ |
1 | .\" Copyright (c) 1991, 1991 The Regents of the University of California. |
2 | .\" 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 5.5 (Berkeley) 6/27/91 | |
36 | .\" | |
37 | .Dd June 27, 1991 | |
38 | .Dt CKSUM 1 | |
39 | .Os | |
40 | .Sh NAME | |
41 | .Nm cksum | |
42 | .Nd display file checksums and block counts | |
43 | .Sh SYNOPSIS | |
44 | .Nm cksum | |
45 | .Op Fl o Op \&1 \&| \&2 | |
46 | .Op Ar file ... | |
47 | .Sh DESCRIPTION | |
48 | The | |
49 | .Nm cksum | |
50 | utility writes to standard output three whitespace separated fields for each | |
51 | input file (or the standard input by default). | |
52 | These fields are a checksum | |
53 | .Tn CRC , | |
54 | the total number of bytes in the file and | |
55 | the file name. | |
56 | .Pp | |
57 | The options are as follows: | |
58 | .Bl -tag -width indent | |
59 | .It Fl o | |
60 | Use historic algorithms instead of the (superior) default one. | |
61 | .Pp | |
62 | Algorithm 1 is the algorithm used by historic | |
63 | .Bx | |
64 | systems as the | |
65 | .Xr sum 1 | |
66 | algorithm and by historic | |
67 | .At V | |
68 | systems as the | |
69 | .Xr sum | |
70 | algorithm when using the | |
71 | .Fl r | |
72 | option. | |
73 | This is a 16-bit checksum, with a right rotation before each addition; | |
74 | overflow is discarded. | |
75 | .Pp | |
76 | Algorithm 2 is the algorithm used by historic | |
77 | .At V | |
78 | systems as the | |
79 | default | |
80 | .Xr sum | |
81 | algorithm. | |
82 | This is a 32-bit checksum, and is defined as follows: | |
83 | .Bd -unfilled -offset indent | |
84 | s = sum of all bytes; | |
85 | r = s % 2^16 + (s % 2^32) / 2^16; | |
86 | cksum = (r % 2^16) + r / 2^16; | |
87 | .Ed | |
88 | .Pp | |
89 | Both algorithm 1 and 2 write to standard output the same fields as | |
90 | the default algorithm except that the size of the file in bytes is | |
91 | replaced with the size of the file in blocks. | |
92 | For historic reasons, the block size is 1024 for algorithm 1 and 512 | |
93 | for algorithm 2. | |
94 | Partial blocks are rounded up. | |
95 | .El | |
96 | .Pp | |
97 | The default | |
98 | .Tn CRC | |
99 | used is based on the polynomial used for | |
100 | .Tn CRC | |
101 | error checking | |
102 | in the networking standard | |
103 | .St -iso8802-3 | |
104 | The | |
105 | .Tn CRC | |
106 | checksum encoding is defined by the generating polynomial: | |
107 | .Pp | |
108 | .Bd -unfilled -offset indent | |
109 | G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + | |
110 | x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 | |
111 | .Ed | |
112 | .Pp | |
113 | Mathematically, the | |
114 | .Tn CRC | |
115 | value corresponding to a given file is defined by | |
116 | the following procedure: | |
117 | .Bd -filled -offset indent | |
118 | The | |
119 | .Ar n | |
120 | bits of the file are considered to be the coefficients of a mod 2 | |
121 | polynomial M(x) of degree | |
122 | .Ar n Ns \-1 . | |
123 | .Pp | |
124 | M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by | |
125 | G(x) using mod 2 division, producing a remainder R(x) of degree <= 31. | |
126 | During the division, each time the intermediate remainder is zero, it | |
127 | is changed to the next value from a predefined sequence of | |
128 | 32-bit integers before completing the division. | |
129 | This sequence is long and complex -- see the source code for more | |
130 | information. | |
131 | .Pp | |
132 | The coefficients of R(x) are considered to be a 32-bit sequence. | |
133 | .Ed | |
134 | .Pp | |
135 | The calculation used is identical to that given in pseudo-code in | |
136 | the | |
137 | .Tn ACM | |
138 | article referenced below. | |
139 | .Pp | |
140 | The | |
141 | .Nm cksum | |
142 | utility exits 0 on success, and >0 if an error occurs. | |
143 | .Sh SEE ALSO | |
144 | .Rs | |
145 | .%T "Computation of Cyclic Redundancy Checks Via Table Lookup" | |
146 | .%A Dilip V. Sarwate | |
147 | .%J "Communications of the \\*(tNACM\\*(sP" | |
148 | .%D "August 1988" | |
149 | .Re | |
150 | .Sh STANDARDS | |
151 | .Nm Cksum | |
152 | is expected to conform to | |
153 | .St -p1003.2 . | |
154 | .Sh HISTORY | |
155 | The | |
156 | .Nm cksum | |
157 | utility is | |
158 | .Ud . |