What are similarities and differences between a "checksum" algorithm and a "hash" function?

Can they be used instead of each other? Or their usage are different?

For example, for verifying the integrity of a text, which one is better to be used?


A checksum is an application of a hash function.

From wikipedia - cryptographic hash function:

A cryptographic hash... is a mathematical algorithm that maps data of arbitrary size to a bit string of a fixed size (a hash) and is designed to be a one-way function, that is, a function which is infeasible to invert.

From wikipedia - checksum:

A checksum is a small-sized datum derived from a block of digital data for the purpose of detecting errors which may have been introduced during its transmission or storage.

As an example of how hash functions and checksums are applied in bitcoin, consider how a bitcoin address is generated from a public key (for full details see this link):

  • By employing a hash function, the user's public key remains unknown until an address is spent from, so this keeps a user's funds safe in the case ECDSA is broken (see this question for further reasoning).

  • Adding a checksum to the address ensures that a user will not lose coins due to a simple keying/copying error when submitting payments.

So, we can see that using a hash function allows the user to hide their public key (but easily confirm the address once we know the public key), while also retaining enough bytes in the address to ensure a very large address space.

In contrast, the checksum is short (4 bytes), so obviously we could not use a checksum as the address (the address space would be far too tiny!). But a checksum works well to ensure the address is legitimate, the chance of making a keying error and still having a valid checksum is incredibly small- it is basically impossible in practise! Using the entire hash output as the checksum would work as well, but it would be overkill, and an inefficient use of space (instead of an extra 4 bytes, the address would basically double in size).

  • In general, can we say that all hash algorithms cannot be used as a checksum? meaning that only some specific hash algorithms are eligible to be used as checksum? Thanks – Questioner Sep 23 '18 at 11:32
  • 1
    There are many types of hash functions, choosing the correct one for a certain application is important. Not all hash functions will be appropriate to use in creating a checksum. See en.wikipedia.org/wiki/Hash_function#Hash_function_algorithms – chytrik Sep 23 '18 at 11:41
  • This answer (bitcoin.stackexchange.com/a/3602/41513) says that use of hash of public key as an address is only to get shorter addresses and there no security or privacy reason. Unlike you who believe it allows the user to hide their public key, meaning that there is a security and privacy reason. So don't you agree with that answer about the reason of using hash of public key as an address? Thanks – Questioner Sep 23 '18 at 12:34
  • 1
    @sas read the second paragraph of that answer, and the comments, both of which mention a security aspect. Shortening the payable address is another reason for employing a hash that I didn’t explicitly mention, but instead linked to other answers as supplemental material. In general there may be many advantages to using a certain hash function, not just one single reason. – chytrik Sep 23 '18 at 17:31

Sometimes these terms are used more or less interchangeably. Traditionally, a checksum is used to detect corruption and a hash is used to map large elements into slots randomly. In Bitcoin-land we're often concerned with "cryptographic hashes" which are hashes that have special security properties.

Things called checksums are usually designed to have certain uniformity properties that make them maximally likely to detect errors. Things called hashes are usually designed to be very fast to compute and not be too non-uniform. Things called cryptographic hashes are designed to make it difficult to compute a collision.

The security properties of cryptographic hashes often make them slower and less uniform than functions you would use for cases where the security isn't required.

Generally any function from any of the three groups could be used in any of the applications, the result would just not achieve the security, performance, or reliability that you'd get for using the right tool for the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.