Hashing is the process of turning data inputs into a fixed string of characters. It has all sorts of applications, including data authentication and storage, and it's an essential part of both blockchain networks and their cryptocurrencies. The most secure type of hashing uses an algorithm called a cryptographic hash function.

cryptographic_keys_image
Source: Getty Images

By understanding how these functions work, you'll discover what makes them so important in the world of cryptocurrency.

What are they?

What are cryptographic hash functions?

A cryptographic hash function is a mathematical algorithm that takes a data input, often referred to as a message, and produces a fixed-length encrypted output. The output can be called the hash, hash value, or message digest.

This hash serves as an encrypted representation of the original data input. A cryptographic hash function must be deterministic, which means a given data input must always generate the same output.

Cryptographic hash functions must meet high security standards. Most importantly, they need to be able to withstand all known types of cryptanalytic attacks that are meant to determine vulnerabilities in a cryptographic system. Simply put, if an attacker can find a weak point to exploit, then the function doesn't qualify as a cryptographic hash function.

Common applications

Cryptographic hash function explained

We've covered what cryptographic hash functions do, but to fully understand them, we also need to look at how they're used. Here are a few common applications:

  • Verifying data integrity: When sending and receiving data, a cryptographic hash function can verify that no one has tampered with it. Both the sender and recipient can run the data through the same algorithm, and, if the hashes don't match, then the data isn't the same.
  • Storing passwords: Many websites and applications offer to store passwords, but storing the actual passwords would be a massive risk. Instead, they can use cryptographic hash functions on passwords and store the resulting hash values.
  • Identifying files: A hash can serve as an identifier for a file or data. This allows users to look up and refer to files using the hash.

Blockchain networks also use cryptographic hash functions in several different ways. One of the earliest and most well-known examples is the proof-of-work system used by Bitcoin (BTC -2.28%) to validate transactions and mint new coins.

In proof of work, a cryptographic hash function is used on a block (group) of transactions. Bitcoin miners then use computing devices to find part of that hash in what's called a partial hash inversion. The first miner to accomplish that is chosen to validate the transactions and receives a reward for their efforts.

Cryptographic hash functions are also used to generate addresses for blockchain wallets. Each blockchain wallet has a public key that is used to receive transactions. A wallet address is generated by hashing the public key. Instead of giving out a lengthy public key, the user can instead share their wallet address.

Cryptographic hash function vs. hash function

Cryptographic hash functions and hash functions both refer to functions that convert a data input into a fixed-length output. A cryptographic hash function refers to a specific type of hash function that aims to provide specific security properties. That means all cryptographic hash functions are hash functions, but not all hash functions are cryptographic.

An ideal cryptographic hash function will provide the following security properties:

  • It's deterministic, meaning a given input will always produce the same hash.
  • It can quickly compute a hash for any input.
  • It's non-reversible. The original data input shouldn't be decipherable from the hash.
  • Any small change to the input should change at least half of the hash. This is referred to as the avalanche effect.
  • It shouldn't produce collisions, which are when two or more inputs generate the same hash.
  • It should be resistant to pre-image attacks, which involve attempting to find an input from a specific hash value.

If a cryptographic hash function is found to have flaws that attackers can exploit, it's demoted to a non-cryptographic hash function.

How they work

How cryptographic hash functions work

When you use a cryptographic hash function, you're running a data input through an algorithm. The algorithm then provides a hash value. Both the hash provided and its length depend on the cryptographic hash function that you use.

Let's say you're using a cryptographic hash function that provides outputs that are 40 characters long. No matter the size of the input, the resulting output will be 40 characters whether you're hashing one word or this entire article.

Related investing topics

Examples

Cryptographic hash function examples

There are quite a few cryptographic hash functions, each with their pros and cons. Here are some of the more popular options and notable types of cryptocurrency that use them:

  • SHA-256: Used by Bitcoin. This function is part of SHA-2, a set of cryptographic hash functions developed by the National Security Agency.
  • KECCAK-256: Used by Ethereum (ETH -0.74%). This function is part of SHA-3, which was developed by the National Institute of Standards and Technology.
  • SHA-512: Used by Stellar (XLM -0.58%) and XRP (XRP -1.91%). This function is also part of SHA-2.

If you're investing in cryptocurrency or considering it, it helps to understand the technology behind it. Although this technology is impressive, remember that the crypto market itself is still volatile, and investing in it is risky. Be prepared for the volatility if you decide to buy any crypto, and only put in money you could afford to lose.

Lyle Daly has positions in Bitcoin and Ethereum. The Motley Fool has positions in and recommends Bitcoin, Ethereum, and XRP. The Motley Fool has a disclosure policy.