## 4 ACE and Blockchain-Based IoT Knowledge Sharing Scheme
### Multi-Level ACE-Based IoT Knowledge Sharing Algorithm  
We implement a multi-level IoT knowledge sharing scheme based on the ACE algorithm [19]. We define ACE\({}^{n}\) as an access control encryption algorithm with \(n\) security levels. The construction of ACE\({}^{1}\) is as follows:  
**Setup. ** With the security parameter \(\lambda\), this algorithm produces the public parameter \(pp=(G,g,q,h)\) and the master secret key \(msk=(\alpha,\beta)\), where \(\alpha,\beta\in\mathbb{Z}_{p}\) is randomly selected. The message space \(M=G\). The ciphertext spaces for the sender and the sanitizer are C and C\({}^{\prime}\), respectively. The details are shown as follows. * Define a cyclic group \(G=\langle g\rangle\) with prime order \(q\). * Compute \(h=g^{\beta}\). **KeyGen. ** Input master secret key \(msk\), algorithm outputs encryption key \(ek\), decryption key \(dk\), and sanitizer key \(rk\):  
\[ek=\alpha,dk=-\beta,rk=-\alpha. \tag{1}\] \begin{table}
\begin{tabular}{c c c c} \hline
**Role** & **Level 1 Receiver** & **Level 2 Receiver** & **Level 3 Receiver** \\ \hline Level 1 Sender & ✓ & \(\times\) & \(\times\) \\ Level 2 Sender & ✓ & ✓ & \(\times\) \\ Level 3 Sender & ✓ & ✓ & ✓ \\ \hline \hline \(\checkmark\): Communicable. \(\times\): Non-Communicable. & & & \\ \end{tabular}
\end{table} 
Table 1: Access control policy of IoT knowledge sharing. **Enc. ** Once input an encryption key \(ek\) and a message \(m\), the algorithm selects \(s_{1},s_{2}\in\mathbb{Z}_{q}\) randomly and computes the ciphertext \(c=(c_{1},c_{2},c_{3},c_{4})\in C\):  
\[c_{1}=g^{s_{1}},c_{2}=g^{s_{2}},c_{3}=g^{ck}h^{s_{1}},c_{4}=mh^{s_{2}}. \tag{2}\]  
**San. ** Once a ciphertext \(c=(c_{1},c_{2},c_{3},c_{4})\in C\) and a sanitizer key \(rk\) are input, the algorithm randomly selects \(r_{1},r_{2}\in\mathbb{Z}_{q}\) and computes the sanitizer ciphertext \(c^{\prime}=\left(c^{\prime}_{1},c^{\prime}_{2}\right)\in C^{\prime}\):  
\[c^{\prime}_{1}=c_{2}c^{r_{1}}_{1}g^{r_{2}},c^{\prime}_{2}=c_{4}(g^{rk}c_{3})^ {r_{1}}h^{r_{2}}. \tag{3}\]  
**Dec.** Once a sanitizer ciphertext \(c^{\prime}=\left(c^{\prime}_{1},c^{\prime}_{2}\right)\in C^{\prime}\) and a decryption key \(dk\) are input, the algorithm recovers a message:  
\[m^{\prime}=c^{\prime}_{2}\big{(}c^{\prime}_{1}\big{)}^{dk}. \tag{4}\]  
Next, we formulate a multi-level IoT knowledge sharing scheme based on ACE1. The idea is to execute the ACE1 algorithm \(n\) times and distribute \(n\) decryption keys to the receivers of the \(n\) security levels. A sender's key comprises a set of the corresponding encryption keys determined by the access policy \(P(i,j)=1\). Each message consists of \(n\) parts, encompassing ciphertext and random numbers. The sender encrypts information using all available keys, placing random numbers where encryption keys are unknown. After receiving the message, the sanitizer processes each part of the message with the sanitizer key and broadcasts the sanitized message to all receivers. A receiver decrypts the part corresponding to its security level using its decryption key to obtain the knowledge. Table 2 illustrates the key and ciphertext structure for a three-security-level system. The table also includes decryption results for the ciphertext when the receiver and sender share the same level. \(R_{12}\), \(R_{13}\), \(R_{23}\) represent the random ciphertext from \(C\). The algorithm ACE\({}^{n}\) is defined as follows:  
Footnote 1: The code is available at [[http://www.cs.uc.edu/~ciao/](http://www.cs.uc.edu/~ciao/)]([http://www.cs.uc.edu/~ciao/](http://www.cs.uc.edu/~ciao/))  
**Setup. ** Given the security parameter \(\lambda\) and access policy \(P:[n]\times[n]\rightarrow\{0,1\}\), this algorithm runs \(n\) copies of the ACE\({}^{1}\).\(Setup\) algorithm and output the public parameter \(pp=\{pp^{1}_{i}\}_{i\in[1,n]}\). The master secret key \(msk=\{ek^{1}_{i},dk^{1}_{i},rk^{1}_{i}\}_{i\in[1,n]}\):  
\[