Topics in this domain

Hashing and Integrity

Cryptography · 3 min read

A fingerprint for data

A fingerprint is tiny, unique to you, and you can’t rebuild a person from it. But if someone claims to be you, comparing fingerprints settles the question.

A cryptographic hash function does the same for data. Input of any size goes in; a fixed-size output (the digest, or message digest) comes out.

Hash properties: one-way, fixed size, avalanche effect, collision-resistant.

A good hash function is:

  • one-way: you can’t work back from the digest to the input
  • collision-resistant: it’s infeasible to find two different inputs with the same digest
  • sensitive: change one bit of input and the digest changes completely (the avalanche effect)

Hashing gives integrity. It doesn’t hide the data, so it gives no confidentiality, and it isn’t encryption.

Algorithms

AlgorithmDigest sizeStatus
MD5128 bitsBroken (collisions found); not for security
SHA-1160 bitsBroken for collision resistance; being retired
SHA-2 (SHA-256, SHA-512)256 / 512 bitsCurrent standard
SHA-3VariableCurrent standard, different design

Stopping deliberate tampering

A plain hash catches accidental changes. But an attacker who changes a message can just compute a new hash for it.

Plain hash, HMAC and digital signature compared for integrity, proving who, and non-repudiation.
  • An HMAC (hash-based message authentication code) mixes in a shared secret key. Only someone with the key can produce a valid HMAC, so it gives integrity and authentication between the two parties. Because both hold the key, it can’t give non-repudiation.
  • A digital signature encrypts the hash with the sender’s private key, giving integrity, authentication and non-repudiation.

Storing passwords

Passwords must never be stored in clear text or with reversible encryption.

Password plus unique salt, slow hash, store the result.
  • Salt: a unique random value added to each password before hashing. Identical passwords then get different hashes, which defeats precomputed rainbow tables. Salts don’t need to be secret.
  • Slow algorithms built for passwords (bcrypt, scrypt, Argon2, PBKDF2) make mass guessing expensive. Fast hashes like plain SHA-256 make guessing fast, which is the wrong goal for passwords.
  • Optionally a pepper: a secret value stored separately from the database.

Example. A breached database stores passwords as unsalted SHA-1 hashes. Attackers crack most of them within hours using precomputed tables. With per-user salts and Argon2, the same attack would take years per password.

Hashes in audit work

Uses of hashing: file integrity monitoring, forensics, downloads, passwords, signatures, deduplication.
  • File integrity monitoring compares the current hashes of system files with known-good values.
  • Forensics: the hash of a forensic image is compared with the original’s to prove the copy is exact.
  • Software downloads: published hashes let users check what they downloaded.
  • Deduplication and blockchains use hashes as identifiers.

How the exam asks about it

If the question asks…The answer is usually…
Purpose of hashingIntegrity (detect changes)
Does hashing provide confidentialityNo
Technique combining a hash with a secret keyHMAC
Defence against rainbow table attacksSalting
How a forensic copy is proven identicalMatching hash values
Weak hash algorithmsMD5, SHA-1

In short

  • A hash function turns any input into a fixed-length digest; it's one-way and should be collision-resistant.
  • Any change to the input, even one bit, produces a very different hash, so hashes detect alteration.
  • Hashing provides integrity, not confidentiality: the original data isn't hidden or encrypted.
  • A plain hash doesn't prove who created it; an HMAC (hash with a secret key) or a digital signature adds authentication.
  • Passwords are stored as salted hashes using deliberately slow algorithms (bcrypt, scrypt, Argon2, PBKDF2).
  • MD5 and SHA-1 are broken for collision resistance; use SHA-2 or SHA-3.

Exam traps

  • Hashing is not encryption and can't be reversed to recover data.
  • An attacker who alters a message can recompute a plain hash; integrity against attackers needs an HMAC or signature.
  • Salts defeat precomputed (rainbow table) attacks; they don't need to be secret.
  • Fast hashes like SHA-256 alone are poor for passwords because they make guessing fast.
  • Forensic images are verified by comparing hashes of the original and the copy.

Slides

Click the slide and use the arrow keys. F toggles full screen.

CISA · Domain 5 · Cryptography

Hashing and Integrity

A fingerprint for data: what a hash is, why it can't be reversed, how keyed hashes and signatures stop deliberate tampering, how passwords should be stored, and where hashes turn up in audit work.

1 / 9