Table of Contents
Table of Contents

Cryptographic Hash Functions: Definition and Examples

Cryptographic Hash Functions

Investopedia / Paige McLaughlin

What Are Cryptographic Hash Functions?

A cryptographic hash function is a mathematical function used in cryptography. Typical hash functions take inputs of variable lengths to return outputs of a fixed length.

A cryptographic hash function combines the message-passing capabilities of hash functions with security properties.

Key Takeaways

  • Hash functions are mathematical functions that transform or "map" a given data set into a bit string of fixed size, also known as the "hash value."
  • Hash functions are used in cryptography and have variable levels of complexity and difficulty.
  • Hash functions are used for cryptocurrency, password security, and message security.

How Cryptographic Hash Functions Work

Hash functions are commonly used data structures in computing systems for tasks such as checking the integrity of messages and authenticating information. While they are considered cryptographically "weak" because they can be solved in polynomial time, they are not easily decipherable.

Cryptographic hash functions add security features to typical hash functions, making it more difficult to detect the contents of a message or information about recipients and senders. 

In particular, cryptographic hash functions exhibit these three properties:

  • They are "collision-free." This means that no different inputs should map to the same output hash
  • They can be hidden. It should be difficult to guess the input value for a hash function from its output. 
  • They should be puzzle-friendly. It should be difficult to select an input that provides a pre-defined output. Thus, the input should be selected from a distribution that's as wide as possible.

The three properties outlined above are desirable but cannot always be implemented in practice.

Examples of Cryptographic Hash Functions

Cryptographic hash functions are widely used in cryptocurrencies to pass transaction information anonymously. For example, Bitcoin, the original and largest cryptocurrency, uses the SHA-256 cryptographic hash function in its algorithm. Ethereum, the second most popular blockchain, uses Keccak-256 to hash information.

However, hashes have other applications in the real world. These are some of the most common cryptographic applications:

Password Verification

Storing passwords in a regular text file is dangerous, so nearly all sites store passwords as hashes. When a user inputs their password, it is hashed, and the result is compared to the list of hashed values stored on the company's servers. However, this is not a fool-proof practice—hackers have created databases of common passwords and their hashes, called rainbow tables, which make it easier for them to get into accounts.

Signature Generation and Verification

Verifying signatures is a mathematical process used to verify the authenticity of digital documents or messages. A valid digital signature, where the prerequisites are satisfied, gives its receiver strong proof that a known sender created the message and that it was not altered in transit.

A digital signature scheme typically consists of three algorithms: a key generation algorithm; a signing algorithm that, given a message and a private key, produces a signature; and a signature verifying algorithm.

Verifying File and Message Integrity

Hashes can ensure messages and files transmitted from sender to receiver are not tampered with during transit. The practice builds a "chain of trust." For example, a user might publish a hashed version of their data and the key so that recipients can compare the hash value they compute to the published value to make sure they align.

What Is the Best Cryptographic Hash Function?

The best cryptographic hash function is the one that meets the needs of whatever it is being used for. SHA 256 is one of the most used, but there are many to choose from.

What's an Example of a Hash Function?

An example of a hash function is MD5, used for encoding sensitive information. Here is the previous sentence in an MD5 hash: d13718d1f2b95ae65888a57fd5bc0056

What Are the 3 Properties of a Hash Function?

The three properties a hash function should have are collision resistance, preimage resistance, and second preimage resistance.

The Bottom Line

Cryptographic hash functions are programs that use a mathematical function, like an algorithm, to convert information to a hexadecimal form. These functions are also used in cryptocurrency to secure blockchain information.

The comments, opinions, and analyses expressed on Investopedia are for informational purposes online. Read our warranty and liability disclaimer for more info.

Article Sources
Investopedia requires writers to use primary sources to support their work. These include white papers, government data, original reporting, and interviews with industry experts. We also reference original research from other reputable publishers where appropriate. You can learn more about the standards we follow in producing accurate, unbiased content in our editorial policy.
  1. O'Reilly. "Mastering Bitcoin | Chapter 7. The Blockchain."

  2. O'Reilly. "Ethereum’s Cryptographic Hash Function: Keccak-256."

  3. National Institute of Standards and Technology. "National Vulnerability Database | CVE-2020-10538 Detail."

  4. National Intitute of Standards and Technology. "Cryptographic Hash Function."

Compare Accounts
×
The offers that appear in this table are from partnerships from which Investopedia receives compensation. This compensation may impact how and where listings appear. Investopedia does not include all offers available in the marketplace.
Provider
Name
Description