Public-key cryptography
Suggest an editThe previous lesson introduced the idea of a key pair without explaining how such a thing is possible. This lesson is about what makes that work.
Proving who you are without revealing the secret
You need a way to prove to anyone in the world that you are who you say you are, without revealing the secret that makes you "you."
A password doesn't work for this. Showing your password to a verifier means they now have your password and can pretend to be you. A shared key, as in symmetric encryption, doesn't work either, because you'd need to share it in advance with every party, including people you've never met.
What you need is a pair of values, mathematically linked, with these properties:
- One value (the secret) generates the other (the public proof token) easily.
- The reverse direction (recovering the secret from the public token) is computationally infeasible.
- The secret can be used to "sign" or "decrypt" things in a way only the holder of the secret could do.
- The public token can be used by anyone to verify the work without ever holding the secret.
This is the key pair from the previous lesson. The secret is the private key, and the public token is the public key.
A one-way function links the two keys
The mathematical idea underneath every key pair is a one-way function, an operation that is easy to compute in one direction and infeasible to reverse.
Multiplying two prime numbers (numbers that divide only by 1 and by themselves) gives a small example. Multiplying 61 by 53 takes one step and gives 3233. The simple way back from 3233 to 61 and 53 is to try divisors one after another, 2, 3, 4 and so on, until 53 divides it evenly. With two numbers twice as long, the multiplication is still quick, and the list of divisors to try is about a hundred times longer.
A key pair uses a different operation with the same property, at a much larger scale. The forward direction takes the private key as input and produces the public key as output, and any device can compute it in a fraction of a second. Reversing it requires an attacker to try enormous numbers of possibilities, and the schemes are designed so that even the largest computer clusters humanity has built would not finish reversing one in the lifetime of the universe.
Bitcoin and Ethereum use secp256k1, Solana uses Ed25519
Two elliptic-curve schemes do almost all of the public-key work in the chains you'll encounter. In both, the one-way operation is a calculation on an elliptic curve. For this course you don't need to be able to do elliptic-curve arithmetic by hand. secp256k1 is used by Bitcoin, Ethereum, and most of the chain families that followed them. Ed25519 is newer and is used by Solana and a growing number of newer chains. Both use a 32-byte private key. Both schemes are believed to be secure against any classical computer, and both are vulnerable to a sufficiently large quantum computer running Shor's algorithm.
A key pair starts from 32 random bytes
The private key is a random 32-byte number, generated by an entropy source (a source of randomness) and not picked by a human. A human-chosen private key is a guessable private key, and the security of the scheme depends on the secret being indistinguishable from random noise to anyone who doesn't have it.
private_key = 32 random bytes from a secure entropy source
public_key = curve_multiply(private_key, generator_point)Key generation is one call to a cryptographic random number generator and one curve operation, the easy direction of the one-way function. Most wallet compromises in history are not breaks of the curve but weak entropy, meaning private keys with predictable bytes.
The playground below has a node that does this generation. Click and you'll see a freshly-derived public key. Change the private-key bytes and watch the public key change completely. The avalanche-like property you saw with hash functions carries over here.
The private key is your identity on the chain
Your address is derived from your public key. The chain doesn't know your name, your country, or your email. It knows the public key that goes with the private key you control, so possession of the private key is the definition of "you" from the chain's perspective.
You prove that you hold the private key by signing a message. The private key produces a short value, a signature, that anyone can check against the message and your public key, and nobody can forge it without the private key. The key itself is not revealed in the process. Every blockchain transaction is authorised this way, and the digital signatures lesson covers how it works.
Anyone can also encrypt a message to your public key, as in the previous lesson, but a public chain does not protect its data this way.
Only you know the private key, so nobody can restore it for you. If you lose it, there is no recovery and no customer support to call. If someone steals it, there is no insurance.
The next lesson covers how a wallet generates that key and how you back it up.