# Securing IoT Devices against Differential-Linear (DL) Attack Used on Serpent Algorithm
### Serpent Algorithm  
The Serpent is the cryptographic algorithm, a block cipher that encrypts and decrypts a data block of 128-bits using different sizes of the keys, such as 128, 192, and 256-bits [10]. The Serpent has three main building blocks. The building blocks are the mathematical functions used in the construction of an algorithm. These three main blocks are described as follows:  
1. Initial Permutation denoted by \(IP\). The function of \(IP\) is to rearrange an original order of the plaintext before the encryption process using Equation (1) where \(OriginalPlaintext\) is the input of \(IP\). A symbol of \(\text{''}*\text{''}\) is a multiplication operator. \(OutputIP\) is an output of \(IP\), and \(mod(127)\) is a mathematical modulus of 127. Refer to Equation (1). \[OutputIP=(OriginalPlaintext\ast 32)mod(127)\] (1)
2. Serpent has a 32-round function composed of subkeys (key mixing), eight S-Boxes, and a linear transformation. The 32-round function is mathematically explained by a mathematical expression provided in Figure 2.  
3. Serpent has final permutation \(IP^{-1}\) function, which is an inverse of initial permutation \(IP\).  
Serpent uses eight 4 \(\times\) 4 S-Boxes during the encryption process. These S-Boxes, together with their inverses, are defined in Tables 1-8. For instance, if the input of \(S_{0}(X)\) is \(0=X\), then the output is 3, and \(S_{0}(0)=3\). If the input of \(S_{1}(X)\) is \(1=X\), then the output is 12 and \(S_{1}(1)=12\). If the input of \(S_{7}(X)\) is \(2=X\), then the output is 15, \(S_{7}(1)=15\), and so on. The same applies to the inverse cases. Refer to Figure 2. Serpent requires 33 of 128-bits, and subkeys are generated from an original key given by the user before encryption starts. The user can provide an original key size of 128, 192, or 256-bits long. In this study, the original 128-bit key is used to demonstrate how other 33-bit subkeys are generated using the mathematical expression given in Figure 3.  
Figure 2: 32-round function of Serpent.  
\begin{table}
\begin{tabular}{l c c c c c c c c c c c c c c c c c} \hline \hline \(X\) & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & C & D & E & F \\ \hline \(S_{5}(X)\) & F & 5 & 2 & B & 4 & A & 9 & C & 0 & 3 & E & 8 & D & 6 & 7 & 1 \\ \hline \(InvS_{5}(X)\) & 8 & F & 2 & 9 & 4 & 1 & D & E & B & 6 & 5 & 3 & 7 & C & B & 0 \\ \hline \hline \end{tabular}
\end{table}
Table 6: Sixth S-Box of Serpent defined as \(S_{5}(X)\).  
\begin{table}
\begin{tabular}{l c c c c c c c c c c c c c c c c c} \hline \hline \(X\) & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & C & D & E & F \\ \hline \(S_{1}(X)\) & F & C & 2 & 7 & 9 & 0 & 5 & A & 1 & B & E & 8 & 6 & D & 3 & 4 \\ \hline \(InvS_{1}(X)\) & 5 & 8 & 2 & E & F & 6 & C & 3 & B & 4 & 7 & 9 & 1 & D & A & 0 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Second S-Box of Serpent defined as \(S_{1}(X)\).  
\begin{table}
\begin{tabular}{l c c c c c c c c c c c c c c c c c c c} \hline \hline \(X\) & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & C & D & E & F \\ \hline \(S_{2}(X)\) & 8 & 6 & 7 & 9 & 3 & C & A & E & C & 1 & E & 4 & 0 & B & 5 & 2 \\ \hline \(InvS_{2}(X)\) & C & 9 & F & 4 & B & C & 1 & 2 & 0 & 3 & 6 & D & 5 & 8 & A & 7 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Fourth S-Box of Serpent defined as \(S_{3}(X)\).  
\begin{table}
\begin{tabular}{lIt receives the 128, 192 or 256-bit secret key as input and generates 33 subkeys with 128 bits each. The input has 8 words indexed from \(w_{-8}\) to \(w_{-1}\).  
Then, the _pre-key_ is calculated, which are 132 words indexed from \(w_{0}\) to \(w_{131}\) in the following manner:  
\[w_{i}=(w_{i-8}\oplus w_{i-5}\oplus w_{i-3}\oplus w_{i-1}\oplus i\oplus\phi)<<1\]  
where \(\phi\) is the golden ratio  
\[(\sqrt{5}+1)/2\text{ or }0x9e3779b9\]  
From the pre-key we generate the 133 words of the subkeys.  
Each word can be written as  
\[\begin{array}{c}k_{i}\,=\,SBox_{(3-(i\mod 33))\mod 32}(w_{i}).\\ \,\