Cryptographic Foundations
Chapter 1 established the problem blockchain solves and the real synthesis Bitcoin achieved in 2008–2009. This chapter opens the toolbox that made that synthesis possible: cryptographic hash functions and public-key cryptography. Nothing about a "block" or a "chain" or a "signed transaction" makes sense without these two tools first, so they get their own chapter before any blockchain-specific mechanics are introduced.
Cryptographic Hash Functions
A cryptographic hash function takes any input — a single word, a whole file, an entire block of transactions — and deterministically produces a fixed-size output called a hash (or "digest"). Bitcoin's own hash function of choice is SHA-256, designed by the NSA and published by NIST in 2001, which always produces a 256-bit output no matter how large or small the input is.
A useful hash function for this purpose needs several real, specific properties:
- Deterministic — the same input always produces exactly the same output, every time, on any machine.
- Fixed-size output — a one-character input and a 10-gigabyte file both produce a 256-bit digest.
- The avalanche effect — changing even a single character of the input produces a wildly, unpredictably different output, with no visible relationship to the small change made.
- Pre-image resistance — given a hash output, there's no practical way to work backward and find an input that produces it, short of brute-force guessing (roughly 2256 attempts in the worst case — a number large enough to be genuinely infeasible with any foreseeable computing power).
- Collision resistance — it's computationally infeasible to find two different inputs that happen to produce the same output.
(The digests above are illustrative placeholders, not computed SHA-256 output — the real point is structural: capitalizing one letter changes nothing about the message's meaning to a human reader, but produces a completely unrelated-looking hash. That unpredictability is the avalanche effect at work.)
Public-Key (Asymmetric) Cryptography
Before public-key cryptography existed, encryption was symmetric: the same single key both locked and unlocked a message, so both parties needed a way to securely share that one key in advance — a real, practical problem in itself.
Public-key (asymmetric) cryptography solves this differently, using a mathematically related pair of keys instead of one shared key:
- a public key, which can be shared with absolutely anyone, openly, with no loss of security; and
- a private key, which must be kept secret by its owner and never shared with anyone.
The two keys are mathematically linked in a specific, one-directional way: it's computationally easy to derive a public key from a private key, but computationally infeasible to go the other direction and derive the private key from the public one. That one-way relationship is the whole basis of public-key cryptography's security.
Digital Signatures
Digital signatures use this same key pair in reverse of what you might expect for "encryption." Rather than encrypting a message so only the recipient can read it, a digital signature lets the owner of a private key prove — publicly and verifiably — that they authorized a specific message, without ever revealing the private key itself:
- The signer uses their private key together with the message (in Bitcoin's case, a transaction) to produce a signature.
- Anyone holding the signer's public key can check that signature against the message and confirm it's valid — without ever needing the private key.
- Nobody who doesn't know the private key can produce a signature that will pass this check, no matter how hard they try, since forging one would require solving the same computationally infeasible problem that protects the key pair itself.
This is exactly how a Bitcoin transaction proves you actually own the funds you're trying to spend: you sign the transaction with your private key, and every node on the network can verify that signature against your public key, without you ever exposing the private key to anyone. Chapter 7 covers exactly how this plays out in a real wallet and a real transaction.
ECDSA: The Specific Signature Scheme Bitcoin Uses
"Public-key cryptography" describes the general idea; a real system still needs a specific
mathematical scheme to actually implement it. Bitcoin's choice is the
Elliptic Curve Digital Signature Algorithm (ECDSA), using a specific,
named elliptic curve called secp256k1.
ECDSA's security rests on the elliptic curve discrete logarithm problem — a different hard mathematical problem than the one classical RSA-based signatures rely on. This difference has a genuinely practical payoff: ECDSA can achieve the same real-world security level as RSA using dramatically shorter keys, which means smaller signatures, less data to transmit and store, and faster verification — all real, concrete advantages when a network needs to process and store millions of signed transactions.
| Scheme | Hard Problem It Relies On | Where It Shows Up on This Site |
|---|---|---|
| RSA | Factoring a large number back into its two secret prime factors | Number Theory & Cryptographic Math's own capstone (a real, working RSA implementation) |
| ECDSA (secp256k1) | The elliptic curve discrete logarithm problem | Bitcoin transaction signing (this course, Chapter 7 in depth) |
Hands-On Exercises
Three exercises reinforcing the two tools this chapter introduces — hashing and public-key signatures — before Chapter 3 assembles them into an actual block.
Quick Reference
- Cryptographic hash function — deterministic, fixed-size output; the avalanche effect makes small input changes produce unrelated-looking output; pre-image and collision resistant.
- SHA-256 — Bitcoin's hash function, 256-bit output, used in mining (proof-of-work) and (as double-SHA-256) in address generation.
- Public-key cryptography — a mathematically linked key pair: a shareable public key, and a private key that must stay secret; easy one direction, infeasible the other.
- Digital signature — sign with the private key, verify with the public key; proves authorization without ever revealing the private key.
- ECDSA / secp256k1 — the specific elliptic-curve signature scheme Bitcoin uses; shorter keys than RSA at equivalent security, but genuinely different math (elliptic curve discrete logarithm vs. RSA's integer factoring).
- Real risk — reused or weak randomness in ECDSA signing can leak the private key; a documented implementation failure, not a flaw in the underlying math.