BSD checksum
Encyclopedia
The BSD checksum algorithm is commonly used, legacy checksum
Checksum
A checksum or hash sum is a fixed-size datum computed from an arbitrary block of digital data for the purpose of detecting accidental errors that may have been introduced during its transmission or storage. The integrity of the data can be checked at any later time by recomputing the checksum and...

 algorithms. It has been implemented in BSD
Berkeley Software Distribution
Berkeley Software Distribution is a Unix operating system derivative developed and distributed by the Computer Systems Research Group of the University of California, Berkeley, from 1977 to 1995...

 and is also available through the GNU sum
Sum (Unix)
Sum is a core GNU utility written by Kayvan Aghaiepour and David MacKenzie and distributed with the UNIX- and Linux-based operating systems. This utility outputs the checksum of each argument file, as well as the number of blocks they take on disk....

 command line utility.

Newer checksum algorithms

The manual page of the GNU sum utility program (that implements the BSD checksum algorithm) states: sum is provided for compatibility; the cksum program is preferable in new applications.

Computation of the BSD checksum

Here is the relevant part of the GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 sum source code (GPL licensed):

FILE *fp; /* The file handle for input data* /
int ch; /* Each character read. */
int checksum = 0; /* The checksum mod 2^16. */

while ((ch = getc (fp)) != EOF)
{
...
checksum = (checksum >> 1) + ((checksum & 1) << 15);
checksum += ch;
checksum &= 0xffff; /* Keep it within bounds. */
}

Description of the algorithm

This algorithm computes a 16-bit checksum by adding up all 16-bit words of the input data stream. In order to avoid many of the weaknesses of simply adding the data, the accumulator is rotated to the right by one bit at each step.

Sources

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK