Skip to content
Blockchain Association of Cameroon
BAC-L0-FOUND-1043 h

Hash functions

What a hash function actually guarantees — collision resistance, the avalanche effect, determinism — and the uses it does not cover.

  • State the three properties expected of a cryptographic hash function
  • Compute and verify a file digest
  • Explain why hashing is not encryption

A cryptographic hash function turns any data, from a word to a film, into a fixed-size digest — 64 hexadecimal characters for SHA-256 — that acts as an identity stamp for the content. This workshop teaches the three properties we expect of it (same input, same output; a tiny change upsets everything; it is infeasible to build two inputs with the same digest), how to compute and verify a file's digest, and why hashing is not encrypting. It is the building block that, further along the curriculum, links the blocks of a chain, builds Merkle trees and underpins proof of work.

Lessons 1/4 · 25 min

The digest: a fixed-size fingerprint of content

How do you check 700 MB without rereading them?

Awa downloads a 700 MB program. The site says: "SHA-256: ba78…". How can she know the file received is exactly the one published, without comparing it byte by byte with an original she does not have? She computes a digest (also called a hash) of the file received and compares it to the published digest: 64 characters to compare instead of 700 million bytes.

What is a hash function?

A hash function takes data of any size (a sequence of bytes) and returns a value of fixed size. SHA-256, from the SHA-2 family defined by the FIPS 180-4 standard, always returns 256 bits, i.e. 32 bytes. They are written in hexadecimal (base 16: digits 0 to 9 then letters a to f), where each character represents 4 bits: 256 ÷ 4 = 64 characters.

Input (text, UTF-8 encoded)SHA-256 digest (64 hexadecimal characters)
(empty text)e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
abcba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
hello2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Type abc into the widget below: you should find the second row. A 700 MB file, too, gives 64 characters.

Two families of "hash" functions

In workshop 102, a hash table's hash function serves to spread keys over buckets: it just needs to be fast and well spread. A cryptographic hash function must also resist someone who is actively trying to break it. The first is used for data structures, the second for security. When we say "hash" without qualification in the rest of the curriculum, we mean the second.

A beginner's trap: what you really hash

You hash bytes. For a text, these are the bytes of its encoding (here UTF-8). An extra space or a hidden line break changes the digest:

printf 'hello' | sha256sum
# 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

echo hello | sha256sum
# 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03

The second command hashes hello followed by a line break (the echo command adds one). It is not the same data, hence not the same digest. When two people do not find the same digest for "the same text", it is almost always an invisible difference of this kind.

What is a digest for?

  • Checking the integrity of a file downloaded or copied (lesson 4).
  • Identifying content by its digest: the Git version-control system names each object this way.
  • Committing to data without revealing it yet: publish the digest, reveal the data later.
  • Linking blocks: each block contains the previous block's digest (lesson 4, then the blockchain workshops).

What this does not guarantee

  • A digest alone does not say who produced the file: anyone can compute the SHA-256 of anything. Proving the author takes a signature (workshop 105).
  • It does not necessarily hide the data (lesson 3).
  • Two files with equal digests are, in practice, identical; the converse "different digests ⇒ different files" is, by contrast, absolutely certain.

Recap

Hash function: bytes of any size → fixed-size digest (SHA-256: 256 bits, 64 hexadecimal characters). It applies to bytes, to the character. The digest identifies content, but does not identify its author.

Interactive tool

SHA-256 digest

Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

Digest (64 hex characters)

…

Digest of the second text

…

Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

Lessons 2/4 · 35 min

Three properties: determinism, avalanche, collision resistance

What should we demand of a good digest?

Suppose Awa uses as her digest "the sum of the letters' codes, modulo 1,000". It is fast, fixed-size… and unusable: "AWA" and "AAW" have the same digest (anagrams), and changing one letter changes the digest by only a few units. The three properties below are the ones this toy lacks.

1. Determinism

The same input always gives the same digest, on any machine, at any time, with no secret key. That is what lets two people who do not know each other compare their results. Determinism comes with a fixed-size output (SHA-256: 256 bits) and a fast computation: hashing a file is nearly instant.

2. The avalanche effect

A tiny change in the input — one character, one bit — changes the digest unpredictably, as if it were entirely new. Compare:

InputSHA-256
hello2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

Only the first letter changes (h → H, a single bit apart in the encoding). Yet the digest no longer resembles the other: comparing position by position, 61 of the 64 hexadecimal characters differ. This is no accident: if two hexadecimal strings were independent, each position would coincide with probability 1/16, i.e. 64 ÷ 16 = 4 identical positions on average and about 60 different ones. Seeing about 60 differences, however close the inputs, is exactly what we expect. This corresponds to about half of the bits: a hexadecimal character differs as soon as any one of its 4 bits differs, which happens 15 times out of 16, whereas each bit taken alone differs one time in two. Use the widget to compare two texts one character apart and count the differences.

Avalanche is a design criterion, visible to the eye, that follows from the security requirements; it is not by itself a proof of security. It does explain why you cannot "creep up" on a target digest by small successive tweaks.

3. Collision resistance (and its two cousins)

A collision is a pair of two different inputs that give the same digest. Collisions necessarily exist: there are infinitely many possible inputs and only 2^256 digests (the pigeonhole principle). The property asked for is that finding them is infeasible. Textbooks distinguish three levels:

PropertyStatement
Preimage resistance ("one-way")Given a digest d, it is infeasible to find an input m such that H(m) = d
Second-preimage resistanceGiven an input m1, it is infeasible to find another one, m2 ≠ m1, with the same digest
Collision resistanceIt is infeasible to find any pair m1 ≠ m2 with the same digest

How many tries? Orders of magnitude

For SHA-256, finding a preimage by blind trial takes on the order of 2^256 ≈ 1.2 × 10^77 tries. For a collision, the birthday paradox shows that one turns up after about the square root of that number, i.e. on the order of 2^128 ≈ 3.4 × 10^38 tries: this is the best generic attack known, and it is why SHA-256 is said to offer about 128 bits of security against collisions. These numbers are beyond the reach of any imaginable hardware.

To feel the principle, truncate the digest to 16 bits (65,536 possible values): by the same reasoning a collision shows up after about √65,536 = 256 inputs, i.e. in moments. The digest length sets the cost of the attack: a short digest is a broken digest.

What this does not guarantee

  • "Infeasible" does not mean "impossible": it is a judgement on the current state of computing and cryptanalysis. A function can be weakened: MD5 and SHA-1 are the examples (lesson 4).
  • To my knowledge no practical collision on SHA-256 has been published; that may change, which is why standards are reviewed. The figures above are for generic attacks on an ordinary computer; quantum computers, if they ever exist at scale, would lower these generic costs (without making them zero), and standards bodies follow the subject.
  • These three properties cover neither secrecy nor authenticity (lesson 3).

Recap

Determinism: same input, same output, fixed size. Avalanche: a small change makes about 60 characters out of 64 differ. Collision resistance: finding two inputs with the same digest is infeasible (about 2^128 tries for SHA-256), although such pairs exist.

Interactive tool

SHA-256 digest

Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

Digest (64 hex characters)

…

Digest of the second text

…

Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

Lessons 3/4 · 30 min

Hashing is not encrypting

"We encrypted the PINs with SHA-256"

A small service keeps, for each customer, the SHA-256 digest of their 4-digit PIN, and says: "the codes are encrypted, nobody can read them". Is that true? The answer means separating two operations that are often confused.

Encrypting and hashing: two different tools

EncryptionHashing
Inputa message and a keybytes
Outputa ciphertext, about the size of the messagea fixed-size digest
Reversible?Yes, with the keyNo, no key, no "decryption"
Secret key?YesNo (the function is public)
Purposekeep content secret, then recover itidentify or verify content

Hashing is one-way for two reasons that add up. First, the function loses information: a 1 GB file gives 32 bytes, and countless inputs give the same digest, so "decrypting" would not even make sense. That is not enough on its own, though (cutting a file after its first 32 bytes also loses information, and is trivially "undone" when the input is short). Second, preimage resistance: finding an input that gives a given digest is believed infeasible… provided the input cannot be guessed.

The trap of guessable inputs

A 4-digit PIN has only 10,000 possible values (0000 to 9999). An attacker who steals the database computes the SHA-256 of those 10,000 candidates and looks each stolen digest up in their list. This takes a fraction of a second on an ordinary computer (a few milliseconds in Python). The SHA-256 of 1234, for example, is 03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4: anyone can compute and recognise it. The digest therefore hides nothing: the security of a hashed secret is the security of how hard it is to guess. The PIN was not protected, only disguised.

Passwords: you need a hash made for the job

A good password hash must be deliberately slow and salted:

  • the salt is a random value specific to each user, stored next to the digest and mixed with the password before hashing. Two users with the same password then get different digests, and precomputed digest tables become useless;
  • a deliberately slow function (Argon2, scrypt, bcrypt, PBKDF2; Argon2 and scrypt also demand a lot of memory) makes each attacker guess expensive. Plain SHA-256, designed to be fast, is a poor choice here.

None of these precautions is "encryption": the password is never recovered, only compared.

Proving who produced a message: HMAC

A digest alone does not prove the author: an attacker can modify the message and recompute the digest. An HMAC mixes a shared secret key into the message before hashing: only someone who knows the key can produce the right HMAC. The widget below computes an HMAC-SHA256: try it with a fictitious key (for example cle-fictive-de-demonstration), then change one character of the message or the key and observe that the HMAC changes entirely. With an HMAC, the verifier must know the same key as the producer: the proof is shared between two people, not public. Workshop 105's signatures will bring a proof anyone can verify.

What this does not guarantee

  • Hashing does not hide guessable data (PIN, first name, phone number): the attacker tries every possibility.
  • Equal digests reveal that two pieces of data are equal: useful (spotting a duplicate) but also a leak.
  • A digest does not prove origin: anyone can hash anything.

Recap

Encrypting = reversible with a key; hashing = no key, one-way, fixed size. A hashed secret is only protected by how hard it is to guess: PINs and passwords call for a slow, salted hash. HMAC adds a key to authenticate a message between two people who share it.

Interactive tool

SHA-256 digest

Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

Digest (64 hex characters)

…

Digest of the second text

…

Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

Interactive tool

HMAC

Message authentication code: a digest that depends on a shared secret. Without the key it cannot be recomputed.

Key format
Message format

HMAC (hex)

…

An empty key is accepted (it is equivalent to a key of zeros).

Lessons 4/4 · 35 min

Verifying a file, then chaining blocks

Verifying a file's digest

On Linux and macOS: sha256sum file (or shasum -a 256 file). On Windows, in PowerShell: Get-FileHash file -Algorithm SHA256. In Python:

import hashlib

def sha256_file(path):
    h = hashlib.sha256()
    with open(path, "rb") as f:
        for chunk in iter(lambda: f.read(65536), b""):
            h.update(chunk)
    return h.hexdigest()

It reads in chunks so as not to load 700 MB into memory; the final digest is the same as if everything had been read at once. Projects often publish a digest file where each line is "digest, two spaces, file name", which sha256sum -c checks automatically.

Reading the result. The two digests are identical to the character, or they are not: there is no "nearly identical". A single difference — even in the last character — means the file is not the one that was published. It may be corruption (interrupted download) or deliberate alteration; either way, do not run it.

Where does the reference digest come from?

Verifying assumes you trust the published digest. If the file and the digest come from the same compromised server, the attacker replaces both and the verification succeeds. A digest therefore protects against accidental corruption, and against an altered file when the digest was obtained through a separate, reliable channel (another official site, a signed announcement). For a proof that holds even if the server is compromised, you need a digital signature (workshop 105).

Chaining blocks by their digests

Workshop 103 ended on a problem: modifying a row of the log left no trace. Here is the idea that solves it. Each block contains its data and the previous block's digest; its own digest is computed over the whole. Our TOY chain, with the convention "number | data | previous digest":

block 1: 1|Awa credit 100|GENESIS
         digest h1 = fa68461319a4bcab4ea332b39bc1d03311f222f813c36432235756047f20c312

block 2: 2|Awa pays Kofi 30|fa68461319a4bcab4ea332b39bc1d03311f222f813c36432235756047f20c312
         digest h2 = fdec2cc6e9c9c0997020c1acc3b3f044ab80cb6fd5a963da3881ac1c035523bd

block 3: 3|Kofi pays Mba 10|fdec2cc6e9c9c0997020c1acc3b3f044ab80cb6fd5a963da3881ac1c035523bd
         digest h3 = eff5f1c07e8133f22ba376f95f24d1692dbcb842b23746824cc84afd1cb10575

You can recompute h1 by typing exactly 1|Awa credit 100|GENESIS into the sha256 widget.

The attack. A fraudster changes, in block 2, "30" to "300". Block 2's digest becomes 2f359f87ad0dcc90… instead of fdec2cc6e9c9c099…. But block 3 still contains the old digest (fdec2cc6…): when recomputing, the verification finds that block 2's digest no longer matches what block 3 announces. The alteration is detected.

To hide it, the fraudster must fix block 3 (putting 2f359f87… in it), which changes block 3's digest, so block 4 must be fixed, and so on to the end of the chain. In a chain of n blocks where block k is modified, all blocks from k + 1 to n must be recomputed. And if someone else kept a copy of the last digest, the rewritten chain will no longer match that copy. The "chain-explorer" widget lets you modify a block and watch the following digests break.

The honest warning

  • Chaining detects a modification; it does not prevent it. If nobody keeps the last digest elsewhere, a fraudster who controls the whole chain can rewrite it entirely, cleanly. Having several independent parties keep the same chain is the subject of the consensus workshop.
  • It does not say who wrote a block, nor that its content is true: it only guarantees the content has not changed since the digest was computed.
  • Our chain convention is a toy. Real chains have a precise format (byte headers, double hashing in Bitcoin), which you will see later.

MD5 and SHA-1: why they are banned

Practical collisions have been published for MD5 (in the 2000s) and for SHA-1 (first public collision in 2017). These functions therefore no longer fulfil collision resistance, and are no longer used for signatures or certificates. MD5 remains fine for spotting accidental corruption, but not against an adversary. See the security exercise.

Recap

Verifying a file = computing its digest and comparing it, character by character, with a reference obtained through a reliable channel. Chaining blocks by their digests makes any modification detectable and forces all following blocks to be recomputed, without making it impossible.

Interactive tool

SHA-256 digest

Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

Digest (64 hex characters)

…

Digest of the second text

…

Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

Interactive tool

Blockchain explorer (toy)

Five blocks linked by their digests. Edit a block's data: its digest changes, the next block's link breaks, and every later block becomes invalid.

Building the chain (mining 5 blocks)…

This is a toy. A block's hash is SHA-256 of "index|previous hash|data|nonce"; difficulty is only two leading hex zeros (about 256 attempts). A real chain requires astronomically more work and a network of nodes that each verify the chain.

Guided lab

Digests are computed here with the page's sha256 widget; verifying a downloaded binary with sha256sum and the toy chain in Python make up the independent lab. The generated tasks give you a different text on every attempt: you really have to compute. The other steps are reasoning questions about the digests you have just observed.

A browser is no substitute for a real terminal: this lab trains reading and reasoning; the real hands-on practice is in the independent lab.

A certified account is required

Graded activities record results in your name and are the basis for a credential. They therefore need a complete certified file and a current consent. Filling in the file does not verify your identity; the Secretariat can verify it afterwards ("Verified" badge).

  1. 1.Compute a digest

    The task below gives a short text. Type it into the sha256 widget exactly, character for character, with no space or line break added or missing, then copy the 64-character digest into the answer field. If your result is refused, reread the text: a hyphen, a digit or a capital copied wrongly is enough to change the whole digest, as you saw in lesson 2.

    Interactive tool

    SHA-256 digest

    Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

    Digest (64 hex characters)

    …

    Digest of the second text

    …

    Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

  2. 2.Measure the avalanche effect

    The task gives two messages A and B that differ only in their last character. Hash both with the widget, copy the first 16 characters of each digest, then count in how many of the 64 hexadecimal positions the two digests differ (the comparison widget counts the differences for you; check that it gives a number close to 60). Before computing, write down your prediction: how many positions do you expect to differ?

    Interactive tool

    SHA-256 digest

    Type some text: the digest updates on every keystroke. Compare with a second text to see the avalanche effect.

    Digest (64 hex characters)

    …

    Digest of the second text

    …

    Differing characters are underlined and bold. Text is UTF-8 encoded with no space or newline added.

  3. 3.Verdict on a download

    A project publishes the expected digest of its installer, obtained from an official page, then you compute the digest of the file received (assume you have copied both by hand, with no reading mistake on your part):

    published: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
    computed : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9825

    Compare them character by character (63 characters out of 64 are identical, but that is not the question), then answer the question asked: what do you conclude, and what do you do with the file? Use lesson 4 for what a difference means.

  4. 4.Break a "hashed" PIN

    The service from lesson 3 stores SHA-256(PIN) for each 4-digit PIN. You steal one record. Describe in three lines your attack method: which candidates, which calculation, how to recognise the right one. Then answer the question asked: at most, how many digests must you compute to be certain of recovering any code? With the sha256 widget, check that the digest of 1234 is indeed the one given in lesson 3.

  5. 5.Rewriting a chain

    Open the five-block chain widget. Modify block 2's data and observe which digests change, then use "Re-mine from here" to get a consistent chain again. Beware: this widget's chain adds to each block a number called a nonce and requires a digest starting with 00; that is a proof-of-work rule which workshop 110 will explain, and its digest formula ("index|previous hash|data|nonce") is not the one from lesson 4. For this workshop, just observe which digests change and which blocks have to be recomputed. Note how many blocks, besides block 2, had to be recomputed. Then restore the original block 2, modify block 4 and repeat the same observation. Then answer the question asked, which concerns a longer chain than the widget's.

    Interactive tool

    Blockchain explorer (toy)

    Five blocks linked by their digests. Edit a block's data: its digest changes, the next block's link breaks, and every later block becomes invalid.

    Building the chain (mining 5 blocks)…

    This is a toy. A block's hash is SHA-256 of "index|previous hash|data|nonce"; difficulty is only two leading hex zeros (about 256 attempts). A real chain requires astronomically more work and a network of nodes that each verify the chain.

Security exercise — A deliberate collision: what it gives an attacker

A service that approves payments "by digest"

A small company has set up a rule: a payment order is approved by the director, who records not the order's text but its digest. Later, the accounting department executes only the orders whose digest matches the one that was approved. To save effort, the company chose a TOY function: the sum of the text's character codes, modulo 1,000. (It is a classroom toy, not a real algorithm.)

The order submitted for approval is: PAY 001 TO KOFI (pay 1 franc to Kofi). The director approves the digest presented: 935. The fraudster, who filed the order under a fake customer's name, hopes to replace it, after approval, with an order that gives the same digest 935.

Work it out: the sum of the character codes of PAY 001 TO KOFI (P = 80, A = 65, Y = 89, space = 32, 0 = 48, 0 = 48, 1 = 49, space = 32, T = 84, O = 79, space = 32, K = 75, O = 79, F = 70, I = 73) is 935, and 935 mod 1,000 = 935.

Why this toy does not resist

The sum depends neither on the order nor on the position of the characters: any permutation of the text keeps the same digest. The attack needs no computing power. With a real cryptographic hash function, changing one character or swapping two upsets the digest (avalanche), and finding two orders with the same digest takes about 2^128 tries.

Real collisions, honestly

With MD5 and SHA-1, methods that build practical collisions have indeed been published. They do not let you "forge a document with the same digest as an existing, imposed document" (that would be a second-preimage attack, still infeasible): the attacker must prepare both documents themselves before one of them is approved, signed or published. That is exactly the scenario above: the attacker proposes, gets the harmless document approved or signed, then circulates the other. That is why these functions are no longer used for signing.

To do

Answer the check question: among the orders proposed, which give the same toy digest, 935, as PAY 001 TO KOFI?

Workshop quiz

Eight questions drawn from a larger pool, 70% to pass. It opens once every lab checkpoint is passed. You can retake it: the draw changes.

A certified account is required

Graded activities record results in your name and are the basis for a credential. They therefore need a complete certified file and a current consent. Filling in the file does not verify your identity; the Secretariat can verify it afterwards ("Verified" badge).

Independent lab (outside the site)

Not graded online: do it on your own machine and publish it to your Git repository.

Independent lab: verify a binary, then build a toy chain

Do this on your machine (Linux, macOS or WSL), with Python 3 and hashlib (nothing to install).

Part 1: verify a download. Choose a small free program whose project publishes a SHA-256 digest through an official channel (download page, release announcement). Download the file, then compute its digest with sha256sum (or shasum -a 256) and compare it with the project's, character by character. Note where your reference digest comes from and what this verification does not cover if the site is compromised. Then change a single byte of a copy of the file (with a hex editor or a small script) and recompute: observe the avalanche.

Part 2: a file's digest in Python. Write sha256_file(path) (see lesson 4, chunked reading) and check that its result equals sha256sum's on three files, one of them over 10 MB.

Part 3: the toy chain. Write a class or functions for blocks (index, data, prev_hash) whose digest is the SHA-256 of the string "index|data|prev_hash" (the first block uses prev_hash = "GENESIS"). Add append_block(chain, data) and verify(chain), which recomputes each digest and checks each link. Write tests: a valid ten-block chain passes; modifying block 4's data makes verify fail and point to the right block; modifying block 4 and then recomputing blocks 5 to 10 in cascade produces a chain that passes verify but whose last digest has changed (which is what someone who kept the old one would detect).

Part 4: say what the toy does not do. In a short note, list three things your chain does not guarantee (the block's author, the truth of the data, the chain's uniqueness) and link each to a workshop in the curriculum that will address it.

To hand in. The code, the tests, the proof of part 1 (the two digests compared, the URL of the reference channel) and the note. The chain must be verifiable by someone else without your explanations: document the exact block format.

Takeaways

  • A cryptographic hash function turns any data into a fixed-size digest (SHA-256: 256 bits, 64 hexadecimal characters); it applies to bytes, to the character.
  • Three properties: determinism (same input, same output), avalanche (a small change makes about 60 characters out of 64 differ) and collision resistance (finding two inputs with the same digest is infeasible, although such pairs exist).
  • Verifying a file means comparing its digest, character by character, with a reference obtained through a reliable channel; it proves neither the author nor the file's good faith.
  • Hashing is not encrypting: no key, no way back. A hashed secret is only protected by how hard it is to guess; PINs and passwords call for a slow, salted hash.
  • Chaining blocks by their digests makes any modification detectable and forces the following blocks to be recomputed, without preventing it; MD5 and SHA-1 are no longer safe against an adversary.

Common misconceptions

  • Misconception : A digest is an encrypted version of the file: you can decrypt it with the right key.

    In fact : There is no key and no decryption. The function is public and one-way: a 1 GB file gives 32 bytes, from which the file cannot be rebuilt.

  • Misconception : If two different inputs gave the same digest, the function would necessarily be broken: collisions do not exist.

    In fact : Collisions always exist (infinitely many inputs, 2^256 outputs). A good function is one for which finding them is infeasible.

  • Misconception : Hashing a PIN or password with SHA-256 is enough to protect it.

    In fact : If the input is guessable, the attacker tries every possibility (10,000 for a 4-digit PIN, in a fraction of a second). A slow, salted hash is needed.

  • Misconception : If the file's digest matches the site's, the file is safe.

    In fact : It only proves the file is the one whose digest was published. If the site is compromised, the attacker changes both; you need a reference through a separate channel or a signature.

Glossary

Hash function
Function that turns data of any size into a fixed-size value (the digest); deterministic and public.
Digest (hash)
Output of a hash function; for SHA-256, 32 bytes, written as 64 hexadecimal characters.
SHA-256
Hash function of the SHA-2 family (FIPS 180-4 standard) producing a 256-bit digest.
Avalanche effect
Property by which a small change of the input modifies about half the digest's bits, unpredictably.
Collision
Two different inputs that give the same digest. They always exist; security rests on the practical impossibility of finding any.
Preimage resistance
Given a digest, it is infeasible to find an input that produces it (the 'one-way' property).
Salt
Random per-user value mixed into the password before hashing so that two identical passwords give different digests.
HMAC
Digest computed with a shared secret key, letting you check that a message comes from a holder of the key and has not been modified.
Hexadecimal
Base-16 notation (0-9, a-f) in which each character represents 4 bits.
Hash chaining
Technique where each block contains the previous block's digest, making any modification of a block detectable in the following ones.