# Blockchain-Based Multiple Authorities Attribute-Based Encryption for EHR Access Control Scheme
## 5 Scheme Implementation
### Decryption Key Generation Phase  
As shown in Figure 4, AAs collaborate using the Shamir secret sharing scheme to generate the user attribute key segmentation and user attribute confused key segmentation off-chain. The UAKGC and the UACTGC reconstruct the user attribute key and user attribute confused key on-chain. User Attribute Key Generation Contract (UAKGC)When DU joins the system, AAs collaborate using the Shamir secret sharing scheme to generate the segmentation \(UAK_{i,\omega,uid}\) of the user attribute key in their respective management domains. As shown in Algorithm 3, after the UAKGC collects \(t_{\omega}\)\(UAK_{i,\omega,uid}\) partitions from AAs, it automatically invokes the Lagrangian interpolation method to calculate the user attribute key \(UAK_{\omega,uid}\) and then sends it to the user for data decryption. Figure 4: Decryption key generation phase. ```
1://AAs invoke SSS to generate the segment of user attribute key
2:if\(segUAKGen(AA_{i},UALK_{i,\omega,uid})\) = true then
3:\(AA_{i}\) send \(UAK_{i,\omega,uid}\) to Contract;
4:Count[\(\omega\)]++;
5:ifCthenount[\(\omega\)] = \(\mathfrak{t}_{\omega}\)
6:\(//\)This contract invokes Lagrangian interpolation method to generate UAK\({}_{\omega}\)
7:\(UAK_{\omega}\gets Lagrangian(t_{\omega},UAK_{i,\omega})\);
8:endif
9:endif
```  
**Algorithm 3** User attribute key generation  
\(UAKGen(GP,S_{uid})\to UAK\): This algorithm is classified into the following two phases. 1. When DU completes registration, \(AA_{i}\) calculates the attribute key segmentation \(UAK_{i,\omega,uid}=g^{sk_{u\omega}}H(uid)^{sk_{u\omega}}\), and sends the segmentation to the UAKGC. 2. After the UAKGC receives at least \(t_{\omega}\)\(UAK_{i,\omega,uid}\), we calculate \[g^{\alpha_{\omega}}H(uid)^{\alpha_{\omega}}=\prod_{i=1}^{t_{\omega}}UAK_{i, \omega,uid}^{\prod_{i=1,\omega}^{\omega}\frac{\pm i_{j}}{\pm i\omega_{j}- \omega}t_{i}}\] (4)  
The user attribute key \(UAK_{\omega,uid}=g^{\alpha_{\omega}}H(uid)^{\alpha_{\omega}}\). _User Attribute Confused Token Generation Contract (UACTGC)_. The user computes \(H(\omega)^{usk}\) for each attribute and sends it to each AA through a secure channel. As shown in Algorithm 4, AAs generate the segmentation \(UACT_{i,\omega,uid}\) of the user attribute confused token in their respective administrative domains. After the UACTGC receives at least \(t_{\omega}\)\(UACT_{i,\omega,uid}\) from the AAs, it automatically invokes Lagrangian interpolation to compute the user attribute confused token \(UACT_{\omega,uid}\). ```
1://AAs invoke SSS to generate the segment of user attribute confused token
2:if\(segUACTGen(AA_{i},UACT_{i,\omega,uid})\) = true then
3:\(AA_{i}\) send \(UACT_{i,\omega,uid}\) to Contract;
4:Count[\(\omega\)]++;
5:ifCthenount[\(\omega\)] = \(\mathfrak{t}_{\omega}\);
6:\(//\)This contract invokes Lagrangian interpolation method to generate UACT\({}_{\omega}\)
7:\(UACT_{\omega}\gets Lagrangian(t_{\omega},UACT_{i,\omega})\);
8:endif
9:endif
```  
**Algorithm 4** User attribute confused token generation  
\(UACKGen(GP,S_{uid})\to UACK\): This algorithm is classified into the following three phases. 1. DU computes \(H(\omega)^{usk}\forall\omega\in[S_{uid}]\), where \(S_{uid}\) is the attribute in the user attribute set, and then sends \(H(\omega)^{usk}\) to each AA through a secure channel. To verify DU's ownership of the attribute, AAs confirm \(e(H(\omega),upk)=e(H(\omega)^{usk},g)\). After successful verification, AAs share the secret between each other secret sharing, compute the partition \(UACT_{i,\omega,uid}=H(\omega)^{usk\cdot\delta_{i}}\) of the confused key token for attribute \(\omega\), and send this partition to the UACTGC. 2. After the UACTGC collects at least \(t_{\omega}UACT_{i,\omega,uid}\), it computes \[H(\omega)^{usk\cdot\delta}=\prod_{i=1}^{t_{\omega}}H(\omega)^{usk\cdot\delta_{ i}\prod_{j=1,j\
eq i}^{t_{\omega}}\frac{\pm i_{j}}{\pm i\omega_{j}-\omega}t_{i}}\] (5) The user attribute confused key \(UACT_{\omega,uid}=H(\omega)^{usk\cdot\delta}\). 3.