## 4 Method
### The Proposed Scheme Uses Extended Chaotic Maps
#### 4.2.3 Key Generation Phase  
This phase comprises two parts. The first part is the protocol that governs the sending of data by the wearable device sensor to the database for storage through the mobile node. It can be subdivided into the sensor data collection stage and the social network information transmission stage, separated by dotted lines in Figure 2. The second part concerns the agreement for medical staff under which they access data; in this part, a data summary is uploaded to the blockchain for subsequent verification and to increase its confidentiality. The second part manifests the main contribution of this paper.  
Step 1: Mobile devices \(M\) connect to sensor \(S\), and send IDM and random number \(x\) to the sensor  
Step 2: The sensor \(S\) calculates the key by using the identity IDM of the mobile devices \(M\)  
\[K_{MS}=T_{h(ID_{M})}(SK_{S})\bmod p.\]  
Then, calculate the encryption key by using the random number \(r_{1}\) and key \(K_{MS}\).  
\[key_{MS}=T_{r_{1}}(K_{MS})\bmod p.\]  
After calculating the encryption key \(key_{MS}\), encrypt the origin data \(P\) by \(key_{MS}\).  
\[C_{1}=P\ \oplus\ key_{MS}.\]  
The sensor \(S\) sends its identity IDS and encrypted data \(C_{1}\) back to the mobile devices M after encrypting the origin data \(P\).  
Step 3: The mobile devices \(M\) calculates the key by using the identity IDS of the Sensor \(S\)  
\[K_{MS}=T_{h(ID_{S})}(SK_{M})\bmod p.\]  
Then, calculate the encryption key by using the random number \(r_{1}\) and key \(K_{MS}\).  
\[Key_{MS}=T_{r1}(K_{MS})\bmod p.\]  
After calculating the encryption key \(key_{MS}\), decrypt the encrypted data \(C_{1}\) by \(key_{MS}\)  
\[P=C_{1}\oplus\ key_{MS}.\]  
After obtaining the original data \(P\), send the identity of mobile device IDM to the medical center server MCS.  
Step 4: Medical center server MCS returned its identity IDMCS and random number \(r_{2}\) to the mobile device \(M\).  
Figure 2: Network entity registration illustration diagram.  
Step 5: The mobile devices \(M\) calculates the key by using the identity of the medical center server IDMSC.  
\[K_{MMCS}=T_{h(ID_{MCS})}(SK_{M})\bmod p.\]  
Then, using the random number \(r_{2}\) and key \(K_{MMCS}\) to calculate the encryption key \(key_{MMCS}\).  
\[key_{MMCS}=T_{r_{2}}(k_{MMCS})\bmod p.\]  
After calculating the encryption key \(key_{MMCS}\), encrypt the origin data \(P\) by \(key_{MMCS}\).  
\[C_{2}=P\ \oplus\ key_{MMCS}.\]  
When the data is encrypted, send the encrypted data \(C_{2}\) to the medical center server MCS.  
Step 6: The medical center server MCS calculates the message summary \(v\) by using the encrypted data \(C_{2}\) and random number \(r_{2}\). After calculating the message summary \(v\), it uploads it to the blockchain.  
Step 7: The medical center server stores the encrypted data \(C_{2}\), random number \(r_{2}\), and messages the summary \(v\) to the database.  
When the data have been stored by the medical center server MCS, when they need to be authorized, an authorization action is performed. When the MCS confirms that the requester has a right to access the data, it decrypts those data and uses its private key and the public key of the requester to generate a new key, which is used to encrypt the data for sending back to the data requester. The data requester can use his or her private key and the public key of the MCS to calculate the encryption and decryption keys to decrypt the data. Having received the file, the data requester can verify the message summary against the message summary that is stored on the blockchain. Figure 3 presents the key agreement in the proposed scheme.  
Figure 3: The key agreement of proposed scheme.