Cryptographic Foundations

Blockchain & Web3 Fundamentals
Course 1 · Chapter 2 · Cryptographic Foundations: Hashing, Digital Signatures & Public-Key Cryptography

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.
"Pay Alice 10 BTC" → SHA-256 → 3f2a...9e7c (illustrative digest)
"pay Alice 10 BTC" → SHA-256 → b81d...44f1 (completely different)

(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.)

Where Bitcoin Actually Uses SHA-256 Two real, distinct places: mining (Chapter 4 covers this fully) has miners repeatedly hashing block data with SHA-256, searching for an output that meets a specific difficulty target — the computational "work" in proof-of-work. Separately, Bitcoin applies SHA-256 twice in sequence ("double-SHA-256") as one step in turning a public key into a Bitcoin address (Chapter 7 covers this in full).

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:

  1. The signer uses their private key together with the message (in Bitcoin's case, a transaction) to produce a signature.
  2. 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.
  3. 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.

A Direct, Honest Cross-Reference If you've taken this site's own Number Theory & Cryptographic Math course, its own capstone builds and breaks a real, working RSA system — the classic public-key scheme whose security rests on how hard it is to factor a large number back into its two prime factors. ECDSA is genuinely different math, not just a rebranded RSA: its security rests on the elliptic curve discrete logarithm problem instead, a structurally unrelated hard problem. Both are real, legitimate ways to build a public/private key pair with the "easy one direction, infeasible the other" property Chapter 2 needs — Bitcoin's own designers chose ECDSA specifically for its shorter-key efficiency advantage over RSA at equivalent security levels.
SchemeHard Problem It Relies OnWhere 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)
A Real, Documented Failure Mode — Not a Flaw in the Math Itself ECDSA's own signing process needs a fresh, genuinely random, secret number for every single signature. If that random value is ever reused across two different signatures from the same private key, or generated by a weak/predictable random number source, an attacker can use the two signatures together to mathematically recover the private key itself — not a theoretical risk, but a real, documented category of attack that has actually compromised real ECDSA implementations in the past (including well-known, publicly documented cases on a games console and an early Android Bitcoin wallet). The elliptic curve math itself isn't broken in these cases — a specific implementation detail (how the random value was generated) was.

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.

Exercise 1
Explain, using this chapter's own listed hash properties, why a blockchain would be insecure if its hash function had weak collision resistance — specifically, what an attacker could do with two different inputs that hash to the same output.
Exercise 2
A colleague says: "A digital signature works like encrypting the message with your private key so only you could have sent it." Identify exactly what's wrong with this description and correct it using this chapter's own actual sign/verify process.
Exercise 3
Using this chapter's own RSA-vs-ECDSA comparison, explain why Bitcoin's designers might have chosen ECDSA over RSA specifically, even though both are legitimate ways to build a public/private key pair.

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.