# Sustainable Data-Driven Secured Optimization Using Dynamic Programming for Green Internet of Things
## 3 Sustainable Data-Driven Secured Decision Protocol with Dynamic Programming
### Model Discussion
The cost function is based on the traffic load and link status; accordingly, the routing phase can be re-formulated dynamically, and information in the routing tables is updated. Afterward, the SDS-GIoT model develops a security algorithm for devices with limited constraints. In this phase, edge devices act as a central hub for their associate sensors, and they help authenticate the peer devices before data transmission. Let us consider that \(i\) and \(j\) are sensor nodes that need to collaborate for data routing. The edge device is denoted by \(ED\), \(E\) is any symmetric encryption algorithm. Firstly, \(i\) intends to communicate with \(ED\) and \(j\). Protocol messages are initiated, and security functions are applied accordingly to achieve this. Then, \(i\) encrypts message \(D\) using \(k_{i,ED}\) along with the identity of the intended recipient \(id_{j}\), and sends this to \(ED\) with its identifier \(id_{i}\), as defined in Equation (6). \[i\to ED:k_{i,ED}\ \big{(}id_{j},\ \ D\big{)}+id_{i} \tag{6}\]  
Upon decrypting the message, \(ED\) determines it is intended for \(j\), looks up the \(k_{j,ED}\) of the indicated recipient, and re-encrypts \(D\) for \(j\). Later, \(ED\) returns the translated message for \(i\) to send towards \(j\), as defined in Equations (7) and (8). \[ED\to i:k_{j,ED}\ (id_{i},\ \ D)\ +\ t \tag{7}\]  
\[i\to j:k_{j,ED}\ (id_{i},\ \ D)\ +\ t^{\prime} \tag{8}\]  
Figure 2: Flowchart of proposed routing algorithm using dynamic programming. where \(t\) and \(t^{\prime}\) denote time stamps to avoid reply attacks. Once nodes are identified as authentic, they initiate the data transmission process with the support of blockchain. In this phase, nodes generate their new session keys and share them with associated devices for communication. \({k_{i}}^{\prime}\) and \({k_{j}}^{\prime}\) are generated session keys for nodes \(i\) and \(j\). Afterward, both devices send the keys with encryption using associated private keys assigned by the edge device. The process for exchanging keys using the encryption function is defined in Equations (9) and (10). \[K\ \varepsilon\ S_{i+1}\]0  
\[K\ \varepsilon\ S_{i+1}\]1  
Later, using received keys, the SDS-GIoT model performs data encryption on data blocks \(B_{i}\) as defined in Equation (11). \[K\ \varepsilon\ S_{i+1}\]2  
This process continued in the form of various increments for maintaining the integrity and privacy of data blocks. Figure 3 illustrates the flowchart of the proposed security algorithm. Initially, network authentication is performed with the intelligence of the central hub. Edge devices perform offloading security functions with their processing capabilities, and only lightweight operations are allowed in constrained devices. When nodes are declared authentic, they generate session keys to initiate the data routing with their associated devices. Also, session keys are encrypted with the private key of nodes that are distributed by edge devices. Later, data blocks are encrypted incrementally by exploring blockchain technology. Algorithm 1 shows the pseudocode in the development of the SDS-GIoT model. ```
Step 1: Procedure Sec_data_driven Step 1: Network-setup Step 2: Multistage graphs with nodes and edges Step 3: Compute the traffic by exploring \(TL=B/P\) Step 4: Compute \(Pr(LS)=no.\ of\ packets/waiting\ time\) Step 5: Cost using objective function \(C(i,\ j)=TL+LS\) Step 6: Threshold evaluation for sending route request \(e(ft)<threshold;\ RREQ=true\) Step 7: If the neighbor state is not equal to the destination then Repeat Steps 3 to 6 End if Step 8: Performs network authentication Step 9: If authenticity is verified then data transmission Else Drop the request packet End if Step 10: Generate random keys and perform a security function Step 11: If all data packets are delivered to the destination then Send ACK to the source device Else Perform incremental encryption End if Step 12: End procedure
```  
**Algorithm 1**Data-driven secured optimization model using dynamic programming