# A Security-Oriented Data-Sharing Scheme Based on Blockchain
## 3 A Security-Oriented Data-Sharing Scheme Based on Blockchain
### Formal Model
#### 3.2.2 Lightweight On-Chain/Off-Chain Cooperative Data Security Algorithm Based on ECC and ECDHE  
The hybrid on-chain/off-chain storage paradigm facilitates efficient data sharing. However, a vulnerability exists in the exposure of plaintext hashes of original data storage addresses on the blockchain, which could lead to data leakage. To address this, our scheme integrates Elliptic Curve Cryptography (ECC) and Elliptic Curve Diffie-Hellman Ephemeral (ECDHE) algorithms to enhance security. This integrated approach ensures data integrity and confidentiality via a comprehensive security algorithm that operates across both on-chain and off-chain environments. Elliptic Curve Cryptography (ECC) is an asymmetric cryptographic algorithm that provides strong security with smaller key sizes than RSA, allowing for quicker cryptographic operations without compromising security. Meanwhile, this scheme uses the ECDHE key negotiation algorithm, enabling the data owner \(u_{i}\) and the data demander \(u_{j}\) to jointly compute an identical negotiated key value for subsequent communication simply by transmitting their respective public keys. The Elliptic Curve Diffie-Hellman Ephemeral (ECDHE) key exchange protocol secures the negotiated key against unauthorized interception, ensuring confidentiality and integrity. It generates ephemeral, session-specific keys, guaranteeing that each session's data are encrypted with a unique key. The transient nature of these keys prevents third parties from decrypting past session data, even if they have accessed a particular key. Furthermore, the protocol's periodic renegotiation or key updates in response to specific events sustain forward security while preserving the security of historical data. This hybrid encryption and decryption framework combines Elliptic Curve Cryptography (ECC) with Elliptic Curve Diffie-Hellman Ephemeral (ECDHE), employing AES-GCMto encrypt the hashed file storage address using a shared key dynamically generated by ECDHE. ECDHE ensures a unique shared key for each communication session, with key pairs being ephemeral and stored in memory. Consequently, even if a private key is exposed, the compromise is limited to the current session, thereby protecting the confidentiality of future communications and ensuring forward security. To enhance security, after negotiating the shared key, the two private keys of the data owner \(u_{i}\) and the data demander \(u_{j}\) can be discarded, which further improves the security. The flow of this encryption algorithm is illustrated in Figure 3.  
As shown in Figure 3, a suitable elliptic curve type is selected to generate a public-private key pair for the data owner \(u_{i}\) and the data demander \(u_{j}\). The data owner \(u_{i}\) selects a random number \(d_{u_{i}}\) as the private key. After generating the private key, \(u_{i}\) uses the private key and the selected base point parameter \(G\) to generate the public key \(P_{u_{i}}\) as follows:  
\[P_{u_{i}}=d_{u_{i}}G \tag{3}\]  
Once the data demander \(u_{j}\) generates the private key \(d_{u_{j}}\) and the public key \(P_{u_{j}}\) in the same way, it proceeds to compute the session key. After generating the public and private keys, the two users exchange their respective public keys. Then, the data owner \(u_{i}\) computes the point \((x_{1},y_{1})=d_{u_{i}}P_{u_{j}}\), and the data demander \(u_{j}\) computes the point \((x_{2},y_{2})=d_{u_{j}}P_{u_{j}}\). Due to the law of multiplicative exchange and union on elliptic curves, it holds that \(d_{u_{i}}P_{u_{j}}=d_{u_{i}}d_{u_{j}}G=d_{u_{j}}d_{u_{i}}G{=}d_{u_{j}}P_{u_{i}}\). Therefore, the \(x\)-coordinate obtained by both parties is the same, making it the shared key \(S\), which serves as the session key. After obtaining the shared key, the plaintext content \(M\) (the hash value of the original file storage address) is encrypted with AES-GCM, as shown in Algorithm 2.