1*49209Scael.\" Copyright (c) 1991, 1991 The Regents of the University of California. 247170Sbostic.\" All rights reserved. 347170Sbostic.\" 4*49209Scael.\" %sccs.include.redist.roff% 547170Sbostic.\" 6*49209Scael.\" @(#)cksum.1 5.3 (Berkeley) 05/06/91 747170Sbostic.\" 8*49209Scael.Dd 9*49209Scael.Dt CKSUM 1 10*49209Scael.Os 11*49209Scael.Sh NAME 12*49209Scael.Nm cksum 13*49209Scael.Nd display file checksums and block counts 14*49209Scael.Sh SYNOPSIS 15*49209Scael.Nm cksum 16*49209Scael.Op Fl o Op Ar \&1 | Ar \&2 17*49209Scael.Op Ar file ... 18*49209Scael.Sh DESCRIPTION 1947170SbosticThe 20*49209Scael.Nm cksum 2147801Sbosticutility writes to standard output three whitespace separated fields for each 2247801Sbosticinput file (or the standard input by default). 23*49209ScaelThese fields are a checksum 24*49209Scael.Tn CRC , 25*49209Scaelthe total number of bytes in the file and 2647801Sbosticthe file name. 27*49209Scael.Pp 2847801SbosticThe options are as follows: 29*49209Scael.Bl -tag -width indent 30*49209Scael.It Fl o 3147801SbosticUse historic algorithms instead of the (superior) default one. 32*49209Scael.Pp 33*49209ScaelAlgorithm 1 is the algorithm used by historic 34*49209Scael.Bx 35*49209Scaelsystems as the 36*49209Scael.Xr sum 1 37*49209Scaelalgorithm and by historic 38*49209Scael.At V 39*49209Scaelsystems as the 40*49209Scael.Xr sum 41*49209Scaelalgorithm when using the 42*49209Scael.Fl r 43*49209Scaeloption. 4447801SbosticThis is a 16-bit checksum, with a right rotation before each addition; 4547801Sbosticoverflow is discarded. 46*49209Scael.Pp 47*49209ScaelAlgorithm 2 is the algorithm used by historic 48*49209Scael.At V 49*49209Scaelsystems as the 5047801Sbosticdefault 51*49209Scael.Xr sum 5247801Sbosticalgorithm. 5347801SbosticThis is a 32-bit checksum, and is defined as follows: 54*49209Scael.Bd -unfilled -offset indent 5547801Sbostics = sum of all bytes; 5647801Sbosticr = s % 2^16 + (s % 2^32) / 2^16; 5747801Sbosticcksum = (r % 2^16) + r / 2^16; 58*49209Scael.Ed 59*49209Scael.Pp 6047801SbosticBoth algorithm 1 and 2 write to standard output the same fields as 6147801Sbosticthe default algorithm except that the size of the file in bytes is 6247801Sbosticreplaced with the size of the file in blocks. 6347801SbosticFor historic reasons, the block size is 1024 for algorithm 1 and 512 6447801Sbosticfor algorithm 2. 6547801SbosticPartial blocks are rounded up. 66*49209Scael.El 67*49209Scael.Pp 68*49209ScaelThe default 69*49209Scael.Tn CRC 70*49209Scaelused is based on the polynomial used for 71*49209Scael.Tn CRC 72*49209Scaelerror checking 73*49209Scaelin the networking standard 74*49209Scael.St -iso8802-3 75*49209ScaelThe 76*49209Scael.Tn CRC 77*49209Scaelchecksum encoding is defined by the generating polynomial: 78*49209Scael.Pp 79*49209Scael.Bd -unfilled -offset indent 8047801SbosticG(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + 81*49209Scael x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 82*49209Scael.Ed 83*49209Scael.Pp 84*49209ScaelMathematically, the 85*49209Scael.Tn CRC 86*49209Scaelvalue corresponding to a given file is defined by 8747170Sbosticthe following procedure: 88*49209Scael.Bd -filled -offset indent 8947170SbosticThe 90*49209Scael.Ar n 9147170Sbosticbits of the file are considered to be the coefficients of a mod 2 9247170Sbosticpolynomial M(x) of degree 93*49209Scael.Ar n Ns \-1 . 94*49209Scael.Pp 9547170SbosticM(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by 9647170SbosticG(x) using mod 2 division, producing a remainder R(x) of degree <= 31. 9747170SbosticDuring the division, each time the intermediate remainder is zero, it 98*49209Scaelis changed to the next value from a predefined sequence of 99*49209Scael32-bit integers before completing the division. 10047170SbosticThis sequence is long and complex -- see the source code for more 10147170Sbosticinformation. 102*49209Scael.Pp 10347170SbosticThe coefficients of R(x) are considered to be a 32-bit sequence. 104*49209Scael.Ed 105*49209Scael.Pp 10647170SbosticThe calculation used is identical to that given in pseudo-code in 107*49209Scaelthe 108*49209Scael.Tn ACM 109*49209Scaelarticle referenced below. 110*49209Scael.Pp 11147170SbosticThe 112*49209Scael.Nm cksum 11347170Sbosticutility exits 0 on success, and >0 if an error occurs. 114*49209Scael.Sh SEE ALSO 115*49209Scael.Rs 116*49209Scael.%T "Computation of Cyclic Redundancy Checks Via Table Lookup" 117*49209Scael.%A Dilip V. Sarwate 118*49209Scael.%J "Communications of the \\*(tNACM\\*(sP" 119*49209Scael.%D "August 1988" 120*49209Scael.Re 121*49209Scael.Sh STANDARDS 122*49209Scael.Nm Cksum 123*49209Scaelis expected to conform to 124*49209Scael.St -p1003.2 . 125*49209Scael.Sh HISTORY 126*49209ScaelThe 127*49209Scael.Nm cksum 128*49209Scaelutility is 129*49209Scael.Ud . 130