Glossary

Hash Function

2 min read

There are many instances of cryptographic hash functions, but all cryptographic hash functions share a few key properties.

  • All cryptographic hash functions take an input, called a preimage, and produce an output, called a hash or digest, of a fixed length. This length varies based on the precise function used.

  • The output of a cryptographic hash function is deterministic. For a given input, the output will always be exactly the same.

  • A cryptographic hash function is a one-way function. An output can easily be calculated from an input. However, there is no known way of determining the input from a given output.

  • The output is random and unpredictable. There is no known method for targeting a specific output and calculating the proper input. Nor can a relationship be drawn between a series of inputs and their outputs. For example, if an input of 100 characters is changed by a single character, the new output bears no resemblance to the old output.

These properties make cryptographic hash functions very useful for Bitcoin. Hashing is random and uncontrollable, ensuring Bitcoin mining is a fair competition. Hashing a public key or a script to obtain an address provides superior security, privacy, and convenience for users. Hashing transactions and blocks provides a simple way of creating universally unique IDs for both transactions and blocks. Finally, Merkle Trees use hashing to create reliable, immutable summaries of all transactions in a block, making mining and block verification significantly more efficient.

Bitcoin only uses a few hash functions for its various aspects. The hash function SHA-256 is used for creating Proofs-of-Work, and SHA-256 is applied twice to generate txids. In order to generate public key hashes or addresses, the hash160 function is used. This is a combination of the SHA-256 and RIPEMD160 hash functions.