# MAC-Based Compression Ratio Improvement for CAN Security
## 2 Existing CAN Data Authentication Methods
### Modified MAC Algorithm Using ICANDR  
In the ICANDR algorithm, the 8-byte CAN data is first divided into three signals: Sig A (3 bytes), Sig B (3 bytes), and Sig C (2 bytes). Next, the bit-wise XOR values between the current signal and the previous signal are computed as shown in Table 1. The difference between two successive CAN signals with the same message ID is usually close to zero. This is because the rate of generation of CAN signals is much greater than the rate of change in car driving. If the calculated XOR value is nonzero, the corresponding header bit is set to one. Otherwise, the corresponding header bit is set to zero. The calculated header bits are arranged in the last column of the CAS map in sequence, as shown in Table 2. Starting in the next row, the XORed values for Sig A and Sig B are placed in bits 23 through 0. However, the XORed values for Sig C are placed in bits 15 through 0 because Sig C is a two-byte signal. If a header bit is 0, the corresponding row is empti \begin{table}
\begin{tabular}{c c c c c} \hline
**Signal** & **Sig A** & **Sig B** & **Sig C** \\ \hline Previous frame & 1\(A\) 2\(B\)\(CA_{16}\) & 9\(A\)\(EC\) 96\({}_{16}\) & 74 \(E3_{16}\) \\ Current frame & 1\(A\) 2\(B\)\(E1_{16}\) & 9\(A\)\(EC\) 92\({}_{16}\) & 74 \(E3_{16}\) \\ XOR & 00 00 2\(B_{16}\) & 00 00 04\({}_{16}\) & 00 00 06 \\ Header bit & 1 & 1 & 0 \\ \hline \end{tabular}
\end{table} 
Table 1: Header bit calculation in the ICANDR algorithm. Figure 1: 32-bit MAC of the Practical Security algorithm in CAN 2.0B. Next, starting from the leftmost column, if all elements of a column are zero, that column is deleted. This process repeats until the first occurrence of a column with a nonzero element. Then the remaining area is designated as a selection area as shown in Table 2.  
Finally, the selection area in Table 2 is arranged using the memory map in Table 3. Thus, in this example, eight-byte data are compressed into only two bytes. In the modified MAC algorithm [29], data compression is performed using the ICANDR algorithm, but the compression ratio is further improved by displaying the header bits in the last byte of the MAC instead of the compression area. For example, if the header bits are \"101\", the decimal value of the header bits is \"5\". Then, the fifth bit from the LSB of the MAC is inverted as shown in Figure 2. The receiving ECU calculates the MAC independently, compares it with the last byte of the received MAC, and determines the header bit value by the inverted bit position. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Signal** & **Bit 23—Bit 6** & **Bit 5** & **Bit 4** & **Bit 3** & **Bit 2** & **Bit 1** & **Bit 0** \\ \hline Header (HA) & & & & & & & **1** \\ \hline Header (HB) & & & & & & & 1 \\ \hline Header (HC) & & & & & & & 0 \\ \hline SA & & & & & & & \\ (Sig \(A_{i}\oplus\) Sig \(A_{i-1}\)) & 0 \(\cdots\) 0 & 1 & 0 & 1 & 0 & 1 & 1 \\ \hline SB & & 0 \(\cdots\) 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ (Sig \(B_{i}\oplus\) Sig \(B_{i-1}\)) & & - & - & - & - & - & - \\ \hline \hline \end{tabular}
\end{table} 
Table 2: CAS map corresponding to Table 1 (shaded area: selection area). \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline  & **Bit 7** & **Bit 6** & **Bit 5** & **Bit 4** & **Bit 3** & **Bit 2** & **Bit 1** & **Bit 0** \\ \hline \multirow{2}{*}{Byte 0} & SA & SB & SA & SB & SA & HC & HB & HA \\  & [2] & [1] & [1] & [0] & [0] & & & \\ \hline \multirow{2}{*}{Byte 1} & \multirow{2}{*}{0} & SB & SA & SB & SA & SB & SA & SB \\  & [5] & [5] & [4] & [4] & [3] & [3] & [2] \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Memory map corresponding to Table 2.  
Figure 2: Header bit representation by modified MAC. The modified MAC algorithm can be applied when the length of compressed data is 0 to 6 bytes. The length of \(MAC_{mod}\), the MAC data of the modified MAC algorithm, is determined as  
\[L(MAC_{mod})=7-L(M_{c}), \tag{4}\]  
where \(L(x)\) means the length of \(x\) in bytes, and \(M_{c}\) means compressed data. In (4), the largest value of \(L(MAC_{mod})\) is 7.