liveBook · Manning

Hash function

As explained in Fundamentals of Cybersecurity

A hash function is a function that maps input data to a fixed-size digest designed to change detectably when the input changes.

A hash function takes data of any size and produces a fixed-length digital fingerprint called a hash or message digest. Hashing is one-way: it does not recover the original data. Unlike encryption, it uses no key and does not keep data confidential. Its job is to help detect changes. section 14.2.4

For an organization, this makes hashing useful when a message, file, or database record must remain unchanged. Calculate its hash, then calculate it again later. If the values differ, the data has changed. Hashing supports integrity; encryption serves the different goal of confidentiality. section 14.2.4 section 14.2

Check a downloaded file

A website publishes a software file’s SHA-256 checksum. After downloading the file, use a hashing tool to calculate its SHA-256 hash. Compare the two values: a match confirms the file was not altered or corrupted during transmission. section 14.2.4

A digital signature adds a way to check who signed a document. The signer hashes the document and creates a signature using a private key. A verifier uses the corresponding public key, hashes the received document, and compares the digests. Hashing provides the change check; the signature connects it to the signer. section 14.2.5

USE
PUROPOSE
SCENARIO
Message
Verifying message integrity during transmission.
Alice sends a message to Bob with a hash. Bob calculates the hash of the received message to ensure it matches.
Files
Verifying file integrity, especially during transfers.
A software file is downloaded with its hash. The user checks the hash after download to ensure the file wasn’t altered.
Records
Ensuring integrity of records in databases or logs.
A database record (e.g., customer info) is hashed. If the record is changed, the new hash will not match the original.

Compare three everyday integrity checks: a message received over a network, a transferred file, and a database record. section 14.2.4

Algorithm
Description
Performance
MD5
A legacy algorithm that produces a 128-bit hash. Useful for file integrity. Not recommended for security purposes.
1x (fastest)
SHA-1
Produces a 160-bit hash and has now been deprecated due to vulnerability to collision attacks. No longer recommended.
~1.1x
SHA-2
A standard of secure algorithms (e.g., SHA-256, SHA-512) generating 256-bit or 512-bit hashes. Widely used in SSL certificates and blockchain.
~1.5–2x (SHA-256)
~2–2.5x (SHA-512)
SHA-3
A newer standard offering strong security, designed as an alternative to SHA-2 for high-security applications.
~3–4x (slowest)

Algorithm choice matters: MD5 is not recommended for security, SHA-1 is deprecated, and SHA-2 and SHA-3 are presented as secure options with different performance. section 14.2.4

How Fundamentals of Cybersecurity covers it

How deep it goes
Defines one-way, fixed-length hashing, walks through digest comparison, and compares algorithms without detailing their mathematical internals.
Examples
Uses a sender–receiver document check, a downloaded file checksum, and a database record comparison.
What it assumes
Introduces cryptography, encryption, hashes, and message digests directly, without requiring knowledge of algorithm internals.
What you can do after
Apply it via a hashing tool to compare a downloaded file’s SHA-256 hash with a published checksum.
How it connects
Links hashing to data integrity, encryption, digital signatures, and asymmetric cryptography.

Also explained in

Compare how 19 books explain hash function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fundamentals of Cybersecurity. The section links point to the parts of the book it draws on.