# Meet-in-the-middle attack

Not to be confused with man-in-the-middle attack.

The Meet-in-the-Middle attack (MITM) is a generic space–time tradeoff cryptographic attack.

## Description

MITM is a generic attack, applicable on several cryptographic systems. The internal structure of a specific system is therefore unimportant to this attack.

An attacker requires the ability to encrypt and decrypt, and the possession of pairs of plaintexts and corresponding ciphertexts.

When trying to improve the security of a block cipher, a tempting idea is to simply use several independent keys to encrypt the data several times using a sequence of functions (encryptions). Then one might think that this doubles or even n-tuples the security of the multiple-encryption scheme, depending on the number of encryptions the data must go through.

The Meet-in-the-Middle attack attempts to find a value 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.

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.

An exhaustive search on all possible combination of keys (simple brute-force) would take 2k·j attempts if j encryptions has been used with different keys in each encryption, where each key is k bits long. MITM or MD-MITM improves on this performance.

## History

It was first developed as an attack on an attempted expansion of a block cipher by Diffie and Hellman in 1977.[1]

Diffie and Hellman, however, devised a space-time tradeoff that could break the scheme in only double the time 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]

## MITM (1D-MITM)

Assume the attacker knows a set of plaintext P and ciphertext C that satisfies the following:

$C=ENC_{k_2}(ENC_{k_1}(P))$   $P=DEC_{k_1}(DEC_{k_2}(C))$


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

The attacker can then compute ENCk1(P) for all possible keys k1 and then decrypt the ciphertext by computing DECk2(C) for each k2. Any matches between these two resulting sets are likely to reveal the correct keys. (To speed up the comparison, the ENCk1(P) set can be stored in an in-memory lookup table, then each DECk2(C) can be matched against the values in the lookup table to find the candidate keys)

This attack is one of the reasons why DES was replaced by Triple DES — "Double DES" does not provide much additional security against exhaustive key search for an attacker with 256 space.[3] However, Triple DES with a "triple length" (168-bit) key is vulnerable to a meet-in-the-middle attack in 256 space and 2112 operations.[4]

An illustration of 1D-MITM attack

Once the matches are discovered, they can be verified with a second test-set of plaintext and ciphertext.

### MITM algorithm

Compute the following:

• $SubCipher_1=ENC_{f_1}(k_{f_1},P)$$k_{f_1}$$K$:
and save each $SubCipher_{1}$ together with corresponding $k_{f_1}$ in a set A
• $SubCipher_1=DEC_{b_1}(k_{b_1},C)$$k_{b_1}$$K$:
and compare each new $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 22·k 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 more 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:

$C=ENC_{k_n}(ENC_{k_{n-1}}(...(ENC_{k_1}(P))...))$
$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:

• $SubCipher_1=ENC_{f_1}(k_{f_1},P)$$k_{f_1}$$K$:
and save each $SubCipher_1$ together with corresponding $k_{f_1}$ in a set $H_1$.
• $SubCipher_{n+1}=DEC_{b_{n+1}}(k_{b_{n+1}},C)$$k_{b_{n+1}}$$K$:
and save each $SubCipher_{n+1}$ together with corresponding $k_{b_{n+1}}$ in a set $H_{n+1}$.

For each possible guess on the intermediate state $s_1$ compute the following:

• $SubCipher_1=DEC_{b_1}(k_{b_1},s_1)$$k_{b_1}$$K$:
and for each match between this $SubCipher_1$ and the set $H_1$, save $k_{b_1}$ and $k_{f_1}$ in a new set $T_1$.
• $SubCipher_2=ENC_{f_2}(k_{f_2},s_1)$$k_{f_2}$$K$:
and save each $SubCipher_2$ together with corresponding $k_{f_2}$ in a set $H_2$.
For each possible guess on an intermediate state $s_2$ compute the following:
1 $SubCipher_2=DEC_{b_2}(k_{b_2},s_2)$$k_{b_1}$$K$
and for each match between this $SubCipher_2$ and the set $H_2$, check also whether
it matches with $T_1$ and then save the combination of sub-keys together in a new set $T_2$.
2 ...
For each possible guess on an intermediate state $s_n$ compute the following:
a) $SubCipher_n=DEC_{b_n}(k_{b_n},s_n)$$k_{b_n}$$K$
and for each match between this $SubCipher_n$ and the set $H_n$, check also whether
it matches with $T_{n-1}$, save $k_{b_n}$ and $k_{f_n}$ in a new set
$T_n$.
b) $SubCipher_{n+1}=ENC_{f_n+1}(k_{f_n+1},s_n)$$k_{f_{n+1}}$$K$
and for each match between this $SubCipher_{n+1}$ and the set $H_{n+1}$, check also
whether it matches with $T_n$. If this is the case then:"

Use the found combination of sub-keys $(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 $2^{|k_{f_1}|}+2^{|k_{b_{n+1}}|}+2^{|s_1|}$$(2^{|k_{b_1}|}+2^{|k_{f_2}|}+2^{|s_2|}$$(2^{|k_{b_2}|}+2^{|k_{f_3}|}+...))$

Regarding the memory complexity, it is easy to see that $T_2,T_3,... ,T_n$ are much smaller than the first built table of candidate values: $T_1$ as i increases, the candidate values contained in $T_i$ must satisfy more conditions thereby fewer candidates will pass on to the end destination $T_n$.

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

$2^{|k_{f_1}|}+2^{|k_{b_{n+1}}|}+2^{|k|-|s_n|}...$

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 $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 $2^{|k|}/2^{|l|}$.

Therefore after the first MITM phase, there are $2^{|k|-b}$$2^{-b} = 2^{|k|-2b}$ ,where $|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 $1/2^{|b|}$.

The part of brute force testing (testing the candidate key on new (P,C)-pairs, have time complexity $2^{|k|-b}+2^{|k|-2b}+2^{|k|-3b}+2^{|k|-4b}$...

,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 ⌈$|k|/n$(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:

• $SubCipher_1=ENC_{f_1}(k_{f_1},P)$$k_{f_1}$$K$
and save each $SubCipher_1$ together with corresponding $k_{f_1}$ in a set A
• $SubCipher_2=DEC_{b_2}(k_{b_2},C)$$k_{b_2}$$K$
and save each $SubCipher_2$ together with corresponding $k_{b_2}$ in a set B.

For each possible guess on an intermediate state s between $SubCipher_1$ and $SubCipher_2$ compute the following:

1 $SubCipher_1=DEC_{b_1}(k_{b_1},s)$$k_{b_1}$$K$
and for each match between this $SubCipher_1$ and the set A, save $k_{b_1}$ and $k_{f_1}$ in a new set T.
2 $SubCipher_2=ENC_{f_2}(k_{f_2},s)$$k_{f_2}$$K$
and for each match between this $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 $(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 $2^{|k_{f_1}|}+2^{|k_{b_2}|}+2^{|s|}$$(2^{|k_{b_1}|}+2^{|k_{f_2}|})$ 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.