Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

Hash functions are a fundamental concept encountered when learning about blockchains. This illustrated introduction focuses on their essential properties and applications, particularly for readers who have encountered hashes but have not yet understood how they work.

It can also serve as a companion to the following Japanese book:

Practical Introduction to Blockchain: From Bitcoin to Ethereum and DApp Development

Properties of hash functions

Properties of hash functions

What is a function?

A function maps an input to an output. A simple analogy is a capsule toy machine: insert a coin and receive a capsule.

A capsule toy machine as an analogy for input and output

Some functions accept multiple inputs. Unlike a random capsule machine, a mathematical function returns a uniquely determined output for a given input.

What is a hash function?

A conventional fixed-output hash function transforms input data of arbitrary supported length into an output of a fixed length.

A hash function transforms an input into a digest

The illustration passes the Japanese text "かるでね" (Cardene) through a hash function to obtain a seemingly unrelated string.

The output is called a hash value, or digest. For a given fixed-output hash algorithm, the digest length is independent of the input length.

Determinism and one-way behavior

A hash function is deterministic: supplying the same input repeatedly produces exactly the same digest.

Repeated hashing of the same input

Determinism is distinct from one-way behavior. A cryptographic hash function is designed to be easy to evaluate but difficult to invert.

Preimage resistance

Given a digest, it should be computationally infeasible to find an input that produces it.

Preimage resistance

The illustration shows the text "かるでね" being hashed. Starting with the resulting digest does not provide a practical way to recover that text through inversion alone.

Computational infeasibility does not mean mathematical impossibility. For an ideal cryptographic hash with an n-bit digest, generic preimage search requires on the order of 2 to the power of n evaluations.

For 256 bits, the search space has:

115792089237316195423570985008687907853269984665640564039457584007913129639936

possible digest values.

This estimate assumes an ideal hash. It does not mean that short or predictable inputs are equally difficult to recover: an attacker can test likely inputs directly.

Similar inputs can produce very different outputs

Consider the Japanese strings "かるでね" and "かるてね", which differ by one character.

Small input changes produce very different digests

Despite their similarity, their digests look very different. This illustrates the avalanche effect: small changes in the input should typically produce substantial changes in the output.

Collision resistance

It should be computationally infeasible to find any two distinct inputs that produce the same digest.

Because a fixed-length digest has a finite number of possible values, collisions necessarily exist.

Two distinct inputs with the same digest

A collision-resistant cryptographic hash makes finding such pairs impractical. For an ideal n-bit hash, the generic collision-search cost is approximately 2 to the power of n/2, due to the birthday bound.

This property helps protect applications that use digests to identify or authenticate data, provided that the application also protects the trusted reference digest.

Second-preimage resistance

Given a specific input, it should be computationally infeasible to find a different input that produces the same digest.

This is not the same as predicting one digest from another. The Japanese article uses a simple character-shift cipher to illustrate predictable transformations: reversing a one-character shift transforms "きれどの" into "かるでね", while shifting "あかさたな" in the opposite direction yields "いきしちに".

Such a substitution is reversible and predictable, unlike a secure cryptographic hash. It illustrates the limitations of simple transformations, rather than a formal test of second-preimage resistance.

Original illustration of second-preimage resistance

For an ideal n-bit hash and an ordinary fixed input, generic second-preimage search typically requires on the order of 2 to the power of n evaluations.

The original illustrations retain their Japanese labels.

Types of hash functions

Types of hash functions

There are many hash algorithms. The following are representative examples. The book below provides additional background.

Practical Introduction to Blockchain: From Bitcoin to Ethereum and DApp Development

SHA-2

SHA-2 is a family of cryptographic hash functions.

  • SHA-224
  • SHA-256
  • SHA-384
  • SHA-512
  • SHA-512/224
  • SHA-512/256

These variants differ in output length, internal parameters, and, in some cases, truncation. They are not all obtained simply by truncating SHA-256 or SHA-512.

SHA-256

Bitcoin uses SHA-256 in several parts of its protocol. The algorithm returns a 256-bit digest.

SHA-512

SHA-512 returns a 512-bit digest. Its internal operations and parameters differ from SHA-256, including its word size.

RIPEMD

RIPEMD is a family of hash functions derived from the design lineage of MD4.

RIPEMD-160

Bitcoin uses RIPEMD-160 together with SHA-256 in HASH160. RIPEMD-160 hashes the SHA-256 digest to produce a new 160-bit digest; it does not merely truncate the original 256-bit value.

SHA-3

SHA-3 was standardized as an alternative to complement SHA-2. Its internal construction is substantially different.

Standard SHA-3 hash functions have fixed output lengths, while the related SHAKE extendable-output functions allow callers to select an output length.

Applications of hash functions

  • Checking data integrity.
  • Storing password verification data.
  • Proof of work and blockchain address generation.

Checking whether data has been modified

A deterministic hash produces the same digest for the same input. If the data changes, its digest will ordinarily change as well.

Comparing the newly computed digest with a trusted reference digest can therefore detect modifications. If an attacker can replace both the data and the reference digest, a plain hash alone does not establish authenticity.

Hashing data for database storage

When registering for a web service, storing a password in plaintext is dangerous. If the database is compromised, plaintext passwords become directly accessible.

Instead, services should store a password verifier generated using a dedicated password-hashing algorithm and a unique random salt. Suitable algorithms include Argon2id, scrypt, and bcrypt, configured with appropriate cost parameters.

During authentication, the service checks the supplied password against the stored verifier.

Preimage resistance helps prevent direct inversion, but passwords often have low entropy. A fast general-purpose hash such as SHA-256 alone does not adequately protect them against offline guessing attacks.

Many web services and applications use password hashing as part of their authentication systems.

Proof of work and address generation

Cryptocurrencies such as Bitcoin use hash functions for proof of work and address-related operations. These applications involve additional protocol details and are beyond the scope of this introduction.

References

References

Conclusion

Conclusion

This article introduced hash functions, their principal security properties, common algorithms, and applications. It intentionally leaves out many mathematical and implementation details.

For additional background, see:

Practical Introduction to Blockchain: From Bitcoin to Ethereum and DApp Development

I regularly publish articles on Python and blockchains and share illustrated explanations on Twitter.