# Mutual Authentication Protocol for D2D Communications in a Cloud-Based E-Health System
## 4 Proposed Protocol
### Patient Upload Phase (Pulp)  
The PUP phase is performed over an insecure channel. The focus of PUP is the mutual authentication between patients and the cloud server and the generation of a session key to encrypt health information measured by the sensors attached to the user's body, prior to sending it to the cloud server. The complete procedure is shown in Figures 3 and 4. The PUP phase starts when the patient's device requests, from the sensors attached to the user's body, the health information measured and collected and stores them. If necessary, the device discovery is performed in order to find other nearby devices as detailed in Section 4.1, based on proximity. However, first, they need to authenticate with a 3 GPP network  
Figure 2: Message exchange in health center upload (HUP). to prove their reliability. All devices interested in performing D2D communication selects a random number \(R_{P}\), calculates and sends the hash of its IMSI to the HSS to be authenticated:  
\[Auth_{p}=h_{1}(IMSI_{p}\parallel R_{P})\]  
The HSS receives each \(Auth_{p}\), calculates \(Auth^{\prime}_{p}=h_{1}(IMSI_{p}\parallel R_{P})\) and verifies if \(Auth_{p}=Auth^{\prime}_{p}\). If the verification passes, it authenticates the device. All devices authenticated by the HSS are enabled to perform D2D. Then, the devices interested in D2D broadcast their TID\({}_{\text{Di-j}}\) to reach other devices nearby, which might demonstrate the intention of establishing a connection with them. Next, they send their own temporary identities to signalize their existence and position. Now, a device located outside the coverage area or inside the coverage area but without access to the 3 GPP network can perform their authentication with the cloud server by relaying their messages through the nearby devices, until the 3 GPP network is reached. Step 1. Calculates \(MAC_{PC}=h_{2}(ID_{P}\parallel R_{P})\) and sends _Message 1_ = (\(TID_{P}\), \(R_{P}\), \(MAC_{PC}\)) with a timestamp \(T_{P}\) to the cloud server. A device with direct access to the 3 GPP network can choose to send data directly or to perform offload through D2D communication until the cloud server is reached. Devices without the 3 GPP coverage send their data through D2D communication. Step 2. The cloud server receives _Message 1_ and \(T_{P}\) and verifies if \(T_{P}\) is valid. If the verification fails, the procedure is terminated. Otherwise, it calculates \(MAC_{PC}\)' = \(h_{2}(ID_{P}\parallel R_{P})\) and verifies if \(MAC_{PC}\)' = \(MAC_{PC}\). If the verification fails, the procedure is interrupted. Otherwise, the cloud server authenticates the device, selects a random number \(R_{CP}\), calculates \(MAC_{CP}=h_{2}(ID_{P}\parallel R_{CP})\) and sends _Message 2_ = (\(MAC_{CP}\), \(R_{CP}\)) with a timestamp \(T_{C}\) to the patient. Step 3. After receiving _Message 2_ and \(T_{C}\) from the cloud server, the patient checks if \(T_{C}\) is valid. If the validation fails, the procedure ends. Otherwise, it calculates \(MAC_{CP}\)' = \(h_{2}(ID_{P}\parallel R_{CP})\) and verifies if \(MAC_{CP}\)' = \(MAC_{CP}\). If the verification fails, the procedure is terminated. Otherwise, the patient authenticates the cloud server, generates the session key \(K_{PC}\) = \(h_{3}(ID_{P}\parallel R_{P}\parallel R_{CP})\) and calculates \(C_{PC}\) = \(h_{4}(K_{PC})\). He/she then encrypts the sensors measures using the session key, \(M_{MS}\) = \(E_{KPC}\) (_Sensors Measures_, \(TID_{P}\), \(C_{PC}\)) and sends _Message 3_ = \(M_{MS}\) with a new timestamp \(T_{P}\) to the cloud server. Step 4. The cloud server receives {_Message 3_, \(T_{P}\)} and verifies if \(T_{P}\) is valid. If the verification fails, it terminates the procedure. Otherwise, it calculates the session key \(K_{PC}=h_{3}(ID_{P}\parallel R_{P}\parallel R_{CP})\), decrypts the sensors measures, (_Sensors Measures_, \(TID_{P}\), \(C_{PC}\)) = \(D_{KPC}(M_{MS})\), calculates \(C_{PC}\) = \(h_{4}(K_{CP})\) and verifies if \(C_{PC}\)' = \(C_{PC}\). If the verification fails, it terminates the procedure.