Checksum (source code)

= Checksum
{wiki}

A <checksum> is a short value calculated from a data block and stored or transmitted with it to help detect corruption. The receiver recomputes the <checksum> from the received data and compares it with the supplied value. Different data blocks can have the same <checksum>, so a successful comparison does not prove equality.

For example, summing four bytes modulo $256$ gives a one-byte <checksum>. The bytes $10,20,30,40$ give $100$; changing the first byte to $11$ changes the <checksum> to $101$, whereas exchanging two bytes leaves it unchanged. The particular <checksum> determines which error patterns are detected.

The Internet <checksum> groups bytes into 16-bit words, adds them with end-around carry, and complements the result. End-around carry adds an overflow bit back into the low end of the sum. Verification includes the <checksum> field and expects a sum with all bits set. The covered fields depend on the protocol; IPv6 has no header <checksum>.<Computing the Internet Checksum (RFC 1071)>[Section 1: generation, verification, and end-around carry]{ref}<Internet Protocol, Version 6 (IPv6) Specification (RFC 8200)>[Section 3: IPv6 header format]{ref}