## 4 Construction Method of Message Hash Chain  
Two communicating parties, A and B, communicate, and sender A transmits the message stream \(P=p_{1},p_{2},\cdots,p_{n},n\in N^{*}\) to receiver B. The structure of each message is \(p_{i}=(m_{i},seq_{i},HC_{i})\). Where \(m_{i}\) is the content of the message sent by sender A in sequence, \(seq_{i}\) is the sequence number of the message, and \(HC_{i}\) is the result calculated by sender A according to \(m_{i}\) and the tail node \(HC_{i-1}\) of the message hash chain by the constructing method of the chain. When receiver B receives \(p_{i}\), it also needs to use \(m_{i}\) and the local tail node \(HC^{\prime}_{i-1}\) of the message hash chain to calculate the \(HC^{\prime}_{i}\) for verification.  
The construction method of the message hash chain is shown in Figure 3. The communication node needs to calculate the first node value \(HC_{1}\) of the message hash chain according to the first message \(m_{1}\), obtained by performing two hash function calculations on \(m_{1}\). After that, each message needs to calculate a digest using a hash function and then splice this digest with the tail node of the message hash chain to calculate the corresponding node value of the chain.  
The last node of each message hash chain is called the tail node, and the other nodes are called the intermediate nodes. The sender updates the node of the message hash chain corresponding to the latest sequentially sent message to a tail node and updates the original tail node to an intermediate node. The receiver verifies the messages in sequence and uses the successfully verified messages to construct a node of the message hash chain. Update this newly constructed node to the tail and the previous tail node to the intermediate nodes.  
Figure 2: Schematic diagram of message hash chain structure.  
The iterative process of the message hash chain node is shown in Algorithm 1. The parameters used in Algorithm 1 are described below:  
* _Get_address_: The role of the _Get_address_ function is to obtain the source and destination addresses from the message header.
* _Match_HC_node_: Match the message hash chain between two addresses.  
```
0:Header content, payload, node value of the message hash chain.
0:A new node value of the chain.
1:\(\mathit{pkt\_hash}\leftarrow\mathit{Hash}(\mathit{hdr},\mathit{seq},\mathit{ payload})\)
2:\(\mathit{src},\mathit{dst}\leftarrow\mathit{Get\_address}(\mathit{hdr})\).
3:\(HC\_\mathit{node}\leftarrow\mathit{Match\_HC\_node}(\mathit{src}, \mathit{dst})\).
4:return\(\mathit{Hash}(HC\_\mathit{node},\mathit{pkt\_hash})\)
```  
**Algorithm 1**\(HC\_\mathit{Iteration}\)  
The message hash chain construction algorithm is shown in Algorithm 2.  
```
1:\(HC\_\mathit{node}=\mathit{\"\"}\)
2:for\(\mathit{MQQueue}\) is not empty do
3:\(\mathit{payload}\leftarrow\mathit{MQQueue.poll}\)
4:\(HC\_\mathit{node}\leftarrow\mathit{HC\_Iteration}(\mathit{hdr},\mathit{payload}, \mathit{HC\_node})\)
5:endfor
```  
**Algorithm 2** The construction process of the message hash chain  
The two communicating parties update the message hash chain every time they construct a message hash chain node. At a specific time \(t\), a message hash chain node of \(m_{i}\) is constructed, then the complete message hash chain expression at time \(t\) is as following:  
\[HC_{i}=\begin{cases}h(h(m_{i})||HC_{i-1}),&i\geq 2\\ HC_{1},&i=1\end{cases}. \tag{2}\]