# Multi-Mobile Agent Trust Framework for Mitigating Internal Attacks and Augmenting RPL Security
## 3 Proposed Framework
### Cluster Builder Module
Key Generator: This module is responsible for securely gathering the trust-related data. When an MA is initiated, a unique key is assigned to it, and this key is sent to the gateway of its cluster. The key is hashed with MD5 by the control layer. Each time an MA visits the device layer, the hashes are crossed-checked. If authenticated, it can enter the respective cluster to fetch the trusted parameters. Using MD5 poses no significant risks since it is a sophisticated and efficient file hash and is a faster and more secure cryptographic hash algorithm than some other functions. For instance, the performance of a hash function can be assessed by its complexity and execution time. MD5 and SHA-256 both have the same complexity of \(O(N)\), but MD5 is faster than SHA-256. Although MD5 is prone to collisions, some researchers have proposed different ways to overcome collisions [44; 45; 46]. The primary advantage of MD5 is that it takes inputs of any size and outputs a 128-bit hash or message digest [47]. It processes each 512-bit block of data separately, including the message digest from the preceding stage. Each 512-bit string is split into 16 words, each of which has 32 bits. Message digests are created with consecutive hexadecimal numbers in the first phase of initialization [48]. MD5 uses message padding to adjust the length. 3. MA Generator: This module generates multiple MAs based on the number of clusters made by the cluster builder module. It is also responsible for initiating all the MAs when required. The MAs begin topology discovery whenever an MA security hash fails or a change in topology is discovered. After the MAs are initiated, they are sent to the MA distributor module. ```
1:initialize variables:
2:\(hop\_count=0\)
3:\(x_{a}\gets node_{a}\)
4:\(x_{b}\gets node_{b}\)
5:centroid node
6:C \(\leftarrow\) cluster
7:for all clusters (C) do
8:calculate \(hop\_count\) from centroid
9:if distance between (\(x_{a}\) and centroid) == \(1\)then
10:\(hop\_count=hop\_count+1\)
11:else
12:\(hop\_count=hop\_count+2\)
13:endif
14:if\(hop\_count<2\)then
15:select node for routing
16:else
17:drop node
18:endif
19:endfor
20:repeat
21:step 7
22:until the centroid does not change
23:while the topology has changed do
24:steps 1 to 7
25:endwhile
```  
**Algorithm 2** Route optimization with the minimum spanning tree algorithm. ```
1:initialize variables:
2:MA = 0
3:itinerary
4:MA = Number of populated clusters
5:for all clusters do
6: initialize security parameter
7:endfor
8:key \(\leftarrow\) security variable
9:if
10:key == 0 then
11: hashed key \(\leftarrow\) MD5(key value)
12: MA \(\leftarrow\) hashed key
13: Gateway (G) \(\leftarrow\) hashed key
14:endif
15:for all clusters (C) do
16:function
17: call \(\leftarrow\) Routing()
18: Routing() \(\leftarrow\) MST algorithm
19: itinerary \(\leftarrow\) every cluster
20: assign every cluster itinerary to MAs
21: MA \(\leftarrow\) itinerary
22:endfunction
23:endfor
24:for all clusters (C) do
25: MA \(\rightarrow\) visit a cluster
26:if MA hashed key \(==\) Gateway hashed key then
27: authenticate MA
28: collect data
29:else
30: invalid key
31:endif
32:endfor
33:for all clusters do
34: steps 15 and 24
35:endfor
36:while the topology has changed do
37: steps 1 to 24
38:endwhile
```  
**Algorithm 3** Dynamic itinerary planner algorithm.