# Efficient and Secure EMR Storage and Sharing Scheme Based on Hyperledger Fabric and IPFS
## 6 Scheme Analysis
### Security Analysis
#### 6.1.3 Patient Privacy and Security  
Our proposed scheme stores \(C_{N_{EMR}}\) and \(uid\) as key-value pairs in the attribution channel, while in the data channel, it saves key-value pairs formed by \(N_{EMR_{\text{label}}}\) and TreatmentData.The confidentiality of the relationship between \(C_{N_{EMR}}\) and \(N_{EMR_{hash}}\) is crucial for patient privacy security. Once the relationship is exposed, attackers can obtain the \(uid\) of patients associated with \(TreatmentData\), thus compromising patient privacy. Based on this dual-channel mechanism, the threat of data leakage in the system mainly includes two scenarios: one of the channels was attacked or both of the channels were attacked. (A) One of the Channels Was Attacked  
Assume that one of the channels is compromised by a malicious node that obtains all the ledger data in that channel. The design of dual channels provides a high degree of isolation, ensuring that attackers still cannot obtain the association between medical data and the corresponding patients. This feature provides additional assurance for patient privacy and security. (B) Both of the Channels Were Attacked  
Assume that both of the channels have malicious nodes and have access to all the ledger data in the system. We proceed to analyze the probability of exposure of the relationship between \(C_{N_{EMR}}\) and \(N_{EMR_{hash}}\). Hash functions are one-way, meaning that for any given original medical record number \(N_{EMR}\), one can compute the corresponding \(N_{EMR_{hash}}=hash(N_{EMR})\). However, if an attacker only obtains \(N_{EMR_{hash}}\), it is computationally infeasible to calculate the original medical record number \(NEMR\) using \(hash^{-1}(N_{EMR_{hash}})\), as the inverse function \(hash^{-1}\) either does not exist or is extremely difficult to compute. With the assurance of patient key security, attackers cannot directly obtain the mapping between \(C_{N_{EMR}}\) and \(N_{EMR_{hash}}\). If \(\left\{C_{N_{EMR}},uid\right\}_{i,1\leq i\leq n}\) in the attribution channel and \(\left\{N_{EMR_{hash}},TreatmentData\right\}_{j,1\leq j\leq n}\) in the data channel are obtained, then the probability of obtaining \(N_{EMR_{hash}}\) corresponding to \(C_{N_{EMR}}\) is  
\[P_{i}(n)=1/n \tag{11}\]  
where \(n\) in Equation (11) is the number of EMRs stored in the system, and as the number of stored EMRs increases, the probability of obtaining \(N_{EMR_{hash}}\) corresponding to \(C_{N_{EMR}}\) decreases gradually. If \(\left\{C_{N_{EMR}},uid\right\}_{i,1\leq i\leq n}\) in the attribution channel and \(\left\{N_{EMR_{hash}},TreatmentData\right\}_{j,1\leq j\leq n}\) in the data channel are obtained, then patient \(U\) is assumed to have \(z\) EMRs, and the probability of obtaining the attribution relationship of \(z\) EMR of \(U\) is  
\[P(z,n)=\prod_{i=1}^{z}P_{i}(n+1-i) \tag{12}\]  
The analysis of the monotonicity of Equation (12) reveals that as the \(n\) or the \(z\) gradually increases, \(P(z,n)\) will decrease significantly. Considering real-world scenarios, as the system continues to be used, both the total number of stored EMRs in the system and the number of EMRs owned by patients will gradually increase. Therefore, the above probability will decrease gradually, indicating that the privacy of patients will be increasingly secure. Even in the scenario where collusion exists among nodes in both channels, and attackers can access all ledger data in the two channels, they still cannot obtain the plaintext \(N_{EMR}\), as long as patient keys remain secure. When confronted with extremely large EMRs, it is extremely difficult for an attacker to obtain a correspondence between \(C_{N_{EMR}}\) and \(N_{EMR_{hash}}\). Since \(N_{EMR_{hash}}\
eq C_{N_{EMR}}\), it follows that \(TreatmentData\
equid\), meaning that medical data cannot be associated with patient information.