# Device-to-Device (D2D) Multi-Criteria Learning Algorithm Using Secured Sensors
## 3 Proposed Multi-Criteria Learning Algorithm Using Secured Sensors
### Secured Data Transmission Using a Secured Session-Oriented Scheme  
The proposed algorithm offers secure IoT-enabled smart data routing by utilizing the interaction of session keys between devices, gateways, and the sink node. This process is comprised of two levels. In the first level, the devices and gateways exchange their session keys and obtain the cipher information over the insecure channel. In the second level, the session keys are shared among the gateway and the sink node. Furthermore, session keys have an expiration time and are revoked after the completion of this time. However, we consider that the devices are mobile, so it might be a case that the device moves to another communication range, thus the session key is also revoked, and it sends a new request to the nearest gateway for providing the new session key and executes the authentication process. The session keys are encrypted using the public key. Let us consider that \((ks_{i})^{n}\) denotes the set of session keys. Then, data encryption, \(E\), from the mobile network device \(i\) to the gateway \(j\) can be obtained as shown in Equation (6). Before this, device \(i\) to the gateway \(j\) performs an authentication function to validate the session key, as defined in Equation (6):  
\[i\to j:E(ks_{i}\left[ \begin{array}{cc}n_{i},&t_{i}\end{array} \right]) \tag{6}\]  
where \(t_{i}\) is a timestamp and \(n_{i}\) is a nonce, also known as a random number. It is encrypted using the symmetric key of mobile device \(i\). On receiving the encrypted session key, the gateway \(j\) includes its nonce, \(n_{j}\), along with the timestamp, \(t_{j}\), and sends back the confirmation message, as defined in Equation (7):  
\[j\to i:E\big{(}ks_{i}\left[ \begin{array}{cc}n_{j},&t_{j}\end{array} \right] \big{)} \tag{7}\]  
Accordingly, both devices on the network authenticate themselves, and now the network messages, \(m_{i}\), can be ciphered using the encryption function, as provided in Equation (8):  
\[i\to j:\ xor\ (m_{i}ks_{i}) \tag{8}\]  
Finally, when data are received by gateways, they establish separate sessions with sink nodes using Equations (6) and (7). Afterward, the device data, \(M\), are forwarded to the sink node, \(sink\), including the digital signature, \(MAC\), of the gateway with its private key, \(R_{j}\), and ciphered data, \(E[m_{i},ks_{i}]\), as shown in Equation (9):  
\[M(j,\ sink)=MAC\big{(}R_{j},E[m_{i},ks_{i}]\big{)} \tag{9}\]  
Figure 3(a,b) describes the flowcharts of the proposed algorithm. Initially, the network services and mobile devices gather the network data from the smart environment. Network keys are generated for D2D authentications, and after their verification, they can be a part of the routing. The proposed algorithm determines the value of route rank based on the multi-criteria and updates the nodes' tables. Afterward, it utilizes reinforcement learning to assign rewards for the nodes. These rewards significantly improve the training process for the devices to extract the optimal neighbors from the set of choices, and accordingly, offer energy-efficient, least error rate delivery paths. Moreover, the proposed algorithm also secures the sessions among the gateway and the sink node for data transfer. Both the gateway and the sink node established secure sessions for their direct communication and are valid for a fixed time interval. After the mutual authentication, the gateways interact with the sink node for forwarding the network data with nominal communication costs. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
1 Byte & 1 Byte & 1 Byte & 2 Bytes & 1 Byte & 2 Bytes & 1 Byte \\ \hline Identity, \(id\) & Energy, \(e_{i}\) & Distance, \(d_{i}\) & Link \(\cos\) t, \(lcost_{i}\) & Radio Coverage, \(CR_{i}\) & Route rank, \(R(i)\) & Reward, \(Rwd\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Node level information. Figure 5 shows the flow of messages between the gateway and sink node for the establishment of a secure session with encrypted data transfer.