Skip to content

Commit 91e8c1c

Browse files
hwamzzxyijun-lee
andauthored
docs/feistelcipher.md (#85)
* docs/feistelcipher.md * docs/ feistelcipher.md * docs/ feistelcipher.md * feistel.md * docs: add link to Feistel Cipher.md and fix markdown errors --------- Co-authored-by: yijun-lee <yijunlee.000@gmail.com> Co-authored-by: Yijun Lee <119404328+yijun-lee@users.noreply.github.com>
1 parent 7c75e0a commit 91e8c1c

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Intro
2+
The Feistel Cipher is a cryptographic structure that divides the input into left and right blocks, repeatedly applying a round function to one block and combining its output with the other block.
3+
Typically, all elements of an encryption process must be invertible, as decryption requires reversing the encryption steps to recover the plaintext. However, the Feistel Cipher uniquely employs both invertible and non-invertible components.
4+
5+
The primary reason the Feistel Cipher can utilize non-invertible elements lies in its design, which is based on the XOR operation.
6+
> [!Question] The Invertibility of XOR
7+
> Due to the "self-inverse" property of XOR, performing the same XOR operation during the decryption phase restores the original data.
8+
> * Self-inverse property: A⊕B⊕B=A
9+
10+
As a result, the Feistel Cipher allows for more flexible designs compared to Non-Feistel Ciphers. Additionally, the use of non-invertible components simplifies management by making the encryption and decryption processes identical.
11+
12+
A well-known example of a Feistel Cipher is [[DES]] (Data Encryption Standard). In contrast, a prominent example of a Non-Feistel Cipher is [[AES]] (Advanced Encryption Standard).
13+
14+
15+
## Design
16+
### 1-Round Feistel Structure
17+
![[Feistel_cipher(1).png]]
18+
19+
The left side represents the encryption process, while the right side shows the decryption process.
20+
21+
#### Encryption Process
22+
23+
In the encryption process, the plaintext input $p = (L_0 \parallel R_0)$ is divided into $L_0$​ and $R_0$​. A function $F$ takes the key $k$ and $R_0$​ as its input. Then, $L_0$​ is XORed with the output of $F(k, R_0)$, producing the left half of the ciphertext $L_1$. Meanwhile, $R_0$​ remains unchanged and becomes the right half of the ciphertext $R_1$​.
24+
25+
The encryption process can be represented mathematically as follows:
26+
$$
27+
L_1 = L_0 \oplus F(k, R_0)
28+
$$
29+
$$
30+
R_1 = R_0
31+
$$
32+
33+
#### Decryption Process
34+
35+
In the decryption process, the input ciphertext $c = (L'_0|R'_0) = (L_1|R_1)$ is divided into $L'_0$​ and $R'_0$.
36+
$L'_0$ is XORed with $F(k, R'_0)$, resulting in the left half of the plaintext $L'_1$. Similarly, $R'_0$ remains unchanged and becomes the right half of the plaintext $R'_1$.
37+
38+
The decryption process can be represented mathematically as follows:
39+
$$
40+
L'_1 = L'_0 \oplus F(k, R'_0)
41+
$$
42+
$$
43+
R'_1 = R'_0
44+
$$
45+
46+
#### Observations
47+
48+
As you may have noticed, the encryption and decryption processes are identical except for their inputs and outputs being reversed.
49+
50+
Encryption:
51+
$$c = p \oplus (F(k, R_0) \parallel 0)$$
52+
Decryption:
53+
$$c \oplus (F(k, R'_0) \parallel 0) \\ = p \oplus (F(k, R_0) \parallel 0) \oplus (F(k, R'_0) \parallel 0) \\ = p \oplus (F(k, R_0) \parallel 0) \oplus (F(k, R'_0) \parallel 0) \\ = p \oplus 0 = p$$
54+
As mentioned in the [[#Intro]], the self-inverse property of the XOR operation ensures that $F(k, R'_0)$ is canceled out during decryption. This means the decryption process works correctly even without requiring the inverse function $F^{-1}$, allowing the use of non-invertible components in the Feistel Cipher.
55+
56+
#### Limitations of a 1-Round Feistel Structure
57+
58+
Analyzing the 1-round Feistel Cipher reveals a critical drawback: the right half of the plaintext, $R_0$, directly becomes the right half of the ciphertext, $R_1$, without undergoing any transformation. This exposes half of the plaintext in the ciphertext, significantly compromising security.
59+
60+
To address this issue, Feistel Cipher structures are designed with multiple rounds. In a multi-round Feistel Cipher, the left and right halves are swapped at the end of each round, effectively ensuring that all parts of the plaintext are processed. However, this design requires more rounds compared to Non-Feistel Ciphers to achieve the same level of security.
61+
62+
### Multi-Round Feistel Structure
63+
![[Feistel_cipher(2).png]]
64+
The diagram above illustrates a Feistel structure with multiple rounds, as opposed to a single round.
65+
66+
#### Encryption Process
67+
68+
Unlike the single-round Feistel structure, in a multi-round Feistel Cipher, the right half of the plaintext ($R_0$) does not directly become the right half of the ciphertext ($R_1$). Instead, it becomes the left half of the output ($L_1$). Additionally, the XOR computation that previously resulted in $L_1$ in the single-round structure now determines $R_1$. In other words, the outputs of the left and right halves are swapped after each round.
69+
In the second round, $L_1$ undergoes further encryption, ensuring that both $L_0$ and $R_0$ are processed through the encryption rounds.
70+
71+
The encryption process can be expressed as follows:
72+
$$L_1 = R_0$$
73+
$$
74+
R_1 = L_0 \oplus F(k_1, R_0)
75+
$$
76+
$$
77+
L_n = L_{n-1} \oplus F(k_n, R_{n-1})
78+
$$
79+
$$
80+
R_2 = R_{n-1}
81+
$$
82+
83+
#### Decryption Process
84+
85+
The decryption process mirrors the encryption process, with the only difference being the reverse order of the keys used during the computation.
86+
The following equation represents the decryption process in a two-round Feistel structure.
87+
$$
88+
L'_1 = R'_0 = R_2 = R_1
89+
$$
90+
$$
91+
R'_1 = L'_0 \oplus F(k_2, R'_0) = L_2 \oplus F(k_2, R_1)
92+
$$
93+
$$
94+
= L_1 \oplus F(k_2, R_1) \oplus F(k_2, R_1) = L_1 = R_0
95+
$$
96+
$$
97+
L'_2 = L'_1 \oplus F(k_1, R'_1) = R_1 \oplus F(k_1, R_0)
98+
$$
99+
$$
100+
= L_0 \oplus F(k_1, R_0) \oplus F(k_1, R_0) = L_0
101+
$$
102+
$$
103+
R'_2 = R'_1 = R_0
104+
$$
105+
106+
> [!Note]
107+
> A Feistel Cipher with two rounds provides the same level of security as a single round of a Non-Feistel Cipher. Therefore, Feistel Ciphers generally require a greater number of rounds to achieve comparable security.
108+

0 commit comments

Comments
 (0)