# Blockchain Based Delay and Energy Harvest Aware Healthcare Monitoring System in WBAN Environment
## 4 System Model
### Patient Block Agent
#### 4.5.2 Security Manager  
In this entity, classified packets are encrypted using the extended-PRESENT algorithm, which is a lightweight blockcipher encryption algorithm. This extended version uses fast bit permutation instruction, which consumes less energy than the traditional PRESENT and AES algorithm. This algorithm consumes a small amount of memory in all programmeddevices due to its reduced size which also minimizes the computation time when compared with other cryptography algorithms. To mitigate the issues of PRESENT, i.e., low security strength (comparatively higher than previous symmetric algorithms), we proposed a modified algorithm in which permutation operation is changed with respect to the fast bits based permutation operation. This step further reduces energy consumption and provides higher security and reliability to the body sensors. In the first step, a secret key is calculated using patient input parameters such as _ID_, _PWD_, location and biometric records. However, key generation is implemented using two types of keys such as 80 bits and 128 bits. Each type of key strength is used in 31 rounds of operation which performs the XOR operation that introduces the round key \(K_{i}\) for \(1\leq i\leq 32\), where \(K_{32}\) is used for post whitening. In this paper, 80 bits of key size are used and the proposed PRESENT algorithm is presented in Figure 4. Computing a security key for the cluster is innovative for this work in which the PRESENT algorithm uses the dynamic keys of cluster members for key generation. Let us assume that a cluster with \(M\) members is \(S_{1},S_{2},S_{3},\ldots,S_{M}\). Every sensor node consists of a secret key as \(SK_{1},SK_{2},SK_{3},\ldots,SK_{M}\) consistently. In the proposed work, the CH is intended for generating \(ot-\mathbb{N}\) in each round R. For that, it put on XOR operations to the secret keys for its member nodes. \(ot-\mathbb{N}\) is generated at time \(t_{1}\) as follows,  
\[ot-\mathbb{N}=SK_{1}\oplus SK_{2}\oplus SK_{3}\cdots\oplus SK_{M} \tag{12}\]  
Similarly, if the cluster is organized with dynamism due to less energy and link quality, then the CM's table is adapted according to the CH. Consequently, in the next round, the CH generates \(ot-\mathbb{N}\) with new CM keys. In this way, the cluster key is changed at each time. The generation of \(ot-\mathbb{N}\) achieves encryption as in the PRESENT algorithm. The \(SK_{i}\) is XOR with the packets on every round that is caused by the previous round. First, the plain text is XOR with \(t-\mathbb{N}\), and then \(ot-\mathbb{N}\) is shifted and provides the security key. The first part of the XOR text is again over XOR with the round key. In this way, 31 rounds are applied to generate the ciphertext for aggregated packets. The pseudocode for the PRESENT algorithm is described in Algorithm 2. Figure 4: Extended version of PRESENT algorithm. ```
1:Input: Packets \(P_{(i)}\) and \(SK_{1},SK_{2},SK_{3},\dots,SK_{M}\)
2:Output:Ciphertext of \(P_{(i)}\)
3:Begin
4:// OneTime Security Key generation
5:for\(\forall S_{i}\in S\)do
6:\(Prepare\gets SK_{1},SK_{2},SK_{3},\dots,SK_{M}\)
7:\(Create\gets ot-\aleph\)
8:endfor
9:// PRESENT encryption
10:R\(\leftarrow\) 1 // R= round
11:state\(\leftarrow\) Plaintext (P)
12:While (R\(<\)31),
13:\(SK=ot-\aleph\)
14:\(state\gets SK\oplus State\)
15:\(state\gets SBoxLayer(State)\)
16:// Extended-PRESENT uses revised Permutation Function
17:\(state\gets FastBitpermutationlayer(State)\)
18:\(R\gets R+1\), do
19:\(R\gets rightCircularShift(ot-\psi,19)\)
20:\(SK[76-79]\gets SBoxLayer(Key[76-79])\)
21:\(SK[15-19]\gets ot-\aleph[16-19]\)
22:enddo
23:End While
24:if (R=31), then
25:\(lastSK\gets generateKey(Key,R)\)
26:\(State\gets State\oplus lastSK\)
27:Ciphertext of \(P_{(i)}\gets State\)
28:endif
29:End
```  
**Algorithm 2** OT-PRESENT algorithm. The pseudocode of the proposed OT-PRESENT algorithm is depicted for 80 bits of key strength.