## 4 Blockchain-Based LWE-CP-ABE Data Sharing Scheme
### Data Sharing Scheme in Key Management Network and Blockchain Network  
In our LWE-CP-ABE approach based on blockchain for data access and sharing, it is essential that DU can securely acquire the master secret key MSK without needing to involve a central authority or trusted third party. Thus, we introduce the PRE algorithm with ECC applied in the blockchain network, which acts as a decentralized key management service to carry out the master key distribution for data users. To grant the MSK to DU, DO creates a random symmetric key, encrypts the MSK for DUs, and each node is responsible for securely storing and managing the re-encryption keys or the key shares. DU must collect the fragments until he obtains a threshold, \(t\), number of fragments to re-constructed and decrypt the ciphertext at the DU side. The mathematical details of the LWE-CP-ABE protocol running in KMN and BN are described as follows. Figure 2: System architecture. In the LWE-CP-ABE scheme, the algorithms select the parameters \(n,m,\sigma,q\) and the noise distributions \(\mathcal{X}_{lue}\), \(\mathcal{X}_{l}\), \(\mathcal{X}_{2}\), \(\mathcal{X}_{big}\). For any \(B\in\mathbb{N}\), the notation \(\mathcal{U}_{B}\) represents the uniform distribution \(\mathbb{Z}\cap[-B,B]\). \[ \begin{array}{l}n=\text{play}(\lambda),\sigma<q,n\cdot q/\sigma<2^{n^{\prime}},\mathcal{X}_{lue}=\widetilde{\mathcal{D}}_{\mathbb{Z},\sigma}(for\ LWE\ security)\\ m>2s_{\max}n\log q+\omega\log n+2\lambda(for\ enhanced\ trapdoor\ sampling\ and\ LHL)\\ \sigma>\sqrt{s_{\max}n\log q\log m}+\lambda(for\ enhanced\ trapdoor\ sampling)\\ \mathcal{X}_{1}=\widetilde{\mathcal{D}}_{\mathbb{Z}^{n-1},\sigma},\mathcal{ X}_{2}=\widetilde{\mathcal{D}}_{\mathbb{Z}^{n},\sigma}(for\ enhanced\ trapdoor\ sampling)\\ \mathcal{X}_{big}=\mathcal{U}_{B},\ \hat{B}>(m^{3/2}\sigma+1)2^{\lambda}(for\ smudging/ security)\\ \left|\mathbb{U}\right|\cdot 3m^{3/2}\sigma\hat{B}<q/4(for\ correctness)\end{array} \] (1) System setup. The DO selects the security parameter \(\lambda\) encoded in unary, the maximum width \(s_{\max}\) supported by the LSSS matrix, and the user attribute set \(\mathbb{U}\) associated with the system. The **Setup** algorithm (Algorithm 1) generates the public key PK and the master secret key MSK. Input: the security parameter \(\lambda\), the maximum width \(s_{\max}\) of an LSSS matrix, and the user attribute set supported by the system;  
Output: the PK and the MSK,  
1. _Choose an LWE modulus \(q\), dimensions \(n\), \(m\) and distributions \(\mathcal{X}_{lue}\), \(\mathcal{X}_{1}\), \(\mathcal{X}_{2}\), \(\mathcal{X}_{big}\);_
2. _Choosevector \(\leftarrow\mathbb{Z}_{q}^{n}\) and a matrices \(\{\mathbf{H}_{u}\}_{u\in\mathbb{U}}\leftarrow\mathbb{Z}_{q}^{n\times m}\) ;_
3. \(\mathbf{EnTrapGen}(1^{n},1^{n},q)\rightarrow\{(A_{u},T_{A_{u}})\}\) /* trapdoors computation */  
\[\text{PK}= \begin{pmatrix}n,m,q,\mathcal{X}_{lue},\mathcal{X}_{1},\mathcal{X}_ {2},\mathcal{X}_{big},\mathcal{Y}_{big},\boldsymbol{y},\\ \{A_{u}\}_{u\in\mathbb{U}},\{\mathbf{H}_{u}\}_{u\in\mathbb{U}}\end{pmatrix} \]  
\[\text{MSK}=\{T_{A_{u}}\}_{u\in\mathbb{U}}\]  
**Algorithm 1****Setup**  
The DO sends the transaction and uploads the PK on the blockchain BN. Specifically, all the public information is recorded in the block through the transaction \(Tx_{lplandPK}=\{DO\), \(BN\), \(A\), \(P\), \(Timestamp\), \(PK\), \(Sig_{DO}\), \(\$Coin\)), where \(A\) is the LSSS matrix of access control policy, and \(P\) represents the operation of a publishing contract, \(Timestamp\) is the time stamp of the transaction, \(Sig_{DO}\) is the signature of DO, and \(\$Coin\) is the payment for transaction fee. In addition, DO has the MSK they want to share with the DUs. DO can create a PRE protocol running on the nodes of KMN to grant access to DUs. Therefore, the KMN system still uses pre-quantum cryptography with a cyclic group \(\mathbb{G}\) of prime order \(q\). Let \(g\in\mathbb{G}\) be the generator. Then, DO generates a pair of public and secret keys in the blockchain system.