Lesson plan: Hashing and Password Storage
AP Cybersecurity · Unit 4 Securing Devices · Topic 4.2 Authentication · Practice set
At a glance
- Suggested time
- 1 class period (45 min)
- Pacing
- First of four sets for Topic 4.2, and it must come before Password Attacks, which assumes the hash model. The CED gives Topic 4.2 five class periods; this plan suggests 1 for this set, 2 for Password Attacks, 1 for Authentication Factors and MFA, and 1 for Login Settings. The split is this plan's suggestion; the CED gives only the topic total.
- Before this set
- None from this unit: the 4.1 sets before it are about devices and malware. Students should know that a bit is a 0 or a 1, and that encryption can be undone with a key. The mini-lesson explains hexadecimal (one character per 4 bits) itself.
- Skills
- 2.A Identify security controls, and explain how they mitigate risks.
The one idea: A hash is a one-way, fixed-length fingerprint of its input. A sign-in server stores the hash, hashes whatever is typed, and compares the two; nobody turns a hash back into a password. A different salt for each account keeps two equal passwords from having equal hashes.
Day by day
Day 1 · Hashes, sign-in, and salt45 min
- Open (3 min)Project CED Figure 4.2A (The Cryptographic Hash Function, printed page 104): seven inputs, two pairs of them identical, and three near-copies of one sentence. Ask which outputs match, and what happened to the output when one letter changed. Collect answers; the mini-lesson names the properties.
- Mini-lesson (13 min)Teach Hashing and Password Storage. Stop where it asks students to count the characters in a SHA-256 output (64 characters at 4 bits each, 256 bits). Stop again in the section "LinkedIn, 2012", where it asks how the hashes were recovered so fast, and take two or three guesses before showing the salt figure.
- Do together (7 min)Problem 4 🔒 Problem 10 🔒 🔒 Teacher notes: sign in as a teacher to see this🔒 Teacher notes: open the full plan to see this
- On their own (11 min)Problem 1 🔒 Problem 2 🔒 Problem 5 🔒 Problem 7 🔒: the properties of a hash and the names of hash functions · Problem 3 🔒 Problem 9 🔒 Problem 12 🔒: what a sign-in server stores, and what that means for an adversary or an administrator.
- In pairs (6 min)Problem 6 🔒: why collisions must exist · Problem 8 🔒: which functions are deprecated · Problem 11 🔒: read a table of four SHA-256 digests. One student reads the item, the other names the property it turns on.
- Discuss (2 min)Problem 11 🔒 🔒 Teacher notes: sign in as a teacher to see this🔒 Teacher notes: open the full plan to see this
- Exit check (3 min)🔒 Teacher notes: sign in as a teacher to see this🔒 Teacher notes: open the full plan to see this
Differentiation
- If students are struggling
- Do Problem 4 🔒 and Problem 9 🔒 as a class with the lesson's figures on screen, tracing what is stored and what is compared. Write the four property names on the board before Problem 7 🔒.
- Extension
- On a Mac or Linux terminal,
printf 'nightrider' | shasum -a 256gives the first line of the lesson's SHA-256 example. Students change one letter, compare the outputs, and then write two sentences on why collisions for SHA-256 exist but are never found by trying inputs by hand. - Vocabulary support
- hash (also digest, checksum, message digest), cryptographic hash function, collision, pre-image, deprecated, plaintext, salt, hexadecimal.
From the course framework
LO 4.2.A Explain why hashes (also called hash outputs, checksums, message digests, or digests) are used to store passwords.
- 4.2.A.1 A cryptographic hash function (also called a message digest function) is a mathematical algorithm that takes binary data of an arbitrary length, processes it according to a set of instructions, and outputs a fixed-length binary string called the hash (or checksum or message digest). Well known cryptographic hashes include: MD5; SHA-1, SHA-256, SHA-512 (SHA stands for Secure Hash Algorithm); NTHash; RIPEMD-160.
- 4.2.A.2 An n-bit hash has 2^n possible outputs. The number of inputs is infinite, and so inevitably two different inputs will produce the same hash. This is called a collision.
- 4.2.A.3 Cryptographic hash functions have the following properties: Hashes are collision resistant; it is difficult to find two different inputs to the same hash function that produce the same output. Hashes have pre-image resistance; given a hash, it is infeasible to figure out the input that generated the hash. Hashes are repeatable; the same input will always produce the same hash. Hashes have a fixed length; the length in bits of the hash for a specific hash function is constant regardless of the size of the input.
- 4.2.A.4 Adversaries try to compromise hashing functions by forcing collisions in their output. If an efficient algorithm exists to force a collision for a specific hash function, then that hash function will be deprecated (no longer used in secure settings). MD5 and SHA1 are examples of deprecated hash functions.
- 4.2.A.5 Password-based authentication services shouldn't store passwords in plaintext, so that if an adversary gains access to the user:password directory they won't immediately know the passwords for all users. Instead, user passwords should be hashed and the hash stored in a database. When a user enters their password, it is hashed, and the hash is compared to the hash stored on file. If the hashes match, then the user is authenticated.
- 4.2.A.6 If two users had the same password, then their passwords would have identical hashes in the user:password directory. To prevent this, a few random bits (called salt) are hashed with a user's password to generate the hash. Each user's salt is unique, so even if two users have the same password they will have a different password hash because they have different salt.
Framework example: CED Figure 4.2A (printed page 104) runs seven inputs through a hash function: "Fox" twice, one sentence twice, and three near-copies of that sentence (one misspelled word, one dropped letter, one added clause). Identical inputs give identical outputs, and any change to the input changes the whole output.