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