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 modified cat picture. Can you spot the difference? The cryptographic hash function certainly did.
Save a hash of the cat picture on a piece of paper
Check the integrity of the cat picture. You detect a change.
Simplistic hash function using byte-wise addition modulo 256.
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.
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.
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.
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.
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.
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.
Lisa has added a row for John’s cookie token transfer after verifying the signature of John’s message.
Someone stole money from John. Who is Melissa and how was this possible? John did not sign any such transfer.
The tools used for signing and verification.
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.
Grokking Bitcoin ebook for free