# PiPatient Privacy Copyright Cloud Management
## 3 The Proposed Mechanism
### Algorithms for Key Agreement, Data Encryption/Decryption, and Updating  
In this subsection, we also give another presentation to describe our protocols. We use different roles to divide the algorithms into four independent but concurrent procedures. As described from Algorithms 1-4```
1.\(B_{i}=imprints\) (\(P_{i}\)'s biometric) // Input patient's biometric
2.\(ID_{Pi}=V_{i}\oplus\) H (\(B_{i}\)) // Retrieves patient's identity
3.\(R_{Pi}{}^{old}=ST_{i}\oplus ID_{Pi}\) // Retrieves prior random number
4.\(R_{Pi}{}^{new}=Random()\) // Generates a new random number
5.\(NID_{Pi}=ID_{Pi}\oplus R_{Pi}{}^{new}\) // Generates new nick ID
6.\(M_{1}=R_{Pi}{}^{old}\oplus S_{i}\oplus R_{Pi}{}^{new}\) // Replaces \(S_{i}\) to \(M_{1}\) with new random number
7.Sends { \(\{\) \(NID_{Pi}\), \(NID_{Pi}\), \(M_{1}\)}, CA } // Sends communication message to CA
8.while{! receive from CA } { do nothing } // Waiting for the response from CA
9.\(SK=\) (\(R_{Pi}{}^{new}\)/\(M_{3}\)) // Computes session key h (\(R_{Pi}{}^{new}\)\(\oplus R_{EPRS}\)\(\oplus R_{D}\))
10.\(ST_{i}=ST_{i}\oplus R_{Pi}{}^{new}\oplus R_{Pi}{}^{old}\) // Updates secret tokens \(ST_{i}\)
11.\(S_{i}=S_{i}\oplus R_{Pi}{}^{new}\oplus R_{Pi}{}^{old}\) // Updates secret tokens \(S_{i}\)
12.\(S_{i}\) // The following statements for privacy data processing in secure tunnel
13.while{! receive from EPRS } { do nothing } // Waiting for the response from EPRS
14.\(\mathrm{E}_{K}(R_{i})=\mathrm{D}_{SK}(\mathrm{E}_{SK}(R_{i}))\) // Deciphers message using session key SK
15.\(R_{i}=\mathrm{D}_{RPi}{}^{old}\) (\(\mathrm{E}_{K}(R_{i})\)) // Deciphers record using private key \(R_{Pi}{}^{old}\)
16.\(M_{7}=\mathrm{E}_{SK}\) (\(R_{i}\)) // Enciphers the original \(R_{i}\) with session key SK
17.Sends { \(\{\) \(M_{7}\), \(D_{j}\) } // Sends cyber record to doctor \(D_{j}\)
18.while{! receive from \(D_{j}\)} { do nothing } // Waiting for the response from \(D_{j}\)
19.\(R_{i}{}^{new}=\mathrm{D}_{SK}\) (\(M_{8}\)) // Deciphers new record using session key SK
20.\(M_{9}=\mathrm{E}_{SK}(\mathrm{E}_{RP}{}^{new}(R_{i}{}^{new}))\) // \(P_{i}\) enciphers privacy using private key \(R_{i}{}^{new}\)
21.Sends { \(\{\) \(M_{9}\), \(EPRS\) } // Sends cyber record to EPRS
```

**Algorithm 1**Procedure of Patient \(\mathrm{P}_{1}\)

```
1.while(! receive from Patient Pi) { do nothing } // Waiting for the ack from Patient Pi
2.\(R_{Pi}{}^{new}=M_{1}\oplus\)H(\(T_{CA}\)) // Deciphers random number
3.\(ID_{Pi}=NID_{Pi}\oplus R_{Pi}{}^{new}\) // Retrieves patient's ID
4. if{ exist (\(ID_{Pi}\))} exit() // Checks if\(ID_{Pi}\) is illegal or not, if not exist session
5.\(ID_{Dj}=NID_{Dj}\oplus R_{Pi}{}^{new}\) // Retrieves doctor's ID
6.\(M_{2}=R_{Pi}{}^{new}\oplus\)H(\(ID_{D}\oplus T_{CA}\)) // Builds exchange message \(M_{2}\)
7.\(M_{3}=R_{Pi}{}^{new}\oplus\)H(\(ID_{Dj}\oplus T_{CA}\)) // Builds exchange message \(M_{3}\)
8.Sends { \(\{\) \(NID_{Pi}\), \(NID_{Dj}\), \(M_{2}\)}, EPRS // Sends communication message to EPRS
9.Sends { \(\{\) \(NID_{Pi}\), \(M_{3}\) }, \(D_{j}\) } // Sends communication message to \(D_{j}\)
10.while{! (receive (\(M_{5}\)))} { do nothing } // Waiting for the response from \(D_{j}\)
11.Sends { \(\{\) \(M_{5}\), whis(\(NID_{Pi}\)) } // Forwards communication message to \(P_{i}\)
```

**Algorithm 2**Procedure of CA

```
1.while(!