Overview

2 Cryptographic hash functions and digital signatures

This chapter introduces a simple “cookie token” payment system as a teaching scaffold and then upgrades it with core Bitcoin primitives so that trust shifts from a person to mathematics. It begins with a centralized spreadsheet run by a trusted operator, then motivates cryptographic tools by highlighting real-world risks such as imposters authorizing transfers. The chapter’s journey shows how cryptographic hash functions and digital signatures transform that fragile system into one where authenticity and integrity can be verified independently, paving the way toward Bitcoin’s trust-minimized design.

Cryptographic hash functions are presented as digital fingerprints: deterministic, fixed-length outputs that change drastically with even tiny input edits. The chapter explains why one-wayness and properties like pre-image, second-pre-image, and collision resistance matter, illustrating the astronomical difficulty of finding alternate inputs that match a given hash. Using SHA-256 (often applied twice in Bitcoin), hashes serve as compact integrity checks that reveal any tampering with data, a foundational capability later used to secure payment histories and tie data together so changes are detectable by anyone verifying.

Digital signatures solve the imposter problem by binding a specific message to a specific private key. Users generate a key pair, sign the hash of a payment request with their private key, and others verify with the corresponding public key, ensuring the request truly came from the claimed sender and hasn’t been altered. The chapter also emphasizes private key hygiene—online vs. offline storage, clear text vs. encrypted protection, and even key splitting—framing the trade-off between convenience and security. With signatures required for every transfer, the cookie token system reaches a more secure “version 2.0,” mirroring how Bitcoin authenticates transactions without relying on someone recognizing faces or names.

  Creating a cryptographic hash of a cat picture. Input is the cat picture and output is a big number of 32 bytes.
hashing a cat.png
  Hashing a modified cat picture. Can you spot the difference? The cryptographic hash function certainly did.
hashing a modified cat.png
  Save a hash of the cat picture on a piece of paper
integrity check 1.png
  Check the integrity of the cat picture. You detect a change.
integrity check 2.png
  Simplistic hash function using byte-wise addition modulo 256.
simplistic hash algorithm.png
  A cryptographic hash function, SHA256, in action. The input "Hello!" will give you the same output every time, but the slightly modified input "Hello" will give you a totally different output.
cryptographic hashing.png
  Different desirable properties for cryptographic hash functions. For collision resistance, X can be anything, as long as the two different inputs give the same output X.
hash properties.png
tool cryptographic hash function.png
simplistic hash algorithm.png
hash properties.png
2ndcol physical vs digital signature.png
   You send a digitally signed cat picture to Fred. Fred verifies the signature to make sure that he’s got the same cat as the cat you signed.
signing overview.png
  The digital signature process. 1. John creates a keypair and gives the public key to Lisa. 2. John signs a message with the private key. 3. Lisa verifies that the message is signed with the private key belonging to the public key she got from John.
generate key pair.png
John creates a key pair. The private key is a huge random number and the public key is derived from that random number. John stores his private key on his hard drive and the public key is handed to Lisa.
create keypair.png
Encrypting and decrypting with the public and private keys. Left: Encrypt with the public key and decrypt with the private key. Right: Encrypt with the private key and decrypt with the public key.
enc dec public private.png
recap keys create.png
recap keys sign verify.png
  Lisa has added a row for John’s cookie token transfer after verifying the signature of John’s message.
cookie sheet basic johns transfer.png
Someone stole money from John. Who is Melissa and how was this possible? John did not sign any such transfer.
cookie sheet john pwned.png
digital signature summary.png
The tools used for signing and verification.
signing overview summary.png
message in a bottle.png

    Recap

In this chapter you learned that

  • Bitcoins are created as rewards to nodes securing the blockchain.
  • The reward halves every four years to limit the money supply.
  • You can use cryptographic hash functions to detect changes in a file or in a message.
  • You can’t make up a pre-image of a cryptographic hash. A pre-image is an input that has a certain known output.
  • Digital signatures are useful to prove the authenticity of a payment. Only the rightful owner of bitcoins may spend them.
  • Someone verifying a digital signature does not have to know who made the signature. She just have to know that the signature was made with the private key the signature claims to be signed with.
  • To receive bitcoins or cookie tokens, you need a public key. First you create a private key for yourself in private. You then derive your public key from your private key.
  • There are several strategies to store private keys ranging from unencrypted on your mobile phone to splitted and encrypted across several off-line devices.
  • General rule of thumb: The more secure the private key is against theft, the easier it is to accidentally lose the key. And vice versa.

FAQ

What are “cookie tokens” and how do they relate to Bitcoin?Cookie tokens (CT) are a simple, spreadsheet-based money system used in the chapter to explain Bitcoin concepts. A spreadsheet row represents a payment (like a Bitcoin transaction), the spreadsheet itself represents the blockchain, and Lisa plays the role of a miner who verifies and appends transfers. The issuance schedule halves over time so total CT approach 21,000,000, mirroring Bitcoin’s capped supply.
What is a cryptographic hash function and why is it important?A cryptographic hash function maps any input data to a fixed-size “fingerprint.” It is deterministic, sensitive to tiny input changes, and hard to reverse or collide. Bitcoin uses hashes everywhere—for integrity checks, identifying data, and securing the history of transactions.
What key properties make a hash function “cryptographic”?Four core properties: deterministic output for the same input, avalanche effect (small input change → very different output), fixed-size output, and resistance properties achievable only by brute force (pre-image, second-pre-image, and collision resistance). These make tampering and forgery astronomically hard.
Why can’t you reverse SHA-256 or easily find another input with the same hash?SHA-256 behaves like a one-way function; the only known method to find a pre-image or a colliding input is trial-and-error across an enormous space (~2^256 possibilities). Even with massive computing power, the expected time needed is far beyond the age of the universe.
How can hashes be used to detect data corruption?Compute and store the hash of the original data. Later, recompute the hash of the current data and compare. A mismatch proves the data changed; a match gives overwhelming confidence it hasn’t.
Why is data hashed before it is digitally signed?Hashing condenses arbitrary-length data to a fixed-size value that the signature algorithm can efficiently process. It also ensures any tiny change to the message yields a different hash, causing signature verification to fail and protecting message integrity.
How do digital signatures prove a payment is authorized?The payer signs the payment message with their private key; anyone with the corresponding public key can verify the signature. Because only the private key holder can produce a valid signature tied to that exact message, signatures prove authorization and prevent imposters.
How does Lisa verify John’s signed payment in the cookie token system?Lisa looks up John’s public key, computes the hash of the exact message she received, and verifies the signature against that hash using John’s public key. If they match, she knows John’s private key authorized that message and appends the transfer to the spreadsheet.
How are private and public keys created and used?A private key is a large random 256-bit number generated by the user. The public key is derived from the private key via a one-way function. The private key signs messages; the public key is shared so others can verify those signatures.
What are the main private key risks and storage trade-offs?If someone copies your private key, they can spend your funds; if you lose it, no one can recover your money. Storage options trade convenience for security: online vs offline, clear text vs encrypted, single whole key vs split across devices. You are fully responsible for protecting your private key.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bitcoin ebook for free