Commit | Line | Data |
---|---|---|
05e12ae3 | 1 | .\" Copyright (c) 1991, 1991 The Regents of the University of California. |
bd2a8a16 KB |
2 | .\" All rights reserved. |
3 | .\" | |
cf136d2c KB |
4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
6 | .\" | |
05e12ae3 | 7 | .\" %sccs.include.redist.roff% |
bd2a8a16 | 8 | .\" |
040b0e93 | 9 | .\" @(#)cksum.1 5.6 (Berkeley) %G% |
bd2a8a16 | 10 | .\" |
05e12ae3 CL |
11 | .Dd |
12 | .Dt CKSUM 1 | |
13 | .Os | |
14 | .Sh NAME | |
15 | .Nm cksum | |
16 | .Nd display file checksums and block counts | |
17 | .Sh SYNOPSIS | |
18 | .Nm cksum | |
87c9f085 | 19 | .Op Fl o Op \&1 \&| \&2 |
05e12ae3 CL |
20 | .Op Ar file ... |
21 | .Sh DESCRIPTION | |
bd2a8a16 | 22 | The |
05e12ae3 | 23 | .Nm cksum |
27de4b45 | 24 | utility writes to standard output three whitespace separated fields for each |
040b0e93 | 25 | input file. |
05e12ae3 CL |
26 | These fields are a checksum |
27 | .Tn CRC , | |
040b0e93 KB |
28 | the total number of octets in the file and the file name. |
29 | If no file name is specified, the standard input is used and no file name | |
30 | is written. | |
05e12ae3 | 31 | .Pp |
27de4b45 | 32 | The options are as follows: |
05e12ae3 CL |
33 | .Bl -tag -width indent |
34 | .It Fl o | |
27de4b45 | 35 | Use historic algorithms instead of the (superior) default one. |
05e12ae3 CL |
36 | .Pp |
37 | Algorithm 1 is the algorithm used by historic | |
38 | .Bx | |
39 | systems as the | |
40 | .Xr sum 1 | |
41 | algorithm and by historic | |
42 | .At V | |
43 | systems as the | |
44 | .Xr sum | |
45 | algorithm when using the | |
46 | .Fl r | |
47 | option. | |
27de4b45 KB |
48 | This is a 16-bit checksum, with a right rotation before each addition; |
49 | overflow is discarded. | |
05e12ae3 CL |
50 | .Pp |
51 | Algorithm 2 is the algorithm used by historic | |
52 | .At V | |
53 | systems as the | |
27de4b45 | 54 | default |
05e12ae3 | 55 | .Xr sum |
27de4b45 KB |
56 | algorithm. |
57 | This is a 32-bit checksum, and is defined as follows: | |
05e12ae3 | 58 | .Bd -unfilled -offset indent |
27de4b45 KB |
59 | s = sum of all bytes; |
60 | r = s % 2^16 + (s % 2^32) / 2^16; | |
61 | cksum = (r % 2^16) + r / 2^16; | |
05e12ae3 CL |
62 | .Ed |
63 | .Pp | |
27de4b45 KB |
64 | Both algorithm 1 and 2 write to standard output the same fields as |
65 | the default algorithm except that the size of the file in bytes is | |
66 | replaced with the size of the file in blocks. | |
67 | For historic reasons, the block size is 1024 for algorithm 1 and 512 | |
68 | for algorithm 2. | |
69 | Partial blocks are rounded up. | |
05e12ae3 CL |
70 | .El |
71 | .Pp | |
72 | The default | |
73 | .Tn CRC | |
74 | used is based on the polynomial used for | |
75 | .Tn CRC | |
76 | error checking | |
77 | in the networking standard | |
78 | .St -iso8802-3 | |
79 | The | |
80 | .Tn CRC | |
81 | checksum encoding is defined by the generating polynomial: | |
82 | .Pp | |
83 | .Bd -unfilled -offset indent | |
27de4b45 | 84 | G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + |
05e12ae3 CL |
85 | x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 |
86 | .Ed | |
87 | .Pp | |
88 | Mathematically, the | |
89 | .Tn CRC | |
90 | value corresponding to a given file is defined by | |
bd2a8a16 | 91 | the following procedure: |
05e12ae3 | 92 | .Bd -filled -offset indent |
bd2a8a16 | 93 | The |
05e12ae3 | 94 | .Ar n |
040b0e93 | 95 | bits to be evaluated are considered to be the coefficients of a mod 2 |
bd2a8a16 | 96 | polynomial M(x) of degree |
05e12ae3 | 97 | .Ar n Ns \-1 . |
040b0e93 KB |
98 | These |
99 | .Ar n | |
100 | bits are the bits from the file, with the most significant bit being the most | |
101 | significant bit of the first octet of the file and the last bit being the least | |
102 | significant bit of the last octet, padded with zero bits (if necessary) to | |
103 | achieve an integral number of octets, followed by one or more octets | |
104 | representing the length of the file as a binary value, least significant octet | |
105 | first. | |
106 | The smallest number of octets capable of representing this integer are used. | |
05e12ae3 | 107 | .Pp |
bd2a8a16 KB |
108 | M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by |
109 | G(x) using mod 2 division, producing a remainder R(x) of degree <= 31. | |
05e12ae3 | 110 | .Pp |
bd2a8a16 | 111 | The coefficients of R(x) are considered to be a 32-bit sequence. |
05e12ae3 | 112 | .Pp |
040b0e93 KB |
113 | The bit sequence is complemented and the result is the CRC. |
114 | .Ed | |
05e12ae3 | 115 | .Pp |
bd2a8a16 | 116 | The |
05e12ae3 | 117 | .Nm cksum |
bd2a8a16 | 118 | utility exits 0 on success, and >0 if an error occurs. |
05e12ae3 | 119 | .Sh SEE ALSO |
040b0e93 KB |
120 | The default calculation is identical to that given in pseudo-code |
121 | in the following | |
122 | .Tn ACM | |
123 | article. | |
05e12ae3 CL |
124 | .Rs |
125 | .%T "Computation of Cyclic Redundancy Checks Via Table Lookup" | |
126 | .%A Dilip V. Sarwate | |
127 | .%J "Communications of the \\*(tNACM\\*(sP" | |
128 | .%D "August 1988" | |
129 | .Re | |
130 | .Sh STANDARDS | |
131 | .Nm Cksum | |
132 | is expected to conform to | |
133 | .St -p1003.2 . | |
134 | .Sh HISTORY | |
135 | The | |
136 | .Nm cksum | |
137 | utility is | |
138 | .Ud . |