# Security, Privacy, and Reliability in Digital Healthcare Systems Using Blockchain
## 5 Proposed Algorithms
### Authentication Mechanism
4:procedurePatient(\(P-ID\))
5:while(True) do
6:if\((P-ID=B-N)\)then
7:if(\(PHR\) does not exist \(B-N\)) then
8: Create\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(B_{N}\))
9:else
10: Update\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(B_{N}\))
11: Read\({}_{records}\) (\(P_{ID}\), \(PHR\), \(C_{ID}\), \(L_{ID}\), \(B_{N}\))
12:endif
13:else
14:Note\({}_{exist}\)(\(P_{ID}\))
15:endif
16:if(Visit (\(P_{ID}\), \(C_{ID}\), \(L_{ID}\), \(B_{N}\))) then
17:\(P_{ID}\) = Medrecord (\(P_{ID}\))
18:if(\(P-ID\)\(PHR\) (\(B_{N}\))) then
19: Grant records (\(P_{ID}\), \(C_{ID}\), \(L_{ID}\), \(B_{N}\))
20:else
21:(\(C_{ID}\), \(L_{ID}\)) \(\leftarrow\) NOTIFY(\"Medical record does not exist\")
22:endif
23:if(\(P_{ID}\)\(C_{ID}\), \(L_{ID}\) Treatment-Completed (\(P_{ID}\))) then
24:Revoke\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(C-ID\), \(L_{ID}\), \(B_{N}\))
25:else
26:(\(C_{ID}\), \(L_{ID}\)) \(\leftarrow\) NOTIFY (\"\(P-ID\) voluntary revoke P-ID\")
27:Revoke\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(C_{ID}\), \(L_{ID}\), \(B_{N}\))
28:endif
29:else
30: Not Visit
31:endif
32:endwhile end procedure
```  
**Algorithm 2**Patient Node  
```
1:Input: \(ID\) and key requested from \(N-admin\)
2:Output: Get access to \(PHL\) transactions
3:Initialization: \(PHL\) should be a valid node. \(PHL\) can read/write/grant/revoke \(EHR\) records. 4:procedurePatient(\(P-ID\))
5:while(True) do
6:if\((P-ID=B-N)\)then
7:if(\(PHR\) does not exist \(B-N\)) then
8: Create\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(B_{N}\))
9:else
10: Update\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(B_{N}\))
11: Read\({}_{records}\) (\(P_{ID}\), \(PHR\), \(C_{ID}\), \(L_{ID}\), \(B_{N}\))
12:endif
13:else
14:\({}_{records}\) (\(P_{ID}\), \(PREC_{ID}\), \(L_{ID}\), \(B_{N}\))
15:endif
16:endif
17:endif
18:endif
19:endif
20:endif
21:endif
22:endwhileend procedure
```  
**Algorithm 3**Patient Node  
```
1:Input: \(ID\) and key requested from \(N-admin\)
2:Output: Get access to \(PHL\) transactions
3:Initialization: \(PHL\) should be a valid node. \(PHL\) can read/write/grant/revoke \(EHR\) records. 4:procedurePatient(\(P-ID\))
5:while(True) do
6:if\((P-ID=B-N)\)then
7:if(\(PHR\) does not exist \(B-N\)) then
8: Create\({}_{records}\) (\(P_{ID}\), \(PREC_{I}\), \(B_{N}\))
9:else
10: Update\(
```
1:Input: Public Key
2:Output: Verification result: succeed or fail. 3:Generate a random integer \(r\in[1,\,N-1]\)
4:Compute \(w=g^{r}\) in \(G_{T}\) and convert the data type of \(w\) into a bit string
5:Compute integer \(h=H2(M||w,N)\)
6:Compute integer \(l=(r-h)modN\); if l = 0, go to step (2);
7:Compute element \(S=[l]ske\) in \(G_{1}\)
8:Convert the data type of \(h\) and \(S\) into a byte string, and output \((h,S)\) as the signature on message \(M\)
```
**Algorithm 4**Attribute-Based Signing Algorithm
```
1:Input: Master public signature key (Ppubs) of domain, system parameters of domain, message (M0), e's identity (IDe), and digital signature (h0, S0)
2:Output: Verification result: succeed or fail. 3:Convert the data type of h0 into an integer; if h0 \(\in[1,\,N-1]\) does not hold, the verification fails;
4:Compute element t = g h0 in GT;
5:Compute integer h = H2(M \(|\) i w, N)
6:Compute integer l = (r - h) mod N; if l = 0, go to step 2
7:Compute integer h1 = H1(IDe \(|\) i hid, N)
8:Compute element P = [h1]P2 + Ppubs in G2
9:Compute element u = e(S0, P) in GT
10:Compute element w0 = u * t in GT, converts the data type of w0 into a bit string
11:Compute integer h2 = H2(M0 \(|\) i w0, N). If h2 = h0 holds, the verification succeeds. Otherwise, the verification fails
```

**Algorithm 5**Attribute-Based Signing Algorithm