Lesson map
Lesson 17 published. Map, example, EX049.
flowchart TD
N0["Learning outcomes"]
N1["17.1 Hash functions"]
N2["17.2 Digital signatures"]
N3["Lab — Detecting altered voucher records"]
N4["Synthesis"]
N0 --> N1 --> N2 --> N3 --> N4
N4 --> EX["Worked example"]
EX --> Q["Exercise EX049"]
Logical drawing
flowchart LR
N0["Learning outcomes"]
N1["17.1 Hash functions"]
N2["17.2 Digital signatures"]
N3["Lab — Detecting altered voucher records"]
N4["Synthesis"]
N0 --> N1 --> N2 --> N3 --> N4 --> Q["EX049"]
[Learning outcomes]
|
v
[17.1 Hash functions]
|
v
[17.2 Digital signatures]
|
v
[Lab — Detecting altered voucher records]
|
v
[Synthesis]
|
v
[Worked example] --> [Exercise EX049]
Learning outcomes
You will (1) explain hash functions and digital signatures; (2) use digests to detect change; (3) recognise cryptographic limits.
17.1 Hash functions
A cryptographic hash function turns any input into a fixed-length digest. Good hash functions make it infeasible to find two inputs with the same digest or to work backwards from a digest. SHA-256, used in Nakamoto's design, produces 256-bit digests, written as 64 hexadecimal characters. Changing a single character of the input changes the digest completely. Sofia uses this property to protect evidence and records: if a stored digest no longer matches a file, the file has changed. Blockchains chain blocks together by including each block's predecessor's digest, so altering an old block would break every link after it.
17.2 Digital signatures
A digital signature lets the holder of a private key sign a message so anyone with the matching public key can verify it. Ethereum-compatible ledgers use elliptic-curve signatures, as described in Wood's yellow paper. A valid signature shows the message came from the key holder and was not altered. It does not show the key holder intended the action wisely, or that the key was not stolen. Sofia explains this to the board: the ledger checks that the right key signed, while the cooperative's processes must check that signing was the right decision for that particular request.
Lab — Detecting altered voucher records
"""Detect altered voucher records by comparing SHA-256 digests (synthetic, read-only)."""
import hashlib
def digest(record):
return hashlib.sha256(record.encode("utf-8")).hexdigest()
ISSUED = ["V001|m014|25", "V002|m233|10", "V003|m087|40", "V004|m512|15"]
STORED = {r.split("|")[0]: digest(r) for r in ISSUED}
CURRENT = ["V001|m014|25", "V002|m233|100", "V003|m087|40", "V004|m512|15"]
def main():
changed = [r.split("|")[0] for r in CURRENT if digest(r) != STORED[r.split("|")[0]]]
print(f"records {len(CURRENT)}; changed {len(changed)}: {', '.join(changed)}")
print(f"digest length {len(STORED['V001'])} hex characters")
if __name__ == "__main__":
main()
Run with python3 lab_digest.py. Verified output:
records 4; changed 1: V002
digest length 64 hex characters
17.3 What the lab shows and its limits
The lab stores SHA-256 digests of four synthetic voucher records when they are issued, then compares them with current records. One record, V002, has had its amount changed from 10 to 100, and its digest no longer matches, so it is reported. Each digest is 64 hexadecimal characters. Sofia notes the limits: a digest detects change only if the stored digest itself is protected, for example by recording it on the ledger. Cryptography also cannot help if the original record was wrong when created. It proves consistency over time, not truth at the moment of creation.
Worked example
The lab flags V002 among four records because its amount changed from 10 to 100, using 64-character SHA-256 digests.
Synthetic case. The voucher records are synthetic; Nakamoto (2008) and Wood's yellow paper are real sources.
Errors and limits
Trusting a digest stored beside the data it protects lets anyone who alters the data alter the digest too.
Exercises
- EX049 — Digest length. How many hex characters does a SHA-256 digest have?
Show marking criteria
Rubric: 3 = 64;; 2 = sixty-four;; 1 = 32;; 0 = none. - EX050 — Signature limit. What does a valid signature not prove?
Show marking criteria
Rubric: 3 = that the action was wise or the key not stolen;; 2 = intent;; 1 = origin;; 0 = none. - EX051 — Lab result. Which record does the lab report as changed?
Show marking criteria
Rubric: 3 = V002, from 10 to 100;; 2 = V002;; 1 = V001;; 0 = none.
Synthesis
Hashes and signatures prove consistency and origin, while processes must ensure correctness.
Continue studying — chapter 17 of 40
← Chapter 16 (draft) · Course chapter index · Chapter 18 (draft) →