1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! # Neo SGX Support
//!
//! Support for running Neo blockchain operations in Intel SGX secure enclaves.
//!
//! ## Overview
//!
//! The neo_sgx module provides interfaces for running Neo blockchain operations
//! within Intel SGX (Software Guard Extensions) secure enclaves. This enables:
//!
//! - **Secure Key Management**: Private keys never leave the enclave
//! - **Remote Attestation**: Prove code integrity to remote parties
//! - **Confidential Computing**: Process sensitive data in isolated memory
//! - **Tamper-Resistant Execution**: Protected from privileged software attacks
//!
//! ## Feature Flag
//!
//! This module requires the `sgx` feature flag to be enabled:
//!
//! ```toml
//! [dependencies]
//! neo3 = { version = "0.5", features = ["sgx"] }
//! ```
//!
//! ## Architecture
//!
//! The SGX module is organized into several submodules:
//!
//! - **allocator**: Custom memory allocator for SGX enclaves
//! - **attestation**: Remote attestation and quote verification
//! - **crypto**: Cryptographic operations within the enclave
//! - **enclave**: Enclave lifecycle management
//! - **networking**: Secure network communication from enclaves
//! - **storage**: Sealed storage for persistent data
//!
//! ## Examples
//!
//! ### Initializing SGX Environment
//!
//! ```ignore
//! use neo3::neo_sgx::prelude::*;
//!
//! fn main() -> Result<(), SgxError> {
//! // Initialize the SGX environment
//! init_sgx()?;
//!
//! println!("SGX environment initialized successfully");
//! Ok(())
//! }
//! ```
//!
//! ### Creating a Secure Enclave for Key Management
//!
//! ```ignore
//! use neo3::neo_sgx::prelude::*;
//!
//! fn main() -> Result<(), SgxError> {
//! // Configure the enclave
//! let config = EnclaveConfig::builder()
//! .debug_mode(false)
//! .heap_size(1024 * 1024) // 1MB heap
//! .stack_size(64 * 1024) // 64KB stack
//! .build();
//!
//! // Create the enclave
//! let enclave = SgxEnclave::create(config)?;
//!
//! // Use the enclave for secure operations
//! let key_manager = SgxKeyManager::new(&enclave)?;
//! let keypair = key_manager.generate_keypair()?;
//!
//! println!("Generated secure keypair in enclave");
//! Ok(())
//! }
//! ```
//!
//! ### Remote Attestation
//!
//! ```ignore
//! use neo3::neo_sgx::prelude::*;
//!
//! async fn verify_enclave() -> Result<(), SgxError> {
//! // Create attestation instance
//! let attestation = RemoteAttestation::new()?;
//!
//! // Generate a quote for remote verification
//! let quote = attestation.generate_quote()?;
//!
//! // Send quote to verifier and get attestation result
//! let verifier = QuoteVerifier::new("https://attestation-service.example.com");
//! let result = verifier.verify("e).await?;
//!
//! if result.is_valid() {
//! println!("Enclave attestation successful");
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Security Considerations
//!
//! - Always use release builds for production enclaves
//! - Disable debug mode in production
//! - Regularly update SGX SDK and platform software
//! - Implement proper error handling for attestation failures
//! - Use sealed storage for persistent sensitive data
//!
//! ## Platform Requirements
//!
//! - Intel CPU with SGX support (different generations have different capabilities)
//! - SGX-enabled BIOS settings
//! - Intel SGX SDK installed
//! - Linux with SGX driver or Windows with SGX PSW
extern crate sgx_tstd as std;
use *;
pub use SgxAllocator;
pub use SgxCrypto;
pub use SgxEnclave;
pub use SgxNetworking;
/// Initialize SGX environment
/// SGX-specific error types
/// Re-export commonly used SGX types