# Meet-in-the-middle attack

The Meet-in-the-Middle attack (MITM) is a generic space–time tradeoff cryptographic attack against encryption schemes which rely on performing multiple encryption operations in sequence. The MITM attack is the primary reason why Double DES is not used and why a Triple DES key (168-bit) can be bruteforced by an attacker with 256 space and 2112 operations.

## Description

When trying to improve the security of a block cipher, a tempting idea is to encrypt the data several times using multiple keys. One might think this doubles or even n-tuples the security of the multiple-encryption scheme, depending on the number of times the data is encrypted, because an exhaustive search on all possible combination of keys (simple brute-force) would take 2n·k attempts if the data is encrypted with k-bit keys n times.

The Meet-in-the-Middle is a generic attack which weakens the security benefits of using multiple encryptions by storing intermediate values from the encryptions or decryptions and using those to improve the time required to brute force the decryption keys. This makes a Meet-in-the-Middle attack (MITM) a generic space–time tradeoff cryptographic attack.

The Meet-in-the-Middle attack attempts to find the keys by using both of the range (ciphertext) and domain (plaintext) of the composition of several functions (or block ciphers) such that the forward mapping through the first functions is the same as the backward mapping (inverse image) through the last functions, quite literally meeting in the middle of the composed function. For example, although Double DES encrypts the data with two different 56-bit keys, Double DES can be broken with 257 encryption and decryption operations.

The Multidimensional MITM (MD-MITM) uses a combination of several simultaneous MITM-attacks like described above, where the meeting happens in multiple positions in the composed function.

## History

Diffie and Hellman first proposed the Meet-in-the-middle attack on a hypothetical expansion of a block cipher in 1977.[1] Their attack used a space-time tradeoff to break the double-encryption scheme in only twice the time needed to break the single-encryption scheme.

In 2011, Bo Zhu and Guang Gong investigated the Multidimensional Meet-in-the-Middle attack and presented new attacks on the block ciphers GOST, KTANTAN and Hummingbird-2.[2]

## Meet-in-the-middle (1D-MITM)

Assume someone wants to attack an encryption scheme with the following characteristics for a given plaintext P and ciphertext C:

{\displaystyle {\begin{aligned}C&=ENC_{k_{2}}(ENC_{k_{1}}(P))\\P&=DEC_{k_{1}}(DEC_{k_{2}}(C))\\\end{aligned}}}

where ENC is the encryption function, DEC the decryption function defined as ENC−1 (inverse mapping) and k1 and k2 are two keys.

The naive approach at brute-forcing this encryption scheme is to decrypt the ciphertext with every possible k1, and decrypt each of those outputs with every possible k2, for a total of 2k1 * 2k2 operations.

The meet-in-the-middle attack uses a more efficient approach. By decrypting C with k2, one obtains the following equivalence:

{\displaystyle {\begin{aligned}C&=ENC_{k_{2}}(ENC_{k_{1}}(P))\\DEC_{k_{2}}(C)&=DEC_{k_{2}}(ENC_{k_{2}}[ENC_{k_{1}}(P)])\\DEC_{k_{2}}(C)&=ENC_{k_{1}}(P)\\\end{aligned}}}

The attacker can compute ENCk1(P) for all values of k1 and DECk2(C) for all possible values of k2, for a total of 2k1 + 2k2 operations. If the result from any of the ENCk1(P) operations matches a result from the DECk2(C) operations, the pair of k1 and k2 is possibly the correct key. This potentially-correct key is called a candidate key. The attacker can determine which candidate key is correct by testing it with a second test-set of plaintext and ciphertext.

The MITM attack is one of the reasons why DES was replaced with Triple DES and not Double DES. Double DES was not used because it is vulnerable to a MITM attack and an attacker can bruteforce the keyspace with 257 operations and 256 space. [3] Triple DES uses a "triple length" (168-bit) key and is also vulnerable to a meet-in-the-middle attack in 256 space and 2112 operations, but is considered secure due to the size of its keyspace.[4]

An illustration of 1D-MITM attack

### MITM algorithm

Compute the following:

• ${\displaystyle SubCipher_{1}=ENC_{f_{1}}(k_{f_{1}},P),\;\forall k_{f_{1}}\in K}$:
and save each ${\displaystyle SubCipher_{1}}$ together with corresponding ${\displaystyle k_{f_{1}}}$ in a set A
• ${\displaystyle SubCipher_{1}=DEC_{b_{1}}(k_{b_{1}},C),\;\forall k_{b_{1}}\in K}$:
and compare each new ${\displaystyle SubCipher_{1}}$ with the set A

When a match is found, keep kf1,kb1 as candidate key-pair in a table T. Test pairs in T on a new pair of (P,C) to confirm validity. If the key-pair does not work on this new pair, do MITM again on a new pair of (P,C).

### MITM complexity

If the keysize is k, this attack uses only 2k+1encryptions (and decryptions) (and O(2k) memory in case a look-up table have been built for the set of forward computations) in contrast to the naive attack, which needs 2k encryptions but O(1) space.

## Multidimensional-MITM

While 1D-MITM can be efficient, a more sophisticated attack has been developed: Multi Dimensional-Meet In The Middle attack, also abbreviated MD-MITM. This is preferred when the data has been encrypted using more than 2 encryptions with different keys. Instead of meeting in the middle (one place in the sequence), the MD-MITM attack attempts to reach several specific intermediate states using the forward and backward computations at several positions in the cipher.[2]

Assume that the attack has to be mounted on a block cipher, where the encryption and decryption is defined as before:

${\displaystyle C=ENC_{k_{n}}(ENC_{k_{n-1}}(...(ENC_{k_{1}}(P))...))}$
${\displaystyle P=DEC_{k_{1}}(DEC_{k_{2}}(...(DEC_{k_{n}}(C))...))}$

that is a plaintext P is encrypted multiple times using a repetition of the same block cipher

An illustration of MD-MITM attack

The MD-MITM has been used for cryptanalysis of among many, the GOST block cipher, where it has been shown that a 3D-MITM has significantly reduced the time complexity for an attack on it.[2]

### MD-MITM algorithm

Compute the following:

${\displaystyle SubCipher_{1}=ENC_{f_{1}}(k_{f_{1}},P)\qquad \forall k_{f_{1}}\in K}$
and save each ${\displaystyle SubCipher_{1}}$ together with corresponding ${\displaystyle k_{f_{1}}}$ in a set ${\displaystyle H_{1}}$.
${\displaystyle SubCipher_{n+1}=DEC_{b_{n+1}}(k_{b_{n+1}},C)\qquad \forall k_{b_{n+1}}\in K}$
and save each ${\displaystyle SubCipher_{n+1}}$ together with corresponding ${\displaystyle k_{b_{n+1}}}$ in a set ${\displaystyle H_{n+1}}$.

For each possible guess on the intermediate state ${\displaystyle s_{1}}$ compute the following:

${\displaystyle SubCipher_{1}=DEC_{b_{1}}(k_{b_{1}},s_{1})\qquad \forall k_{b_{1}}\in K}$
and for each match between this ${\displaystyle SubCipher_{1}}$ and the set ${\displaystyle H_{1}}$, save ${\displaystyle k_{b_{1}}}$ and ${\displaystyle k_{f_{1}}}$ in a new set ${\displaystyle T_{1}}$.
${\displaystyle SubCipher_{2}=ENC_{f_{2}}(k_{f_{2}},s_{1})\qquad \forall k_{f_{2}}\in K}$[verification needed]
and save each ${\displaystyle SubCipher_{2}}$ together with corresponding ${\displaystyle k_{f_{2}}}$ in a set ${\displaystyle H_{2}}$.
For each possible guess on an intermediate state ${\displaystyle s_{2}}$ compute the following:
• ${\displaystyle SubCipher_{2}=DEC_{b_{2}}(k_{b_{2}},s_{2})\qquad \forall k_{b_{2}}\in K}$
and for each match between this ${\displaystyle SubCipher_{2}}$ and the set ${\displaystyle H_{2}}$, check also whether
it matches with ${\displaystyle T_{1}}$ and then save the combination of sub-keys together in a new set ${\displaystyle T_{2}}$.
• For each possible guess on an intermediate state ${\displaystyle s_{n}}$ compute the following:
1. ${\displaystyle SubCipher_{n}=DEC_{b_{n}}(k_{b_{n}},s_{n})\qquad \forall k_{b_{n}}\in K}$ and for each match between this ${\displaystyle SubCipher_{n}}$ and the set ${\displaystyle H_{n}}$, check also whether it matches with ${\displaystyle T_{n-1}}$, save ${\displaystyle k_{b_{n}}}$ and ${\displaystyle k_{f_{n}}}$ in a new set ${\displaystyle T_{n}}$.
2. ${\displaystyle SubCipher_{n+1}=ENC_{f_{n}+1}(k_{f_{n}+1},s_{n})\qquad \forall k_{f_{n+1}}\in K}$ and for each match between this ${\displaystyle SubCipher_{n+1}}$ and the set ${\displaystyle H_{n+1}}$, check also

whether it matches with ${\displaystyle T_{n}}$. If this is the case then:"

Use the found combination of sub-keys ${\displaystyle (k_{f_{1}},k_{b_{1}},k_{f_{2}},k_{b_{2}},...,k_{f_{n+1}},k_{b_{n+1}})}$ on another pair of plaintext/ciphertext to verify the correctness of the key.

Note the nested element in the algorithm. The guess on every possible value on sj is done for each guess on the previous sj-1. This make up an element of exponential complexity to overall time complexity of this MD-MITM attack.

### MD-MITM complexity

Time complexity of this attack without brute force, is ${\displaystyle 2^{|k_{f_{1}}|}+2^{|k_{b_{n+1}}|}+2^{|s_{1}|}}$${\displaystyle (2^{|k_{b_{1}}|}+2^{|k_{f_{2}}|}+2^{|s_{2}|}}$${\displaystyle (2^{|k_{b_{2}}|}+2^{|k_{f_{3}}|}+\cdots ))}$

Regarding the memory complexity, it is easy to see that ${\displaystyle T_{2},T_{3},...,T_{n}}$ are much smaller than the first built table of candidate values: ${\displaystyle T_{1}}$ as i increases, the candidate values contained in ${\displaystyle T_{i}}$ must satisfy more conditions thereby fewer candidates will pass on to the end destination ${\displaystyle T_{n}}$.

An upper bound of the memory complexity of MD-MITM is then

${\displaystyle 2^{|k_{f_{1}}|}+2^{|k_{b_{n+1}}|}+2^{|k|-|s_{n}|}\cdots }$

where k denotes the length of the whole key (combined).

The data complexity depends on the probability that a wrong key may pass (obtain a false positive), which is ${\displaystyle 1/2^{|l|}}$, where l is the intermediate state in the first MITM phase. The size of the intermediate state and the block size is often the same! Considering also how many keys that are left for testing after the first MITM-phase, it is ${\displaystyle 2^{|k|}/2^{|l|}}$.

Therefore, after the first MITM phase, there are ${\displaystyle 2^{|k|-b}}$${\displaystyle 2^{-b}=2^{|k|-2b}}$, where ${\displaystyle |b|}$ is the block size.

For each time the final candidate value of the keys are tested on a new plaintext/ciphertext-pair, the amount of keys that will pass will be multiplied by the probability that a key may pass which is ${\displaystyle 1/2^{|b|}}$.

The part of brute force testing (testing the candidate key on new ${\displaystyle (P,C)}$-pairs, have time complexity ${\displaystyle 2^{|k|-b}+2^{|k|-2b}+2^{|k|-3b}+2^{|k|-4b}\cdots }$ , clearly for increasing multiples of b in the exponent, number tends to zero.

The conclusion on data complexity is by similar reasoning restricted by that around ${\displaystyle \lceil |k|/n\rceil }$ ${\displaystyle (P,C)}$-pairs.

Below is a specific example of how a 2D-MITM is mounted:

## A general example of 2D-MITM

This is a general description of how 2D-MITM is mounted on a block cipher encryption.

In Two-dimensional MITM (2D-MITM) the method is to reach 2 intermediate states inside the multiple encryption of the plaintext. See below figure:

An illustration of 2D-MITM attack

### 2D-MITM algorithm

Compute the following:

${\displaystyle SubCipher_{1}=ENC_{f_{1}}(k_{f_{1}},P)\qquad \forall k_{f_{1}}\in K}$
and save each ${\displaystyle SubCipher_{1}}$ together with corresponding ${\displaystyle k_{f_{1}}}$ in a set A
${\displaystyle SubCipher_{2}=DEC_{b_{2}}(k_{b_{2}},C)\qquad \forall k_{b_{2}}\in K}$
and save each ${\displaystyle SubCipher_{2}}$ together with corresponding ${\displaystyle k_{b_{2}}}$ in a set B.

For each possible guess on an intermediate state s between ${\displaystyle SubCipher_{1}}$ and ${\displaystyle SubCipher_{2}}$ compute the following:

• ${\displaystyle SubCipher_{1}=DEC_{b_{1}}(k_{b_{1}},s)\qquad \forall k_{b_{1}}\in K}$
and for each match between this ${\displaystyle SubCipher_{1}}$ and the set A, save ${\displaystyle k_{b_{1}}}$ and ${\displaystyle k_{f_{1}}}$ in a new set T.
• ${\displaystyle SubCipher_{2}=ENC_{f_{2}}(k_{f_{2}},s)\qquad \forall k_{f_{2}}\in K}$
and for each match between this ${\displaystyle SubCipher_{2}}$ and the set B, check also whether it matches with T for
if this is the case then:

Use the found combination of sub-keys ${\displaystyle (k_{f_{1}},k_{b_{1}},k_{f_{2}},k_{b_{2}})}$ on another pair of plaintext/ciphertext to verify the correctness of the key.

### 2D-MITM complexity

Time complexity of this attack without brute force, is ${\displaystyle 2^{|k_{f_{1}}|}+2^{|k_{b_{2}}|}+2^{|s|}\cdot \left(2^{|k_{b_{1}}|}+2^{|k_{f_{2}}|}\right)}$ where |⋅| denotes the length.

Main memory consumption is restricted by the construction of the sets A and B where T is much smaller than the others.

For data complexity see subsection on complexity for MD-MITM.