At a high level, cryptographic systems attempt to provide (some or all of) the following three objectives.
These three security objectives are sometimes referred to as the "CIA triad."
We have spent the past few lectures discussing how to record transactions within a blockchain.
As long as the majority of computational power is controlled by honest miners, then everybody's view of the blockchain is eventually consistent.
[Image source: Nakamoto whitepaper]
Last time, we designed some new cryptographic algorithms, and then used them to add features to Bitcoin.
A light client can be convinced that a transaction exists in the blockchain using a Merkle tree.
[Image source: Nakamoto whitepaper]
This is our first example of a proof system, which allows a prover who knows why a claim is true to convince a verifier of this fact. We will see more proof systems throughout this course.
Prover | Verifier | |
---|---|---|
$\longrightarrow$ |
We also discussed how to resolve a conundrum for light clients.
We designed a pseudorandom generator, which allows the light client to make several random-looking keys in a deterministic fashion.
Given a single key $m$, the client can generate many new values $H(m, 0)$, $H(m, 1)$ and use all of these as keys.
In fact, it is possible to make a hierarchy of keys in this way.
[Image source: BIP-32 specification]
Finally, we can store the master key $m$ in a human-memorable way as a sequence of 24 words. Since each word is chosen from a list of 2048 options, the total number of choices is $2048^{24} > 2^{256}$ so the words can collectively encode a 256-bit key.
Our starting point for today's lecture is to construct a new kind of digital signature that can make life easier for the nodes.
Last week, we saw the RSA digital signature scheme. It is named after its inventors: Rivest, Shamir, and Adleman. While RSA works fine, one concern is that its keys and signatures are about a few thousand bits long.
That may not sound big, and indeed a single signature is small. But they add up quickly.
Remember that each node stores a record of every single transaction, and so far there have been over 800 million transactions on Bitcoin.
The punchline here is: space on the blockchain is a valuable resource, so we should try to minimize usage of it. Let's discuss another signature scheme that can use less space.
Recall that digital signature schemes have a tricky property: from the public key it is impossible to create a digital signature but easy to verify if someone else has done so.
As a result, we must build signature schemes from math problems that we believe to have this property of "difficult to solve but easy to check."
One such problem is factoring, as we discussed last week. We want to find another problem that is hard(er) to break.
Here is another hard math problem: taking logarithms.
...Wait, this doesn't sound right. If I tell you that I have taken the number $5$ to some power $x$ and the result is $125$, can you compute $x$ such that $5^x = 125$?
Taking logarithms to find $x = \log_5(125)$ is easy over the real numbers $\mathbb{R}$.
But: it turns out though that for certain finite spaces, it is difficult to compute discrete logarithms.
Consider the following function: $f(x) = 5^x \bmod{7}$. Can you find a value $x$ such that $5^x = 3 \bmod{7}$?
This does not seem as simple to calculate. The good news is that calculating this function in the forward direction is easy: all we have to do is multiply. So, here is the truth table of the function $f$.
x | f(x) |
---|---|
1 | 5 |
2 | 4 |
3 | 6 |
4 | 2 |
5 | 3 |
6 | 1 |
Now can you solve the question from above? (It took a lot of work to do so!)
It turns out the act of exponentiation modulo a prime number is:
Computationally difficult to invert... at least if we choose a prime modulus that is large enough.
(There is one additional caveat: we must take only the subgroup of quadratic residues, i.e., the even half of the truth table.)
[Image source: Wikipedia]
Here is another, admittedly strange way to perform multiplication and exponentiation.
[Image source: Wikipedia]
This is a very strange operation! Don't worry too much about the math details here. The most important thing to remember here is that it also leads to a hard math problem, where exponentiating is easy but the inverse is practically impossible.
Elliptic curve discrete logarithm assumption: Given two points $P$ and $Q$ such that $P^x = Q$, it is computationally infeasible for anyone to find the discrete logarithm $x$.
(Note: all of the exponentiations and logarithms in today's lecture are done modulo a prime number, but I'm going to stop writing that explicitly from now onward.)
In fact, this problem is really hard to solve, even harder than factoring (as far as we know). So, we can get away with smaller keys.
We have a new tool in our crypto toolbox. What can we do with this?
Here's one option: we can use the hardness of discrete logarithms as the basis for another type of public key cryptography.
Taking a slight detour from cryptocurrencies, let's go back to a question I raised in the first lecture. Suppose you want to send data back and forth to a public website, like kaggle.com, in such a way that nobody else can read or tamper with its contents.
We already know that digital signatures can provide evidence of tampering. But what about message confidentiality?
To solve this problem, you need symmetric key encryption. This is the digital equivalent to a combination safe -- it allows for two computers to exchange messages confidentially, as long as they have a shared secret that the two of them know but nobody else in the world does.
It is the basis for end-to-end encrypted secure messaging systems like Signal and WhatsApp.
In order to encrypt data, your computer and the kaggle.com server both need to have a secret key that nobody else in the world does.
You | kaggle.com | |
---|---|---|
$\quad \Longleftrightarrow \quad$ |
But how can they do that? If you could physically meet, then you could exchange secrets. But we want to enable secure communication over the Internet, which is a public network where most pairs of people have never met before.
In the digital world, they need a secure way to exchange secrets in plain view.
“The Internet is just the world passing notes in a classroom.”
– Jon Stewart
Amazingly, this can be done!
Based on the hardness of the discrete logarithm problem, here is an approach that you and the kaggle.com server can take.
Now, there is a shared secret that both of you can compute: $s = g^{ab}$.
Moreover, nobody else can compute this secret! Other people hear $A$ and $B$. But they don't know -- and cannot compute -- either secret exponent. So as far as we know, they have no way to compute $s$.
(Slight caveat: the last sentence does not actually follow from the one before it. Nevertheless, we do believe that it is a true statement too.)
This ingenious protocol was discovered in the late 1970s by Whitfield Diffie and Martin Hellman, and it is named Diffie-Hellman key exchange in their honor. It was based on concepts developed earlier by Ralph Merkle... the same person who invented Merkle trees.
Here is another application of the math of discrete logarithms: we can build an amazing new kind of proof.
A zero knowledge proof allows a prover to convince a verifier that a particular claim is true, but without revealing the evidence for this claim!
Prover | Verifier | |
---|---|---|
$\longrightarrow$ |
Let's see how this works in the case of discrete logarithms. Suppose that:
How can we do this?
The key idea is that the prover can show only discrete logarithms of values of her own choosing, and not $g^x$ specifically. Here's how the prover and verifier can interact.
The verifier accepts this proof only if $g$ raised to the power of the final message equals the challenge.
We will provide a formal definition of zero knowledge proofs in a future lecture. At a high level:
One downside of this protocol is that the prover can cheat with probability $\frac{1}{2}$.
For instance, even if I have no idea what $x$ is, I can run the first part of the protocol honestly and I will be able to respond to a challenge to produce $k$.
To fix this problem, the prover and verifier can repeat the protocol many times until the verifier is convinced that the prover isn't cheating.
A faster approach is to introduce more challenges that the verifier can ask.
As before, the verifier accepts this proof only if $g$ raised to the power of the final message equals the challenge.
Returning back to our goal: how can we form a digital signature algorithm based on the fact that discrete logarithms are hard?
Remember that a signature scheme needs a secret key and public key, such that it is easy to go from the secret to the public key, but hard to go in the other direction.
Based on the zero knowledge proof, here's an idea for KeyGen.
This satisfies our criteria.
There are a few digital signature schemes that can be designed using keys of this form.
One of them is a NIST standard called the digital signature algorithm, or DSA. If you use an elliptic curve group to build it, then we refer to the construction as ECDSA. (Note: this is the construction we used in Homework 1.)
Another scheme, which is slightly simpler, is called Schnorr signatures.
I reproduce the construction of Schnorr signatures below; it is adapted from the presentation on Wikipedia. Don't worry too much on the math details; the main ideas are the same as the zero knowledge proof we constructed earlier.
To sign a message $M$:
The signature is the pair $\sigma = (s, e)$.
To verify the claimed signature $\sigma = (s, e)$ of a message $M$:
If $e^* = e$, then return true
(i.e., that the signature is valid). Otherwise return false
.
An observation: this signature scheme is randomized. If you request to sign the same message twice, you will likely get two different signatures back in response.
Nevertheless, all possible signatures will correctly be accepted by $\operatorname{Verify}$.
Why does this construction work?
Correctness: if all parties are honest, it is a straightforward math calculation to check that the $\operatorname{Sign}$ algorithm produces a signature that passes the $\operatorname{Verify}$ algorithm. Try writing it out to convince yourself of this fact!
Unforgeability: the Schnorr signature algorithm has cleverly interwoven two hard problems here -- the difficulty of solving discrete logarithms and the random oracle property of the cryptographic hash function $H$.
I will only give some intuition about the argument here. Put yourself in the shoes of Mallory. How would you break this construction?
Remember that we started down this path in order to produce smaller signatures. How well did we do?
By comparison: ECDSA signatures are 72 bytes long, and RSA signatures are several hundred bytes in size.