├── CEE.tar.gz ├── CEE ├── .cproject ├── .project ├── Makefile ├── README.txt ├── isv_app │ ├── isv_app.cpp │ ├── operations.cpp │ ├── operations.h │ ├── refTxGen.js │ ├── refTxGen_realmoney.js │ ├── sample_messages.h │ ├── svm-train.c │ ├── svm.h │ ├── txEncode.js │ ├── txRLP_hash.txt │ ├── txRawHex.txt │ ├── txSend.js │ ├── txSignature_r.txt │ ├── txSignature_s.txt │ └── txSignature_v.txt ├── isv_enclave │ ├── Edger8rSyntax │ │ ├── Arrays.cpp │ │ ├── Arrays.edl │ │ ├── Functions.cpp │ │ ├── Functions.edl │ │ ├── Pointers.cpp │ │ ├── Pointers.edl │ │ ├── Types.cpp │ │ └── Types.edl │ ├── TrustedLibrary │ │ ├── Libc.cpp │ │ ├── Libc.edl │ │ ├── Libcxx.cpp │ │ ├── Libcxx.edl │ │ ├── Thread.cpp │ │ └── Thread.edl │ ├── asm_avr.inc │ ├── asm_avr_mult_square.inc │ ├── curve-specific.inc │ ├── enclave_fann.cpp │ ├── enclave_keccak.cpp │ ├── enclave_svm.cpp │ ├── enclave_utilities.cpp │ ├── ethers.h │ ├── include │ │ ├── enclave_utilities.h │ │ ├── fann │ │ │ ├── CMakeFiles │ │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ │ └── progress.marks │ │ │ ├── CMakeLists.txt │ │ │ ├── Makefile │ │ │ ├── cmake_install.cmake │ │ │ ├── config.h │ │ │ ├── doublefann.h │ │ │ ├── fann.h │ │ │ ├── fann_activation.h │ │ │ ├── fann_cascade.h │ │ │ ├── fann_cpp.h │ │ │ ├── fann_data.h │ │ │ ├── fann_data_cpp.h │ │ │ ├── fann_error.h │ │ │ ├── fann_internal.h │ │ │ ├── fann_io.h │ │ │ ├── fann_train.h │ │ │ ├── fann_training_data_cpp.h │ │ │ ├── fixedfann.h │ │ │ ├── floatfann.h │ │ │ ├── parallel_fann.h │ │ │ └── parallel_fann.hpp │ │ ├── keccak.h │ │ ├── secp256k1.h │ │ ├── secp256k1_ecdh.h │ │ ├── secp256k1_recovery.h │ │ └── svm.h │ ├── isv_enclave.config.xml │ ├── isv_enclave.cpp │ ├── isv_enclave.edl │ ├── isv_enclave.lds │ ├── isv_enclave_private.pem │ ├── keccak256.h │ ├── platform-specific.inc │ ├── types.h │ ├── uECC.h │ └── uECC_vli.h ├── sample_libcrypto │ ├── libsample_libcrypto.so │ └── sample_libcrypto.h └── service_provider │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── remote_attestation_result.h │ ├── service_provider.cpp │ └── service_provider.h ├── CEE_old ├── .cproject ├── .project ├── Makefile ├── README.md ├── README.txt ├── isv_app │ ├── isv_app.cpp │ ├── operations.cpp │ ├── operations.h │ ├── refTxGen.js │ ├── refTxGen_realmoney.js │ ├── sample_messages.h │ ├── svm-train.c │ ├── svm.h │ ├── txEncode.js │ ├── txRLP_hash.txt │ ├── txRawHex.txt │ ├── txSend.js │ ├── txSignature_r.txt │ ├── txSignature_s.txt │ └── txSignature_v.txt ├── isv_enclave │ ├── Edger8rSyntax │ │ ├── Arrays.cpp │ │ ├── Arrays.edl │ │ ├── Functions.cpp │ │ ├── Functions.edl │ │ ├── Pointers.cpp │ │ ├── Pointers.edl │ │ ├── Types.cpp │ │ └── Types.edl │ ├── TrustedLibrary │ │ ├── Libc.cpp │ │ ├── Libc.edl │ │ ├── Libcxx.cpp │ │ ├── Libcxx.edl │ │ ├── Thread.cpp │ │ └── Thread.edl │ ├── asm_avr.inc │ ├── asm_avr_mult_square.inc │ ├── curve-specific.inc │ ├── ethers.h │ ├── include │ │ ├── secp256k1.h │ │ ├── secp256k1_ecdh.h │ │ ├── secp256k1_recovery.h │ │ └── svm.h │ ├── isv_enclave.config.xml │ ├── isv_enclave.cpp │ ├── isv_enclave.edl │ ├── isv_enclave.lds │ ├── isv_enclave_private.pem │ ├── keccak256.h │ ├── platform-specific.inc │ ├── types.h │ ├── uECC.h │ └── uECC_vli.h ├── sample_libcrypto │ └── sample_libcrypto.h └── service_provider │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── remote_attestation_result.h │ ├── service_provider.cpp │ └── service_provider.h ├── CloudStorage └── Reserved_ML_Data │ ├── 101.txt │ ├── 102.txt │ ├── DO1_1.txt │ ├── DO1_10.txt │ ├── DO1_11.txt │ ├── DO1_12.txt │ ├── DO1_13.txt │ ├── DO1_14.txt │ ├── DO1_15.txt │ ├── DO1_16.txt │ ├── DO1_17.txt │ ├── DO1_18.txt │ ├── DO1_19.txt │ ├── DO1_2.txt │ ├── DO1_20.txt │ ├── DO1_21.txt │ ├── DO1_22.txt │ ├── DO1_23.txt │ ├── DO1_24.txt │ ├── DO1_25.txt │ ├── DO1_26.txt │ ├── DO1_27.txt │ ├── DO1_28.txt │ ├── DO1_29.txt │ ├── DO1_3.txt │ ├── DO1_30.txt │ ├── DO1_31.txt │ ├── DO1_32.txt │ ├── DO1_33.txt │ ├── DO1_34.txt │ ├── DO1_35.txt │ ├── DO1_36.txt │ ├── DO1_37.txt │ ├── DO1_38.txt │ ├── DO1_39.txt │ ├── DO1_4.txt │ ├── DO1_40.txt │ ├── DO1_5.txt │ ├── DO1_6.txt │ ├── DO1_7.txt │ ├── DO1_8.txt │ ├── DO1_9.txt │ ├── adult.txt │ ├── digits.png │ └── heart_scale ├── Contracts ├── DataBroker_v1.js ├── DataBroker_v1.sol ├── DataBroker_v2.js ├── DataBroker_v2.sol ├── DataBroker_v3.js ├── DataBroker_v3.sol ├── DataOwner_v1.js ├── DataOwner_v1.sol ├── DataOwner_v2.js ├── DataOwner_v2.sol ├── DataOwner_v3.js ├── DataOwner_v3.sol ├── DistributeFund.js ├── DistributeFund.sol ├── DistributeFund_2.js ├── DistributeFund_2.sol └── HowToDeploy&AccessContract.md ├── DataBroker ├── App │ ├── app.cpp │ ├── attestation_service.cpp │ ├── attestation_service.h │ ├── clientdata_operation.cpp │ ├── clientdata_operation.h │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── operations.cpp │ ├── operations.h │ ├── remote_attestation_result.h │ ├── txCheckContract.js │ └── txSendDirectly.js ├── Enclave │ ├── Edger8rSyntax │ │ ├── Arrays.cpp │ │ ├── Arrays.edl │ │ ├── Functions.cpp │ │ ├── Functions.edl │ │ ├── Pointers.cpp │ │ ├── Pointers.edl │ │ ├── Types.cpp │ │ └── Types.edl │ ├── TrustedLibrary │ │ ├── Libc.cpp │ │ ├── Libc.edl │ │ ├── Libcxx.cpp │ │ ├── Libcxx.edl │ │ ├── Thread.cpp │ │ └── Thread.edl │ ├── asm_avr.inc │ ├── asm_avr_mult_square.inc │ ├── curve-specific.inc │ ├── enclave.config.xml │ ├── enclave.cpp │ ├── enclave.edl │ ├── enclave.lds │ ├── enclave_private.pem │ ├── ethers.h │ ├── include │ │ ├── secp256k1.h │ │ ├── secp256k1_ecdh.h │ │ ├── secp256k1_recovery.h │ │ └── svm.h │ ├── keccak256.h │ ├── platform-specific.inc │ ├── types.h │ ├── uECC.h │ └── uECC_vli.h ├── Makefile └── sample_libcrypto │ ├── libsample_libcrypto.so │ └── sample_libcrypto.h ├── DataConsumer ├── App │ ├── Datause.sol │ ├── app.cpp │ ├── attestation_service.cpp │ ├── attestation_service.h │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── keccak.cpp │ ├── keccak.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── operations.cpp │ ├── operations.h │ ├── remote_attestation_result.h │ └── txSendDirectly.js ├── Makefile └── sample_libcrypto │ ├── libsample_libcrypto.so │ ├── sample_libcrypto.h │ └── txGenSend.js ├── DataOwner ├── App │ ├── DO_sim.h │ ├── app.cpp │ ├── attestation_service.cpp │ ├── attestation_service.h │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── operations.cpp │ ├── operations.h │ ├── remote_attestation_result.h │ └── txSendDirectly.js ├── DataFiles │ └── Reserved_ML_Data │ │ ├── adult.txt │ │ ├── digits.png │ │ └── heart_scale ├── Makefile ├── process_adult_data.py └── sample_libcrypto │ ├── libsample_libcrypto.so │ ├── sample_libcrypto.h │ └── txGenSend.js ├── DataOwner_group ├── App │ ├── DO_sim.h │ ├── app.cpp │ ├── attestation_service.cpp │ ├── attestation_service.h │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── operations.cpp │ ├── operations.h │ ├── remote_attestation_result.h │ └── txSendDirectly.js ├── DataFiles │ └── Reserved_ML_Data │ │ ├── adult.txt │ │ ├── digits.png │ │ └── heart_scale ├── Makefile ├── process_adult_data.py └── sample_libcrypto │ ├── libsample_libcrypto.so │ ├── sample_libcrypto.h │ └── txGenSend.js ├── Enclave_testML ├── .cproject ├── .project ├── Makefile ├── README.txt ├── isv_app │ ├── enclave_keccak.cpp │ ├── isv_app.cpp │ ├── keccak.h │ ├── operations.cpp │ ├── operations.h │ ├── refTxGen.js │ ├── refTxGen_realmoney.js │ ├── sample_messages.h │ ├── txEncode.js │ ├── txRLP_hash.txt │ ├── txRawHex.txt │ ├── txSend.js │ ├── txSignature_r.txt │ ├── txSignature_s.txt │ └── txSignature_v.txt ├── isv_enclave │ ├── Edger8rSyntax │ │ ├── Arrays.cpp │ │ ├── Arrays.edl │ │ ├── Functions.cpp │ │ ├── Functions.edl │ │ ├── Pointers.cpp │ │ ├── Pointers.edl │ │ ├── Types.cpp │ │ └── Types.edl │ ├── TrustedLibrary │ │ ├── Libc.cpp │ │ ├── Libc.edl │ │ ├── Libcxx.cpp │ │ ├── Libcxx.edl │ │ ├── Thread.cpp │ │ └── Thread.edl │ ├── asm_avr.inc │ ├── asm_avr_mult_square.inc │ ├── curve-specific.inc │ ├── enclave_fann.cpp │ ├── enclave_keccak.cpp │ ├── enclave_svm.cpp │ ├── enclave_utilities.cpp │ ├── ethers.h │ ├── include │ │ ├── enclave_utilities.h │ │ ├── fann │ │ │ ├── CMakeFiles │ │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ │ └── progress.marks │ │ │ ├── CMakeLists.txt │ │ │ ├── Makefile │ │ │ ├── cmake_install.cmake │ │ │ ├── config.h │ │ │ ├── doublefann.h │ │ │ ├── fann.h │ │ │ ├── fann_activation.h │ │ │ ├── fann_cascade.h │ │ │ ├── fann_cpp.h │ │ │ ├── fann_data.h │ │ │ ├── fann_data_cpp.h │ │ │ ├── fann_error.h │ │ │ ├── fann_internal.h │ │ │ ├── fann_io.h │ │ │ ├── fann_train.h │ │ │ ├── fann_training_data_cpp.h │ │ │ ├── fixedfann.h │ │ │ ├── floatfann.h │ │ │ ├── parallel_fann.h │ │ │ └── parallel_fann.hpp │ │ ├── keccak.h │ │ ├── secp256k1.h │ │ ├── secp256k1_ecdh.h │ │ ├── secp256k1_recovery.h │ │ └── svm.h │ ├── isv_enclave.config.xml │ ├── isv_enclave.cpp │ ├── isv_enclave.edl │ ├── isv_enclave.lds │ ├── isv_enclave_private.pem │ ├── platform-specific.inc │ ├── types.h │ ├── uECC.h │ └── uECC_vli.h ├── process_adult_data.py ├── sample_libcrypto │ ├── libsample_libcrypto.so │ └── sample_libcrypto.h └── service_provider │ ├── ecp.cpp │ ├── ecp.h │ ├── ias_ra.cpp │ ├── ias_ra.h │ ├── network_ra.cpp │ ├── network_ra.h │ ├── remote_attestation_result.h │ ├── service_provider.cpp │ └── service_provider.h ├── Eval&Tools ├── Config.md ├── ExpData.ods ├── attestationTimes-a.png ├── attestationTimes-b.png ├── attestationTimes-new.png ├── computationRuntimes.png ├── contractCallTimes.png ├── costCallingDBContract.png ├── createDataOwnerContracts_batch.js ├── getPrivateKeyLocally.js ├── getPrivateKeyLocally_batch.js ├── plot_attest_time.py ├── plot_comp_time.py ├── plot_contract_call_time.py ├── plot_cost.py ├── plot_total_cost.py └── totalCostCallingContract.png ├── Intel ├── client.cnf ├── client.crt ├── client.key ├── client.pfx ├── client.req ├── server.crt └── server.key ├── LICENSE ├── README.md ├── allmake.sh ├── cleanmake.sh └── iDataAgent ├── App ├── app.cpp ├── attestation_service.cpp ├── attestation_service.h ├── clientdata_operation.cpp ├── clientdata_operation.h ├── ecp.cpp ├── ecp.h ├── ias_ra.cpp ├── ias_ra.h ├── network_ra.cpp ├── network_ra.h ├── operations.cpp ├── operations.h ├── remote_attestation_result.h ├── txCheckContract.js └── txSendDirectly.js ├── Enclave ├── Edger8rSyntax │ ├── Arrays.cpp │ ├── Arrays.edl │ ├── Functions.cpp │ ├── Functions.edl │ ├── Pointers.cpp │ ├── Pointers.edl │ ├── Types.cpp │ └── Types.edl ├── TrustedLibrary │ ├── Libc.cpp │ ├── Libc.edl │ ├── Libcxx.cpp │ ├── Libcxx.edl │ ├── Thread.cpp │ └── Thread.edl ├── asm_avr.inc ├── asm_avr_mult_square.inc ├── curve-specific.inc ├── enclave.config.xml ├── enclave.cpp ├── enclave.edl ├── enclave.lds ├── enclave_private.pem ├── ethers.h ├── include │ ├── secp256k1.h │ ├── secp256k1_ecdh.h │ ├── secp256k1_recovery.h │ └── svm.h ├── keccak256.h ├── platform-specific.inc ├── types.h ├── uECC.h └── uECC_vli.h ├── Makefile └── sample_libcrypto ├── libsample_libcrypto.so └── sample_libcrypto.h /CEE.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE.tar.gz -------------------------------------------------------------------------------- /CEE/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RemoteAttestation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | org.eclipse.cdt.core.ccnature 26 | com.intel.sgx.sgxnature 27 | 28 | 29 | -------------------------------------------------------------------------------- /CEE/README.txt: -------------------------------------------------------------------------------- 1 | ---------------------------- 2 | Purpose of RemoteAttestation 3 | ---------------------------- 4 | The project demonstrates: 5 | - How an application enclave can attest to a remote party 6 | - How an application enclave and the remote party can establish a secure session 7 | 8 | ------------------------------------ 9 | How to Build/Execute the Sample Code 10 | ------------------------------------ 11 | 1. Install Intel(R) SGX SDK for Linux* OS 12 | 2. Build the project with the prepared Makefile: 13 | a. Hardware Mode, Debug build: 14 | $ make 15 | b. Hardware Mode, Pre-release build: 16 | $ make SGX_PRERELEASE=1 SGX_DEBUG=0 17 | c. Hardware Mode, Release build: 18 | $ make SGX_DEBUG=0 19 | d. Simulation Mode, Debug build: 20 | $ make SGX_MODE=SIM 21 | e. Simulation Mode, Pre-release build: 22 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 23 | f. Simulation Mode, Release build: 24 | $ make SGX_MODE=SIM SGX_DEBUG=0 25 | 3. Execute the binary directly: 26 | $ ./app 27 | 4. Remember to "make clean" before switching build mode 28 | -------------------------------------------------------------------------------- /CEE/isv_app/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENCLAVE_OPERATION_H_ 2 | #define _ENCLAVE_OPERATION_H_ 3 | 4 | 5 | #include "isv_enclave_u.h" 6 | #include "sgx_urts.h" 7 | #include "sgx_uae_service.h" 8 | #include "remote_attestation_result.h" 9 | 10 | #if defined(__cplusplus) 11 | extern "C" { 12 | #endif 13 | 14 | #define AESGCM_KEY_SIZE 16 15 | #define AESGCM_MAC_SIZE 16 16 | #define KECCAK_HASH_SIZE 32 17 | 18 | #define TASK1_RESULT_SIZE 4 // Bytes. Summation of single digits 19 | #define TASK2_RESULT_SIZE 1000 // Bytes. SVM model 20 | #define TASK3_RESULT_SIZE 10000 // Bytes. ANN model 21 | 22 | 23 | 24 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/ 25 | typedef enum _op_msg_type_t 26 | { 27 | TYPE_OP_AUTH, // Authentication message 28 | TYPE_OP_COMP_RES, // computation result message 29 | }op_msg_type_t; 30 | 31 | typedef struct _enclave_info_t{ 32 | sgx_enclave_id_t enclave_id; 33 | sgx_ra_context_t context; 34 | uint32_t extended_epid_group_id; 35 | }enclave_info_t; 36 | 37 | typedef struct _auth_msg_header_t{ 38 | uint8_t type; 39 | uint8_t challenger_type; 40 | }auth_msg_header_t; 41 | 42 | typedef struct _K_result_msg_t{ // to iDA/DB 43 | int DO_ID; 44 | int file_num; 45 | uint8_t K_result_en[AESGCM_KEY_SIZE]; 46 | uint8_t K_result_mac[AESGCM_MAC_SIZE]; 47 | }K_result_msg_t; 48 | 49 | typedef struct _K_result_hash_msg_t{ // to DC 50 | int DO_ID; 51 | int file_num; 52 | uint8_t K_result_hash_en[KECCAK_HASH_SIZE]; 53 | uint8_t K_result_hash_mac[AESGCM_MAC_SIZE]; 54 | uint8_t C_result_hash_en[KECCAK_HASH_SIZE]; // Hash of the encrypted result 55 | uint8_t C_result_hash_mac[AESGCM_MAC_SIZE]; 56 | }K_result_hash_msg_t; 57 | 58 | typedef struct _operation_config_msg_t{ 59 | int DC_ID; 60 | int type; 61 | int start; 62 | int end; 63 | int operation; 64 | }operation_config_msg_t; 65 | 66 | bool enclave_init(enclave_info_t* enclave_info); 67 | 68 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info); 69 | int remote_attest_enclave_parallel(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info_original); 70 | 71 | int enclave_close(enclave_info_t* enclave_info); 72 | 73 | int enclave_compute_task(enclave_info_t* enclave_info, int Request_DC, int Request_type, int Request_start, int Request_end, int Request_operation); 74 | 75 | int send_K_result_msgs(enclave_info_t* enclave_info, int sock_iDA_DB, int sock_DC); 76 | 77 | // Produce an off-line transaction that invokes the record() function in the contract 78 | // The transaction is marshalled outside the enclave but signed inside enclave 79 | int record_datause(enclave_info_t* enclave_info, char* contract_addr); 80 | 81 | 82 | #if defined(__cplusplus) 83 | } 84 | #endif 85 | #endif -------------------------------------------------------------------------------- /CEE/isv_app/refTxGen.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | // var privateKey = '0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de'; 9 | // var publicKey = util.bufferToHex(util.privateToPublic(privateKey)); 10 | // console.log(publicKey); 11 | // var address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); //0x53ae893e4b22d707943299a8d0c844df0e3d5557 12 | 13 | 14 | var rawTx = { 15 | nonce: web3.utils.numberToHex('0'), 16 | gasPrice: web3.utils.numberToHex('20000000000'), 17 | gasLimit: web3.utils.numberToHex('100000'), 18 | to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85', 19 | value: web3.utils.numberToHex('0'), 20 | data: '0xc0de' 21 | }; 22 | var p = new Buffer('c0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de', 'hex'); 23 | 24 | 25 | var transaction = new tx(rawTx); 26 | 27 | // console.log('0x' + transaction.serialize().toString('hex')); 28 | 29 | console.log('\nTransaction cefore signing:\n', transaction); 30 | 31 | transaction.sign(p); // This step needs to be done in the enclave 32 | 33 | console.log('\nTransaction after signing:\n', transaction); 34 | 35 | // console.log('from: '+ transaction.from.toString('hex')); 36 | 37 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 38 | 39 | // // Send the raw transaction hex 40 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 41 | // if (err) { 42 | // console.log(err); 43 | // } 44 | // else { 45 | // console.log(hash); 46 | // } 47 | // }); 48 | 49 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 50 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 51 | console.log('\n- Transaction hash:\n' + txHash); -------------------------------------------------------------------------------- /CEE/isv_app/txEncode.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | var RLP = require('rlp'); 6 | var fs = require("fs"); 7 | 8 | // console.log(process.argv); 9 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 10 | 11 | var argv = process.argv; 12 | 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | } 18 | else { 19 | var txCount = res; 20 | var nonce = ''; 21 | var value = ''; 22 | if(txCount != 0){ 23 | nonce = web3.utils.numberToHex(txCount); 24 | } 25 | if(argv[5] != '0'){ 26 | value = web3.utils.numberToHex(argv[5]); 27 | } 28 | 29 | var txNake = [ 30 | nonce, 31 | web3.utils.numberToHex(argv[2]), 32 | web3.utils.numberToHex(argv[3]), 33 | argv[4], 34 | value, 35 | argv[6] 36 | ]; 37 | 38 | var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 39 | var txRLP_hash = util.sha3(txSixFieldRLP); 40 | 41 | 42 | // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 43 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 44 | 45 | fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 46 | if (err) { 47 | return console.error(err); 48 | } 49 | }); 50 | } 51 | }); 52 | 53 | 54 | 55 | 56 | // var nonce = null; 57 | // if(argv[2] != '0'){ 58 | // nonce = web3.utils.numberToHex(argv[2]); 59 | // } 60 | 61 | // var txNake = [ 62 | // nonce, 63 | // web3.utils.numberToHex(argv[3]), 64 | // web3.utils.numberToHex(argv[4]), 65 | // argv[5], 66 | // web3.utils.numberToHex(argv[6]), 67 | // argv[7] 68 | // ]; 69 | 70 | // var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 71 | // var txRLP_hash = util.sha3(txSixFieldRLP); 72 | 73 | 74 | // // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 75 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 76 | 77 | // fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 78 | // if (err) { 79 | // return console.error(err); 80 | // } 81 | // }); 82 | -------------------------------------------------------------------------------- /CEE/isv_app/txRLP_hash.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txRLP_hash.txt -------------------------------------------------------------------------------- /CEE/isv_app/txRawHex.txt: -------------------------------------------------------------------------------- 1 | 0xf87840843b9aca0083030d4094992d8b41e547d40920172e5369fe0fa0d769bc5c80947bd780c747a35fd12a5454ecb45065f77df87f271ca0a8a12781ee4d8212c033c165c69f5c8650c3b7815a60eeba2093c9db4a3d6a70a0451484ba4f28e734b388779d03294a96bc18ab4e791294143564ff7263266f11 -------------------------------------------------------------------------------- /CEE/isv_app/txSend.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | // var tx = require('ethereumjs-tx'); 6 | var RLP = require('rlp'); 7 | var fs = require("fs"); 8 | 9 | // console.log(process.argv); 10 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 11 | var argv = process.argv; 12 | 13 | var data; 14 | 15 | data = fs.readFileSync('isv_app/txSignature_v.txt'); 16 | var txSignature_v = util.bufferToHex(data).toString(); 17 | 18 | data = fs.readFileSync('isv_app/txSignature_r.txt'); 19 | var txSignature_r = util.bufferToHex(data).toString(); 20 | 21 | data = fs.readFileSync('isv_app/txSignature_s.txt'); 22 | var txSignature_s = util.bufferToHex(data).toString(); 23 | 24 | 25 | web3.eth.getTransactionCount(address).then(function (res, err){ 26 | if (err) { 27 | console.log('error: ' + err); 28 | } 29 | else { 30 | var txCount = res; 31 | var nonce = ''; 32 | var value = ''; 33 | if(txCount != 0){ 34 | nonce = web3.utils.numberToHex(txCount); 35 | } 36 | if(argv[5] != '0'){ 37 | value = web3.utils.numberToHex(argv[5]); 38 | } 39 | 40 | var txFull = [ 41 | nonce, 42 | web3.utils.numberToHex(argv[2]), 43 | web3.utils.numberToHex(argv[3]), 44 | argv[4], 45 | value, 46 | argv[6], 47 | txSignature_v, 48 | txSignature_r, 49 | txSignature_s 50 | ]; 51 | 52 | // console.log(txFull); 53 | 54 | var txRawHex = util.bufferToHex(RLP.encode(txFull)); 55 | 56 | console.log('\ntxRawHex: \n' + txRawHex); 57 | 58 | // Send the raw transaction hex 59 | console.log('\nTxHash: '); 60 | 61 | // web3.eth.sendSignedTransaction(txRawHex, function (err, hash) { 62 | // if (err) { 63 | // console.log(err); 64 | // } 65 | // else { 66 | // console.log(hash); 67 | // } 68 | // }); 69 | 70 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 71 | 72 | // Write the raw transaction hex into a file which may be used later 73 | fs.writeFile('isv_app/txRawHex.txt', txRawHex, function(err) { 74 | if (err) { 75 | return console.error(err); 76 | } 77 | }); 78 | } 79 | }); -------------------------------------------------------------------------------- /CEE/isv_app/txSignature_r.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txSignature_r.txt -------------------------------------------------------------------------------- /CEE/isv_app/txSignature_s.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/isv_app/txSignature_s.txt -------------------------------------------------------------------------------- /CEE/isv_app/txSignature_v.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /CEE/isv_enclave/TrustedLibrary/Libc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | #include 34 | #include "sgx_cpuid.h" 35 | 36 | #include "sgx_trts.h" 37 | #include "../Enclave.h" 38 | #include "Enclave_t.h" 39 | 40 | /* ecall_malloc_free: 41 | * Uses malloc/free to allocate/free trusted memory. 42 | */ 43 | void ecall_malloc_free(void) 44 | { 45 | void *ptr = malloc(100); 46 | assert(ptr != NULL); 47 | memset(ptr, 0x0, 100); 48 | free(ptr); 49 | } 50 | 51 | /* ecall_sgx_cpuid: 52 | * Uses sgx_cpuid to get CPU features and types. 53 | */ 54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf) 55 | { 56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); 57 | if (ret != SGX_SUCCESS) 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /CEE/isv_enclave/TrustedLibrary/Libc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libc.edl - EDL sample for trusted C library. */ 34 | 35 | enclave { 36 | 37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex; 38 | 39 | /* 40 | * A subset of the C99 standard is supported as well as SGX customized functions: 41 | * sgx_cpuid, etc. 42 | */ 43 | 44 | trusted { 45 | /* 46 | * Utilize malloc/free in enclave. 47 | */ 48 | public void ecall_malloc_free(void); 49 | 50 | /* 51 | * Utilize SGX version __cpuid() in enclave. 52 | */ 53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf); 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /CEE/isv_enclave/TrustedLibrary/Libcxx.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libcxx.edl - EDL sample for trusted C++ library. */ 34 | 35 | enclave { 36 | 37 | /* 38 | * A subset of the C++03 standard is supported. 39 | */ 40 | 41 | trusted { 42 | /* 43 | * Throw/catch exception inside the enclave. 44 | */ 45 | public void ecall_exception(void); 46 | 47 | /* 48 | * Utilize inside the enclave. 49 | */ 50 | public void ecall_map(void); 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /CEE/isv_enclave/TrustedLibrary/Thread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* Thread.edl - EDL sample for trusted thread library. */ 33 | 34 | enclave { 35 | 36 | from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; 37 | 38 | trusted { 39 | /* 40 | * Use SGX mutex. 41 | */ 42 | public size_t ecall_increase_counter(); 43 | 44 | /* 45 | * Use SGX condition variables. 46 | */ 47 | public void ecall_producer(); 48 | public void ecall_consumer(); 49 | 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/enclave_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENCLAVE_UTILITIES_H 2 | #define _ENCLAVE_UTILITIES_H 3 | 4 | #define LIBSVM_VERSION 323 5 | 6 | #include "sgx_tkey_exchange.h" 7 | #include "sgx_tcrypto.h" 8 | #include "sgx_trts.h" 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | void printf(const char *fmt, ...); 16 | 17 | double s2dou(uint8_t* str, int len); 18 | 19 | void u_array2c_array(char *c_arr, uint8_t *u_arr, int len); 20 | 21 | void string2u_array(uint8_t *u_arr, std::string str, int len); 22 | 23 | 24 | float fann_rand(float min_value, float max_value); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* _ENCLAVE_UTILITIES_H */ -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/yang/GitHub/fann") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/yang/GitHub/fann") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########### install files ############### 2 | 3 | IF(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 4 | SET(PARALLEL_INCLUDES "") 5 | ELSE(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 6 | SET(PARALLEL_INCLUDES parallel_fann.h parallel_fann.hpp) 7 | ENDIF(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 8 | 9 | install (FILES fann.h doublefann.h fann_internal.h floatfann.h fann_data.h fixedfann.h fann_activation.h fann_cascade.h fann_error.h fann_train.h fann_io.h fann_cpp.h fann_data_cpp.h fann_training_data_cpp.h ${PARALLEL_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}) 10 | 11 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/config.h: -------------------------------------------------------------------------------- 1 | /* Name of package */ 2 | /* #undef PACKAGE */ 3 | 4 | /* Version number of package */ 5 | /* #undef VERSION */ 6 | 7 | /* Define for the x86_64 CPU famyly */ 8 | /* #undef X86_64 */ 9 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/doublefann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __doublefann_h__ 21 | #define __doublefann_h__ 22 | 23 | typedef double fann_type; 24 | 25 | #undef DOUBLEFANN 26 | #define DOUBLEFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%le" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/fixedfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __fixedfann_h__ 21 | #define __fixedfann_h__ 22 | 23 | typedef int fann_type; 24 | 25 | #undef FIXEDFANN 26 | #define FIXEDFANN 27 | #define FANNPRINTF "%d" 28 | #define FANNSCANF "%d" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/floatfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __floatfann_h__ 21 | #define __floatfann_h__ 22 | 23 | typedef float fann_type; 24 | 25 | #undef FLOATFANN 26 | #define FLOATFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%f" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/parallel_fann.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_FANN.h 3 | * 4 | * Author: Alessandro Pietro Bardelli 5 | */ 6 | #ifndef DISABLE_PARALLEL_FANN 7 | #ifndef PARALLEL_FANN_H_ 8 | #define PARALLEL_FANN_H_ 9 | 10 | #include "fann.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | 16 | #ifndef __cplusplus 17 | } /* to fool automatic indention engines */ 18 | #endif 19 | #endif /* __cplusplus */ 20 | 21 | #ifndef FIXEDFANN 22 | FANN_EXTERNAL float FANN_API fann_train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 23 | 24 | FANN_EXTERNAL float FANN_API fann_train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 25 | 26 | FANN_EXTERNAL float FANN_API fann_train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 27 | 28 | FANN_EXTERNAL float FANN_API fann_train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 29 | 30 | FANN_EXTERNAL float FANN_API fann_train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data); 31 | 32 | FANN_EXTERNAL float FANN_API fann_test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 33 | #endif /* FIXEDFANN */ 34 | 35 | #ifdef __cplusplus 36 | #ifndef __cplusplus 37 | /* to fool automatic indention engines */ 38 | { 39 | 40 | #endif 41 | } 42 | #endif /* __cplusplus */ 43 | 44 | #endif /* PARALLEL_FANN_H_ */ 45 | #endif /* DISABLE_PARALLEL_FANN */ 46 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/fann/parallel_fann.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_FANN.hpp 3 | * Author: Alessandro Pietro Bardelli 4 | */ 5 | #ifndef DISABLE_PARALLEL_FANN 6 | #ifndef PARALLEL_FANN_HPP_ 7 | #define PARALLEL_FANN_HPP_ 8 | #include 9 | #include 10 | #include "fann.h" 11 | 12 | #ifndef FIXEDFANN 13 | namespace parallel_fann { 14 | float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 15 | 16 | float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 17 | 18 | float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 19 | 20 | float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 21 | 22 | float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data); 23 | 24 | float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb,std::vector< std::vector >& predicted_outputs); 25 | 26 | float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 27 | 28 | float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 29 | 30 | float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 31 | 32 | float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data, std::vector< std::vector >& predicted_outputs); 33 | 34 | float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 35 | float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 36 | } 37 | #endif /* FIXEDFANN */ 38 | #endif /* PARALLEL_FANN_HPP_ */ 39 | #endif /* DISABLE_PARALLEL_FANN */ 40 | -------------------------------------------------------------------------------- /CEE/isv_enclave/include/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 3 | // see http://create.stephan-brumme.com/disclaimer.html 4 | // 5 | #pragma once 6 | //#include "hash.h" 7 | #include 8 | // define fixed size integer types 9 | #ifdef _MSC_VER 10 | // Windows 11 | typedef unsigned __int8 uint8_t; 12 | typedef unsigned __int64 uint64_t; 13 | #else 14 | // GCC 15 | #include 16 | #endif 17 | /// compute Keccak hash (designated SHA3) 18 | /** Usage: 19 | Keccak keccak; 20 | std::string myHash = keccak("Hello World"); // std::string 21 | std::string myHash2 = keccak("How are you", 11); // arbitrary data, 11 bytes 22 | // or in a streaming fashion: 23 | Keccak keccak; 24 | while (more data available) 25 | keccak.add(pointer to fresh data, number of new bytes); 26 | std::string myHash3 = keccak.getHash(); 27 | */ 28 | class Keccak //: public Hash 29 | { 30 | public: 31 | /// algorithm variants 32 | enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 }; 33 | /// same as reset() 34 | explicit Keccak(Bits bits = Keccak256); 35 | /// compute hash of a memory block 36 | std::string operator()(const void* data, size_t numBytes); 37 | /// compute hash of a string, excluding final zero 38 | std::string operator()(const std::string& text); 39 | /// add arbitrary number of bytes 40 | void add(const void* data, size_t numBytes); 41 | /// return latest hash as hex characters 42 | std::string getHash(); 43 | /// restart 44 | void reset(); 45 | private: 46 | /// process a full block 47 | void processBlock(const void* data); 48 | /// process everything left in the internal buffer 49 | void processBuffer(); 50 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 51 | enum { StateSize = 1600 / (8 * 8), 52 | MaxBlockSize = 200 - 2 * (224 / 8) }; 53 | /// hash 54 | uint64_t m_hash[StateSize]; 55 | /// size of processed data in bytes 56 | uint64_t m_numBytes; 57 | /// block size (less or equal to MaxBlockSize) 58 | size_t m_blockSize; 59 | /// valid bytes in m_buffer 60 | size_t m_bufferSize; 61 | /// bytes not processed yet 62 | uint8_t m_buffer[MaxBlockSize]; 63 | /// variant 64 | Bits m_bits; 65 | }; -------------------------------------------------------------------------------- /CEE/isv_enclave/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_ECDH_H 2 | #define SECP256K1_ECDH_H 3 | 4 | #include "secp256k1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SECP256K1_ECDH_H */ 32 | -------------------------------------------------------------------------------- /CEE/isv_enclave/isv_enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x80000 5 | 0x5C00000 6 | 4 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /CEE/isv_enclave/isv_enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | g_peak_heap_used; 8 | local: 9 | *; 10 | }; 11 | -------------------------------------------------------------------------------- /CEE/isv_enclave/isv_enclave_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /CEE/isv_enclave/keccak256.h: -------------------------------------------------------------------------------- 1 | /* sha3 - an implementation of Secure Hash Algorithm 3 (Keccak). 2 | * based on the 3 | * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011 4 | * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche 5 | * 6 | * Copyright: 2013 Aleksey Kravchenko 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! 18 | */ 19 | 20 | #ifndef __KECCAK256_H_ 21 | #define __KECCAK256_H_ 22 | 23 | #include 24 | 25 | #define sha3_max_permutation_size 25 26 | #define sha3_max_rate_in_qwords 24 27 | 28 | typedef struct SHA3_CTX { 29 | /* 1600 bits algorithm hashing state */ 30 | uint64_t hash[sha3_max_permutation_size]; 31 | /* 1536-bit buffer for leftovers */ 32 | uint64_t message[sha3_max_rate_in_qwords]; 33 | /* count of bytes in the message[] buffer */ 34 | uint16_t rest; 35 | /* size of a message block processed at once */ 36 | //unsigned block_size; 37 | } SHA3_CTX; 38 | 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | 45 | void keccak_init(SHA3_CTX *ctx); 46 | void keccak_update(SHA3_CTX *ctx, const unsigned char *msg, uint16_t size); 47 | void keccak_final(SHA3_CTX *ctx, unsigned char* result); 48 | 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* __KECCAK256_H_ */ 55 | -------------------------------------------------------------------------------- /CEE/isv_enclave/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /CEE/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /CEE_old/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RemoteAttestation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | org.eclipse.cdt.core.ccnature 26 | com.intel.sgx.sgxnature 27 | 28 | 29 | -------------------------------------------------------------------------------- /CEE_old/README.md: -------------------------------------------------------------------------------- 1 | # CEE_old 2 | 3 | In this version of CEE, the the record() transaction is signed inside CEE's enclave. This might be a useful feature in future projects. 4 | -------------------------------------------------------------------------------- /CEE_old/README.txt: -------------------------------------------------------------------------------- 1 | ---------------------------- 2 | Purpose of RemoteAttestation 3 | ---------------------------- 4 | The project demonstrates: 5 | - How an application enclave can attest to a remote party 6 | - How an application enclave and the remote party can establish a secure session 7 | 8 | ------------------------------------ 9 | How to Build/Execute the Sample Code 10 | ------------------------------------ 11 | 1. Install Intel(R) SGX SDK for Linux* OS 12 | 2. Build the project with the prepared Makefile: 13 | a. Hardware Mode, Debug build: 14 | $ make 15 | b. Hardware Mode, Pre-release build: 16 | $ make SGX_PRERELEASE=1 SGX_DEBUG=0 17 | c. Hardware Mode, Release build: 18 | $ make SGX_DEBUG=0 19 | d. Simulation Mode, Debug build: 20 | $ make SGX_MODE=SIM 21 | e. Simulation Mode, Pre-release build: 22 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 23 | f. Simulation Mode, Release build: 24 | $ make SGX_MODE=SIM SGX_DEBUG=0 25 | 3. Execute the binary directly: 26 | $ ./app 27 | 4. Remember to "make clean" before switching build mode 28 | -------------------------------------------------------------------------------- /CEE_old/isv_app/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENCLAVE_OPERATION_H_ 2 | #define _ENCLAVE_OPERATION_H_ 3 | 4 | 5 | #include "isv_enclave_u.h" 6 | #include "sgx_urts.h" 7 | #include "sgx_uae_service.h" 8 | #include "remote_attestation_result.h" 9 | 10 | #if defined(__cplusplus) 11 | extern "C" { 12 | #endif 13 | 14 | #define AESGCM_KEY_SIZE 16 15 | #define AESGCM_MAC_SIZE 16 16 | #define TASK1_RESULT_SIZE 4 17 | 18 | 19 | 20 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/ 21 | typedef enum _op_msg_type_t 22 | { 23 | TYPE_OP_AUTH, // Authentication message 24 | TYPE_OP_COMP_RES, // computation result message 25 | }op_msg_type_t; 26 | 27 | typedef struct _enclave_info_t{ 28 | sgx_enclave_id_t enclave_id; 29 | sgx_ra_context_t context; 30 | uint32_t extended_epid_group_id; 31 | }enclave_info_t; 32 | 33 | typedef struct _auth_msg_header_t{ 34 | uint8_t type; 35 | uint8_t challenger_type; 36 | }auth_msg_header_t; 37 | 38 | typedef struct _computation_result_msg_t{ 39 | uint8_t type; 40 | int DO_ID; 41 | int file_num; 42 | uint8_t* result_encrypted; 43 | uint8_t result_gcm_mac[AESGCM_MAC_SIZE]; 44 | }computation_result_msg_t; 45 | 46 | 47 | 48 | bool enclave_init(enclave_info_t* enclave_info); 49 | 50 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info); 51 | 52 | int enclave_close(enclave_info_t* enclave_info); 53 | 54 | int enclave_compute_task1(enclave_info_t* enclave_info, int user_ID, int file_num); 55 | 56 | int enclave_compute_task2(enclave_info_t* enclave_info, int user_ID, int file_num); 57 | 58 | // Produce an off-line transaction that invokes the record() function in the contract 59 | // The transaction is marshalled outside the enclave but signed inside enclave 60 | int record_datause(enclave_info_t* enclave_info, char* contract_addr); 61 | 62 | 63 | #if defined(__cplusplus) 64 | } 65 | #endif 66 | #endif -------------------------------------------------------------------------------- /CEE_old/isv_app/refTxGen.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | // var privateKey = '0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de'; 9 | // var publicKey = util.bufferToHex(util.privateToPublic(privateKey)); 10 | // console.log(publicKey); 11 | // var address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); //0x53ae893e4b22d707943299a8d0c844df0e3d5557 12 | 13 | 14 | var rawTx = { 15 | nonce: web3.utils.numberToHex('0'), 16 | gasPrice: web3.utils.numberToHex('20000000000'), 17 | gasLimit: web3.utils.numberToHex('100000'), 18 | to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85', 19 | value: web3.utils.numberToHex('0'), 20 | data: '0xc0de' 21 | }; 22 | var p = new Buffer('c0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de', 'hex'); 23 | 24 | 25 | var transaction = new tx(rawTx); 26 | 27 | // console.log('0x' + transaction.serialize().toString('hex')); 28 | 29 | console.log('\nTransaction cefore signing:\n', transaction); 30 | 31 | transaction.sign(p); // This step needs to be done in the enclave 32 | 33 | console.log('\nTransaction after signing:\n', transaction); 34 | 35 | // console.log('from: '+ transaction.from.toString('hex')); 36 | 37 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 38 | 39 | // // Send the raw transaction hex 40 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 41 | // if (err) { 42 | // console.log(err); 43 | // } 44 | // else { 45 | // console.log(hash); 46 | // } 47 | // }); 48 | 49 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 50 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 51 | console.log('\n- Transaction hash:\n' + txHash); -------------------------------------------------------------------------------- /CEE_old/isv_app/txEncode.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | var RLP = require('rlp'); 6 | var fs = require("fs"); 7 | 8 | // console.log(process.argv); 9 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 10 | 11 | var argv = process.argv; 12 | 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | } 18 | else { 19 | var txCount = res; 20 | var nonce = ''; 21 | var value = ''; 22 | if(txCount != 0){ 23 | nonce = web3.utils.numberToHex(txCount); 24 | } 25 | if(argv[5] != '0'){ 26 | value = web3.utils.numberToHex(argv[5]); 27 | } 28 | 29 | var txNake = [ 30 | nonce, 31 | web3.utils.numberToHex(argv[2]), 32 | web3.utils.numberToHex(argv[3]), 33 | argv[4], 34 | value, 35 | argv[6] 36 | ]; 37 | 38 | var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 39 | var txRLP_hash = util.sha3(txSixFieldRLP); 40 | 41 | 42 | // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 43 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 44 | 45 | fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 46 | if (err) { 47 | return console.error(err); 48 | } 49 | }); 50 | } 51 | }); 52 | 53 | 54 | 55 | 56 | // var nonce = null; 57 | // if(argv[2] != '0'){ 58 | // nonce = web3.utils.numberToHex(argv[2]); 59 | // } 60 | 61 | // var txNake = [ 62 | // nonce, 63 | // web3.utils.numberToHex(argv[3]), 64 | // web3.utils.numberToHex(argv[4]), 65 | // argv[5], 66 | // web3.utils.numberToHex(argv[6]), 67 | // argv[7] 68 | // ]; 69 | 70 | // var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 71 | // var txRLP_hash = util.sha3(txSixFieldRLP); 72 | 73 | 74 | // // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 75 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 76 | 77 | // fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 78 | // if (err) { 79 | // return console.error(err); 80 | // } 81 | // }); 82 | -------------------------------------------------------------------------------- /CEE_old/isv_app/txRLP_hash.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE_old/isv_app/txRLP_hash.txt -------------------------------------------------------------------------------- /CEE_old/isv_app/txRawHex.txt: -------------------------------------------------------------------------------- 1 | 0xf87840843b9aca0083030d4094992d8b41e547d40920172e5369fe0fa0d769bc5c80947bd780c747a35fd12a5454ecb45065f77df87f271ca0a8a12781ee4d8212c033c165c69f5c8650c3b7815a60eeba2093c9db4a3d6a70a0451484ba4f28e734b388779d03294a96bc18ab4e791294143564ff7263266f11 -------------------------------------------------------------------------------- /CEE_old/isv_app/txSend.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | // var tx = require('ethereumjs-tx'); 6 | var RLP = require('rlp'); 7 | var fs = require("fs"); 8 | 9 | // console.log(process.argv); 10 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 11 | var argv = process.argv; 12 | 13 | var data; 14 | 15 | data = fs.readFileSync('isv_app/txSignature_v.txt'); 16 | var txSignature_v = util.bufferToHex(data).toString(); 17 | 18 | data = fs.readFileSync('isv_app/txSignature_r.txt'); 19 | var txSignature_r = util.bufferToHex(data).toString(); 20 | 21 | data = fs.readFileSync('isv_app/txSignature_s.txt'); 22 | var txSignature_s = util.bufferToHex(data).toString(); 23 | 24 | 25 | web3.eth.getTransactionCount(address).then(function (res, err){ 26 | if (err) { 27 | console.log('error: ' + err); 28 | } 29 | else { 30 | var txCount = res; 31 | var nonce = ''; 32 | var value = ''; 33 | if(txCount != 0){ 34 | nonce = web3.utils.numberToHex(txCount); 35 | } 36 | if(argv[5] != '0'){ 37 | value = web3.utils.numberToHex(argv[5]); 38 | } 39 | 40 | var txFull = [ 41 | nonce, 42 | web3.utils.numberToHex(argv[2]), 43 | web3.utils.numberToHex(argv[3]), 44 | argv[4], 45 | value, 46 | argv[6], 47 | txSignature_v, 48 | txSignature_r, 49 | txSignature_s 50 | ]; 51 | 52 | // console.log(txFull); 53 | 54 | var txRawHex = util.bufferToHex(RLP.encode(txFull)); 55 | 56 | console.log('\ntxRawHex: \n' + txRawHex); 57 | 58 | // Send the raw transaction hex 59 | console.log('\nTxHash: '); 60 | 61 | web3.eth.sendSignedTransaction(txRawHex, function (err, hash) { 62 | if (err) { 63 | console.log(err); 64 | } 65 | else { 66 | console.log(hash); 67 | } 68 | }); 69 | 70 | 71 | // Write the raw transaction hex into a file which may be used later 72 | fs.writeFile('isv_app/txRawHex.txt', txRawHex, function(err) { 73 | if (err) { 74 | return console.error(err); 75 | } 76 | }); 77 | } 78 | }); -------------------------------------------------------------------------------- /CEE_old/isv_app/txSignature_r.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE_old/isv_app/txSignature_r.txt -------------------------------------------------------------------------------- /CEE_old/isv_app/txSignature_s.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CEE_old/isv_app/txSignature_s.txt -------------------------------------------------------------------------------- /CEE_old/isv_app/txSignature_v.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /CEE_old/isv_enclave/TrustedLibrary/Libc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | #include 34 | #include "sgx_cpuid.h" 35 | 36 | #include "sgx_trts.h" 37 | #include "../Enclave.h" 38 | #include "Enclave_t.h" 39 | 40 | /* ecall_malloc_free: 41 | * Uses malloc/free to allocate/free trusted memory. 42 | */ 43 | void ecall_malloc_free(void) 44 | { 45 | void *ptr = malloc(100); 46 | assert(ptr != NULL); 47 | memset(ptr, 0x0, 100); 48 | free(ptr); 49 | } 50 | 51 | /* ecall_sgx_cpuid: 52 | * Uses sgx_cpuid to get CPU features and types. 53 | */ 54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf) 55 | { 56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); 57 | if (ret != SGX_SUCCESS) 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/TrustedLibrary/Libc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libc.edl - EDL sample for trusted C library. */ 34 | 35 | enclave { 36 | 37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex; 38 | 39 | /* 40 | * A subset of the C99 standard is supported as well as SGX customized functions: 41 | * sgx_cpuid, etc. 42 | */ 43 | 44 | trusted { 45 | /* 46 | * Utilize malloc/free in enclave. 47 | */ 48 | public void ecall_malloc_free(void); 49 | 50 | /* 51 | * Utilize SGX version __cpuid() in enclave. 52 | */ 53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf); 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/TrustedLibrary/Libcxx.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libcxx.edl - EDL sample for trusted C++ library. */ 34 | 35 | enclave { 36 | 37 | /* 38 | * A subset of the C++03 standard is supported. 39 | */ 40 | 41 | trusted { 42 | /* 43 | * Throw/catch exception inside the enclave. 44 | */ 45 | public void ecall_exception(void); 46 | 47 | /* 48 | * Utilize inside the enclave. 49 | */ 50 | public void ecall_map(void); 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/TrustedLibrary/Thread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* Thread.edl - EDL sample for trusted thread library. */ 33 | 34 | enclave { 35 | 36 | from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; 37 | 38 | trusted { 39 | /* 40 | * Use SGX mutex. 41 | */ 42 | public size_t ecall_increase_counter(); 43 | 44 | /* 45 | * Use SGX condition variables. 46 | */ 47 | public void ecall_producer(); 48 | public void ecall_consumer(); 49 | 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_ECDH_H 2 | #define SECP256K1_ECDH_H 3 | 4 | #include "secp256k1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SECP256K1_ECDH_H */ 32 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/isv_enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x100000 6 | 1 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/isv_enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | g_peak_heap_used; 8 | local: 9 | *; 10 | }; 11 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/isv_enclave_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/keccak256.h: -------------------------------------------------------------------------------- 1 | /* sha3 - an implementation of Secure Hash Algorithm 3 (Keccak). 2 | * based on the 3 | * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011 4 | * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche 5 | * 6 | * Copyright: 2013 Aleksey Kravchenko 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! 18 | */ 19 | 20 | #ifndef __KECCAK256_H_ 21 | #define __KECCAK256_H_ 22 | 23 | #include 24 | 25 | #define sha3_max_permutation_size 25 26 | #define sha3_max_rate_in_qwords 24 27 | 28 | typedef struct SHA3_CTX { 29 | /* 1600 bits algorithm hashing state */ 30 | uint64_t hash[sha3_max_permutation_size]; 31 | /* 1536-bit buffer for leftovers */ 32 | uint64_t message[sha3_max_rate_in_qwords]; 33 | /* count of bytes in the message[] buffer */ 34 | uint16_t rest; 35 | /* size of a message block processed at once */ 36 | //unsigned block_size; 37 | } SHA3_CTX; 38 | 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | 45 | void keccak_init(SHA3_CTX *ctx); 46 | void keccak_update(SHA3_CTX *ctx, const unsigned char *msg, uint16_t size); 47 | void keccak_final(SHA3_CTX *ctx, unsigned char* result); 48 | 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* __KECCAK256_H_ */ 55 | -------------------------------------------------------------------------------- /CEE_old/isv_enclave/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /CloudStorage/Reserved_ML_Data/digits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/CloudStorage/Reserved_ML_Data/digits.png -------------------------------------------------------------------------------- /Contracts/DistributeFund_2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract DistributeFund_2 { 4 | 5 | address [32] public accounts = [ 6 | 0x154f3d575f404544f65aace4f3cb462f652a4185, // 129 7 | 0x9e2320af88a83077c4445e552ace02fd20b83fbf, 8 | 0xe4347b89a0b63e59ecde1957cd4473ceb8ce0a92, 9 | 0xdbaed106423a7c2e848c6581b66713ad4c8bc7ff, 10 | 0x629ed2bb627ea6e5469b16b1c3dc5ea1c689d347, 11 | 0xb86af8cc002386522748620c45b685ef34cac4cf, 12 | 0x8e043544ea9ac143e441132e1ff9fba47ce12489, 13 | 0x157d6879f13be984594947f4afd7f2f0c9732876, 14 | 0x29ee5a723e9d4b4be56689ac931e7d92bd7f1c86, 15 | 0x0d186638156630e0d0869959ecc568704dbaa0c2, 16 | 0x35f7df7258b55ccb86a223b230c2c8e44b56c24e, 17 | 0x89b1b0ae1e0eb7c9119439c2bdd504957008968a, 18 | 0x133542b7a868d1f25a5cb80eff816c8583a56e98, 19 | 0x8057442400c8634b95ba68b76922b2a486fbe4cf, 20 | 0xfe7079bbebb5fc8ad4a62fddeb3556cb691b2d3e, 21 | 0xe362321eeddfc2513a54f8427c5ba40d088e8294, 22 | 0x9463d8301d38341d5f6f7f5304dd8e3e29867141, 23 | 0x373e7dbf92e86bc510f587ba560707a83d4f795e, 24 | 0x5c1c58978037c723583482cd38c5d40ecd2d7398, 25 | 0xb144f3d8e20bc55e468e5f43b5ccc032ca84ba74, 26 | 0x42906762aaaa468ce56219b3205848154b4cc0e7, 27 | 0x46ca0f770485fe09a704f0b4f400e74da55e262e, 28 | 0x9db25ef4239411a0ee6dfc75e11303a1c75fb6e3, 29 | 0x0c64c370d595ada819656de2674e4877b484b1d7, 30 | 0x22f2b4a4dfc20e4a2bf25239b0125ce31dab50e5, 31 | 0xecc4e97c4111259996931d689ad016d4e550ace3, 32 | 0xfcad6bb861d1af44d05b60c61b6336bce16ffdf7, 33 | 0xfde6be6b88f1de8b53506869fc9132ceade74c44, 34 | 0xee200296748ab60e2d3b67243ff763fbdd89269a, 35 | 0x9e7fff61ce55a9e97c2bb1670ab902925f523b7e, 36 | 0x057f0bce633834c3dc5401164a274ae762231cbd, 37 | 0x7ed00465e851440597acd7bac5da8c96cbe91b19 // 160 38 | ]; 39 | 40 | constructor() public { 41 | 42 | } 43 | 44 | function deposit() public payable { 45 | } 46 | 47 | function distribute(uint value) public { 48 | for(uint i = 0; i < 32; i++) { 49 | accounts[i].transfer(value); 50 | } 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /Contracts/HowToDeploy&AccessContract.md: -------------------------------------------------------------------------------- 1 | # To compile and deploy a contract in the hard way 2 | 3 | ## Use solidity to write the contract source code 4 | Contract filename: X.sol 5 | Contract name: X 6 | 7 | ## Generate Javascript file from the Solidity source code file: 8 | echo "var ContractOutput=`solc --optimize --combined-json abi,bin,interface X.sol`" > X.js 9 | 10 | ## Compile and deploy the contract in a geth console (in the same folder as with the .js file): 11 | loadScript('X.js'); 12 | var ContractAbi = ContractOutput.contracts['X.sol:X'].abi; 13 | var Contract = eth.contract(JSON.parse(ContractAbi)); 14 | var BinCode = "0x" + ContractOutput.contracts['X.sol:X'].bin; 15 | personal.unlockAccount("0x..."); 16 | var deployTransationObject = { from: "0x...", data: BinCode, gas: 2000000 }; 17 | var Instance = Contract.new(deployTransationObject); 18 | 19 | ## Interact with the deployed contract 20 | var Address = eth.getTransactionReceipt(Instance.transactionHash).contractAddress; 21 | var ThisContract = Contract.at(Address); 22 | 23 | 24 | 25 | # To access a contract with source code and contract address 26 | 27 | ## Generate Javascript file in the contract folder: 28 | echo "var ContractOutput=`solc --optimize --combined-json abi,bin,interface X.sol`" > X.js 29 | 30 | ## Compile and access the contract in a geth console 31 | loadScript('X.js'); 32 | var ContractAbi = ContractOutput.contracts['X.sol:X'].abi; 33 | var Contract = eth.contract(JSON.parse(ContractAbi)); 34 | var ThisContract = Contract.at("0x..."); -------------------------------------------------------------------------------- /DataBroker/App/clientdata_operation.h: -------------------------------------------------------------------------------- 1 | #ifndef _CLIENTDATA_OPERATION_H_ 2 | #define _CLIENTDATA_OPERATION_H_ 3 | 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | 10 | 11 | /* Generate AES key shell command 12 | openssl enc -aes-128-cbc -k secret -P -md sha256 -nosalt 13 | */ 14 | 15 | 16 | 17 | int getdata_encrypt_store(); 18 | int encrypt_store(); 19 | 20 | // int VerifyDeposit(); 21 | 22 | #if defined(__cplusplus) 23 | } 24 | #endif 25 | 26 | #endif -------------------------------------------------------------------------------- /DataBroker/App/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATIONS_H_ 2 | #define _OPERATIONS_H_ 3 | 4 | 5 | #include 6 | #include "enclave_u.h" 7 | #include "sgx_urts.h" 8 | #include "sgx_uae_service.h" 9 | #include "remote_attestation_result.h" 10 | #include "network_ra.h" 11 | 12 | 13 | #if defined(__cplusplus) 14 | extern "C" { 15 | #endif 16 | 17 | 18 | 19 | #define AESGCM_KEY_SIZE 16 20 | #define AESGCM_MAC_SIZE 16 21 | #define KECCAK_HASH_SIZE 32 22 | 23 | 24 | 25 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/ 26 | typedef enum _op_msg_type_t 27 | { 28 | TYPE_OP_AUTH, // Authentication message 29 | TYPE_OP_COMP_RES, // computation result message 30 | }op_msg_type_t; 31 | 32 | typedef struct _enclave_info_t{ 33 | sgx_enclave_id_t enclave_id; 34 | sgx_ra_context_t context; 35 | uint32_t extended_epid_group_id; 36 | }enclave_info_t; 37 | 38 | // typedef struct _auth_msg_header_t{ 39 | // uint8_t type; 40 | // uint8_t challenger_type; 41 | // }auth_msg_header_t; 42 | 43 | typedef struct _computation_result_msg_t{ 44 | uint8_t type; 45 | int DO_ID; 46 | int file_num; 47 | uint8_t result_encrypted[4]; 48 | uint8_t result_gcm_mac[16]; 49 | }computation_result_msg_t; 50 | 51 | typedef struct _operation_config_msg_t{ 52 | int DC_ID; 53 | int type; 54 | int start; 55 | int end; 56 | int operation; 57 | }operation_config_msg_t; 58 | 59 | typedef struct _K_result_msg_t{ // to iDA/DB 60 | int DO_ID; 61 | int file_num; 62 | uint8_t K_result_en[AESGCM_KEY_SIZE]; 63 | uint8_t K_result_mac[AESGCM_MAC_SIZE]; 64 | }K_result_msg_t; 65 | 66 | 67 | bool enclave_init(enclave_info_t* enclave_info); 68 | 69 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info); 70 | 71 | int remote_attest_init_enclave(enclave_info_t* enclave_info); 72 | int remote_attest_enclave_parallel(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info_original); 73 | 74 | int enclave_close(enclave_info_t* enclave_info); 75 | 76 | int remote_attest_challenger(int sock_num, int type, uint8_t* secret, int secret_size); 77 | 78 | int process_DO_data(enclave_info_t* enclave_info, do_provision_data_header_t* DO_msg_header, uint8_t* DO_data); 79 | 80 | int checkContractStatus(char *contract_addr); 81 | 82 | int confirmRegistries(char *ContractAddress); 83 | 84 | #if defined(__cplusplus) 85 | } 86 | #endif 87 | #endif -------------------------------------------------------------------------------- /DataBroker/App/txSendDirectly.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | 9 | var p = new Buffer('6307a6a04aa0e59aa308d64073ddbe28c81914a1e96353d7c89aa6c88cb611a4', 'hex'); // DB/iDA' Ethereum private key 10 | var address = '0x0a4a2f95e8625eb07a67f8dfa0cd566c515a01c3'; // DB/iDA's Ethereum address 11 | 12 | var argv = process.argv; 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | 18 | } 19 | else { 20 | // console.log('success: ' + res); 21 | var txCount = res; 22 | // console.log(txCount); 23 | 24 | var rawTx = { 25 | nonce: web3.utils.numberToHex(txCount), 26 | gasPrice: web3.utils.numberToHex(argv[2]), 27 | gasLimit: web3.utils.numberToHex(argv[3]), 28 | to: argv[4], // DO's address 29 | value: web3.utils.numberToHex(argv[5]), // 0.01 ether 30 | data: argv[6] 31 | }; 32 | 33 | var transaction = new tx(rawTx); 34 | transaction.sign(p); // This step needs to be done in the enclave 35 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 36 | console.log('\nRawTxHex:\n' + RawTxHex); 37 | 38 | // Send the raw transaction hex 39 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 40 | // if (err) { 41 | // console.log(err); 42 | // } 43 | // else { 44 | // console.log('\nTransaction hash: ' + hash); 45 | // } 46 | // }); 47 | 48 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 49 | } 50 | }); -------------------------------------------------------------------------------- /DataBroker/Enclave/TrustedLibrary/Libc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | #include 34 | #include "sgx_cpuid.h" 35 | 36 | #include "sgx_trts.h" 37 | #include "../Enclave.h" 38 | #include "Enclave_t.h" 39 | 40 | /* ecall_malloc_free: 41 | * Uses malloc/free to allocate/free trusted memory. 42 | */ 43 | void ecall_malloc_free(void) 44 | { 45 | void *ptr = malloc(100); 46 | assert(ptr != NULL); 47 | memset(ptr, 0x0, 100); 48 | free(ptr); 49 | } 50 | 51 | /* ecall_sgx_cpuid: 52 | * Uses sgx_cpuid to get CPU features and types. 53 | */ 54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf) 55 | { 56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); 57 | if (ret != SGX_SUCCESS) 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /DataBroker/Enclave/TrustedLibrary/Libc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libc.edl - EDL sample for trusted C library. */ 34 | 35 | enclave { 36 | 37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex; 38 | 39 | /* 40 | * A subset of the C99 standard is supported as well as SGX customized functions: 41 | * sgx_cpuid, etc. 42 | */ 43 | 44 | trusted { 45 | /* 46 | * Utilize malloc/free in enclave. 47 | */ 48 | public void ecall_malloc_free(void); 49 | 50 | /* 51 | * Utilize SGX version __cpuid() in enclave. 52 | */ 53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf); 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /DataBroker/Enclave/TrustedLibrary/Libcxx.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libcxx.edl - EDL sample for trusted C++ library. */ 34 | 35 | enclave { 36 | 37 | /* 38 | * A subset of the C++03 standard is supported. 39 | */ 40 | 41 | trusted { 42 | /* 43 | * Throw/catch exception inside the enclave. 44 | */ 45 | public void ecall_exception(void); 46 | 47 | /* 48 | * Utilize inside the enclave. 49 | */ 50 | public void ecall_map(void); 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /DataBroker/Enclave/TrustedLibrary/Thread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* Thread.edl - EDL sample for trusted thread library. */ 33 | 34 | enclave { 35 | 36 | from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; 37 | 38 | trusted { 39 | /* 40 | * Use SGX mutex. 41 | */ 42 | public size_t ecall_increase_counter(); 43 | 44 | /* 45 | * Use SGX condition variables. 46 | */ 47 | public void ecall_producer(); 48 | public void ecall_consumer(); 49 | 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /DataBroker/Enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x80000 5 | 0x1C00000 6 | 128 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /DataBroker/Enclave/enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | g_peak_heap_used; 8 | local: 9 | *; 10 | }; 11 | -------------------------------------------------------------------------------- /DataBroker/Enclave/enclave_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIG4wIBAAKCAYEA0MvI9NpdP4GEqCvtlJQv00OybzTXzxBhPu/257VYt9cYw/ph 3 | BN1WRyxBBcrZs15xmcvlb3xNmFGWs4w5oUgrFBNgi6g+CUOCsj0cM8xw7P/y3K0H 4 | XaZUf+T3CXCp8NvlkZHzfdWAFA5lGGR9g6kmuk7SojE3h87Zm1KjPU/PvAe+BaMU 5 | trlRr4gPNVnu19Vho60xwuswPxfl/pBFUIk7qWEUR3l2hiqWMeLgf3Ays/WSnkXA 6 | uijwPt5g0hxsgIlyDrI3jKbf0zkFB56jvPwSykfU8aw4Gkbo5qSZxUAKnwH2L8Uf 7 | yM6inBaaYtM79icRwsu45Yt6X0GAt7CSb/1TKBrnm5exmK1sug3YSQ/YuK1FYawU 8 | vIaDD0YfzOndTNVBewA+Hr5xNPvqGJoRKHuGbyu2lI9jrKYpVxQWsmx38wnxF6kE 9 | zX6N4m7KZiLeLpDdBVQtLuOzIdIE4wT3t/ckeqElxO/1Ut9bj765GcTTrYwMKHRw 10 | ukWIH7ZtHtAjj0KzAgEDAoIBgQCLMoX4kZN/q63Fcp5jDXU3gnb0zeU0tZYp9U9F 11 | I5B6j2XX/ECt6OQvctYD3JEiPvZmh+5KUt5li7nNCCZrhXINYkBdGtQGLQHMKL13 12 | 3aCd//c9yK+TxDhVQ09boHFLPUO2YUz+jlVitENlmFOtG28m3zcWy3paieZnjGzT 13 | iop9Wn6ubLh50OEfsAojkUnlOOvCc3aB8iAqD+6ptYOLBifGQLgvpk8EHGQhQer/ 14 | oCHNTmG+2SsmxfV/Pus2vZ2rBkrUbZU0hwrnvKOIPhnt3Qwtmx9xsC67jF+MpWko 15 | UisJXC27FAGz2gpIGMhBp35HEppwG9hhCuMQdK2g62bvweyr1tC4qOVdQrKvhksN 16 | r6CMjS9eSXvmWdF7lU4oxStN0V56/LICSIsLbggUaxTPKhAVEgfTSqwEJoQuFA3Q 17 | 4GmgTydPhcRH1L/lhbWJqZQm7V1Gt+5i5J6iATD32uNQQ2iZi5GsUhr+jZC+WlE5 18 | 6lS813cRNiaK52HIk62bG7IXOksCgcEA+6RxZhQ5GaCPYZNsk7TqxqsKopXKoYAr 19 | 2R4KWuexJTd+1kcNMk0ETX8OSgpY2cYL2uPFWmdutxPpLfpr8S2u92Da/Wxs70Ti 20 | QSb0426ybTmnS5L7nOnGOHiddXILhW175liAszTeoR7nQ6vpr9YjfcnrXiB8bKIm 21 | akft2DQoxrBPzEe9tA8gfkyDTsSG2j7kncSbvYRtkKcJOmmypotVU6uhRPSrSXCc 22 | J59uBQkg6Bk4CKA1mz8ctG07MluFY0/ZAoHBANRpZlfIFl39gFmuEER7lb80GySO 23 | J190LbqOca3dGOvAMsDgEAi6juJyX7ZNpbHFHj++LvmTtw9+kxhVDBcswS7304kt 24 | 7J2EfnGdctEZtXif1wiq30YWAp1tjRpQENKtt9wssmgcwgK39rZNiEHmStHGv3l+ 25 | 5TnKPKeuFCDnsLvi5lQYoK2wTYvZtsjf+Rnt7H17q90IV54pMjTS8BkGskCkKf2A 26 | IYuaZkqX0T3cM6ovoYYDAU6rWL5rrYPLEwkbawKBwQCnwvZEDXtmawpBDPMNI0cv 27 | HLHBuTHBAB07aVw8mnYYz6nkL14hiK2I/17cBuXmhAfnQoORmknPYptz/Ef2HnSk 28 | 6zyo8vNKLewrb03s9Hbze8TdDKe98S7QUGj49rJY86fu5asiIz8WFJotHUZ1OWz+ 29 | hpzpav2dwW7xhUk6zXCEdYqIL9PNX2r+3azfLa88Ke2+gxJ+WEkLGgYm8SHEXOON 30 | HRYt+HIw9b1vv56uBhXwENAFwCO81L3Nnid2565CNTsCgcEAjZuZj9q5k/5VkR61 31 | gv0Of3gSGF7E6k1z0bRLyT4QnSrMgJVgBdG0lvbqeYkZIS4UKn7J+7fPX6m3ZY4I 32 | D3MrdKU3sMlIaQL+9mj3NhEjpb/ksHHqLrlXE55eEYq14cklPXMhmr3WrHqkeYkF 33 | gUQx4S8qUP9De9wob8liwJp10pdEOBBrHnWJB+Z52z/7Zp6dqP0dPgWPvsYheIyg 34 | EK8hgG1xU6rBB7xEMbqLfpLNHB/BBAIA3xzl1EfJAodiBhJHAoHAeTS2znDHYayI 35 | TvK86tBAPVORiBVTSdRUONdGF3dipo24hyeyrI5MtiOoMc3sKWXnSTkDQWa3WiPx 36 | qStBmmO/SbGTuz7T6+oOwGeMiYzYBe87Ayn8Y0KYYshFikieJbGusHjUlIGmCVPy 37 | UHrDMYGwFGUGBwW47gBsnZa+YPHtxWCPDe/U80et2Trx0RXJJQPmupAVMSiJWObI 38 | 9k5gRU+xDqkHanyD1gkGGwhFTUNX94EJEOdQEWw3hxLnVtePoke/ 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /DataBroker/Enclave/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_ECDH_H 2 | #define SECP256K1_ECDH_H 3 | 4 | #include "secp256k1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SECP256K1_ECDH_H */ 32 | -------------------------------------------------------------------------------- /DataBroker/Enclave/keccak256.h: -------------------------------------------------------------------------------- 1 | /* sha3 - an implementation of Secure Hash Algorithm 3 (Keccak). 2 | * based on the 3 | * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011 4 | * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche 5 | * 6 | * Copyright: 2013 Aleksey Kravchenko 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! 18 | */ 19 | 20 | #ifndef __KECCAK256_H_ 21 | #define __KECCAK256_H_ 22 | 23 | #include 24 | 25 | #define sha3_max_permutation_size 25 26 | #define sha3_max_rate_in_qwords 24 27 | 28 | typedef struct SHA3_CTX { 29 | /* 1600 bits algorithm hashing state */ 30 | uint64_t hash[sha3_max_permutation_size]; 31 | /* 1536-bit buffer for leftovers */ 32 | uint64_t message[sha3_max_rate_in_qwords]; 33 | /* count of bytes in the message[] buffer */ 34 | uint16_t rest; 35 | /* size of a message block processed at once */ 36 | //unsigned block_size; 37 | } SHA3_CTX; 38 | 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | 45 | void keccak_init(SHA3_CTX *ctx); 46 | void keccak_update(SHA3_CTX *ctx, const unsigned char *msg, uint16_t size); 47 | void keccak_final(SHA3_CTX *ctx, unsigned char* result); 48 | 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* __KECCAK256_H_ */ 55 | -------------------------------------------------------------------------------- /DataBroker/Enclave/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /DataBroker/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataBroker/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /DataConsumer/App/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 3 | // see http://create.stephan-brumme.com/disclaimer.html 4 | // 5 | #pragma once 6 | //#include "hash.h" 7 | #include 8 | // define fixed size integer types 9 | #ifdef _MSC_VER 10 | // Windows 11 | typedef unsigned __int8 uint8_t; 12 | typedef unsigned __int64 uint64_t; 13 | #else 14 | // GCC 15 | #include 16 | #endif 17 | /// compute Keccak hash (designated SHA3) 18 | /** Usage: 19 | Keccak keccak; 20 | std::string myHash = keccak("Hello World"); // std::string 21 | std::string myHash2 = keccak("How are you", 11); // arbitrary data, 11 bytes 22 | // or in a streaming fashion: 23 | Keccak keccak; 24 | while (more data available) 25 | keccak.add(pointer to fresh data, number of new bytes); 26 | std::string myHash3 = keccak.getHash(); 27 | */ 28 | class Keccak //: public Hash 29 | { 30 | public: 31 | /// algorithm variants 32 | enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 }; 33 | /// same as reset() 34 | explicit Keccak(Bits bits = Keccak256); 35 | /// compute hash of a memory block 36 | std::string operator()(const void* data, size_t numBytes); 37 | /// compute hash of a string, excluding final zero 38 | std::string operator()(const std::string& text); 39 | /// add arbitrary number of bytes 40 | void add(const void* data, size_t numBytes); 41 | /// return latest hash as hex characters 42 | std::string getHash(); 43 | /// restart 44 | void reset(); 45 | private: 46 | /// process a full block 47 | void processBlock(const void* data); 48 | /// process everything left in the internal buffer 49 | void processBuffer(); 50 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 51 | enum { StateSize = 1600 / (8 * 8), 52 | MaxBlockSize = 200 - 2 * (224 / 8) }; 53 | /// hash 54 | uint64_t m_hash[StateSize]; 55 | /// size of processed data in bytes 56 | uint64_t m_numBytes; 57 | /// block size (less or equal to MaxBlockSize) 58 | size_t m_blockSize; 59 | /// valid bytes in m_buffer 60 | size_t m_bufferSize; 61 | /// bytes not processed yet 62 | uint8_t m_buffer[MaxBlockSize]; 63 | /// variant 64 | Bits m_bits; 65 | }; -------------------------------------------------------------------------------- /DataConsumer/App/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATIONS_H_ 2 | #define _OPERATIONS_H_ 3 | 4 | #include "remote_attestation_result.h" 5 | #include "string" 6 | 7 | #if defined(__cplusplus) 8 | extern "C" { 9 | #endif 10 | 11 | 12 | #define AESGCM_KEY_SIZE 16 13 | #define AESGCM_MAC_SIZE 16 14 | #define KECCAK_HASH_SIZE 32 15 | 16 | #define TASK1_RESULT_SIZE 4 // Bytes. Summation of single digits 17 | #define TASK2_RESULT_SIZE 1000 // Bytes. SVM model 18 | #define TASK3_RESULT_SIZE 10000 // Bytes. ANN model 19 | 20 | 21 | typedef struct _K_result_hash_msg_t{ // to DC 22 | int DO_ID; 23 | int file_num; 24 | uint8_t K_result_hash_en[KECCAK_HASH_SIZE]; 25 | uint8_t K_result_hash_mac[AESGCM_MAC_SIZE]; 26 | uint8_t C_result_hash_en[KECCAK_HASH_SIZE]; // Hash of the encrypted result 27 | uint8_t C_result_hash_mac[AESGCM_MAC_SIZE]; 28 | }K_result_hash_msg_t; 29 | 30 | typedef struct _operation_config_msg_t{ 31 | int DC_ID; 32 | int type; 33 | int start; 34 | int end; 35 | int operation; 36 | }operation_config_msg_t; 37 | 38 | void u_array2c_array(char *c_arr, uint8_t *u_arr, int len); 39 | 40 | void string2u_array(uint8_t *u_arr, std::string str, int len); 41 | 42 | int request_Contract(char* ContractAddress, int range_start, int range_end, int operation, double payment); 43 | 44 | int cancelTransaction(char* contract_addr); 45 | 46 | 47 | #if defined(__cplusplus) 48 | } 49 | #endif 50 | #endif -------------------------------------------------------------------------------- /DataConsumer/App/txSendDirectly.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | 9 | var p = new Buffer('fcfc028c752996a2d29a5e2f1c1acaee2fe05892d38f7338059ce844b80819de', 'hex'); // DataConsumer's Ethereum private key 10 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; // DataConsumer's Ethereum address 11 | 12 | var argv = process.argv; 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | 18 | } 19 | else { 20 | // console.log('success: ' + res); 21 | var txCount = res; 22 | // console.log(txCount); 23 | 24 | var rawTx = { 25 | nonce: web3.utils.numberToHex(txCount), 26 | gasPrice: web3.utils.numberToHex(argv[2]), 27 | gasLimit: web3.utils.numberToHex(argv[3]), 28 | to: argv[4], // DO's address 29 | value: web3.utils.numberToHex(argv[5]), // 0.01 ether 30 | data: argv[6] 31 | }; 32 | 33 | var transaction = new tx(rawTx); 34 | transaction.sign(p); // This step needs to be done in the enclave 35 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 36 | console.log('\nRawTxHex:\n' + RawTxHex); 37 | 38 | // Send the raw transaction hex 39 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 40 | // if (err) { 41 | // console.log(err); 42 | // } 43 | // else { 44 | // console.log('\nTransaction hash: ' + hash); 45 | // } 46 | // }); 47 | 48 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 49 | } 50 | }); 51 | 52 | /* 53 | web3.eth.sendTransaction({from: '0x123...', data: '0x432...'}) 54 | .once('transactionHash', function(hash){ ... }) 55 | .once('receipt', function(receipt){ ... }) 56 | .on('confirmation', function(confNumber, receipt){ ... }) 57 | .on('error', function(error){ ... }) 58 | .then(function(receipt){ 59 | // will be fired once the receipt is mined 60 | }); 61 | */ -------------------------------------------------------------------------------- /DataConsumer/Makefile: -------------------------------------------------------------------------------- 1 | C_FLAGS := -fPIC -Wno-attributes -Isample_libcrypto -IApp 2 | 3 | CPP_FLAGS := $(C_FLAGS) -std=c++11 4 | CPP_FILES := App/app.cpp App/ecp.cpp App/network_ra.cpp App/attestation_service.cpp App/ias_ra.cpp App/operations.cpp App/keccak.cpp 5 | LINK_FLAGS := -Lsample_libcrypto -lsample_libcrypto -Wl,-rpath=$(CURDIR)/sample_libcrypto -Wl,-rpath=$(CURDIR) 6 | 7 | app: $(CPP_FILES) 8 | @ rm -f .config_* app 9 | @ g++ -o app $(CPP_FILES) $(CPP_FLAGS) $(LINK_FLAGS) 10 | 11 | 12 | .PHONY: clean 13 | 14 | clean: 15 | @ rm -f .config_* app 16 | -------------------------------------------------------------------------------- /DataConsumer/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataConsumer/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /DataConsumer/sample_libcrypto/txGenSend.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | var rawTx = { 9 | nonce: web3.utils.numberToHex('1'), 10 | gasPrice: web3.utils.numberToHex('20000000000'), 11 | gasLimit: web3.utils.numberToHex('100000'), 12 | to: '0xe81f56753c8a0096458bab4bb358574268454b05', 13 | value: web3.utils.numberToHex('1000000000000000000'), // 1 ether 14 | data: '0xc0de' 15 | }; 16 | var p = new Buffer('fcfc028c752996a2d29a5e2f1c1acaee2fe05892d38f7338059ce844b80819de', 'hex'); 17 | 18 | 19 | var transaction = new tx(rawTx); 20 | 21 | // console.log('0x' + transaction.serialize().toString('hex')); 22 | 23 | console.log('\nTransaction cefore signing:\n', transaction); 24 | 25 | transaction.sign(p); // This step needs to be done in the enclave 26 | 27 | console.log('\nTransaction after signing:\n', transaction); 28 | 29 | // console.log('from: '+ transaction.from.toString('hex')); 30 | 31 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 32 | 33 | // Send the raw transaction hex 34 | web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 35 | if (err) { 36 | console.log(err); 37 | } 38 | else { 39 | console.log(hash); 40 | } 41 | }); 42 | 43 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 44 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 45 | console.log('\n- Transaction hash:\n'); -------------------------------------------------------------------------------- /DataOwner/App/operations.cpp: -------------------------------------------------------------------------------- 1 | #include "operations.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | /* Data preparation. */ 12 | // dataType = 1: For simple summation. 13 | // dataType = 2: For machine learning operations. Each data point is a vector. 14 | int generate_data_type(int DO_ID, int data_counter, int num_data_points, int dataType) 15 | { 16 | int index = data_counter + 1; 17 | 18 | switch(dataType) 19 | { 20 | case 1: 21 | { 22 | int j; 23 | srand(time(NULL)); 24 | ofstream outfile ("DataFiles/DO" + to_string(DO_ID) + "_" + to_string(index) + ".txt"); 25 | for (j = 1; j <= num_data_points; j++) 26 | { 27 | outfile << rand() % 10; // data range: 0~9 28 | } 29 | outfile.close(); 30 | break; 31 | } 32 | 33 | case 2: 34 | { 35 | char buffer1[1000]; 36 | sprintf(buffer1, "python3 process_adult_data.py %d %d %d", DO_ID, index, num_data_points); 37 | system(buffer1); 38 | } 39 | } 40 | return index; 41 | } 42 | 43 | /* Send a transaction invoking the register function of DO's/DB's contract */ 44 | // payment unit: ether 45 | int register_data_on_Contract(char *contract_addr, char *DO_address, char *DO_pkey, int contractType, int data_num, int operation, double price, char* DC_addr, int DC_action) 46 | { 47 | int ret = 0; 48 | char buffer1[1000], nodejs_arg[1000]; 49 | 50 | /* Six fields of a naked transaction */ 51 | long gas_price = 1000000000; 52 | long gasLimit = 300000; 53 | char to[100]; 54 | long value = 0; // unit: wei 55 | char data[500]; 56 | 57 | char address[100], pkey[200]; 58 | sprintf(to, "%s", contract_addr); 59 | sprintf(address, "%s", DO_address); 60 | sprintf(pkey, "%s", DO_pkey); 61 | 62 | long price_wei = price * 1000000000000000000; 63 | 64 | switch(contractType) 65 | { 66 | case 0: // DO's own contract 67 | sprintf(data, "0xcc527740%064X%064X%064lX%024X%s%064X", data_num, operation, price_wei, 0, DC_addr, DC_action); 68 | break; 69 | case 1: 70 | sprintf(data, "0x80ac1323%064X%064lX%024X%s%064X", operation, price_wei, 0, DC_addr, DC_action); 71 | } 72 | 73 | 74 | /* Get the digest (RLP_hash) of the nake transaction */ 75 | sprintf(nodejs_arg, "%ld %ld %s %ld %s %s %s", gas_price, gasLimit, to, value, data, address, pkey); 76 | sprintf(buffer1, "node App/txSendDirectly.js %s", nodejs_arg); 77 | printf("%s\n", buffer1); 78 | 79 | ret = system(buffer1); 80 | return ret; 81 | } -------------------------------------------------------------------------------- /DataOwner/App/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATIONS_H_ 2 | #define _OPERATIONS_H_ 3 | 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | 10 | int generate_data_type(int DO_ID, int data_counter, int num_data_points, int dataType); 11 | 12 | int register_data_on_Contract(char* contract_addr, char *DO_address, char *DO_pkey, int contractType, int data, int operation, double price, char* DC_addr, int DC_action); 13 | 14 | 15 | #if defined(__cplusplus) 16 | } 17 | #endif 18 | #endif -------------------------------------------------------------------------------- /DataOwner/App/txSendDirectly.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | 9 | var argv = process.argv; 10 | 11 | // var address = '0xac5d434a4a9cf170baaa5d1be12b48c7fe358fa0'; 12 | // var pkey = new Buffer('3bdc966729b1c929efa2053c40c77f31cf2e9048950c8f86af937780e5686dbd', 'hex'); 13 | var address = argv[7]; 14 | var pkey = new Buffer(argv[8], 'hex'); 15 | 16 | 17 | web3.eth.getTransactionCount(address).then(function (res, err){ 18 | if (err) { 19 | console.log('error: ' + err); 20 | 21 | } 22 | else { 23 | // console.log('success: ' + res); 24 | var txCount = res; 25 | // console.log(txCount); 26 | 27 | var rawTx = { 28 | nonce: web3.utils.numberToHex(txCount), 29 | gasPrice: web3.utils.numberToHex(argv[2]), 30 | gasLimit: web3.utils.numberToHex(argv[3]), 31 | to: argv[4], // DO's address 32 | value: web3.utils.numberToHex(argv[5]), // 0.01 ether 33 | data: argv[6] 34 | }; 35 | 36 | var transaction = new tx(rawTx); 37 | transaction.sign(pkey); // This step needs to be done in the enclave 38 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 39 | console.log('\nRawTxHex:\n' + RawTxHex); 40 | 41 | // Send the raw transaction hex 42 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 43 | // if (err) { 44 | // console.log(err); 45 | // } 46 | // else { 47 | // console.log('\nTransaction hash: ' + hash); 48 | // } 49 | // }); 50 | 51 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 52 | } 53 | }); -------------------------------------------------------------------------------- /DataOwner/DataFiles/Reserved_ML_Data/digits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataOwner/DataFiles/Reserved_ML_Data/digits.png -------------------------------------------------------------------------------- /DataOwner/Makefile: -------------------------------------------------------------------------------- 1 | C_FLAGS := -fPIC -Wno-attributes -Isample_libcrypto -IApp 2 | 3 | CPP_FLAGS := $(C_FLAGS) -std=c++11 4 | CPP_FILES := App/app.cpp App/ecp.cpp App/network_ra.cpp App/attestation_service.cpp App/ias_ra.cpp App/operations.cpp 5 | LINK_FLAGS := -Lsample_libcrypto -lsample_libcrypto -Wl,-rpath=$(CURDIR)/sample_libcrypto -Wl,-rpath=$(CURDIR) 6 | 7 | app: $(CPP_FILES) 8 | @ rm -f .config_* app 9 | @ g++ -o app $(CPP_FILES) $(CPP_FLAGS) $(LINK_FLAGS) 10 | 11 | 12 | .PHONY: clean 13 | 14 | clean: 15 | @ rm -f .config_* app DataFiles/*.txt 16 | -------------------------------------------------------------------------------- /DataOwner/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataOwner/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /DataOwner/sample_libcrypto/txGenSend.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | var rawTx = { 9 | nonce: web3.utils.numberToHex('1'), 10 | gasPrice: web3.utils.numberToHex('20000000000'), 11 | gasLimit: web3.utils.numberToHex('100000'), 12 | to: '0xe81f56753c8a0096458bab4bb358574268454b05', 13 | value: web3.utils.numberToHex('1000000000000000000'), // 1 ether 14 | data: '0xc0de' 15 | }; 16 | var p = new Buffer('fcfc028c752996a2d29a5e2f1c1acaee2fe05892d38f7338059ce844b80819de', 'hex'); 17 | 18 | 19 | var transaction = new tx(rawTx); 20 | 21 | // console.log('0x' + transaction.serialize().toString('hex')); 22 | 23 | console.log('\nTransaction cefore signing:\n', transaction); 24 | 25 | transaction.sign(p); // This step needs to be done in the enclave 26 | 27 | console.log('\nTransaction after signing:\n', transaction); 28 | 29 | // console.log('from: '+ transaction.from.toString('hex')); 30 | 31 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 32 | 33 | // Send the raw transaction hex 34 | web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 35 | if (err) { 36 | console.log(err); 37 | } 38 | else { 39 | console.log(hash); 40 | } 41 | }); 42 | 43 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 44 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 45 | console.log('\n- Transaction hash:\n'); -------------------------------------------------------------------------------- /DataOwner_group/App/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATIONS_H_ 2 | #define _OPERATIONS_H_ 3 | 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | 10 | int generate_data_type(int DO_ID, int data_counter, int num_data_points, int dataType); 11 | 12 | int register_data_on_Contract(double* fTime, char* contract_addr, char *DO_address, char *DO_pkey, int contractType, int data, int operation, double price, char* DC_addr, int DC_action); 13 | 14 | 15 | #if defined(__cplusplus) 16 | } 17 | #endif 18 | #endif -------------------------------------------------------------------------------- /DataOwner_group/App/txSendDirectly.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | 9 | var argv = process.argv; 10 | 11 | // var address = '0xac5d434a4a9cf170baaa5d1be12b48c7fe358fa0'; 12 | // var pkey = new Buffer('3bdc966729b1c929efa2053c40c77f31cf2e9048950c8f86af937780e5686dbd', 'hex'); 13 | var address = argv[7]; 14 | var pkey = new Buffer(argv[8], 'hex'); 15 | 16 | 17 | web3.eth.getTransactionCount(address).then(function (res, err){ 18 | if (err) { 19 | console.log('error: ' + err); 20 | 21 | } 22 | else { 23 | // console.log('success: ' + res); 24 | var txCount = res; 25 | // console.log(txCount); 26 | 27 | var rawTx = { 28 | nonce: web3.utils.numberToHex(txCount), 29 | gasPrice: web3.utils.numberToHex(argv[2]), 30 | gasLimit: web3.utils.numberToHex(argv[3]), 31 | to: argv[4], // DO's address 32 | value: web3.utils.numberToHex(argv[5]), // 0.01 ether 33 | data: argv[6] 34 | }; 35 | 36 | var transaction = new tx(rawTx); 37 | transaction.sign(pkey); // This step needs to be done in the enclave 38 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 39 | console.log('\nRawTxHex:\n' + RawTxHex); 40 | // Send the raw transaction hex 41 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 42 | // if (err) { 43 | // console.log(err); 44 | // } 45 | // else { 46 | // console.log('\nTransaction hash: ' + hash); 47 | // } 48 | // }); 49 | 50 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 51 | } 52 | }); -------------------------------------------------------------------------------- /DataOwner_group/DataFiles/Reserved_ML_Data/digits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataOwner_group/DataFiles/Reserved_ML_Data/digits.png -------------------------------------------------------------------------------- /DataOwner_group/Makefile: -------------------------------------------------------------------------------- 1 | C_FLAGS := -fPIC -Wno-attributes -Isample_libcrypto -IApp 2 | 3 | CPP_FLAGS := $(C_FLAGS) -std=c++11 4 | CPP_FILES := App/app.cpp App/ecp.cpp App/network_ra.cpp App/attestation_service.cpp App/ias_ra.cpp App/operations.cpp 5 | LINK_FLAGS := -lpthread -Lsample_libcrypto -lsample_libcrypto -Wl,-rpath=$(CURDIR)/sample_libcrypto -Wl,-rpath=$(CURDIR) 6 | 7 | app: $(CPP_FILES) 8 | @ rm -f .config_* app 9 | @ g++ -o app $(CPP_FILES) $(CPP_FLAGS) $(LINK_FLAGS) 10 | 11 | 12 | .PHONY: clean 13 | 14 | clean: 15 | @ rm -f .config_* app DataFiles/*.txt 16 | -------------------------------------------------------------------------------- /DataOwner_group/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/DataOwner_group/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /DataOwner_group/sample_libcrypto/txGenSend.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | var rawTx = { 9 | nonce: web3.utils.numberToHex('1'), 10 | gasPrice: web3.utils.numberToHex('20000000000'), 11 | gasLimit: web3.utils.numberToHex('100000'), 12 | to: '0xe81f56753c8a0096458bab4bb358574268454b05', 13 | value: web3.utils.numberToHex('1000000000000000000'), // 1 ether 14 | data: '0xc0de' 15 | }; 16 | var p = new Buffer('fcfc028c752996a2d29a5e2f1c1acaee2fe05892d38f7338059ce844b80819de', 'hex'); 17 | 18 | 19 | var transaction = new tx(rawTx); 20 | 21 | // console.log('0x' + transaction.serialize().toString('hex')); 22 | 23 | console.log('\nTransaction cefore signing:\n', transaction); 24 | 25 | transaction.sign(p); // This step needs to be done in the enclave 26 | 27 | console.log('\nTransaction after signing:\n', transaction); 28 | 29 | // console.log('from: '+ transaction.from.toString('hex')); 30 | 31 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 32 | 33 | // Send the raw transaction hex 34 | web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 35 | if (err) { 36 | console.log(err); 37 | } 38 | else { 39 | console.log(hash); 40 | } 41 | }); 42 | 43 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 44 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 45 | console.log('\n- Transaction hash:\n'); -------------------------------------------------------------------------------- /Enclave_testML/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RemoteAttestation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | org.eclipse.cdt.core.ccnature 26 | com.intel.sgx.sgxnature 27 | 28 | 29 | -------------------------------------------------------------------------------- /Enclave_testML/README.txt: -------------------------------------------------------------------------------- 1 | ---------------------------- 2 | Purpose of RemoteAttestation 3 | ---------------------------- 4 | The project demonstrates: 5 | - How an application enclave can attest to a remote party 6 | - How an application enclave and the remote party can establish a secure session 7 | 8 | ------------------------------------ 9 | How to Build/Execute the Sample Code 10 | ------------------------------------ 11 | 1. Install Intel(R) SGX SDK for Linux* OS 12 | 2. Build the project with the prepared Makefile: 13 | a. Hardware Mode, Debug build: 14 | $ make 15 | b. Hardware Mode, Pre-release build: 16 | $ make SGX_PRERELEASE=1 SGX_DEBUG=0 17 | c. Hardware Mode, Release build: 18 | $ make SGX_DEBUG=0 19 | d. Simulation Mode, Debug build: 20 | $ make SGX_MODE=SIM 21 | e. Simulation Mode, Pre-release build: 22 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 23 | f. Simulation Mode, Release build: 24 | $ make SGX_MODE=SIM SGX_DEBUG=0 25 | 3. Execute the binary directly: 26 | $ ./app 27 | 4. Remember to "make clean" before switching build mode 28 | -------------------------------------------------------------------------------- /Enclave_testML/isv_app/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 3 | // see http://create.stephan-brumme.com/disclaimer.html 4 | // 5 | #pragma once 6 | //#include "hash.h" 7 | #include 8 | // define fixed size integer types 9 | #ifdef _MSC_VER 10 | // Windows 11 | typedef unsigned __int8 uint8_t; 12 | typedef unsigned __int64 uint64_t; 13 | #else 14 | // GCC 15 | #include 16 | #endif 17 | /// compute Keccak hash (designated SHA3) 18 | /** Usage: 19 | Keccak keccak; 20 | std::string myHash = keccak("Hello World"); // std::string 21 | std::string myHash2 = keccak("How are you", 11); // arbitrary data, 11 bytes 22 | // or in a streaming fashion: 23 | Keccak keccak; 24 | while (more data available) 25 | keccak.add(pointer to fresh data, number of new bytes); 26 | std::string myHash3 = keccak.getHash(); 27 | */ 28 | class Keccak //: public Hash 29 | { 30 | public: 31 | /// algorithm variants 32 | enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 }; 33 | /// same as reset() 34 | explicit Keccak(Bits bits = Keccak256); 35 | /// compute hash of a memory block 36 | std::string operator()(const void* data, size_t numBytes); 37 | /// compute hash of a string, excluding final zero 38 | std::string operator()(const std::string& text); 39 | /// add arbitrary number of bytes 40 | void add(const void* data, size_t numBytes); 41 | /// return latest hash as hex characters 42 | std::string getHash(); 43 | /// restart 44 | void reset(); 45 | private: 46 | /// process a full block 47 | void processBlock(const void* data); 48 | /// process everything left in the internal buffer 49 | void processBuffer(); 50 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 51 | enum { StateSize = 1600 / (8 * 8), 52 | MaxBlockSize = 200 - 2 * (224 / 8) }; 53 | /// hash 54 | uint64_t m_hash[StateSize]; 55 | /// size of processed data in bytes 56 | uint64_t m_numBytes; 57 | /// block size (less or equal to MaxBlockSize) 58 | size_t m_blockSize; 59 | /// valid bytes in m_buffer 60 | size_t m_bufferSize; 61 | /// bytes not processed yet 62 | uint8_t m_buffer[MaxBlockSize]; 63 | /// variant 64 | Bits m_bits; 65 | }; -------------------------------------------------------------------------------- /Enclave_testML/isv_app/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENCLAVE_OPERATION_H_ 2 | #define _ENCLAVE_OPERATION_H_ 3 | 4 | 5 | #include "isv_enclave_u.h" 6 | #include "sgx_urts.h" 7 | #include "sgx_uae_service.h" 8 | #include "remote_attestation_result.h" 9 | 10 | // #include 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | #define AESGCM_KEY_SIZE 16 17 | #define AESGCM_MAC_SIZE 16 18 | #define KECCAK_HASH_SIZE 32 19 | 20 | #define TASK1_RESULT_SIZE 4 // Bytes. Summation of single digits 21 | #define TASK2_RESULT_SIZE 1000 // Bytes. SVM model 22 | #define TASK3_RESULT_SIZE 10000 // Bytes. ANN model 23 | 24 | 25 | 26 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/ 27 | typedef enum _op_msg_type_t 28 | { 29 | TYPE_OP_AUTH, // Authentication message 30 | TYPE_OP_COMP_RES, // computation result message 31 | }op_msg_type_t; 32 | 33 | typedef struct _enclave_info_t{ 34 | sgx_enclave_id_t enclave_id; 35 | sgx_ra_context_t context; 36 | uint32_t extended_epid_group_id; 37 | }enclave_info_t; 38 | 39 | typedef struct _auth_msg_header_t{ 40 | uint8_t type; 41 | uint8_t challenger_type; 42 | }auth_msg_header_t; 43 | 44 | typedef struct _computation_result_msg_t{ 45 | uint8_t type; 46 | int DO_ID; 47 | int file_num; 48 | uint8_t result_gcm_mac[AESGCM_MAC_SIZE]; 49 | uint8_t* result_encrypted; 50 | }computation_result_msg_t; 51 | 52 | 53 | 54 | bool enclave_init(enclave_info_t* enclave_info); 55 | 56 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info); 57 | 58 | int enclave_close(enclave_info_t* enclave_info); 59 | 60 | int enclave_compute_task1(enclave_info_t* enclave_info, int user_ID, int file_num); 61 | 62 | // int enclave_compute_task(enclave_info_t* enclave_info, int task_num, int user_ID, int file_num); 63 | int enclave_compute_task(enclave_info_t* enclave_info, int Request_DC, int Request_type, int Request_start, int Request_end, int Request_operation); 64 | 65 | int enclave_compute_task_normal(int Request_type, int Request_start, int Request_end, int Request_operation); 66 | 67 | // Produce an off-line transaction that invokes the record() function in the contract 68 | // The transaction is marshalled outside the enclave but signed inside enclave 69 | int record_datause(enclave_info_t* enclave_info, char* contract_addr); 70 | 71 | int encrypt_file(int DO_ID, int file_num); 72 | 73 | 74 | #if defined(__cplusplus) 75 | } 76 | #endif 77 | #endif -------------------------------------------------------------------------------- /Enclave_testML/isv_app/refTxGen.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | // var privateKey = '0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de'; 9 | // var publicKey = util.bufferToHex(util.privateToPublic(privateKey)); 10 | // console.log(publicKey); 11 | // var address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); //0x53ae893e4b22d707943299a8d0c844df0e3d5557 12 | 13 | 14 | var rawTx = { 15 | nonce: web3.utils.numberToHex('0'), 16 | gasPrice: web3.utils.numberToHex('20000000000'), 17 | gasLimit: web3.utils.numberToHex('100000'), 18 | to: '0x687422eEA2cB73B5d3e242bA5456b782919AFc85', 19 | value: web3.utils.numberToHex('0'), 20 | data: '0xc0de' 21 | }; 22 | var p = new Buffer('c0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0dec0de', 'hex'); 23 | 24 | 25 | var transaction = new tx(rawTx); 26 | 27 | // console.log('0x' + transaction.serialize().toString('hex')); 28 | 29 | console.log('\nTransaction cefore signing:\n', transaction); 30 | 31 | transaction.sign(p); // This step needs to be done in the enclave 32 | 33 | console.log('\nTransaction after signing:\n', transaction); 34 | 35 | // console.log('from: '+ transaction.from.toString('hex')); 36 | 37 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 38 | 39 | // // Send the raw transaction hex 40 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 41 | // if (err) { 42 | // console.log(err); 43 | // } 44 | // else { 45 | // console.log(hash); 46 | // } 47 | // }); 48 | 49 | console.log('\n- Raw Transaction Hex:\n' + RawTxHex); 50 | var txHash = util.bufferToHex(util.sha3(RawTxHex)); 51 | console.log('\n- Transaction hash:\n' + txHash); -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txEncode.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | var RLP = require('rlp'); 6 | var fs = require("fs"); 7 | 8 | // console.log(process.argv); 9 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 10 | 11 | var argv = process.argv; 12 | 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | } 18 | else { 19 | var txCount = res; 20 | var nonce = ''; 21 | var value = ''; 22 | if(txCount != 0){ 23 | nonce = web3.utils.numberToHex(txCount); 24 | } 25 | if(argv[5] != '0'){ 26 | value = web3.utils.numberToHex(argv[5]); 27 | } 28 | 29 | var txNake = [ 30 | nonce, 31 | web3.utils.numberToHex(argv[2]), 32 | web3.utils.numberToHex(argv[3]), 33 | argv[4], 34 | value, 35 | argv[6] 36 | ]; 37 | 38 | var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 39 | var txRLP_hash = util.sha3(txSixFieldRLP); 40 | 41 | 42 | // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 43 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 44 | 45 | fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 46 | if (err) { 47 | return console.error(err); 48 | } 49 | }); 50 | } 51 | }); 52 | 53 | 54 | 55 | 56 | // var nonce = null; 57 | // if(argv[2] != '0'){ 58 | // nonce = web3.utils.numberToHex(argv[2]); 59 | // } 60 | 61 | // var txNake = [ 62 | // nonce, 63 | // web3.utils.numberToHex(argv[3]), 64 | // web3.utils.numberToHex(argv[4]), 65 | // argv[5], 66 | // web3.utils.numberToHex(argv[6]), 67 | // argv[7] 68 | // ]; 69 | 70 | // var txSixFieldRLP = util.bufferToHex(RLP.encode(txNake)); 71 | // var txRLP_hash = util.sha3(txSixFieldRLP); 72 | 73 | 74 | // // console.log('\nSixFieldRLP hex:\n' + txSixFieldRLP); 75 | // console.log('\nTransaction RLP+Hash:\n' + util.bufferToHex(txRLP_hash)); 76 | 77 | // fs.writeFile('isv_app/txRLP_hash.txt', txRLP_hash, function(err) { 78 | // if (err) { 79 | // return console.error(err); 80 | // } 81 | // }); 82 | -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txRLP_hash.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Enclave_testML/isv_app/txRLP_hash.txt -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txRawHex.txt: -------------------------------------------------------------------------------- 1 | 0xf87840843b9aca0083030d4094992d8b41e547d40920172e5369fe0fa0d769bc5c80947bd780c747a35fd12a5454ecb45065f77df87f271ca0a8a12781ee4d8212c033c165c69f5c8650c3b7815a60eeba2093c9db4a3d6a70a0451484ba4f28e734b388779d03294a96bc18ab4e791294143564ff7263266f11 -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txSend.js: -------------------------------------------------------------------------------- 1 | var Web3 = require('web3'); 2 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 3 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 4 | var util = require('ethereumjs-util'); 5 | // var tx = require('ethereumjs-tx'); 6 | var RLP = require('rlp'); 7 | var fs = require("fs"); 8 | 9 | // console.log(process.argv); 10 | var address = '0x65843be2dd4ad3bc966584e2fcbb38838d49054b'; 11 | var argv = process.argv; 12 | 13 | var data; 14 | 15 | data = fs.readFileSync('isv_app/txSignature_v.txt'); 16 | var txSignature_v = util.bufferToHex(data).toString(); 17 | 18 | data = fs.readFileSync('isv_app/txSignature_r.txt'); 19 | var txSignature_r = util.bufferToHex(data).toString(); 20 | 21 | data = fs.readFileSync('isv_app/txSignature_s.txt'); 22 | var txSignature_s = util.bufferToHex(data).toString(); 23 | 24 | 25 | web3.eth.getTransactionCount(address).then(function (res, err){ 26 | if (err) { 27 | console.log('error: ' + err); 28 | } 29 | else { 30 | var txCount = res; 31 | var nonce = ''; 32 | var value = ''; 33 | if(txCount != 0){ 34 | nonce = web3.utils.numberToHex(txCount); 35 | } 36 | if(argv[5] != '0'){ 37 | value = web3.utils.numberToHex(argv[5]); 38 | } 39 | 40 | var txFull = [ 41 | nonce, 42 | web3.utils.numberToHex(argv[2]), 43 | web3.utils.numberToHex(argv[3]), 44 | argv[4], 45 | value, 46 | argv[6], 47 | txSignature_v, 48 | txSignature_r, 49 | txSignature_s 50 | ]; 51 | 52 | // console.log(txFull); 53 | 54 | var txRawHex = util.bufferToHex(RLP.encode(txFull)); 55 | 56 | console.log('\ntxRawHex: \n' + txRawHex); 57 | 58 | // Send the raw transaction hex 59 | console.log('\nTxHash: '); 60 | 61 | web3.eth.sendSignedTransaction(txRawHex, function (err, hash) { 62 | if (err) { 63 | console.log(err); 64 | } 65 | else { 66 | console.log(hash); 67 | } 68 | }); 69 | 70 | 71 | // Write the raw transaction hex into a file which may be used later 72 | fs.writeFile('isv_app/txRawHex.txt', txRawHex, function(err) { 73 | if (err) { 74 | return console.error(err); 75 | } 76 | }); 77 | } 78 | }); -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txSignature_r.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Enclave_testML/isv_app/txSignature_r.txt -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txSignature_s.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Enclave_testML/isv_app/txSignature_s.txt -------------------------------------------------------------------------------- /Enclave_testML/isv_app/txSignature_v.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/TrustedLibrary/Libc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | #include 34 | #include "sgx_cpuid.h" 35 | 36 | #include "sgx_trts.h" 37 | #include "../Enclave.h" 38 | #include "Enclave_t.h" 39 | 40 | /* ecall_malloc_free: 41 | * Uses malloc/free to allocate/free trusted memory. 42 | */ 43 | void ecall_malloc_free(void) 44 | { 45 | void *ptr = malloc(100); 46 | assert(ptr != NULL); 47 | memset(ptr, 0x0, 100); 48 | free(ptr); 49 | } 50 | 51 | /* ecall_sgx_cpuid: 52 | * Uses sgx_cpuid to get CPU features and types. 53 | */ 54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf) 55 | { 56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); 57 | if (ret != SGX_SUCCESS) 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/TrustedLibrary/Libc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libc.edl - EDL sample for trusted C library. */ 34 | 35 | enclave { 36 | 37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex; 38 | 39 | /* 40 | * A subset of the C99 standard is supported as well as SGX customized functions: 41 | * sgx_cpuid, etc. 42 | */ 43 | 44 | trusted { 45 | /* 46 | * Utilize malloc/free in enclave. 47 | */ 48 | public void ecall_malloc_free(void); 49 | 50 | /* 51 | * Utilize SGX version __cpuid() in enclave. 52 | */ 53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf); 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/TrustedLibrary/Libcxx.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libcxx.edl - EDL sample for trusted C++ library. */ 34 | 35 | enclave { 36 | 37 | /* 38 | * A subset of the C++03 standard is supported. 39 | */ 40 | 41 | trusted { 42 | /* 43 | * Throw/catch exception inside the enclave. 44 | */ 45 | public void ecall_exception(void); 46 | 47 | /* 48 | * Utilize inside the enclave. 49 | */ 50 | public void ecall_map(void); 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/TrustedLibrary/Thread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* Thread.edl - EDL sample for trusted thread library. */ 33 | 34 | enclave { 35 | 36 | from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; 37 | 38 | trusted { 39 | /* 40 | * Use SGX mutex. 41 | */ 42 | public size_t ecall_increase_counter(); 43 | 44 | /* 45 | * Use SGX condition variables. 46 | */ 47 | public void ecall_producer(); 48 | public void ecall_consumer(); 49 | 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/enclave_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENCLAVE_UTILITIES_H 2 | #define _ENCLAVE_UTILITIES_H 3 | 4 | #define LIBSVM_VERSION 323 5 | 6 | #include "sgx_tkey_exchange.h" 7 | #include "sgx_tcrypto.h" 8 | #include "sgx_trts.h" 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | void printf(const char *fmt, ...); 16 | 17 | double s2dou(uint8_t* str, int len); 18 | 19 | void u_array2c_array(char *c_arr, uint8_t *u_arr, int len); 20 | 21 | void string2u_array(uint8_t *u_arr, std::string str, int len); 22 | 23 | float fann_rand(float min_value, float max_value); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* _ENCLAVE_UTILITIES_H */ -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/yang/GitHub/fann") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/yang/GitHub/fann") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########### install files ############### 2 | 3 | IF(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 4 | SET(PARALLEL_INCLUDES "") 5 | ELSE(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 6 | SET(PARALLEL_INCLUDES parallel_fann.h parallel_fann.hpp) 7 | ENDIF(NOT OPENMP_FOUND OR DISABLE_PARALLEL_FANN) 8 | 9 | install (FILES fann.h doublefann.h fann_internal.h floatfann.h fann_data.h fixedfann.h fann_activation.h fann_cascade.h fann_error.h fann_train.h fann_io.h fann_cpp.h fann_data_cpp.h fann_training_data_cpp.h ${PARALLEL_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}) 10 | 11 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/config.h: -------------------------------------------------------------------------------- 1 | /* Name of package */ 2 | /* #undef PACKAGE */ 3 | 4 | /* Version number of package */ 5 | /* #undef VERSION */ 6 | 7 | /* Define for the x86_64 CPU famyly */ 8 | /* #undef X86_64 */ 9 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/doublefann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __doublefann_h__ 21 | #define __doublefann_h__ 22 | 23 | typedef double fann_type; 24 | 25 | #undef DOUBLEFANN 26 | #define DOUBLEFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%le" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/fixedfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __fixedfann_h__ 21 | #define __fixedfann_h__ 22 | 23 | typedef int fann_type; 24 | 25 | #undef FIXEDFANN 26 | #define FIXEDFANN 27 | #define FANNPRINTF "%d" 28 | #define FANNSCANF "%d" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/floatfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __floatfann_h__ 21 | #define __floatfann_h__ 22 | 23 | typedef float fann_type; 24 | 25 | #undef FLOATFANN 26 | #define FLOATFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%f" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/parallel_fann.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_FANN.h 3 | * 4 | * Author: Alessandro Pietro Bardelli 5 | */ 6 | #ifndef DISABLE_PARALLEL_FANN 7 | #ifndef PARALLEL_FANN_H_ 8 | #define PARALLEL_FANN_H_ 9 | 10 | #include "fann.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | 16 | #ifndef __cplusplus 17 | } /* to fool automatic indention engines */ 18 | #endif 19 | #endif /* __cplusplus */ 20 | 21 | #ifndef FIXEDFANN 22 | FANN_EXTERNAL float FANN_API fann_train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 23 | 24 | FANN_EXTERNAL float FANN_API fann_train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 25 | 26 | FANN_EXTERNAL float FANN_API fann_train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 27 | 28 | FANN_EXTERNAL float FANN_API fann_train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 29 | 30 | FANN_EXTERNAL float FANN_API fann_train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data); 31 | 32 | FANN_EXTERNAL float FANN_API fann_test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 33 | #endif /* FIXEDFANN */ 34 | 35 | #ifdef __cplusplus 36 | #ifndef __cplusplus 37 | /* to fool automatic indention engines */ 38 | { 39 | 40 | #endif 41 | } 42 | #endif /* __cplusplus */ 43 | 44 | #endif /* PARALLEL_FANN_H_ */ 45 | #endif /* DISABLE_PARALLEL_FANN */ 46 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/fann/parallel_fann.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_FANN.hpp 3 | * Author: Alessandro Pietro Bardelli 4 | */ 5 | #ifndef DISABLE_PARALLEL_FANN 6 | #ifndef PARALLEL_FANN_HPP_ 7 | #define PARALLEL_FANN_HPP_ 8 | #include 9 | #include 10 | #include "fann.h" 11 | 12 | #ifndef FIXEDFANN 13 | namespace parallel_fann { 14 | float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 15 | 16 | float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 17 | 18 | float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 19 | 20 | float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 21 | 22 | float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data); 23 | 24 | float train_epoch_batch_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb,std::vector< std::vector >& predicted_outputs); 25 | 26 | float train_epoch_irpropm_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 27 | 28 | float train_epoch_quickprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 29 | 30 | float train_epoch_sarprop_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 31 | 32 | float train_epoch_incremental_mod(struct fann *ann, struct fann_train_data *data, std::vector< std::vector >& predicted_outputs); 33 | 34 | float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb); 35 | float test_data_parallel(struct fann *ann, struct fann_train_data *data, const unsigned int threadnumb, std::vector< std::vector >& predicted_outputs); 36 | } 37 | #endif /* FIXEDFANN */ 38 | #endif /* PARALLEL_FANN_HPP_ */ 39 | #endif /* DISABLE_PARALLEL_FANN */ 40 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 3 | // see http://create.stephan-brumme.com/disclaimer.html 4 | // 5 | #pragma once 6 | //#include "hash.h" 7 | #include 8 | // define fixed size integer types 9 | #ifdef _MSC_VER 10 | // Windows 11 | typedef unsigned __int8 uint8_t; 12 | typedef unsigned __int64 uint64_t; 13 | #else 14 | // GCC 15 | #include 16 | #endif 17 | /// compute Keccak hash (designated SHA3) 18 | /** Usage: 19 | Keccak keccak; 20 | std::string myHash = keccak("Hello World"); // std::string 21 | std::string myHash2 = keccak("How are you", 11); // arbitrary data, 11 bytes 22 | // or in a streaming fashion: 23 | Keccak keccak; 24 | while (more data available) 25 | keccak.add(pointer to fresh data, number of new bytes); 26 | std::string myHash3 = keccak.getHash(); 27 | */ 28 | class Keccak //: public Hash 29 | { 30 | public: 31 | /// algorithm variants 32 | enum Bits { Keccak224 = 224, Keccak256 = 256, Keccak384 = 384, Keccak512 = 512 }; 33 | /// same as reset() 34 | explicit Keccak(Bits bits = Keccak256); 35 | /// compute hash of a memory block 36 | std::string operator()(const void* data, size_t numBytes); 37 | /// compute hash of a string, excluding final zero 38 | std::string operator()(const std::string& text); 39 | /// add arbitrary number of bytes 40 | void add(const void* data, size_t numBytes); 41 | /// return latest hash as hex characters 42 | std::string getHash(); 43 | /// restart 44 | void reset(); 45 | private: 46 | /// process a full block 47 | void processBlock(const void* data); 48 | /// process everything left in the internal buffer 49 | void processBuffer(); 50 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 51 | enum { StateSize = 1600 / (8 * 8), 52 | MaxBlockSize = 200 - 2 * (224 / 8) }; 53 | /// hash 54 | uint64_t m_hash[StateSize]; 55 | /// size of processed data in bytes 56 | uint64_t m_numBytes; 57 | /// block size (less or equal to MaxBlockSize) 58 | size_t m_blockSize; 59 | /// valid bytes in m_buffer 60 | size_t m_bufferSize; 61 | /// bytes not processed yet 62 | uint8_t m_buffer[MaxBlockSize]; 63 | /// variant 64 | Bits m_bits; 65 | }; -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_ECDH_H 2 | #define SECP256K1_ECDH_H 3 | 4 | #include "secp256k1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SECP256K1_ECDH_H */ 32 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/isv_enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x800000 5 | 0x10000000 6 | 4 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/isv_enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | g_peak_heap_used; 8 | local: 9 | *; 10 | }; 11 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/isv_enclave_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /Enclave_testML/isv_enclave/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /Enclave_testML/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Enclave_testML/sample_libcrypto/libsample_libcrypto.so -------------------------------------------------------------------------------- /Eval&Tools/Config.md: -------------------------------------------------------------------------------- 1 | # Configuration and Useful Notes 2 | 3 | ## Network 4 | 1 DataBroker (DB) 5 | 1 DataConsumer (DC) 6 | N DataOwners (DO) 7 | N iDataAgents (iDA) 8 | 9 | ## Ethereum rinkeby testnet nodes: 10 | DB/iDA address: 0x0a4a2f95e8625eb07a67f8dfa0cd566c515a01c3 11 | private key: 6307a6a04aa0e59aa308d64073ddbe28c81914a1e96353d7c89aa6c88cb611a4 12 | DC address: 0x65843BE2Dd4ad3bC966584E2Fcbb38838d49054B 13 | private key: fcfc028c752996a2d29a5e2f1c1acaee2fe05892d38f7338059ce844b80819de 14 | DO1 address: 0xac5d434a4a9cf170baaa5d1be12b48c7fe358fa0 15 | private key: 3bdc966729b1c929efa2053c40c77f31cf2e9048950c8f86af937780e5686dbd 16 | 17 | ## Created contracts 18 | DistributeFund: 0x6F8E9B88FA2D61a88034321E46fA98205ddaDb76 19 | DataBroker_v1: 0x058943a672aF6a2D06b4374eD39544DEF4bC039C 20 | DataBroker_v2: 0x669eEf9F9DF482C8f9b6E2087E890c945d7A7d8D 21 | DataBroker_v3: 0x7CAC532e3E93666247a56D987e25AEa5050B8cee 22 | DataOwner_v1: 0x992d8b41E547D40920172E5369fe0fA0d769BC5c 23 | DataOwner_v2: 0x208D3CEdFE8918298A726264B578A9BA2AE8c85B 24 | 25 | ## Keccak-256 hashes (no parenthesis) 26 | cc527740 <= "register(int256,int256,uint256,address,int256)" 27 | 80ac1323 <= "register(int256,uint256,address,int256)" 28 | 7022b58e <= "confirm()" 29 | ad352967 <= "request(int256,int256,int256)" 30 | 4092a8d9 <= "computationComplete(bytes32)" 31 | 8438e7ea <= "completeTransaction(string)" 32 | ea8a1af0 <= "cancel()" 33 | b6549f75 <= "revoke()" -------------------------------------------------------------------------------- /Eval&Tools/ExpData.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/ExpData.ods -------------------------------------------------------------------------------- /Eval&Tools/attestationTimes-a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/attestationTimes-a.png -------------------------------------------------------------------------------- /Eval&Tools/attestationTimes-b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/attestationTimes-b.png -------------------------------------------------------------------------------- /Eval&Tools/attestationTimes-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/attestationTimes-new.png -------------------------------------------------------------------------------- /Eval&Tools/computationRuntimes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/computationRuntimes.png -------------------------------------------------------------------------------- /Eval&Tools/contractCallTimes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/contractCallTimes.png -------------------------------------------------------------------------------- /Eval&Tools/costCallingDBContract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/costCallingDBContract.png -------------------------------------------------------------------------------- /Eval&Tools/getPrivateKeyLocally.js: -------------------------------------------------------------------------------- 1 | var argv = process.argv; 2 | 3 | var keythereum = require("keythereum"); 4 | var datadir = "/home/yang/.ethereum/rinkeby"; 5 | var address= argv[2]; 6 | const password = argv[3]; 7 | var keyObject = keythereum.importFromFile(address, datadir); 8 | var privateKey = keythereum.recover(password, keyObject); 9 | console.log(privateKey.toString('hex')); -------------------------------------------------------------------------------- /Eval&Tools/getPrivateKeyLocally_batch.js: -------------------------------------------------------------------------------- 1 | var keythereum = require("keythereum"); 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | var accounts = [ 11 | "0x154f3d575f404544f65aace4f3cb462f652a4185", 12 | "0x9e2320af88a83077c4445e552ace02fd20b83fbf", 13 | "0xe4347b89a0b63e59ecde1957cd4473ceb8ce0a92", 14 | "0xdbaed106423a7c2e848c6581b66713ad4c8bc7ff", 15 | "0x629ed2bb627ea6e5469b16b1c3dc5ea1c689d347", 16 | "0xb86af8cc002386522748620c45b685ef34cac4cf", 17 | "0x8e043544ea9ac143e441132e1ff9fba47ce12489", 18 | "0x157d6879f13be984594947f4afd7f2f0c9732876", 19 | "0x29ee5a723e9d4b4be56689ac931e7d92bd7f1c86", 20 | "0x0d186638156630e0d0869959ecc568704dbaa0c2", 21 | "0x35f7df7258b55ccb86a223b230c2c8e44b56c24e", 22 | "0x89b1b0ae1e0eb7c9119439c2bdd504957008968a", 23 | "0x133542b7a868d1f25a5cb80eff816c8583a56e98", 24 | "0x8057442400c8634b95ba68b76922b2a486fbe4cf", 25 | "0xfe7079bbebb5fc8ad4a62fddeb3556cb691b2d3e", 26 | "0xe362321eeddfc2513a54f8427c5ba40d088e8294", 27 | "0x9463d8301d38341d5f6f7f5304dd8e3e29867141", 28 | "0x373e7dbf92e86bc510f587ba560707a83d4f795e", 29 | "0x5c1c58978037c723583482cd38c5d40ecd2d7398", 30 | "0xb144f3d8e20bc55e468e5f43b5ccc032ca84ba74", 31 | "0x42906762aaaa468ce56219b3205848154b4cc0e7", 32 | "0x46ca0f770485fe09a704f0b4f400e74da55e262e", 33 | "0x9db25ef4239411a0ee6dfc75e11303a1c75fb6e3", 34 | "0x0c64c370d595ada819656de2674e4877b484b1d7", 35 | "0x22f2b4a4dfc20e4a2bf25239b0125ce31dab50e5", 36 | "0xecc4e97c4111259996931d689ad016d4e550ace3", 37 | "0xfcad6bb861d1af44d05b60c61b6336bce16ffdf7", 38 | "0xfde6be6b88f1de8b53506869fc9132ceade74c44", 39 | "0xee200296748ab60e2d3b67243ff763fbdd89269a", 40 | "0x9e7fff61ce55a9e97c2bb1670ab902925f523b7e", 41 | "0x057f0bce633834c3dc5401164a274ae762231cbd", 42 | "0x7ed00465e851440597acd7bac5da8c96cbe91b19" 43 | ]; 44 | 45 | var datadir = "/home/yang/.ethereum/rinkeby"; 46 | // var address= argv[2]; 47 | const password = "123666"; 48 | 49 | // display accounts and private keys 50 | for (var i = 0; i < accounts.length; i++) { 51 | var address = accounts[i]; 52 | var keyObject = keythereum.importFromFile(address, datadir); 53 | var privateKey = keythereum.recover(password, keyObject); 54 | console.log("{\""+address+"\", \""+privateKey.toString('hex')+"\"},"); 55 | } 56 | 57 | // // display accounts only 58 | // for (var i = 0; i < accounts.length; i++) { 59 | // var address = accounts[i]; 60 | // console.log(address+','); 61 | // } 62 | -------------------------------------------------------------------------------- /Eval&Tools/plot_attest_time.py: -------------------------------------------------------------------------------- 1 | # Figure 2 | # Running times of computation tasks 3 | 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | # from brokenaxes import brokenaxes 7 | 8 | 9 | # x = np.linspace(1, 8, 8) 10 | x = np.array([1,16,32,48,64,80,96,112,128,144,160]) 11 | y1 = [0.685,10.985,22.058,33.032,43.961,55.007,66.084,77.082,87.850,99.113,110.151] # DataBroker attesting to parallel DataOwners TCSNUM = 1 (sequential) 12 | y2 = [0.674,3.366,6.728,10.147,13.515,16.896,20.277,23.582,26.979,30.460,33.799] # DataBroker attesting to parallel DataOwners TCSNUM = 4 13 | y3 = [0.688,1.500,2.956,4.501,6.012,7.448,8.899,10.395,11.929,13.343,14.831] # DataBroker attesting to parallel DataOwners TCSNUM = 16 14 | y4 = [0.689,1.509,2.386,3.834,4.746,6.173,6.990,8.457,9.255,10.822,11.712] # DataBroker attesting to parallel DataOwners TCSNUM = 32 15 | y5 = [0.690,1.506,2.376,3.203,4.030,5.557,6.387,7.285,8.157,9.583,10.398] # DataBroker attesting to parallel DataOwners TCSNUM = 64 16 | y6 = [0.697,1.517,2.396,3.287,4.143,4.972,5.838,6.612,7.467,8.972,9.881] # DataBroker attesting to parallel DataOwners TCSNUM = 128 17 | 18 | 19 | fig, ax = plt.subplots() 20 | # ax = brokenaxes(ylims=((0, 20.0), (100.0, 140.0)), hspace=.1) 21 | 22 | line1 = ax.plot(x, y1, 'o-', label='Sequential (30.88MB enclave)', color='black', markersize=6) 23 | line2 = ax.plot(x, y2, 'x-', label='4 threads (32.51MB enclave)', color='magenta', markersize=6) 24 | line3 = ax.plot(x, y3, 's-', label='16 threads (38.99MB enclave)', color='green', markersize=6) 25 | # line4 = ax.plot(x, y4, 's-', label='32 threads (47.64MB enclave)', color='red', markersize=6) 26 | line5 = ax.plot(x, y5, '^-', label='64 threads (64.95MB enclave)', color='blue', markersize=6) 27 | # line6 = ax.plot(x, y6, 'o-', label='128 threads (99.55MB enclave)', color='cyan', markersize=6) 28 | 29 | 30 | 31 | 32 | 33 | ax.set_xlabel('N (Number of DataOwners)', fontsize=12) 34 | ax.set_ylabel('Attestation Time (seconds)', fontsize=12) 35 | # ax.set_title('Runtimes of Training a 14x8x8x2 ANN Classifier', fontsize=14) 36 | ax.legend(fontsize = 12, loc = 'upper left') 37 | 38 | # plt.ylim(-5,170) 39 | # plt.ylim(0,8) 40 | plt.xticks(x, ['1','16','32','48','64','80','96','112','128','144','160'], fontsize=11) 41 | # plt.yticks([-10,0,20,40,60,80,100,120,140,160], ['-10','0','20','40','60','80','100','120','140','160'], fontsize=11) 42 | 43 | # plt.text(80, 15, 'DataBroker \nenclave size: 2.3 MB', color='magenta', fontsize=12) 44 | # plt.text(90, 60, 'CEE enclave size: \n118.7 MB', color='blue', fontsize=12) 45 | 46 | plt.grid() 47 | plt.show() -------------------------------------------------------------------------------- /Eval&Tools/plot_comp_time.py: -------------------------------------------------------------------------------- 1 | # Figure 2 | # Running times of computation tasks 3 | 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | 7 | x = np.linspace(1000, 10000, 10) 8 | y1 = [68.514,137.098,204.863,273.898,341.774,408.749,476.726,543.549,611.941,680.712] # Enclave version. Hyperthreading enabled. 9 | y2 = [23.036,46.634,69.956,94.085,114.878,138.770,160.354,182.203,204.876,224.062] # Untrusted version. Hyperthreading enabled. 10 | y3 = [102.183,203.106,306.470,405.573,505.770,615.641,708.963,807.100,914.400,1008.540] # Enclave version. Hyperthreading disabled. 11 | y4 = [27.477,54.664,83.988,108.266,136.446,164.205,191.825,214.827,240.129,260.814] # Untrusted version. Hyperthreading disabled. 12 | 13 | fig, ax = plt.subplots() 14 | 15 | # Using set_dashes() to modify dashing of an existing line 16 | line1 = ax.plot(x, y1, 's-', label='Inside Enclave. HTT enabled', color='magenta', markersize=7) 17 | line2 = ax.plot(x, y2, 'o-', label='Outside Enclave. HTT enabled', color='black', markersize=7) 18 | line3 = ax.plot(x, y3, '^--', label='Inside Enclave. HTT disabled', color='blue', markersize=7) 19 | line4 = ax.plot(x, y4, 'v--', label='Outside Enclave. HTT disabled', color='green', markersize=7) 20 | 21 | # ax2 = ax.twinx() 22 | # ax2.set_ylabel('Runtime Overhead') 23 | 24 | ax.set_xlabel('Number of Training Data Samples', fontsize=12) 25 | ax.set_ylabel('Runtime (seconds)', fontsize=12) 26 | # ax.set_title('Runtimes of Training a 14x8x8x2 ANN Classifier', fontsize=14) 27 | ax.legend(fontsize = 12) 28 | 29 | plt.ylim(0,400) 30 | plt.xticks(x, ['1K','2K','3K','4K','5K','6K','7K','8K','9K','10K'], fontsize=11) 31 | plt.yticks([0,100,200,300,400,500,600,700,800,900,1000,1100], ['0','100','200','300','400','550','600','700','800','900','1000','1100'], fontsize=11) 32 | 33 | plt.text(6000, 570, 'avg. overhead = 196.55%', color='magenta', fontsize=12, rotation=24) 34 | plt.text(6000, 90, 'base case', color='black', fontsize=12, rotation=8) 35 | plt.text(6000, 850, 'avg. overhead = 341.37%', color='blue', fontsize=12, rotation=32) 36 | plt.text(6000, 310, 'avg. overhead = 17.99%', color='green', fontsize=12, rotation=9) 37 | 38 | plt.grid() 39 | plt.show() -------------------------------------------------------------------------------- /Eval&Tools/plot_contract_call_time.py: -------------------------------------------------------------------------------- 1 | # Figure 2 | # Times of contract function calls 3 | 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | 7 | 8 | # x = np.linspace(1, 8, 8) 9 | x = np.array([1,16,32,48,64,80,96,112,128,144,160]) 10 | y1 = [11.347,18.694,22.724,24.619,26.942,29.968,36.295,43.399,50.380,91.505,95.497] # DOs calling register() of their own contracts 11 | y2 = [10.331,18.377,19.158,22.663,33.650,35.492,38.588,43.221,51.158,77.397,89.880] # DOs calling register() of the DB contract 12 | 13 | 14 | fig, ax = plt.subplots() 15 | 16 | line1 = ax.plot(x, y1, 's-', label='Calling register() of DataOwners\' contracts', color='magenta', markersize=8) 17 | line2 = ax.plot(x, y2, 'o-', label='Calling register() of the DataBroker contract', color='blue', markersize=8) 18 | 19 | ax.set_xlabel('N (Number of DataOwners)', fontsize=12) 20 | ax.set_ylabel('Average Time to Finalize (seconds)', fontsize=12) 21 | # ax.set_title('Runtimes of Training a 14x8x8x2 ANN Classifier', fontsize=14) 22 | ax.legend(fontsize = 12, loc = 'upper left') 23 | 24 | plt.ylim(0,120) 25 | # plt.ylim(0,50) 26 | plt.xticks(x, ['1','16','32','48','64','80','96','112','128','144','160'], fontsize=11) 27 | # plt.yticks([-10,0,20,40,60,80,100,120,140,160], ['-10','0','20','40','60','80','100','120','140','160'], fontsize=11) 28 | 29 | # plt.text(80, 15, 'DataBroker \nenclave size: 2.3 MB', color='magenta', fontsize=12) 30 | # plt.text(90, 60, 'CEE enclave size: \n118.7 MB', color='blue', fontsize=12) 31 | 32 | plt.grid() 33 | plt.show() -------------------------------------------------------------------------------- /Eval&Tools/plot_total_cost.py: -------------------------------------------------------------------------------- 1 | # Figure 2 | # Cost of calling contract functions 3 | 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | from sklearn import datasets, linear_model 7 | 8 | 9 | N = 10 10 | 11 | x = np.linspace(1, N, N) 12 | 13 | a1 = 125392 # Cost: DO calling DO contract's register() (new registry) 14 | z2 = 80402 # Cost: DC calling DO contract's request() 15 | z3 = 134563 # Cost: DC calling DO contract's computationComplete() 16 | z4 = 90393 # Cost: iDA calling DO contract's completeTransaction() 17 | 18 | b1 = 156414 # Cost: DO calling DB contract's register() (new registry) 19 | y1 = [92498,107498,122498,137498,152498,167498,182498,197498,212498,227498] # Cost: DB calling DB contract's confirm() 20 | y2 = [80717,98029,115341,132653,149965,167277,184589,201901,219213,236525] # Cost: DC calling DB contract's request() 21 | y3 = [134563,148916,163946,179651,196033,213091,230826,249236,268323,288681] # Cost: DC calling DB contract's computationComplete() 22 | y4 = [91323,99915,108507,117099,125691,134283,142875,151467,160059,168651] # Cost: DB calling DB contract's completeTransaction() 23 | 24 | # Compute the total cost for each N 25 | TC_DB = np.zeros(N) 26 | TC_iDA = np.zeros(N) 27 | 28 | for i in range(N): 29 | n = i + 1 30 | TC_DB[i] = n * b1 + y1[i] + y2[i] + y3[i] + y4[i] 31 | TC_iDA[i] = n * a1 + n * z2 + n * z3 + n * z4 32 | 33 | print(TC_DB) 34 | print(TC_iDA) 35 | 36 | # Create linear regression object 37 | regr1 = linear_model.LinearRegression() 38 | regr2 = linear_model.LinearRegression() 39 | regr1.fit(x.reshape(-1, 1), TC_DB) 40 | regr2.fit(x.reshape(-1, 1), TC_iDA) 41 | print('Coefficients: \n', regr1.coef_) 42 | print('Coefficients: \n', regr2.coef_) 43 | 44 | 45 | fig, ax = plt.subplots() 46 | 47 | # Using set_dashes() to modify dashing of an existing line 48 | line1 = ax.plot(x, TC_DB, 'o-', label='Total cost of DataBroker-based system', color='magenta', markersize=7) 49 | line2 = ax.plot(x, TC_iDA, 'v-', label='Total cost of iDataAgent-based system', color='blue', markersize=7) 50 | 51 | ax.set_xlabel('N (Number of DataOwners)', fontsize=12) 52 | ax.set_ylabel('Cost in Gas (Dollar Equiv.)', fontsize=12) 53 | # ax.set_title('Total Cost Comparison', fontsize=14) 54 | ax.legend(fontsize = 12) 55 | 56 | plt.ylim(0,4500000) 57 | plt.xticks(x, ['1','2','3','4','5','6','7','8','9','10'], fontsize=11) 58 | plt.yticks([0,1000000,2000000,3000000,4000000,5000000], ['0', '1000000\n($0.19785)','2000000\n($0.39570)','3000000\n($0.59355)','4000000\n($0.79140)','5000000\n($0.98925)'],fontsize=11) 59 | 60 | plt.text(6, 1900000, r'$\Delta = 214409$ (\$0.04242)', color='magenta', fontsize=11, rotation=16) 61 | plt.text(6, 3400000, r'$\Delta = 430750$ (\$0.08522)', color='blue', fontsize=11, rotation=32) 62 | 63 | plt.grid() 64 | plt.show() -------------------------------------------------------------------------------- /Eval&Tools/totalCostCallingContract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Eval&Tools/totalCostCallingContract.png -------------------------------------------------------------------------------- /Intel/client.cnf: -------------------------------------------------------------------------------- 1 | [ ssl_client ] 2 | keyUsage = digitalSignature, keyEncipherment, keyCertSign 3 | subjectKeyIdentifier=hash 4 | authorityKeyIdentifier=keyid,issuer 5 | extendedKeyUsage = clientAuth, serverAuth 6 | -------------------------------------------------------------------------------- /Intel/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEGTCCAwGgAwIBAgIJAJexsKGrFacJMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD 3 | VQQGEwJVUzERMA8GA1UECAwIVmlyZ2luaWExFTATBgNVBAcMDEZhbGxzIENodXJj 4 | aDEWMBQGA1UECgwNVmlyZ2luaWEgVGVjaDERMA8GA1UECwwIQ05TUiBMYWIxEjAQ 5 | BgNVBAMMCVlhbmcgWGlhbzEbMBkGCSqGSIb3DQEJARYMeGlhb3lAdnQuZWR1MB4X 6 | DTE4MDkyNzE0NTgxNVoXDTE5MDkyNzE0NTgxNVowgZMxCzAJBgNVBAYTAlVTMREw 7 | DwYDVQQIDAhWaXJnaW5pYTEVMBMGA1UEBwwMRmFsbHMgQ2h1cmNoMRYwFAYDVQQK 8 | DA1WaXJnaW5pYSBUZWNoMREwDwYDVQQLDAhDTlNSIExhYjESMBAGA1UEAwwJWWFu 9 | ZyBYaWFvMRswGQYJKoZIhvcNAQkBFgx4aWFveUB2dC5lZHUwggEiMA0GCSqGSIb3 10 | DQEBAQUAA4IBDwAwggEKAoIBAQCxMrDmmnguPgzUu1KO0LpAOUusJ/kfAcz8+94/ 11 | BEWH7XSnAXWzx/fR3zfmLS9VjJYhikU6VI6jNQil/gpE8EL8iNnG7E8MACnq6D2t 12 | J0ayhc8XMvWexo5k0khNNX2lX2eVwOks5IDjnbBZP80FgrKT0SqbtbYHUACtWeno 13 | RVUSAgeZ8kHO7RJrAHhDU4HAuidmJcsgJX1Nnbp5VOSeHr8tX+o3Oc1agED3OOtR 14 | CY3k6ZEhRHc4mjbl67tSsau0RJ9Buiym42//pW5DP1KzzrXT6vp5bk3ADEU+gJkv 15 | FiviOkB4BklmVXf1QFIgyYURtyUFWTrFkSAuSJthVMhvpoUNAgMBAAGjbjBsMAsG 16 | A1UdDwQEAwICpDAdBgNVHQ4EFgQU6DdrPMFK6mK5kDmOg4ieSgxRR+AwHwYDVR0j 17 | BBgwFoAU6DdrPMFK6mK5kDmOg4ieSgxRR+AwHQYDVR0lBBYwFAYIKwYBBQUHAwIG 18 | CCsGAQUFBwMBMA0GCSqGSIb3DQEBCwUAA4IBAQA/mVcV3FHg70OYTpzEu67T0OLF 19 | mjO0BT0yoS7YYIUafgKffAPQfQpdPiZV9h+VnfNW2emKGcMHpanAIPgruSuUDhDa 20 | DukNpBap/cwftm0HVhmhnF3hvq6OloBA91xC07ISXOz0QlVnfn6NaNaAG9ykPjwu 21 | T7wfqCns0zLxmMREuMLJJXNKRNjqHTZ3povgTTduX004vUYidWLfzgnSw1ggZgeV 22 | Z3EtLerTahQyd0ih+4QYJnn88+fQddgW3beE/t0+5Pm9lyY6+u/oSXQhqLSta8OJ 23 | GHSdw/14jRxHrYSu2r3klemyj9uphXEqIRMRRIhYZ11GHI2ZZYwhb+3GCSWO 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /Intel/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAsTKw5pp4Lj4M1LtSjtC6QDlLrCf5HwHM/PvePwRFh+10pwF1 3 | s8f30d835i0vVYyWIYpFOlSOozUIpf4KRPBC/IjZxuxPDAAp6ug9rSdGsoXPFzL1 4 | nsaOZNJITTV9pV9nlcDpLOSA452wWT/NBYKyk9Eqm7W2B1AArVnp6EVVEgIHmfJB 5 | zu0SawB4Q1OBwLonZiXLICV9TZ26eVTknh6/LV/qNznNWoBA9zjrUQmN5OmRIUR3 6 | OJo25eu7UrGrtESfQbospuNv/6VuQz9Ss8610+r6eW5NwAxFPoCZLxYr4jpAeAZJ 7 | ZlV39UBSIMmFEbclBVk6xZEgLkibYVTIb6aFDQIDAQABAoIBAC40ep5XDxl3wp7C 8 | DcABu1890Xadob8tGAeroYMrGPpdt7pIjimH7h4Cp6/UfnA/TXKHfI++Nsdl79Bg 9 | 0sqxH7Z79NWDDwWhEU0Yq+R3xl6Mt7hj6FozijPOBV5koVO68ebBu8uh9d3kY3SS 10 | R2K1dt1GgGbD1ihH+zU4qd6QHaOpBsDsh7Y1Gz67JlRxNVD/LBFCI/IvzsJFRubE 11 | UicwtAAIztqg8DRaWc1Vjddadpsf/neItqq9IE9nCBhRahReabwZ7QVIaosWxEPh 12 | tMtzxO/Xi0uoL9aNaNRrhbkyyYDkxD99gzXKMB7FQoWRuX0RL7ePremCNK3oI3+z 13 | 0bWefMECgYEA1e/3gpwqD5Ohyz5DLE1jO1wjJAoXCQtzvtNMjlSuaOWNvrpnt/PG 14 | SaqzYO4V4oEp7m+JNN2bhSdOyVFDdKVbrpu7F1UTgrj5WvOS8yQ4ZfZEWBIy/m9K 15 | HhlmyNl4aFXS9BdyKQenOT0oFmabxn8VGGYT/0XT3K+E6mbl/i5eAtECgYEA1AmJ 16 | AZSSTZS3VDUF4Y8ixjjdrZFZTAjwN0zC1EeCLQN0DLntxRZF/Ebxj8QQr+eoLq2b 17 | 8nkjeG/H9io26p3UnC5l5FSfOmrj30J2B30fc6E+JOEmX/KWgmDK3W52ClIUreko 18 | klnlW/YjRPzaTYD9sAg3l9muCm7jTxGaSXZEFX0CgYEAw381vrTV+sX946xR1foh 19 | 4+yecCCITEuayZZtLuNTPagHj3LntMGfQVIr+TeX6BQALVLfHuAjbdottOn9qmox 20 | Da5hmUC1Q4+kzegnMOi4YPRaH+EBmGA6aqbrtj6EOVO0IjoKqFPGDBhGubGqSAl5 21 | TYJ6Y5t7rv71hv3gzhWw8wECgYEAv7PvPpKIw8OVDHjz3D6A/h4jre0fgvMB2712 22 | 2F3ef7wDjA39vpaop7GsbIKjY6ZaE/m6aLrFKvpFG3aHOA+CTcJVNN6dJz/EzfFU 23 | rOifKve5K7az70NweGfygciAyEv1jlai686C42Xh9Vl2NWRN+H01ZgDUrXIb6TzM 24 | 9WYLoDECgYEAv+wyWJ25qS3BqCxzdIQ/lRPFYrWYKbhWgxJ+3CGiRvwo8mTtJP7e 25 | Al0LlIMDHfkkyU+mZFDArZJNF55GYLi7tVMYY88E6KwZa3iOlTVwSwWNhhgdCtjU 26 | FETf9X1jxMDObmHN5YmdzgMJ/R7kHt6Yxf6Y1obCY8xE33Tqkj6atjY= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /Intel/client.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/Intel/client.pfx -------------------------------------------------------------------------------- /Intel/client.req: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIC8DCCAdgCAQAwgZMxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhWaXJnaW5pYTEV 3 | MBMGA1UEBwwMRmFsbHMgQ2h1cmNoMRYwFAYDVQQKDA1WaXJnaW5pYSBUZWNoMREw 4 | DwYDVQQLDAhDTlNSIExhYjESMBAGA1UEAwwJWWFuZyBYaWFvMRswGQYJKoZIhvcN 5 | AQkBFgx4aWFveUB2dC5lZHUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 6 | AQCxMrDmmnguPgzUu1KO0LpAOUusJ/kfAcz8+94/BEWH7XSnAXWzx/fR3zfmLS9V 7 | jJYhikU6VI6jNQil/gpE8EL8iNnG7E8MACnq6D2tJ0ayhc8XMvWexo5k0khNNX2l 8 | X2eVwOks5IDjnbBZP80FgrKT0SqbtbYHUACtWenoRVUSAgeZ8kHO7RJrAHhDU4HA 9 | uidmJcsgJX1Nnbp5VOSeHr8tX+o3Oc1agED3OOtRCY3k6ZEhRHc4mjbl67tSsau0 10 | RJ9Buiym42//pW5DP1KzzrXT6vp5bk3ADEU+gJkvFiviOkB4BklmVXf1QFIgyYUR 11 | tyUFWTrFkSAuSJthVMhvpoUNAgMBAAGgFzAVBgkqhkiG9w0BCQcxCAwGMTIzNjY2 12 | MA0GCSqGSIb3DQEBCwUAA4IBAQB9DUdHm+vEeFlb5608LPPLOhixemvXejWZXU0C 13 | fYstwABPMT+ljlOdVp0RFERFjVJXImtZdzSsqEp60zw6jXAQt28vT4cRb17so5EW 14 | iaNaM1QI4D6fH/EHXqb/nTTo14Avp/7SQZtmbTYeBpG9p8NF/T9EobS33uRWlI3W 15 | FpBb1qYBWlRfOF52ot2Xew17Q7uUelTXknKklVPlHi8mmqu9CXS7XBndYoyn2CSC 16 | Z+woA8rd5wmFvme7VeU5C+0SsyRsRkr9t0FCtDYuzIEf1SYMXwWajWKprreP4js8 17 | 6hOHKvA+SKoB8EIijwx6wteu1wXz5DDSx37SXn/rX5O/4VIo 18 | -----END CERTIFICATE REQUEST----- 19 | -------------------------------------------------------------------------------- /Intel/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 33 | SOS5tek= 34 | -----END CERTIFICATE----- 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Yang Xiao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Dear users, we kindly note that this repo provides a proof-of-concept implementation of PrivacyGuard, not a product release. An older generation (2.0.1) of Intel SGX is used. We recommend readers to use our code as a workflow reference, rather than a product baseline. Thanks!* 2 | 3 | ## Entities to be run in the cloud: 4 | - iDA (iDataAgent) 5 | - DB (Data Broker) 6 | - CEE (Contract Execution Environment) 7 | 8 | ## Entities to be run remotely 9 | - DC (Data Consumer) 10 | - DO (Data Owner) 11 | 12 | ## System requirements 13 | - OS: Ubuntu 16.04 LTS 14 | - Intel SGX driver, PSW, SDK (see https://github.com/intel/linux-sgx) 15 | 16 | ## Deployed contracts (on Ethereum Rinkeby) 17 | - DataBroker Contract address: 0x7CAC532e3E93666247a56D987e25AEa5050B8cee 18 | - DataOwner Contract address: 0x208D3CEdFE8918298A726264B578A9BA2AE8c85B 19 | (Search contract addresses at https://rinkeby.etherscan.io/) 20 | 21 | ## How to run 22 | - To build all programs: bash ./allmake 23 | - To clean all programs: bash ./allclean 24 | - Executables will appear in individual directories. 25 | 26 | ## System workflow for single data usage case with 1 DO, 1 iDA, 1 CEE 27 | 1. DO publishes its data usage policy through Ethereum smart contracts. 28 | 2. DO remotely attests iDA's enclave. 29 | 3. DC observes DO's contract from blockchain and parses the policy. 30 | 4. DC invokes the smart contract by sending a transaction with the required deposit amount to call the contract's request() function. 31 | 5. DC sends a REQUEST message to DO's iDataAgent. 32 | 6. iDataAgent checks DC's deposit amount in the contract and then deploys CEE. 33 | 7. iDataAgent and DC remotely attest CEE's enclave. 34 | 8. With the secure channel establish by step 6, iDataAgent provisions DO's data decryption key K_data to CEE. 35 | 9. CEE performs data operation. 36 | 10. CEE securely provisions C_result, Hash(C_result), Hash(K_result) to DC; K_result to iDA. Then destructs the enclave. 37 | 11. DC calls the contract's computationComplete() function with Hash(K_result). 38 | 12. DO calls the contract's completeTransaction() function with K_result. 39 | 40 | ## Test the Enclave Program ML Model Training Only (i.e., off-chain execution) 41 | - Go to Enclave_testML and there should be a similar executable, which only instantiates the in-enclave ML training functions. 42 | - Try option 3,4,5,6 to reproduce the enclave benchmark results in our paper. 43 | 44 | ## Publication 45 | The paper titled "PrivacyGuard: Enforcing Private Data Usage Control with Blockchain and Attested Off-chain Contract Execution" has appeared in ESORICS 2020, Sep 14-18, 2020. 46 | -------------------------------------------------------------------------------- /allmake.sh: -------------------------------------------------------------------------------- 1 | cd DataOwner 2 | make 3 | cd ../DataOwner_group 4 | make 5 | cd ../iDataAgent 6 | make 7 | cd ../DataBroker 8 | make 9 | cd ../DataConsumer 10 | make 11 | cd ../CEE 12 | make 13 | cd ../Enclave_testML 14 | make 15 | cd .. 16 | -------------------------------------------------------------------------------- /cleanmake.sh: -------------------------------------------------------------------------------- 1 | cd DataOwner 2 | make clean 3 | cd ../DataOwner_group 4 | make clean 5 | cd ../iDataAgent 6 | make clean 7 | cd ../DataBroker 8 | make clean 9 | cd ../DataConsumer 10 | make clean 11 | cd ../CEE 12 | make clean 13 | cd ../Enclave_testML 14 | make clean 15 | cd .. 16 | -------------------------------------------------------------------------------- /iDataAgent/App/clientdata_operation.h: -------------------------------------------------------------------------------- 1 | #ifndef _CLIENTDATA_OPERATION_H_ 2 | #define _CLIENTDATA_OPERATION_H_ 3 | 4 | 5 | #if defined(__cplusplus) 6 | extern "C" { 7 | #endif 8 | 9 | 10 | 11 | /* Generate AES key shell command 12 | openssl enc -aes-128-cbc -k secret -P -md sha256 -nosalt 13 | */ 14 | 15 | 16 | 17 | int getdata_encrypt_store(); 18 | int encrypt_store(); 19 | 20 | // int VerifyDeposit(); 21 | 22 | #if defined(__cplusplus) 23 | } 24 | #endif 25 | 26 | #endif -------------------------------------------------------------------------------- /iDataAgent/App/operations.h: -------------------------------------------------------------------------------- 1 | #ifndef _OPERATIONS_H_ 2 | #define _OPERATIONS_H_ 3 | 4 | 5 | #include 6 | #include "enclave_u.h" 7 | #include "sgx_urts.h" 8 | #include "sgx_uae_service.h" 9 | #include "remote_attestation_result.h" 10 | #include "network_ra.h" 11 | 12 | 13 | #if defined(__cplusplus) 14 | extern "C" { 15 | #endif 16 | 17 | 18 | 19 | #define AESGCM_KEY_SIZE 16 20 | #define AESGCM_MAC_SIZE 16 21 | #define KECCAK_HASH_SIZE 32 22 | 23 | #define TASK1_RESULT_SIZE 4 // Bytes. Summation of single digits 24 | #define TASK2_RESULT_SIZE 1000 // Bytes. SVM model 25 | #define TASK3_RESULT_SIZE 10000 // Bytes. ANN model 26 | 27 | 28 | /* Enum for all possible operation message types (except for attestation related) between CEE and DC, iDA*/ 29 | typedef enum _op_msg_type_t 30 | { 31 | TYPE_OP_AUTH, // Authentication message 32 | TYPE_OP_COMP_RES, // computation result message 33 | }op_msg_type_t; 34 | 35 | typedef struct _enclave_info_t{ 36 | sgx_enclave_id_t enclave_id; 37 | sgx_ra_context_t context; 38 | uint32_t extended_epid_group_id; 39 | }enclave_info_t; 40 | 41 | // typedef struct _auth_msg_header_t{ 42 | // uint8_t type; 43 | // uint8_t challenger_type; 44 | // }auth_msg_header_t; 45 | 46 | typedef struct _computation_result_msg_t{ 47 | uint8_t type; 48 | int DO_ID; 49 | int file_num; 50 | uint8_t result_encrypted[4]; 51 | uint8_t result_gcm_mac[16]; 52 | }computation_result_msg_t; 53 | 54 | typedef struct _operation_config_msg_t{ 55 | int DC_ID; 56 | int type; 57 | int start; 58 | int end; 59 | int operation; 60 | }operation_config_msg_t; 61 | 62 | typedef struct _K_result_msg_t{ // to iDA/DB 63 | int DO_ID; 64 | int file_num; 65 | uint8_t K_result_en[AESGCM_KEY_SIZE]; 66 | uint8_t K_result_mac[AESGCM_MAC_SIZE]; 67 | }K_result_msg_t; 68 | 69 | 70 | bool enclave_init(enclave_info_t* enclave_info); 71 | 72 | int remote_attest_enclave(int sock_num, int* p_challenger_type, enclave_info_t* enclave_info); 73 | 74 | int enclave_close(enclave_info_t* enclave_info); 75 | 76 | int remote_attest_challenger(int sock_num, int type, uint8_t* secret, int secret_size); 77 | 78 | int process_DO_data(enclave_info_t* enclave_info, do_provision_data_header_t* DO_msg_header, uint8_t* DO_data); 79 | 80 | int checkContractStatus(char* contract_addr); 81 | 82 | #if defined(__cplusplus) 83 | } 84 | #endif 85 | #endif -------------------------------------------------------------------------------- /iDataAgent/App/txSendDirectly.js: -------------------------------------------------------------------------------- 1 | // The orginal full tx generation process of geth 2 | var Web3 = require('web3'); 3 | // var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/')); 4 | var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); 5 | var util = require('ethereumjs-util'); 6 | var tx = require('ethereumjs-tx'); 7 | 8 | 9 | var p = new Buffer('3bdc966729b1c929efa2053c40c77f31cf2e9048950c8f86af937780e5686dbd', 'hex'); // DO's Ethereum private key 10 | var address = '0xac5d434a4a9cf170baaa5d1be12b48c7fe358fa0'; // DO's Ethereum address 11 | 12 | var argv = process.argv; 13 | 14 | web3.eth.getTransactionCount(address).then(function (res, err){ 15 | if (err) { 16 | console.log('error: ' + err); 17 | 18 | } 19 | else { 20 | // console.log('success: ' + res); 21 | var txCount = res; 22 | // console.log(txCount); 23 | 24 | var rawTx = { 25 | nonce: web3.utils.numberToHex(txCount), 26 | gasPrice: web3.utils.numberToHex(argv[2]), 27 | gasLimit: web3.utils.numberToHex(argv[3]), 28 | to: argv[4], // DO's address 29 | value: web3.utils.numberToHex(argv[5]), // 0.01 ether 30 | data: argv[6] 31 | }; 32 | 33 | var transaction = new tx(rawTx); 34 | transaction.sign(p); // This step needs to be done in the enclave 35 | var RawTxHex = '0x' + transaction.serialize().toString('hex'); // This is what we need to feed the api 36 | console.log('\nRawTxHex:\n' + RawTxHex); 37 | 38 | // Send the raw transaction hex 39 | // web3.eth.sendSignedTransaction(RawTxHex, function (err, hash) { 40 | // if (err) { 41 | // console.log(err); 42 | // } 43 | // else { 44 | // console.log('\nTransaction hash: ' + hash); 45 | // } 46 | // }); 47 | 48 | web3.eth.sendSignedTransaction(RawTxHex).on('receipt', console.log); 49 | } 50 | }); -------------------------------------------------------------------------------- /iDataAgent/Enclave/TrustedLibrary/Libc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | #include 34 | #include "sgx_cpuid.h" 35 | 36 | #include "sgx_trts.h" 37 | #include "../Enclave.h" 38 | #include "Enclave_t.h" 39 | 40 | /* ecall_malloc_free: 41 | * Uses malloc/free to allocate/free trusted memory. 42 | */ 43 | void ecall_malloc_free(void) 44 | { 45 | void *ptr = malloc(100); 46 | assert(ptr != NULL); 47 | memset(ptr, 0x0, 100); 48 | free(ptr); 49 | } 50 | 51 | /* ecall_sgx_cpuid: 52 | * Uses sgx_cpuid to get CPU features and types. 53 | */ 54 | void ecall_sgx_cpuid(int cpuinfo[4], int leaf) 55 | { 56 | sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); 57 | if (ret != SGX_SUCCESS) 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/TrustedLibrary/Libc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libc.edl - EDL sample for trusted C library. */ 34 | 35 | enclave { 36 | 37 | from "sgx_tstdc.edl" import sgx_oc_cpuidex; 38 | 39 | /* 40 | * A subset of the C99 standard is supported as well as SGX customized functions: 41 | * sgx_cpuid, etc. 42 | */ 43 | 44 | trusted { 45 | /* 46 | * Utilize malloc/free in enclave. 47 | */ 48 | public void ecall_malloc_free(void); 49 | 50 | /* 51 | * Utilize SGX version __cpuid() in enclave. 52 | */ 53 | public void ecall_sgx_cpuid([out] int cpuinfo[4], int leaf); 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/TrustedLibrary/Libcxx.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | 33 | /* Libcxx.edl - EDL sample for trusted C++ library. */ 34 | 35 | enclave { 36 | 37 | /* 38 | * A subset of the C++03 standard is supported. 39 | */ 40 | 41 | trusted { 42 | /* 43 | * Throw/catch exception inside the enclave. 44 | */ 45 | public void ecall_exception(void); 46 | 47 | /* 48 | * Utilize inside the enclave. 49 | */ 50 | public void ecall_map(void); 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/TrustedLibrary/Thread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2018 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /* Thread.edl - EDL sample for trusted thread library. */ 33 | 34 | enclave { 35 | 36 | from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; 37 | 38 | trusted { 39 | /* 40 | * Use SGX mutex. 41 | */ 42 | public size_t ecall_increase_counter(); 43 | 44 | /* 45 | * Use SGX condition variables. 46 | */ 47 | public void ecall_producer(); 48 | public void ecall_consumer(); 49 | 50 | }; 51 | }; 52 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x100000 6 | 1 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | g_peak_heap_used; 8 | local: 9 | *; 10 | }; 11 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/enclave_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef SECP256K1_ECDH_H 2 | #define SECP256K1_ECDH_H 3 | 4 | #include "secp256k1.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* SECP256K1_ECDH_H */ 32 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/keccak256.h: -------------------------------------------------------------------------------- 1 | /* sha3 - an implementation of Secure Hash Algorithm 3 (Keccak). 2 | * based on the 3 | * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011 4 | * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche 5 | * 6 | * Copyright: 2013 Aleksey Kravchenko 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so. 14 | * 15 | * This program is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! 18 | */ 19 | 20 | #ifndef __KECCAK256_H_ 21 | #define __KECCAK256_H_ 22 | 23 | #include 24 | 25 | #define sha3_max_permutation_size 25 26 | #define sha3_max_rate_in_qwords 24 27 | 28 | typedef struct SHA3_CTX { 29 | /* 1600 bits algorithm hashing state */ 30 | uint64_t hash[sha3_max_permutation_size]; 31 | /* 1536-bit buffer for leftovers */ 32 | uint64_t message[sha3_max_rate_in_qwords]; 33 | /* count of bytes in the message[] buffer */ 34 | uint16_t rest; 35 | /* size of a message block processed at once */ 36 | //unsigned block_size; 37 | } SHA3_CTX; 38 | 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | 45 | void keccak_init(SHA3_CTX *ctx); 46 | void keccak_update(SHA3_CTX *ctx, const unsigned char *msg, uint16_t size); 47 | void keccak_final(SHA3_CTX *ctx, unsigned char* result); 48 | 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* __KECCAK256_H_ */ 55 | -------------------------------------------------------------------------------- /iDataAgent/Enclave/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /iDataAgent/sample_libcrypto/libsample_libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yang-sec/PrivacyGuard/1ef665fca9dadf00bc0bb363842ab471a747ab0a/iDataAgent/sample_libcrypto/libsample_libcrypto.so --------------------------------------------------------------------------------