## 3 The Location-aware Dynamic Session-key Generation for Grid-based WSNs Scheme
### Communication Protocol  
In our proposed protocol, we use a dynamic key management mechanism. In this mechanism, two keys are preset in each sensor node. These two keys generate a new key for the next round, and will also be preset in the cluster node. The generation of the session key will be the same as the generation of the key in the sensor node. Using this key management mechanism, we can thus ensure the security of the data transmission. The transmission paths of the sensor network are shown in Figure 11.  
We divide our protocol into the following steps, as shown in Figure 12.  
Step 1: When the deployed sensor node \(i\) returns the collected data \(M_{i}\), the sensor node will make use of the preset parameters \(a_{i}\) and \(a_{i\text{-}1}\) to generate a key, \(K_{si}\), where  
\[K_{si}=h(a_{i},a_{i\text{-}1}) \tag{2}\]  
Furthermore, the two parameters \(K_{msg}\) and the Seed preset in each of the nodes will use the hash function to generate a new message key, \(K^{{}^{\prime}}_{msg}\), where:  
\[K^{{}^{\prime}}_{msg}=h(K_{msg},Seed) \tag{3}\]  
At that time, the sensor node generates \(N_{1}\) and makes use of \(K_{si}\) to encrypt the collected data \(M_{i}\), the preset \(K^{{}^{\prime}}_{msg}\), and \(N_{1}\) into packet \(C_{si}\) as follows:  
\[C_{si}=E((M_{i},K^{{}^{\prime}}_{msg},N_{i}),K_{si}) \tag{4}\]  
The sensor node also computes the message authentication code \(MAC_{l}\) as follows:  
\[MAC_{l}=h\ (ID_{si},K_{si}) \tag{5}\]  
The \((C_{si},MAC_{l},ID_{si})\) is then transmitted to the cluster node. Figure 11: Transmission paths for the sensor network. Step 2: When the cluster node receives more than \(t\) packets, or when the period is longer than a specified time, the cluster node will record and transmit the identity, \(ID_{si}\), of the sensor node. It will also arrange a list, \(ID_{list}\)  
\[ID_{list}=(ID_{s1},ID_{s2},...,ID_{sr}) \tag{6}\]  
The cluster node will make use of the two preset parameters \(a_{i}\) and \(a_{i-1}\) to generate a key, \(K_{ci}\), where  
\[K_{ci}=h(a_{i},a_{i-1}) \tag{7}\]  
At that time, the cluster node will generate \(N_{2}\) and make use of \(K_{ci}\) to encrypt \(ID_{list}\) and \(N_{2}\)  
\[C_{ci}=E((ID_{list},N_{2}),K_{ci}) \tag{8}\]  
After that, the cluster node computes the following message authentication code \(MAC_{2}\) and \(MAC_{3}\) as follows:  
Figure 12.0  
Figure 12.1  
The cluster node sends (\(C_{ci}\), \(MAC_{1}\), \(MAC_{2}\), \(MAC_{3}\), \(ID_{ci}\)) to the base station. Step 3: After receiving the packet from the cluster node, the base station will seek the corresponding key \(K_{ci}\) to verify the cluster node's identity and decrypt \(C_{ci}\) as follows:  
Figure 12.2  
Figure 12.3  
Next, the base station will check the integrity of the \(ID_{list}\) using  
Figure 12.4  
Figure 12.5 The communication protocol. Based on the _IDlist_, the base station will search for the corresponding key \(K_{si}\) and arrange them into the key list \(K_{list}\), where \(K_{list}=\left(K_{s1},K_{s2},...,K_{s}\right).\) It will verify the sensor node's identity using  
Figure 12.6  
If the above verifications fail, this packet will be discarded. At that time, the base station will generate \(N_{3}\) and make use of \(K_{ci}\) to encrypt\(\left(K_{list},ID_{list},N_{2},N_{3}\right).\) The encrypted data \(C_{b}\) will be sent to the cluster node, where  
Figure 12.7  
Step 4: When the cluster node receives the response data \(C_{b}\) from the base station, it will make use of the key \(K_{ci}\), which is generated by itself, to decrypt \(C_{b}\)  
Figure 12.8  
The cluster node will then check whether \(N_{2}\) is equal to the \(N_{2}\) generated in step 2. The cluster node can only use the ith key \(K_{si}\) of the sensor node of \(K_{list}\) to decrypt \(C_{si}\); otherwise, this packet is discarded.