Return to Video

Exhaustive search attacks (20 min)

  • 0:00 - 0:04
    Now that we understand how DES works, let's look at a few attacks on DES,
  • 0:04 - 0:07
    and we're going to start with an attack called exhaustive search.
  • 0:07 - 0:13
    So our goal here is basically that given a few input-output pairs, (mi, ci),
  • 0:13 - 0:17
    our goal is to find the key that maps these m's to the c's.
  • 0:17 - 0:25
    In other words, our goal is to find the key that maps m1, m2, m3 into c1, c2, c3,
  • 0:25 - 0:28
    and as I said, our goal is to find the key that does this mapping.
  • 0:28 - 0:31
    The first question is, how do we know that this key is unique?
  • 0:31 - 0:34
    And so, let's do a little bit of analysis to show that in fact
  • 0:34 - 0:38
    just one pair is enough to completely constrain a DES key,
  • 0:38 - 0:41
    and that's why this question makes sense.
  • 0:41 - 0:43
    OK, so let's see. So we're going to prove this simple lemma.
  • 0:43 - 0:47
    Now let's assume that DES is what's called an ideal cipher.
  • 0:47 - 0:52
    So what is an ideal cipher? Basically we're going to pretend like DES is made up of
  • 0:52 - 0:59
    random invertible functions. In other words, for every key, DES implements a random invertible function.
  • 0:59 - 1:05
    Since there are 2^56 keys in DES, we're going to pretend like DES really is a collection
  • 1:05 - 1:15
    of 2^56 functions that are invertible from {0,1}^64 to {0,1}^64. OK? So of course,
  • 1:15 - 1:22
    DES is not a collection of 2^56 random functions, but we can idealize about the cipher and pretend
  • 1:22 - 1:25
    that it is such a collection. Then what can we say?
  • 1:25 - 1:31
    Then in fact it turns out that just given one message and ciphertext, you just give me
  • 1:31 - 1:39
    one pair, message and ciphertext, there's already only one key that maps this message to that ciphertext.
  • 1:39 - 1:46
    So already just given one pair m and c, I can ask you, find me the key that maps m to c,
  • 1:46 - 1:53
    and the solution is very likely to be unique. In fact it's going to be unique with probability roughly 99.5%.
  • 1:53 - 1:58
    I should say that this statement is true for all m and c, and the probability is just over the choice
  • 1:58 - 2:02
    of the random permutations that make up the cipher.
  • 2:02 - 2:06
    So let's write a proof. This is fairly straightforward. So what we're basically asking is,
  • 2:06 - 2:11
    what's the probability that there exists some key that's not equal to k such that,
  • 2:11 - 2:19
    well, c we know is equal to DES(k, m) by defintion of c and m, but we're asking how likely is it
  • 2:19 - 2:24
    that there's this other key, k-prime, that also satisfies this equality?
  • 2:24 - 2:30
    You realize that if this is true, if such a key k-prime exists, then just given m and c,
  • 2:30 - 2:35
    you can't decide whether the right key is k or k-prime, because both of them work. OK?
  • 2:35 - 2:38
    But I want to argue that this happens with low probability.
  • 2:38 - 2:42
    Well, so what does it mean that there exists a key k-prime that satisfies this relation?
  • 2:42 - 2:48
    Well, we're asking, what's the probability that the first key, the all-zero key, satisfies it?
  • 2:48 - 2:52
    Or, the second key satisfies it. Or, the third key satisfies it. And so on and so forth.
  • 2:52 - 2:59
    So by the union bound, we can bound this probability by the sum over all keys k-prime,
  • 2:59 - 3:10
    over all 56-bit keys, of the probability that DES(k,m) is equal to DES(k-prime, m).
  • 3:10 - 3:16
    OK? So we're asking, basically, what is this probability, for a fixed key k-prime,
  • 3:16 - 3:21
    that it happens to collide with the key k at the message m? Well, let's think about this for a second.
  • 3:21 - 3:25
    Let's fix this value, let's suppose it's some fixed value. And then we're asking,
  • 3:25 - 3:31
    how likely is it that a random permutation, pi k-prime, at the point m,
  • 3:31 - 3:37
    happens to produce exactly the same output as the key k at the point m?
  • 3:37 - 3:43
    Well, it's not difficult to answer and see that in fact this is, for a single key k-prime,
  • 3:43 - 3:50
    the probability is at most one over 2^64. Right? There are 2^64 possible outputs for the permutation,
  • 3:50 - 3:56
    what's the probability that it lands exactly on this output, well, it's one over 2^64.
  • 3:56 - 4:01
    And we're summing over all 2^56 keys, so we just multiply the two,
  • 4:01 - 4:07
    we get one over 2^8, which is basically one over 256. OK? So the probability
  • 4:07 - 4:12
    that the key is not unique is one over 256, therefore the probability that it is unique
  • 4:12 - 4:19
    is one minus that, which is 99.5%. OK? So already, if you give me one plaintext-ciphertext pair,
  • 4:19 - 4:23
    the key is completely determined. There's only one key that will map that plaintext
  • 4:23 - 4:27
    to that ciphertext, and the question is just, can you find that key?
  • 4:27 - 4:33
    Now it turns out in fact if you give me two pairs, so you give me m1 and m2,
  • 4:33 - 4:38
    and their corresponding outputs, c1 and c2, the probability basically
  • 4:38 - 4:42
    —just do exactly the same analysis, the probability basically becomes one.
  • 4:42 - 4:47
    That there's only one such key. OK, essentially, this is very, very, very close to 1,
  • 4:47 - 4:51
    and basically it says given two pairs, it's very very likely that only one key
  • 4:51 - 4:56
    will map this pair of messages to this pair of ciphertexts, and as a result again,
  • 4:56 - 5:01
    we can ask, well, find me that unique key. And by the way, the same is true for AES,
  • 5:01 - 5:05
    if you look at AES-128, again, just given two input-output pairs,
  • 5:05 - 5:10
    there's going to be only one key with very high probability. So essentially now
  • 5:10 - 5:15
    we can ask this exhaustive search problem, I give you two or three pairs, and I ask you,
  • 5:15 - 5:19
    well, find me the key. So how are you going to do it? Well, you're going to do it by exhaustive search,
  • 5:19 - 5:25
    essentially by trying all possible keys, one by one, until you find the right one.
  • 5:25 - 5:30
    So this is what's known as the DES challenge. So let me explain how the DES challenge worked.
  • 5:30 - 5:34
    The challenge was issued by a company called RSA, and what they did is basically,
  • 5:34 - 5:40
    they published a number of ciphertexts, but three of the ciphertexts had known plaintexts.
  • 5:40 - 5:46
    So in particular, what they did is they took the message here: The unknown message is, colon,
  • 5:46 - 5:51
    and you can see they broke it up into blocks. If you look at these, these are basically
  • 5:51 - 5:57
    eight-byte blocks. Eight bytes, as you know, is 64 bits, right, so each of these is 64 bits.
  • 5:57 - 6:02
    And then they encrypted them using a secret key. They encrypted them all using the same
  • 6:02 - 6:08
    secret key to get three ciphertexts. So this gives us three plaintext-ciphertext pairs,
  • 6:08 - 6:12
    and then they gave us a whole bunch of other ciphertexts, you know, c4, c5, c6,
  • 6:12 - 6:16
    and the challenge was, decrypt these guys using the key that you found
  • 6:16 - 6:21
    from an exhaustive search over the first three pairs that you were given.
  • 6:21 - 6:26
    OK. So that was called the DES challenge, and let me tell you a little bit
  • 6:26 - 6:31
    about how long it took to solve it. So interestingly, in 1997, using an Internet search,
  • 6:31 - 6:37
    using distributed.net, basically, they were able to search through enough of the keyspace
  • 6:37 - 6:43
    to find the correct key in about three months. You realize the keyspace has size 2^56,
  • 6:43 - 6:47
    but on average you only have to search through half the keyspace to find the key,
  • 6:47 - 6:52
    and so it took them three months. Then, kind of a miraculous thing happened.
  • 6:52 - 6:58
    The EFF actually contracted Paul Kocher to build special-purpose hardware to break DES.
  • 6:58 - 7:03
    This was a machine called Deep Crack. It cost about 250,000 dollars, and it broke
  • 7:03 - 7:10
    the next DES challenge in only three days. Interestingly, by the way, RSA said that
  • 7:10 - 7:14
    they would pay ten thousand dollars for each solution of a challenge, so you can see
  • 7:14 - 7:18
    that this is not quite economical. They spent 250K, they got ten thousand dollars
  • 7:18 - 7:22
    for solving the challenge. The next thing that happened is in 1999,
  • 7:22 - 7:27
    RSA issued another challenge, and they said, well, I'm gonna solve it in half the time
  • 7:27 - 7:33
    of the previous solution, and so using both Deep Crack and the Internet search together,
  • 7:33 - 7:36
    they were able to break DES in 22 hours.
  • 7:36 - 7:40
    So the bottom line here is, essentially, DES is completely dead.
  • 7:40 - 7:45
    Essentially, if you forget, or you lose your DES 56-bit key, don't worry—
  • 7:45 - 7:51
    within 22 hours, you can actually recover it and in fact, anyone can recover it, and so
  • 7:51 - 7:56
    DES essentially is dead and no longer secure. And just kind of a final nail in the coffin,
  • 7:56 - 8:04
    as hardware technology improved, there was another project called COPACABANA that used FPGAs,
  • 8:04 - 8:11
    just off-the-shelf FPGAs, only 120 FPGAs. It only cost 10,000 dollars. And they were able to break,
  • 8:11 - 8:17
    to do an exhaustive key search in about seven days. So very, very cheap hardware, just off the shelf,
  • 8:17 - 8:21
    you can break DES already very quickly. So the lesson from all this is essentially,
  • 8:21 - 8:26
    56-bit ciphers are totally, totally dead. And so the question is what to do.
  • 8:26 - 8:31
    People really liked DES, it was deployed in a lot of places, there were a lot of implementations,
  • 8:31 - 8:34
    there was a lot of hardware support for it, so the question was what to do.
  • 8:34 - 8:38
    And so the first thing that came to mind is, well maybe we can take DES
  • 8:38 - 8:43
    and we can kind of artificially expand the key size, so we strengthen it against
  • 8:43 - 8:47
    this exhaustive search attack. And the first idea that comes to mind is basically,
  • 8:47 - 8:52
    well, let's iterate the block cipher a couple of times. And this is what's called Triple DES.
  • 8:52 - 8:56
    So Triple DES is a general construction. Basically it says the following.
  • 8:56 - 9:00
    Suppose you gave me a block cipher E. So here, it has a keyspace K,
  • 9:00 - 9:04
    it has a message space M, and an output space of course M as well.
  • 9:04 - 9:10
    Let's define the triple construction, which now uses three keys, and it's defined as follows,
  • 9:10 - 9:16
    basically, here, the triple construction uses three independent keys, encrypts the same
  • 9:16 - 9:21
    message block as before, and what it does is, it will encrpyt using the key k3,
  • 9:21 - 9:29
    then it will decrypt using the key k2, then it will encrypt again using the key k1.
  • 9:29 - 9:34
    OK so basically encrpyting three times, using three independent keys.
  • 9:34 - 9:40
    You might be wondering, why is it doing E, D, E, why not just do E, E, E?
  • 9:40 - 9:44
    Why do we have to have a D in the middle? Well, that's just for, uh, kind of a hack.
  • 9:44 - 9:50
    You notice what happens if you set up k1 equals k2 equals k3? What happens if all three keys
  • 9:50 - 9:57
    are the same? Well, basically, what will happen is, one E and one D would cancel,
  • 9:57 - 10:02
    and you would just get normal DES out. So it's just a hack so that if you have a hardware implementation
  • 10:02 - 10:08
    of Triple DES, you can set all three keys to be the same, and you'll get a hardware implementation
  • 10:08 - 10:12
    of single DES. Of course it'll be three times as slow as a regular impelmentation of single DES,
  • 10:12 - 10:17
    but nevertheless, it's still an option. OK, so for Triple DES now we get a key size
  • 10:17 - 10:25
    that's 3 times 56, which is 168 bits; this is, 168 bits is way too long to do an exhaustive search on.
  • 10:25 - 10:31
    That will take time 2^168, which is more than all the machines on earth working for ten years
  • 10:31 - 10:37
    would be able to do. Unfortunately, of course, the cipher is three times slower than DES.
  • 10:37 - 10:41
    So this is a real problem with Triple DES. Now I want to mention that in fact you might think
  • 10:41 - 10:49
    Triple DES has security 2^168, but in fact, there is a simple attack that runs in time 2^118,
  • 10:49 - 10:56
    and I want to show you how that attack works. OK? So— but in fact 2^118 is still a large number.
  • 10:56 - 11:03
    In fact, anything that's, kind of, bigger than 2^90 is considered sufficiently secure.
  • 11:03 - 11:07
    2^118 is definitely sufficiently secure against exhaustive search,
  • 11:07 - 11:10
    and generally is considered a high enough level of security.
  • 11:10 - 11:14
    So clearly Triple DES is three times as slow as DES. So the question is,
  • 11:14 - 11:18
    why did they repeat the cipher three times? Why not repeat the cipher just two times,
  • 11:18 - 11:21
    or in particular, the question is, what's wrong with double DES?
  • 11:21 - 11:26
    So here we have double DES. Basically you see it uses only two keys, and it uses only
  • 11:26 - 11:31
    two applications of the block cipher, and as a result it's only going to be twice as slow as DES,
  • 11:31 - 11:36
    not three times as slow as DES. Well, the key length for double DES is 2 times 56, which is
  • 11:36 - 11:43
    112 bits, and in fact doing exhaustive search on a space of 112 bits is too much.
  • 11:43 - 11:47
    2^112 is too big of a number to do exhaustive search over such a large space.
  • 11:47 - 11:51
    So the question is, what's wrong with this construction. Well, it turns out
  • 11:51 - 11:55
    this construction is completely insecure, and I want to show you an attack.
  • 11:55 - 12:01
    So, suppose I'm given a bunch of inputs, say m1 to m10, and I'm given the corresponding outputs
  • 12:01 - 12:09
    c1 to c10. What's my goal? Well, my goal is basically to find keys, you know, a pair of keys k1, k2,
  • 12:09 - 12:18
    such that if I encrypt the message M using these keys, in other words if I do this encryption,
  • 12:18 - 12:23
    this double DES encryption, then I get the ciphertext vector that was given to me.
  • 12:23 - 12:28
    OK, so our goal is to solve this equation here. Now you stare at this equation a little bit,
  • 12:28 - 12:32
    and you realize, hey wait a minute, I can rewrite it in kind of an interesting way;
  • 12:32 - 12:36
    I can apply the decryption algorithm, and then what I'll get is that I'm really looking for
  • 12:36 - 12:44
    keys k1, k2 that satisfy this equation here, where basically all I did is I applied
  • 12:44 - 12:51
    the decryption algorithm using k1 to both sides. OK, now whenever you see an equation like this,
  • 12:51 - 12:56
    what just happened here is that we separated our variables into two sides,
  • 12:56 - 13:00
    the variables now appear on independent sides of the equation, and that usually means
  • 13:00 - 13:05
    that there is a faster attack than exhaustive search, and in fact this attack is called
  • 13:05 - 13:09
    a meet-in-the-middle attack, where really the meet-in-the-middle is going to somehow
  • 13:09 - 13:14
    attack this particular point in the construction. OK, so we're going to try and find a key
  • 13:14 - 13:19
    that maps m to a particular value here, and maps c to the same value.
  • 13:19 - 13:23
    OK, so let me show you how the attack works. So the first thing we're going to do is
  • 13:23 - 13:26
    we're going to build a table. Here, let me clear up some space here.
  • 13:26 - 13:31
    The first step is to build a table that for all possible values of k2,
  • 13:31 - 13:36
    encrypts m under that value. OK, so here we have this table, so you notice
  • 13:36 - 13:46
    these are all 2^56 Single DES keys, OK, so the table has 2^56 entries,
  • 13:46 - 13:51
    and what we do is basically, for each entry, we compute the encryption of m
  • 13:51 - 13:55
    under the appropriate key. So this is the encryption of m under the all-zero key,
  • 13:55 - 13:59
    the encryption of m under the one key, and at the bottom, we have the encryption of m
  • 13:59 - 14:05
    under the all-one key. OK, so there are 2^56 entries, and we sort this table based on the second column.
  • 14:05 - 14:10
    OK, so far, so good. So by the way this takes time—to build this table takes time 2^56,
  • 14:10 - 14:18
    and I guess we also want to sort, sorting takes n log n time, so it's 2^56 times log 2^56. OK.
  • 14:18 - 14:22
    So now that we have this table, we've essentially built all possible values
  • 14:22 - 14:25
    in the forward direction for this point.
  • 14:25 - 14:29
    Now what we're going to do is this meet-in-the-middle attack,
  • 14:29 - 14:33
    where now we try to go in the reverse direction with all possible keys k.
  • 14:33 - 14:38
    Essentially we compute the decryption of c under all possible keys k1.
  • 14:38 - 14:43
    OK, so now for each potential decryption, remember the table holds all possible values
  • 14:43 - 14:50
    in the midpoint, so then for each possible decrpytion, we check, hey, is the decryption in the table,
  • 14:50 - 14:53
    in the second column in the table? If it is in the table, then aha, we found the match,
  • 14:53 - 14:58
    and then what do we know? We know that essentially, well, we found the match, so we know that
  • 14:58 - 15:05
    say for example a decryption using a particular key k1 happened to match this entry in the table,
  • 15:05 - 15:11
    say, k2 or more generally ki, then we know that the encryption of m under ki
  • 15:11 - 15:18
    is equal to the decryption of c under k. OK, so we kind of build this meet-in-the-middle,
  • 15:18 - 15:26
    where the two sides, you know, the encryption of m under ki and the decryption of c under k,
  • 15:26 - 15:32
    collided, but if they collided, then we know that in fact this pair, ki and k, is equal to
  • 15:32 - 15:36
    the pair that we're looking for. And so we've just solved our challenge.
  • 15:36 - 15:41
    So now let's look at what's the running time of this? Well, we had to build a table,
  • 15:41 - 15:48
    and sort it, and then for all possible decryptions, we had to do a search through the table.
  • 15:48 - 15:54
    So there were 2^56 possible decryptions, each search in a sorted table takes log(2^56) time,
  • 15:54 - 15:59
    if you just work it out this turns out to be 2^63, which is way, way, way, way, way smaller
  • 15:59 - 16:07
    than 2^112. OK, so this is a serious attack, it's probably doable today, that runs in a total time
  • 16:07 - 16:12
    of 2^63, which is about the same time as the exhaustive search attack on DES.
  • 16:12 - 16:16
    So really, double DES really didn't solve the exhaustive search problem,
  • 16:16 - 16:20
    because, well, there's an attack on it that runs in about the same time
  • 16:20 - 16:23
    as exhaustive search on single DES. Now someone might complain
  • 16:23 - 16:27
    that in fact this algorithm, well, we have to store this big table,
  • 16:27 - 16:31
    so it takes up a lot of space, but you know, so be it. Nevertheless, the running time
  • 16:31 - 16:35
    is still quite small or significantly smaller than 2^112.
  • 16:35 - 16:39
    Now you notice, by the way, this same attack applies to Triple DES.
  • 16:39 - 16:42
    What you would do is you would implement the meet-in-the-middle attack against this point,
  • 16:42 - 16:48
    you would build a table of size 2^56 of all possible encryptions of m,
  • 16:48 - 16:53
    and then you would try to decrypt with all 2^112 keys until you find a collision,
  • 16:53 - 16:57
    and when you find a collision, you have basically found k1, k2, k3.
  • 16:57 - 17:03
    OK, so even Triple DES has an attack that basically explores only 2^112 possible keys.
  • 17:03 - 17:08
    But 2^112 is a large enough number, so Triple DES in fact, as far as we know,
  • 17:08 - 17:14
    is sufficiently secure. I should mention that Triple DES is actually a NIST standard,
  • 17:14 - 17:20
    and so Triple DES is actually used quite a bit, and in fact DES should never ever ever be used,
  • 17:20 - 17:25
    if for some reason you're forced to use some version of DES, use Triple DES, not DES.
  • 17:25 - 17:29
    OK, I want to mention one more method for strengthening DES against exhaustive search attacks.
  • 17:29 - 17:33
    This method actually is not standardized by NIST, because it doesn't defend against
  • 17:33 - 17:38
    more subtle attacks on DES, but nevertheless if all you're worried about is exhaustive search,
  • 17:38 - 17:43
    and you don't want to pay the performance penalties of Triple DES, then this is an interesting idea.
  • 17:43 - 17:48
    So let me show you how it works. So let E be a block cipher that operates on n-bit blocks.
  • 17:48 - 17:53
    We're going to define the EX construction, and for DES we're going to get DESX, to be the following.
  • 17:53 - 18:00
    So we use three keys, k1, k2, k3, and then basically before encrpytion, we XOR with k3,
  • 18:00 - 18:05
    then we encrypt using k2, and then after encryption we XOR with k1. That's it.
  • 18:05 - 18:09
    That's the whole construction. So basically, you'll notice it doesn't slow the block cipher much,
  • 18:09 - 18:14
    because all we did is we applied the cipher plus two additional XORs, which are super fast.
  • 18:14 - 18:20
    The key length for this is in fact, well, we got two keys that are as long as the block size,
  • 18:20 - 18:25
    and we got one key that's as long as the key size, so the total is 184 bits.
  • 18:25 - 18:31
    Now, it turns out actually the best attack that's known is actually an attack that takes time 2^120,
  • 18:31 - 18:37
    and this is actually fairly simple. So it's a generic attack on EX, it will always take time basically
  • 18:37 - 18:41
    block size plus the key size, and it's a simple homework problem
  • 18:41 - 18:44
    for you to try to figure out this attack. I think this is a good exercise.
  • 18:44 - 18:49
    OK, in fact there is some analysis to show that there is no exhaustive search attack
  • 18:49 - 18:53
    on this type of construction, so it's a fine construction against exhaustive search,
  • 18:53 - 18:57
    but there are more subtle attacks on DES that we'll talk about in the next segment,
  • 18:57 - 19:00
    that basically this construction will not prevent.
  • 19:00 - 19:06
    One thing that I want to point out, unfortunately I found this mistake in a number of products,
  • 19:06 - 19:12
    is if you just decide to XOR on the outside, or if you just decide to XOR on the inside,
  • 19:12 - 19:14
    as opposed to XOR-ing on both sides, which is what DESX does,
  • 19:14 - 19:18
    you notice DESX XORs both on the outside and on the inside,
  • 19:18 - 19:22
    If you just do one of them, then basically this construction does nothing
  • 19:22 - 19:27
    to secure your cipher. It'll still be as vulnerable to exhaustive search
  • 19:27 - 19:31
    as the original block cipher E. OK, so this is another homework problem,
  • 19:31 - 19:34
    and actually you'll see that as part of our homeworks. OK.
  • 19:34 - 19:38
    So this basically concludes our discussion of exhaustive search attacks,
  • 19:38 - 19:41
    and next we'll talk about more sophisticated attacks on DES.
Title:
Exhaustive search attacks (20 min)
Video Language:
English

English subtitles

Revisions