├── .clang-tidy ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── COPYING ├── COPYING.APACHE ├── CTestConfig.cmake ├── README.md ├── bin ├── iris.data ├── iris_data.ini └── ypcd.conf ├── build.sh ├── cmake ├── ClangTidy.cmake ├── Config.cmake.in ├── Coverage.cmake ├── Doxygen.cmake ├── FindSGX.cmake ├── GTest.cmake ├── HunterGate.cmake ├── SGXHelper.cmake ├── Util.cmake.in ├── Version.cmake ├── project_path.h.in ├── vendor.cmake └── version.h.in ├── doc ├── .gitkeep ├── Compile-ZH.md ├── Debug_EN.md ├── Debug_ZH.md ├── Developer_EN.md ├── Developer_ZH.md ├── Fidelius-Infr.png ├── README_ZH.md ├── Release_EN.md ├── Release_ZH.md ├── pdf │ ├── delegation.pdf │ ├── hpda.pdf │ ├── multi_stream.pdf │ ├── offchain.pdf │ ├── programming.pdf │ ├── shukey.pdf │ └── task_graph.pdf └── wechat_image.JPG ├── example ├── CMakeLists.txt ├── iris │ ├── CMakeLists.txt │ ├── analyzer │ │ ├── enclave │ │ │ ├── CMakeLists.txt │ │ │ ├── enclave.config.debug.xml │ │ │ ├── enclave.config.xml │ │ │ ├── enclave.lds │ │ │ ├── enclave_debug.lds │ │ │ ├── enclave_iris_parser.h │ │ │ ├── enclave_private.pem │ │ │ ├── eparser.cpp │ │ │ └── user_type.h │ │ └── enclave_for_offchain │ │ │ ├── CMakeLists.txt │ │ │ ├── enclave.config.xml │ │ │ ├── enclave_debug.lds │ │ │ ├── enclave_private.pem │ │ │ └── eparser.cpp │ ├── classifier │ │ ├── CMakeLists.txt │ │ ├── enclave │ │ │ ├── CMakeLists.txt │ │ │ ├── enclave.config.debug.xml │ │ │ ├── enclave.config.xml │ │ │ ├── enclave.lds │ │ │ ├── enclave_debug.lds │ │ │ ├── enclave_iris_classifier.h │ │ │ ├── enclave_private.pem │ │ │ └── eparser.cpp │ │ ├── input.cpp │ │ ├── main.cpp │ │ ├── model.h │ │ └── user_type.h │ ├── iris │ │ ├── CMakeLists.txt │ │ ├── output │ │ │ └── user_type.h │ │ └── reader │ │ │ ├── CMakeLists.txt │ │ │ └── reader.cpp │ └── plugin │ │ ├── CMakeLists.txt │ │ ├── iris_reader.cpp │ │ └── iris_reader.h ├── multi_personlist │ ├── CMakeLists.txt │ ├── common.h │ ├── common_t.h │ ├── first_match │ │ ├── enclave │ │ │ ├── CMakeLists.txt │ │ │ ├── enclave.config.debug.xml │ │ │ ├── enclave.config.xml │ │ │ ├── enclave.lds │ │ │ ├── enclave_debug.lds │ │ │ ├── enclave_private.pem │ │ │ ├── eparser.cpp │ │ │ ├── first_match_parser.h │ │ │ └── user_type.h │ │ ├── enclave_for_offchain │ │ │ ├── CMakeLists.txt │ │ │ ├── enclave.config.debug.xml │ │ │ ├── enclave.config.xml │ │ │ ├── enclave.lds │ │ │ ├── enclave_debug.lds │ │ │ ├── enclave_private.pem │ │ │ └── eparser.cpp │ │ └── normal │ │ │ ├── CMakeLists.txt │ │ │ └── main.cpp │ └── generator │ │ ├── CMakeLists.txt │ │ └── main.cpp └── personlist │ ├── CMakeLists.txt │ ├── common.h │ ├── common_t.h │ ├── first_match │ ├── enclave │ │ ├── CMakeLists.txt │ │ ├── enclave.config.debug.xml │ │ ├── enclave.config.xml │ │ ├── enclave.lds │ │ ├── enclave_debug.lds │ │ ├── enclave_private.pem │ │ ├── eparser.cpp │ │ ├── first_match_parser.h │ │ └── user_type.h │ └── normal │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── generator │ ├── CMakeLists.txt │ └── main.cpp │ └── plugin │ ├── CMakeLists.txt │ ├── person_reader.cpp │ └── person_reader.h ├── hpda ├── CMakeLists.txt ├── src │ ├── engine │ │ ├── engine.cpp │ │ └── functor.cpp │ ├── extractor │ │ ├── internal │ │ │ └── https_request.cpp │ │ └── paged_https_extractor.cpp │ └── util │ │ └── ntobject_helper.cpp └── test │ ├── CMakeLists.txt │ ├── extractor │ ├── test_https_extractor.cpp │ └── test_paged_https_extractor.cpp │ ├── gtest_main.cpp │ ├── kmeans │ ├── test_kmeans_iris.cpp │ ├── test_kmeans_tuple.cpp │ ├── test_loyd_tuple.cpp │ ├── test_loyd_vector.cpp │ ├── tuple_point.cpp │ └── tuple_point.h │ ├── processor │ ├── test_all.cpp │ ├── test_concat.cpp │ ├── test_filter.cpp │ ├── test_groupby.cpp │ ├── test_json_to_data_batch.cpp │ ├── test_set.cpp │ ├── test_split.cpp │ └── test_trim.cpp │ └── test_basic.cpp ├── include ├── hpda │ ├── algorithm │ │ ├── algorithm.h │ │ ├── internal │ │ │ └── kmeans_loyd.h │ │ └── kmeans.h │ ├── common │ │ ├── common.h │ │ ├── processor_with_input.h │ │ ├── processor_with_output.h │ │ └── stream_policy.h │ ├── engine │ │ ├── engine.h │ │ └── functor.h │ ├── extractor │ │ ├── extractor.h │ │ ├── extractor_base.h │ │ ├── internal │ │ │ └── https_request.h │ │ ├── paged_https_extractor.h │ │ └── raw_data.h │ ├── hpda.h │ ├── output │ │ ├── memory_output.h │ │ ├── output.h │ │ └── output_base.h │ ├── processor │ │ ├── processor.h │ │ ├── processor_base.h │ │ ├── query │ │ │ └── filter.h │ │ ├── set │ │ │ ├── difference.h │ │ │ ├── helper │ │ │ │ ├── copy_helper.h │ │ │ │ └── upper_stream_helper.h │ │ │ ├── intersection.h │ │ │ └── union.h │ │ └── transform │ │ │ ├── all.h │ │ │ ├── concat.h │ │ │ ├── group.h │ │ │ ├── json_to_data_batch.h │ │ │ ├── split.h │ │ │ └── trim.h │ └── util │ │ └── ntobject_helper.h ├── toolkit │ └── plugins │ │ ├── csv │ │ ├── csv.h │ │ ├── csv_read_assign_helper.h │ │ └── csv_reader.h │ │ └── mysql │ │ └── mysql_reader.h ├── xgboost │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── booster │ │ ├── linear │ │ │ └── xgboost_linear.hpp │ │ ├── tree │ │ │ ├── xgboost_base_treemaker.hpp │ │ │ ├── xgboost_col_treemaker.hpp │ │ │ ├── xgboost_row_treemaker.hpp │ │ │ ├── xgboost_svdf_tree.hpp │ │ │ ├── xgboost_tree.hpp │ │ │ └── xgboost_tree_model.h │ │ ├── xgboost-inl.hpp │ │ ├── xgboost.h │ │ ├── xgboost_data.h │ │ └── xgboost_gbmbase.h │ ├── regression │ │ ├── xgboost_reg.h │ │ ├── xgboost_reg_data.h │ │ ├── xgboost_reg_eval.h │ │ ├── xgboost_reg_main.cpp │ │ └── xgboost_reg_task.h │ └── utils │ │ ├── xgboost_config.h │ │ ├── xgboost_fmap.h │ │ ├── xgboost_matrix_csr.h │ │ ├── xgboost_omp.h │ │ ├── xgboost_random.h │ │ ├── xgboost_stream.h │ │ └── xgboost_utils.h └── ypc │ ├── common │ ├── access_policy.h │ ├── byte.h │ ├── byte │ │ ├── base58.h │ │ ├── base64.h │ │ ├── bytes.h │ │ ├── bytes_common.h │ │ ├── bytes_util.h │ │ └── fix_bytes.h │ ├── crypto_prefix.h │ ├── endian.h │ ├── ignore.h │ ├── limits.h │ ├── parser_type.h │ └── version.h │ ├── core │ ├── block_data_source.h │ ├── blockfile.h │ ├── byte.h │ ├── command_executor.h │ ├── configuration.h │ ├── db.h │ ├── filesystem.h │ ├── memref.h │ ├── ntjson.h │ ├── ntobject_file.h │ ├── poption_require.h │ ├── privacy_data_reader.h │ ├── ref.h │ ├── sealed_file.h │ ├── sgx │ │ ├── parser_sgx_module.h │ │ └── util │ │ │ ├── cxxfile_bridge.h │ │ │ ├── kv_bridge.h │ │ │ └── util.h │ ├── singleton.h │ ├── status.def │ ├── status.h │ └── version.h │ ├── core_t │ ├── analyzer │ │ ├── algo_wrapper.h │ │ ├── analyzer_context.h │ │ ├── data_source.h │ │ ├── eparser_t_interface.h │ │ ├── helper │ │ │ ├── ecall_impl_helper.h │ │ │ └── parser_type_traits.h │ │ ├── interface │ │ │ ├── algo_interface.h │ │ │ ├── allowance_interface.h │ │ │ ├── data_hash_interface.h │ │ │ ├── data_interface.h │ │ │ ├── do_parse_interface.h │ │ │ ├── forward_interface.h │ │ │ ├── keymgr_interface.h │ │ │ ├── model_interface.h │ │ │ └── parser_interface.h │ │ ├── internal │ │ │ ├── data_streams │ │ │ │ ├── multi_data_stream.h │ │ │ │ ├── noinput_data_stream.h │ │ │ │ ├── raw_data_stream.h │ │ │ │ └── sealed_data_stream.h │ │ │ ├── is_multi_datasource.h │ │ │ ├── is_param_encrypted.h │ │ │ ├── keymgr_session.h │ │ │ └── results │ │ │ │ ├── forward_result.h │ │ │ │ ├── local_result.h │ │ │ │ ├── offchain_file_result.h │ │ │ │ ├── offchain_result.h │ │ │ │ └── onchain_result.h │ │ ├── macro.h │ │ ├── ntpackage_item_parser.h │ │ ├── raw_data_provider.h │ │ ├── sealed_data_provider.h │ │ ├── to_type.h │ │ ├── var │ │ │ ├── data_hash_var.h │ │ │ ├── data_source_var.h │ │ │ ├── enclave_hash_var.h │ │ │ ├── encrypted_param_var.h │ │ │ ├── internal_key_var.h │ │ │ ├── keymgr_var.h │ │ │ ├── model_var.h │ │ │ ├── parser_var.h │ │ │ ├── request_key_var.h │ │ │ └── result_var.h │ │ └── yaenclave_t_interface.h │ ├── ecommon │ │ ├── package.h │ │ └── signer_verify.h │ ├── file │ │ └── blockfile.h │ └── util │ │ ├── cxxfile.h │ │ ├── file_openmode.h │ │ ├── fpos.h │ │ └── kv.h │ ├── corecommon │ ├── allowance.h │ ├── blockfile │ │ ├── blockfile_base.h │ │ ├── blockfile_base_r.h │ │ ├── blockfile_interface.h │ │ ├── blockfile_v1.h │ │ ├── blockfile_v2.h │ │ └── traits.h │ ├── crypto │ │ ├── aes_gcm_traits.h │ │ ├── crypto_pack.h │ │ ├── example │ │ │ ├── README.md │ │ │ ├── aes_gcm.h │ │ │ ├── ecc.h │ │ │ ├── ecdh.h │ │ │ └── eth_hash.h │ │ ├── gmssl.h │ │ ├── gmssl │ │ │ ├── sm2_ecc.h │ │ │ ├── sm3_hash.h │ │ │ └── sm4_aes.h │ │ ├── interface │ │ │ ├── aes_impl.h │ │ │ ├── ecc_impl.h │ │ │ ├── ecdh_impl.h │ │ │ ├── hash_impl.h │ │ │ └── sign_impl.h │ │ ├── stdeth.h │ │ └── stdeth │ │ │ ├── eth_hash.h │ │ │ ├── rijndael128GCM.h │ │ │ ├── secp256k1.h │ │ │ ├── secp256k1.ipp │ │ │ └── secp256k1_ecdh_sgx128.h │ ├── data_source.h │ ├── exceptions.h │ ├── nt_cols.h │ ├── package.h │ └── to_type.h │ ├── edl │ ├── ecc.edl │ ├── eparser.edl │ ├── util │ │ ├── file.edl │ │ └── kv.edl │ └── yaenclave.edl │ ├── keymgr │ ├── common │ │ └── util.h │ └── default │ │ ├── ekeymgr.ipp │ │ ├── enclave │ │ ├── common.h │ │ └── ekeymgr.edl │ │ └── keymgr_sgx_module.h │ ├── stbox │ ├── ebyte.h │ ├── exception.h │ ├── gmssl │ │ ├── aes.h │ │ ├── asn1.h │ │ ├── block_cipher.h │ │ ├── endian.h │ │ ├── gcm.h │ │ ├── gf128.h │ │ ├── hex.h │ │ ├── mem.h │ │ ├── oid.h │ │ ├── sha2.h │ │ ├── sm2.h │ │ ├── sm3.h │ │ └── sm4.h │ ├── keccak │ │ └── keccak.h │ ├── scope_guard.h │ ├── sgx_status.def │ ├── stbox.edl │ ├── stx_common.h │ ├── stx_status.def │ ├── stx_status.h │ ├── tsgx │ │ ├── channel │ │ │ ├── dh_cdef.h │ │ │ ├── dh_session.h │ │ │ ├── dh_session_initiator.h │ │ │ └── dh_session_responder.h │ │ ├── crypto │ │ │ ├── seal.h │ │ │ └── seal_sgx.h │ │ ├── log.h │ │ ├── memory │ │ │ ├── allocator.h │ │ │ ├── memory_pool.h │ │ │ └── pool_allocator.h │ │ ├── ocall.h │ │ ├── secp256k1 │ │ │ ├── secp256k1.h │ │ │ ├── secp256k1_ecdh.h │ │ │ ├── secp256k1_preallocated.h │ │ │ └── secp256k1_recovery.h │ │ └── util.h │ └── usgx │ │ ├── error_message.h │ │ ├── sgx_module.h │ │ └── sgx_module_function_object.ipp │ ├── terminus │ ├── crypto_pack.h │ ├── enclave_interaction.h │ ├── interaction.h │ └── single_data_onchain_result.h │ └── version.h ├── test ├── CMakeLists.txt ├── core │ ├── CMakeLists.txt │ ├── enclave │ │ ├── CMakeLists.txt │ │ ├── enclave.config.xml │ │ ├── enclave.cpp │ │ ├── enclave.edl │ │ ├── enclave.lds │ │ ├── enclave_debug.lds │ │ └── enclave_private.pem │ ├── file_enclave │ │ ├── CMakeLists.txt │ │ ├── enclave.config.xml │ │ ├── enclave.lds │ │ ├── enclave_basic.cpp │ │ ├── enclave_debug.lds │ │ ├── enclave_private.pem │ │ ├── enclave_read.cpp │ │ └── enclave_write.cpp │ ├── gen_input_param.cpp │ ├── gen_sign_for_ypc.cpp │ ├── gtest_base58.cpp │ ├── gtest_base64.cpp │ ├── gtest_blockfile.cpp │ ├── gtest_byte.cpp │ ├── gtest_command_executor.cpp │ ├── gtest_common.cpp │ ├── gtest_common.h │ ├── gtest_configuration.cpp │ ├── gtest_core.cpp │ ├── gtest_db.cpp │ ├── gtest_filesystem.cpp │ ├── gtest_ntjson.cpp │ ├── gtest_ntobject_file.cpp │ ├── gtest_sealed_file.cpp │ ├── gtest_sgx_blockfile.cpp │ ├── main.cpp │ ├── test_ypc_module.cpp │ └── test_ypc_module.h ├── crypto │ ├── CMakeLists.txt │ ├── enclave │ │ ├── CMakeLists.txt │ │ ├── enclave.config.xml │ │ ├── enclave.cpp │ │ ├── enclave.edl │ │ ├── enclave.lds │ │ ├── enclave_debug.lds │ │ └── enclave_private.pem │ ├── gtest_crypto.cpp │ ├── gtest_gmssl.cpp │ ├── main.cpp │ ├── test_crypto_module.cpp │ └── test_crypto_module.h ├── integrate │ ├── CMakeLists.txt │ ├── classic_job.py │ ├── classify_job.py │ ├── common.py │ ├── commonjs.py │ ├── data_host.py │ ├── job_step.py │ ├── js │ │ ├── blockfile.js │ │ ├── dataprovider.js │ │ ├── package.json │ │ ├── simdataprovider.js │ │ ├── simjs.js │ │ ├── ypccrypto.js │ │ └── ypcntobject.js │ ├── multistream_job.py │ ├── multistream_job_offchain.py │ ├── prepare.py │ ├── project.py.in │ ├── test_findperson.py │ ├── test_findperson_multi.py │ ├── test_findperson_multi_offchain.py │ ├── test_iris.py │ └── test_iris_classifier.py ├── keymgr │ ├── CMakeLists.txt │ ├── gtest_enclave.cpp │ └── main.cpp └── toolkit │ ├── CMakeLists.txt │ └── plugins │ ├── CMakeLists.txt │ ├── csv │ ├── CMakeLists.txt │ ├── main.cpp │ └── test1.csv │ └── mysql │ ├── CMakeLists.txt │ └── main.cpp ├── toolkit ├── CMakeLists.txt ├── analyzer │ ├── CMakeLists.txt │ ├── db │ │ ├── db.cpp │ │ └── db.h │ ├── iodef.h │ ├── main.cpp │ ├── parsers │ │ ├── parser.cpp │ │ └── parser.h │ ├── sgx_bridge.cpp │ └── sgx_bridge.h ├── datahub │ ├── CMakeLists.txt │ ├── main.cpp │ └── unseal.cpp ├── plugins │ └── plugen.py ├── terminus │ ├── CMakeLists.txt │ ├── cmd │ │ ├── CMakeLists.txt │ │ └── cterminus │ │ │ ├── CMakeLists.txt │ │ │ ├── allowance.cpp │ │ │ ├── cmd_line.cpp │ │ │ ├── cmd_line.h │ │ │ ├── crypto.cpp │ │ │ ├── forward.cpp │ │ │ ├── gen_key.cpp │ │ │ ├── helper.cpp │ │ │ ├── main.cpp │ │ │ ├── relay.cpp │ │ │ ├── request.cpp │ │ │ └── sign.cpp │ ├── lib │ │ ├── CMakeLists.txt │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ ├── crypto_pack.cpp │ │ │ ├── enclave_interaction.cpp │ │ │ └── single_data_onchain_result.cpp │ │ └── test │ │ │ ├── CMakeLists.txt │ │ │ ├── gtest_intel_sgx.cpp │ │ │ └── main.cpp │ └── python │ │ ├── CMakeLists.txt │ │ └── module.cpp ├── verifier │ ├── CMakeLists.txt │ └── dian_pubkey_verifier └── ydump │ ├── CMakeLists.txt │ ├── main.cpp │ └── nouse_bridge.cpp ├── vendor └── keccak │ ├── keccak.c │ └── keccak.h └── ypc ├── CMakeLists.txt ├── common ├── CMakeLists.txt ├── README.md ├── byte │ ├── base58.cpp │ └── base64.cpp └── version.cpp ├── core ├── CMakeLists.txt └── src │ ├── CMakeLists.txt │ ├── core │ ├── CMakeLists.txt │ ├── command_executor.cpp │ ├── configuration.cpp │ ├── crypto │ │ ├── CMakeLists.txt │ │ ├── gmssl │ │ │ ├── CMakeLists.txt │ │ │ ├── sm2_ecc.cpp │ │ │ └── sm4_aes.cpp │ │ └── stdeth │ │ │ ├── CMakeLists.txt │ │ │ ├── openssl.cpp │ │ │ ├── openssl.h │ │ │ ├── rijndael128GCM.cpp │ │ │ ├── secp256k1.cpp │ │ │ ├── secp256k1_ecdh_sgx128.cpp │ │ │ └── zallocator.h │ ├── db.cpp │ ├── filesystem.cpp │ ├── poption_require.cpp │ ├── privacy_data_reader.cpp │ ├── sealed_file.cpp │ ├── sgx │ │ ├── CMakeLists.txt │ │ ├── parser_sgx_module.cpp │ │ └── util │ │ │ ├── cxxfile_bridge.cpp │ │ │ ├── kv_bridge.cpp │ │ │ └── util.cpp │ ├── status.cpp │ └── version.cpp │ ├── core_t │ ├── CMakeLists.txt │ ├── analyzer │ │ ├── CMakeLists.txt │ │ ├── analyzer_version.cpp │ │ ├── internal │ │ │ └── keymgr_session.cpp │ │ └── var │ │ │ └── enclave_hash_var.cpp │ ├── crypto │ │ ├── CMakeLists.txt │ │ ├── gmssl │ │ │ ├── CMakeLists.txt │ │ │ ├── sm2_ecc.cpp │ │ │ └── sm4_aes.cpp │ │ └── stdeth │ │ │ ├── CMakeLists.txt │ │ │ ├── rijndael128GCM.cpp │ │ │ ├── secp256k1.cpp │ │ │ └── secp256k1_ecdh_sgx128.cpp │ ├── ecommon │ │ ├── package.cpp │ │ └── signer_verify.cpp │ ├── sgx_ecc │ │ ├── CMakeLists.txt │ │ ├── ecc_impl.ipp │ │ ├── gmssl_ecc_impl.cpp │ │ └── stdeth_ecc_impl.cpp │ └── util │ │ ├── CMakeLists.txt │ │ ├── cxxfile.cpp │ │ └── kv.cpp │ └── corecommon │ └── crypto │ ├── eth_hash.cpp │ └── sm3_hash.cpp ├── keymgr ├── CMakeLists.txt ├── common │ ├── CMakeLists.txt │ └── util.cpp └── default │ ├── CMakeLists.txt │ ├── enclave │ ├── CMakeLists.txt │ ├── ekeymgr.config.debug.xml │ ├── ekeymgr.config.xml │ ├── ekeymgr.cpp │ ├── ekeymgr.lds │ ├── ekeymgr_debug.lds │ └── ekeymgr_private.pem │ ├── gmssl │ ├── CMakeLists.txt │ └── ekeymgr.cpp │ ├── keymgr_sgx_module.cpp │ ├── main.cpp │ └── no_use_extra_data_bridge.cpp └── stbox ├── CMakeLists.txt └── src ├── CMakeLists.txt ├── exception.cpp ├── gmssl ├── CMakeLists.txt ├── aes.c ├── aes_modes.c ├── asn1.c ├── block_cipher.c ├── gcm.c ├── gf128.c ├── hex.c ├── sha256.c ├── sm2_alg.c ├── sm2_key.c ├── sm2_lib.c ├── sm3.c ├── sm4_common.c ├── sm4_enc.c ├── sm4_lcl.h ├── sm4_modes.c └── sm4_setkey.c ├── keccak ├── CMakeLists.txt └── keccak.c ├── stx_common.cpp ├── stx_status.cpp ├── tsgx ├── CMakeLists.txt ├── channel │ ├── CMakeLists.txt │ ├── dh_session.cpp │ ├── dh_session_initiator.cpp │ └── dh_session_responder.cpp ├── crypto │ ├── CMakeLists.txt │ └── seal_sgx.cpp ├── log.cpp ├── secp256k1 │ ├── CMakeLists.txt │ ├── asm │ │ └── field_10x26_arm.s │ ├── basic-config.h │ ├── ecdsa.h │ ├── ecdsa_impl.h │ ├── eckey.h │ ├── eckey_impl.h │ ├── ecmult.h │ ├── ecmult_const.h │ ├── ecmult_const_impl.h │ ├── ecmult_gen.h │ ├── ecmult_gen_impl.h │ ├── ecmult_impl.h │ ├── ecmult_static_context.h │ ├── field.h │ ├── field_10x26.h │ ├── field_10x26_impl.h │ ├── field_5x52.h │ ├── field_5x52_asm_impl.h │ ├── field_5x52_impl.h │ ├── field_5x52_int128_impl.h │ ├── field_impl.h │ ├── gen_context.c │ ├── group.h │ ├── group_impl.h │ ├── hash.h │ ├── hash_impl.h │ ├── java │ │ ├── .deps │ │ │ ├── libsecp256k1_jni_la-org_bitcoin_NativeSecp256k1.Plo │ │ │ └── libsecp256k1_jni_la-org_bitcoin_Secp256k1Context.Plo │ │ ├── org │ │ │ └── bitcoin │ │ │ │ ├── NativeSecp256k1.java │ │ │ │ ├── NativeSecp256k1Test.java │ │ │ │ ├── NativeSecp256k1Util.java │ │ │ │ └── Secp256k1Context.java │ │ ├── org_bitcoin_NativeSecp256k1.c │ │ ├── org_bitcoin_NativeSecp256k1.h │ │ ├── org_bitcoin_Secp256k1Context.c │ │ └── org_bitcoin_Secp256k1Context.h │ ├── libsecp256k1-config.h │ ├── libsecp256k1-config.h.in │ ├── modules │ │ ├── ecdh │ │ │ ├── Makefile.am.include │ │ │ ├── main_impl.h │ │ │ └── tests_impl.h │ │ └── recovery │ │ │ ├── Makefile.am.include │ │ │ ├── main_impl.h │ │ │ └── tests_impl.h │ ├── num.h │ ├── num_gmp.h │ ├── num_gmp_impl.h │ ├── num_impl.h │ ├── scalar.h │ ├── scalar_4x64.h │ ├── scalar_4x64_impl.h │ ├── scalar_8x32.h │ ├── scalar_8x32_impl.h │ ├── scalar_impl.h │ ├── scalar_low.h │ ├── scalar_low_impl.h │ ├── scratch.h │ ├── scratch_impl.h │ ├── secp256k1.c │ ├── stamp-h1 │ └── util.h ├── stx_common_trusted.cpp └── util.cpp └── usgx ├── error_message.cpp ├── sgx_module.cpp └── stx_common_untrusted.cpp /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | WarningsAsErrors: '*' 3 | HeaderFilterRegex: 'include/ypc/.*(? 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/iris/analyzer/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "enclave_iris_parser.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/gmssl.h" 5 | #include "ypc/corecommon/crypto/stdeth.h" 6 | #include "ypc/core_t/analyzer/interface/allowance_interface.h" 7 | 8 | using Crypto = ypc::crypto::eth_sgx_crypto; 9 | // using Crypto = ypc::crypto::gmssl_sgx_crypto; 10 | 11 | ypc::algo_wrapper, void, ypc::check_data_allowance> 13 | pw; 14 | 15 | YPC_PARSER_IMPL(pw); 16 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave/user_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | define_nt(sepal_len, double); 7 | define_nt(sepal_wid, double); 8 | define_nt(petal_len, double); 9 | define_nt(petal_wid, double); 10 | define_nt(species, std::string); 11 | 12 | typedef ff::net::ntpackage<0, sepal_len, sepal_wid, petal_len, petal_wid> 13 | iris_data_t; 14 | define_nt(iris_data, iris_data_t); 15 | 16 | typedef ff::util::ntobject iris_item_t; 17 | typedef iris_item_t user_item_t; 18 | 19 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave_for_offchain/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(T_SRCS eparser.cpp ) 2 | 3 | add_ypc_applet(iris_parser_for_offchain 4 | CRYPTO stdeth 5 | SRCS ${T_SRCS} 6 | ) 7 | 8 | enclave_sign(iris_parser_for_offchain KEY enclave_private.pem 9 | CONFIG enclave.config.xml) 10 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave_for_offchain/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave_for_offchain/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/iris/analyzer/enclave_for_offchain/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "../enclave/enclave_iris_parser.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | #include "ypc/core_t/analyzer/interface/allowance_interface.h" 6 | 7 | ypc::algo_wrapper, void, ypc::check_data_allowance> 10 | pw; 11 | 12 | YPC_PARSER_IMPL(pw); 13 | 14 | -------------------------------------------------------------------------------- /example/iris/classifier/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(enclave) 2 | add_executable(iris_gen_model main.cpp) 3 | target_link_libraries(iris_gen_model core) 4 | 5 | add_executable(iris_gen_classify_input input.cpp) 6 | target_link_libraries(iris_gen_classify_input core boost_program_options) 7 | target_include_directories(iris_gen_classify_input PUBLIC 8 | "$" 9 | "$" 10 | "$" 11 | ) 12 | -------------------------------------------------------------------------------- /example/iris/classifier/enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(T_SRCS eparser.cpp ) 2 | 3 | add_ypc_applet(iris_classifier 4 | CRYPTO stdeth 5 | SRCS ${T_SRCS}) 6 | 7 | if(SGX_MODE STREQUAL "Debug") 8 | enclave_sign(iris_classifier KEY enclave_private.pem 9 | CONFIG enclave.config.debug.xml) 10 | else() 11 | enclave_sign(iris_classifier KEY enclave_private.pem 12 | CONFIG enclave.config.xml) 13 | endif() 14 | 15 | -------------------------------------------------------------------------------- /example/iris/classifier/enclave/enclave.config.debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/iris/classifier/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/iris/classifier/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/iris/classifier/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/iris/classifier/enclave/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "enclave_iris_classifier.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | 6 | // ypc::algo_wrapper 8 | // pw; 9 | 10 | ypc::algo_wrapper 13 | pw; 14 | 15 | YPC_PARSER_IMPL(pw); 16 | -------------------------------------------------------------------------------- /example/iris/classifier/main.cpp: -------------------------------------------------------------------------------- 1 | #include "model.h" 2 | #include "ypc/core/byte.h" 3 | #include "ypc/corecommon/package.h" 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | means_t model; 9 | std::vector means; 10 | 11 | mean_t m1; 12 | iris_data_t md1; 13 | md1.set(5.004082, 3.416327, 14 | 1.465306, 0.244898); 15 | 16 | m1.set("setosa", md1, 0); 17 | means.push_back(m1.make_copy()); 18 | 19 | md1.set(5.883607, 2.740984, 20 | 4.388525, 1.434426); 21 | m1.set("versicolor", md1.make_copy(), 0); 22 | means.push_back(m1.make_copy()); 23 | 24 | md1.set(6.864864, 3.067567, 25 | 5.735135, 2.059460); 26 | m1.set("virginica", md1.make_copy(), 0); 27 | means.push_back(m1.make_copy()); 28 | 29 | model.set(means); 30 | typename ypc::cast_obj_to_package::type pkg = model; 31 | auto ret = ypc::make_bytes::for_package(pkg); 32 | std::cout << ret; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /example/iris/classifier/user_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | define_nt(sepal_len, double); 7 | define_nt(sepal_wid, double); 8 | define_nt(petal_len, double); 9 | define_nt(petal_wid, double); 10 | define_nt(species, std::string); 11 | 12 | typedef ff::net::ntpackage<0, sepal_len, sepal_wid, petal_len, petal_wid> 13 | iris_data_t; 14 | define_nt(iris_data, iris_data_t); 15 | 16 | typedef ff::util::ntobject iris_item_t; 17 | typedef iris_item_t user_item_t; 18 | 19 | -------------------------------------------------------------------------------- /example/iris/iris/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #project(iris) 2 | #cmake_minimum_required(VERSION 3.9.3) 3 | add_definitions(-std=c++11) 4 | #include_directories(${PROJECT_SOURCE_DIR}) 5 | add_subdirectory(reader) 6 | -------------------------------------------------------------------------------- /example/iris/iris/output/user_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | define_nt(sepal_len, double); 5 | define_nt(sepal_wid, double); 6 | define_nt(petal_len, double); 7 | define_nt(petal_wid, double); 8 | define_nt(species, std::string); 9 | typedef ff::util::ntobject iris_item_t; 10 | -------------------------------------------------------------------------------- /example/iris/iris/reader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(iris_reader SHARED reader.cpp) 2 | target_link_libraries(iris_reader pthread ff_net) 3 | target_include_directories(iris_reader PUBLIC 4 | "$" 5 | "$" 6 | "$" 7 | ) 8 | target_link_directories(iris_reader PUBLIC ${FF_LIB_DIR}) 9 | -------------------------------------------------------------------------------- /example/iris/iris/reader/reader.cpp: -------------------------------------------------------------------------------- 1 | #include "../output/user_type.h" 2 | #include "toolkit/plugins/csv/csv_reader.h" 3 | typedef ypc::plugins::typed_csv_reader iris_reader_t; 4 | impl_csv_reader(iris_reader_t) 5 | -------------------------------------------------------------------------------- /example/iris/plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(iris_reader 2 | SHARED 3 | iris_reader.cpp) 4 | -------------------------------------------------------------------------------- /example/iris/plugin/iris_reader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | void *create_item_reader(const char *file_path, int len); 8 | 9 | int reset_for_read(void *handle); 10 | int read_item_data(void *handle, char *buf, int *len); 11 | int close_item_reader(void *handle); 12 | uint64_t get_item_number(void *handle); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /example/multi_personlist/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(generator) 2 | add_subdirectory(first_match/enclave) 3 | add_subdirectory(first_match/enclave_for_offchain) 4 | add_subdirectory(first_match/normal) 5 | -------------------------------------------------------------------------------- /example/multi_personlist/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common_t.h" 3 | #include "ypc/core/blockfile.h" 4 | typedef ypc::blockfile<0x82, 2, 1024 * 1024, 256 * 64 * 1024> file_t; 5 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(T_SRCS eparser.cpp) 2 | 3 | add_ypc_applet(person_first_match_multi 4 | CRYPTO stdeth 5 | SRCS ${T_SRCS}) 6 | 7 | if(SGX_MODE STREQUAL "Debug") 8 | enclave_sign(person_first_match_multi KEY enclave_private.pem 9 | CONFIG enclave.config.debug.xml) 10 | else() 11 | enclave_sign(person_first_match_multi KEY enclave_private.pem 12 | CONFIG enclave.config.xml) 13 | endif() 14 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/enclave.config.debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "first_match_parser.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | 6 | ypc::algo_wrapper, void, 9 | ypc::check_data_allowance> 10 | pw; 11 | 12 | YPC_PARSER_IMPL(pw); 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave/user_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../common_t.h" 3 | #include 4 | #include 5 | #include 6 | 7 | typedef row_t user_item_t; 8 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(T_SRCS eparser.cpp) 2 | 3 | add_ypc_applet(person_first_match_multi_offchain 4 | CRYPTO stdeth 5 | SRCS ${T_SRCS}) 6 | 7 | if(SGX_MODE STREQUAL "Debug") 8 | enclave_sign(person_first_match_multi_offchain KEY enclave_private.pem 9 | CONFIG enclave.config.debug.xml) 10 | else() 11 | enclave_sign(person_first_match_multi_offchain KEY enclave_private.pem 12 | CONFIG enclave.config.xml) 13 | endif() 14 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/enclave.config.debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/enclave_for_offchain/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "../enclave/first_match_parser.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | 6 | ypc::algo_wrapper, void, 9 | ypc::check_data_allowance> 10 | pw; 11 | 12 | YPC_PARSER_IMPL(pw); 13 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/normal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #add_executable(find_person_multi main.cpp) 2 | #target_link_libraries(find_person_multi ypc_core stbox_common_u ff_net hpda pthread) 3 | -------------------------------------------------------------------------------- /example/multi_personlist/first_match/normal/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../../common.h" 2 | #include "ypc/common/ignore.h" 3 | #include "ypc/core/block_data_source.h" 4 | #include "ypc/stbox/ebyte.h" 5 | #define EXAMPLE_FM_NORMAL 6 | #include "../enclave/first_match_parser.h" 7 | #undef EXAMPLE_FM_NORMAL 8 | 9 | int main(int argc, char *argv[]) { 10 | std::string fp = "person_list"; 11 | ypc::bytes param("421003198607263380"); 12 | file_t ssf; 13 | ssf.open_for_read(fp.c_str()); 14 | ypc::block_data_source sds(&ssf); 15 | first_match_parser fmp(&sds); 16 | fmp.do_parse(param); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /example/multi_personlist/generator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_executable(personlist_gen_multi main.cpp) 4 | 5 | target_link_libraries(personlist_gen_multi ff_net core) 6 | target_link_directories(personlist_gen_multi PUBLIC ${FF_LIB_DIR}) 7 | -------------------------------------------------------------------------------- /example/personlist/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(generator) 2 | add_subdirectory(plugin) 3 | add_subdirectory(first_match/enclave) 4 | add_subdirectory(first_match/normal) 5 | -------------------------------------------------------------------------------- /example/personlist/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common_t.h" 3 | #include "ypc/core/blockfile.h" 4 | typedef ypc::blockfile<0x82, 2, 1024 * 1024, 256 * 64 * 1024> file_t; 5 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(T_SRCS eparser.cpp) 2 | 3 | add_ypc_applet(person_first_match 4 | CRYPTO stdeth 5 | SRCS ${T_SRCS}) 6 | 7 | if(SGX_MODE STREQUAL "Debug") 8 | enclave_sign(person_first_match KEY enclave_private.pem 9 | CONFIG enclave.config.debug.xml) 10 | else() 11 | enclave_sign(person_first_match KEY enclave_private.pem 12 | CONFIG enclave.config.xml) 13 | endif() 14 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/enclave.config.debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x50000 5 | 0x5000000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /example/personlist/first_match/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/eparser.cpp: -------------------------------------------------------------------------------- 1 | #include "first_match_parser.h" 2 | #include "ypc/core_t/analyzer/algo_wrapper.h" 3 | #include "ypc/core_t/analyzer/macro.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | 6 | ypc::algo_wrapper> 9 | pw; 10 | 11 | YPC_PARSER_IMPL(pw); 12 | -------------------------------------------------------------------------------- /example/personlist/first_match/enclave/user_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../common_t.h" 3 | #include 4 | #include 5 | #include 6 | 7 | typedef row_t user_item_t; 8 | -------------------------------------------------------------------------------- /example/personlist/first_match/normal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(find_person main.cpp) 2 | target_link_libraries(find_person core stbox_common ff_net hpda) 3 | target_link_directories(find_person PUBLIC ${FF_LIB_DIR}) 4 | -------------------------------------------------------------------------------- /example/personlist/first_match/normal/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../../common.h" 2 | #include "ypc/common/ignore.h" 3 | #include "ypc/core/block_data_source.h" 4 | #include "ypc/stbox/ebyte.h" 5 | #define EXAMPLE_FM_NORMAL 6 | #include "../enclave/first_match_parser.h" 7 | #undef EXAMPLE_FM_NORMAL 8 | 9 | int main(int argc, char *argv[]) { 10 | std::string fp = "person_list"; 11 | ypc::bytes param("421003198607263380"); 12 | file_t ssf; 13 | ssf.open_for_read(fp.c_str()); 14 | ypc::block_data_source sds(&ssf); 15 | first_match_parser fmp(&sds); 16 | fmp.do_parse(param); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /example/personlist/generator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_executable(personlist_gen main.cpp) 4 | 5 | target_link_libraries(personlist_gen ff_net core) 6 | target_link_directories(personlist_gen PUBLIC ${FF_LIB_DIR}) 7 | -------------------------------------------------------------------------------- /example/personlist/plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(person_reader 2 | SHARED 3 | person_reader.cpp) 4 | 5 | target_link_libraries(person_reader core) 6 | -------------------------------------------------------------------------------- /example/personlist/plugin/person_reader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | void *create_item_reader(const char *file_path, int len); 8 | 9 | int reset_for_read(void *handle); 10 | int read_item_data(void *handle, char *buf, int *len); 11 | int close_item_reader(void *handle); 12 | uint64_t get_item_number(void *handle); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /hpda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | find_package (Threads REQUIRED) 3 | 4 | add_library(hpda SHARED src/extractor/internal/https_request.cpp 5 | src/extractor/paged_https_extractor.cpp 6 | src/engine/engine.cpp 7 | src/engine/functor.cpp) 8 | target_link_libraries(hpda ssl crypto boost_system curl 9 | ${CMAKE_THREAD_LIBS_INIT} 10 | ) 11 | target_compile_options(hpda PUBLIC $<$:-DHPDA_DEBUG>) 12 | 13 | target_include_directories(hpda PUBLIC 14 | "$" 15 | "$" 16 | "$" 17 | ) 18 | install(TARGETS hpda EXPORT mod_hpda 19 | DESTINATION "${lib_install_dir}") 20 | install(EXPORT mod_hpda 21 | DESTINATION "${config_install_dir}/hpda" 22 | NAMESPACE "${namespace}") 23 | 24 | add_version(hpda) 25 | 26 | if(SGX_MODE STREQUAL "Debug") 27 | add_subdirectory(test) 28 | #add_subdirectory(example) 29 | endif() 30 | -------------------------------------------------------------------------------- /hpda/src/engine/functor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace hpda { 5 | functor::functor() : m_engine(), m_status(), m_has_value(false) {} 6 | 7 | functor::~functor() { 8 | if (m_engine != nullptr) { 9 | m_engine->remove_functor(this); 10 | } 11 | } 12 | 13 | void functor::set_engine(engine *e) { 14 | m_engine = e; 15 | m_engine->add_functor(this); 16 | } 17 | void functor::done_value() { m_has_value = true; } 18 | } // namespace hpda 19 | -------------------------------------------------------------------------------- /hpda/src/util/ntobject_helper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace hpda { 5 | namespace util { 6 | std::string convert_data_format_to_ntobject_type_file( 7 | const boost::property_tree::ptree &tree) { 8 | std::stringstream ss; 9 | return tree.get("start"); 10 | } 11 | } // namespace util 12 | } // namespace hpda 13 | -------------------------------------------------------------------------------- /hpda/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | find_package(OpenSSL REQUIRED) 3 | add_executable(hpda_gtest gtest_main.cpp 4 | test_basic.cpp 5 | extractor/test_https_extractor.cpp 6 | extractor/test_paged_https_extractor.cpp 7 | processor/test_filter.cpp 8 | processor/test_groupby.cpp 9 | processor/test_json_to_data_batch.cpp 10 | processor/test_concat.cpp 11 | processor/test_split.cpp 12 | processor/test_set.cpp 13 | processor/test_trim.cpp 14 | processor/test_all.cpp 15 | kmeans/test_loyd_vector.cpp 16 | kmeans/test_loyd_tuple.cpp 17 | kmeans/test_kmeans_tuple.cpp 18 | kmeans/tuple_point.cpp 19 | kmeans/test_kmeans_iris.cpp 20 | ) 21 | target_link_libraries(hpda_gtest PRIVATE gtest_main glog hpda OpenSSL::SSL OpenSSL::Crypto) 22 | -------------------------------------------------------------------------------- /hpda/test/extractor/test_https_extractor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | TEST(https_request, basic) { 6 | #if 0 7 | hpda::extractor::internal::https_request req("asresearch.io", 8 | "/iris-data?index=1&limit=3"); 9 | //"/iris-data?index=0&limit=10"); 10 | EXPECT_TRUE(req.result().size() != 0); 11 | #endif 12 | } 13 | -------------------------------------------------------------------------------- /hpda/test/extractor/test_paged_https_extractor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | TEST(paged_https_extractor, basic) { 6 | hpda::extractor::paged_https_extractor phe( 7 | "https://asresearch.io", "/iris-data?", 3, 8 | [](const std::string &prefix, int next_index, int page_limit) { 9 | std::stringstream ss; 10 | ss << prefix << "index=" << next_index << "&limit=" << page_limit; 11 | return ss.str(); 12 | }, 13 | [](const boost::property_tree::ptree &tree) { 14 | return tree.get("start"); 15 | }, 16 | [](const boost::property_tree::ptree &tree) { 17 | return tree.get("end"); 18 | }); 19 | 20 | std::cout << "start data" << std::endl; 21 | while (phe.process()) { 22 | std::cout << phe.output_value() << std::endl; 23 | } 24 | std::cout << "end data" << std::endl; 25 | } 26 | -------------------------------------------------------------------------------- /hpda/test/gtest_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char *argv[]) { 3 | ::testing::InitGoogleTest(&argc, argv); 4 | return RUN_ALL_TESTS(); 5 | } 6 | -------------------------------------------------------------------------------- /hpda/test/kmeans/tuple_point.cpp: -------------------------------------------------------------------------------- 1 | #include "tuple_point.h" 2 | #include 3 | 4 | Point operator+(const Point &p1, const Point &p2) { 5 | Point s(p1); 6 | 7 | std::get<0>(s) += std::get<0>(p2); 8 | std::get<1>(s) += std::get<1>(p2); 9 | std::get<2>(s) += std::get<2>(p2); 10 | return s; 11 | } 12 | 13 | Point operator/(const Point &p1, size_t v) { 14 | Point s(p1); 15 | 16 | std::get<0>(s) /= v; 17 | std::get<1>(s) /= v; 18 | std::get<2>(s) /= v; 19 | return s; 20 | } 21 | 22 | std::ostream &operator<<(std::ostream &os, const Point &obj) { 23 | os << "("; 24 | os << std::get<0>(obj) << ", "; 25 | os << std::get<1>(obj) << ", "; 26 | os << std::get<2>(obj); 27 | os << ")"; 28 | return os; 29 | } 30 | -------------------------------------------------------------------------------- /hpda/test/kmeans/tuple_point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | //#include 4 | 5 | typedef std::tuple Point; 6 | 7 | namespace hpda { 8 | template struct euclidean; 9 | 10 | template <> struct euclidean { 11 | static double distance_square(const Point &p1, const Point &p2) { 12 | double ret = 0; 13 | 14 | auto v1 = std::get<0>(p1) - std::get<0>(p2); 15 | auto v2 = std::get<1>(p1) - std::get<1>(p2); 16 | auto v3 = std::get<2>(p1) - std::get<2>(p2); 17 | 18 | ret += v1 * v1; 19 | ret += v2 * v2; 20 | ret += v3 * v3; 21 | return ret; 22 | } 23 | }; 24 | } // namespace hpda 25 | 26 | Point operator+(const Point &p1, const Point &p2); 27 | 28 | Point operator/(const Point &p1, size_t v); 29 | 30 | std::ostream &operator<<(std::ostream &os, const Point &obj); 31 | 32 | define_nt(iid, int); 33 | -------------------------------------------------------------------------------- /hpda/test/processor/test_all.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | define_nt(hash, std::string); 5 | define_nt(value, uint64_t); 6 | typedef hpda::ntobject data_item_t; 7 | 8 | TEST(all, basic) { 9 | hpda::extractor::raw_data rd; 10 | 11 | hpda::engine engine; 12 | rd.set_engine(&engine); 13 | 14 | for (int i = 0; i < 1000; i++) { 15 | data_item_t d; 16 | d.set(std::to_string(i), i); 17 | rd.add_data(d); 18 | } 19 | 20 | hpda::processor::all_t f(&rd); 21 | hpda::output::memory_output mo(&f); 22 | 23 | engine.run(); 24 | auto &s = f.values(); 25 | EXPECT_EQ(s.size(), 1000); 26 | 27 | for (int i = 0; i < 1000; i++) { 28 | EXPECT_EQ(s[i].get<::value>(), i); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hpda/test/processor/test_concat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | define_nt(hash, std::string); 5 | define_nt(value, uint64_t); 6 | typedef hpda::ntobject data_item_t; 7 | 8 | TEST(concat, basic) { 9 | hpda::extractor::raw_data rd1; 10 | hpda::extractor::raw_data rd2; 11 | 12 | hpda::engine engine; 13 | rd1.set_engine(&engine); 14 | rd2.set_engine(&engine); 15 | 16 | for (int i = 0; i < 1000; i++) { 17 | data_item_t d; 18 | d.set(std::to_string(i), i); 19 | rd1.add_data(d); 20 | rd2.add_data(d); 21 | } 22 | hpda::processor::concat con(&rd1); 23 | con.add_upper_stream(&rd2); 24 | 25 | hpda::processor::filter f( 26 | &con, [](const data_item_t &d) { return d.get() >= 500; }); 27 | 28 | hpda::output::memory_output mo(&f); 29 | 30 | engine.run(); 31 | 32 | auto s = mo.values().size(); 33 | EXPECT_EQ(s, 1000); 34 | } 35 | -------------------------------------------------------------------------------- /hpda/test/processor/test_filter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | define_nt(hash, std::string); 5 | define_nt(value, uint64_t); 6 | typedef hpda::ntobject data_item_t; 7 | 8 | TEST(filter, basic) { 9 | hpda::extractor::raw_data rd; 10 | 11 | hpda::engine engine; 12 | rd.set_engine(&engine); 13 | 14 | for (int i = 0; i < 1000; i++) { 15 | data_item_t d; 16 | d.set(std::to_string(i), i); 17 | rd.add_data(d); 18 | } 19 | 20 | hpda::processor::filter f(&rd, [](const data_item_t &d) { 21 | return d.get() >= 500; 22 | }); 23 | 24 | hpda::output::memory_output mo(&f); 25 | 26 | engine.run(); 27 | auto s = mo.values().size(); 28 | EXPECT_EQ(s, 500); 29 | } 30 | -------------------------------------------------------------------------------- /hpda/test/processor/test_split.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | define_nt(hash, std::string); 5 | define_nt(value, uint64_t); 6 | typedef hpda::ntobject data_item_t; 7 | 8 | TEST(split, basic) { 9 | hpda::extractor::raw_data rd; 10 | 11 | hpda::engine engine; 12 | rd.set_engine(&engine); 13 | 14 | for (int i = 0; i < 10; i++) { 15 | data_item_t d; 16 | d.set(std::to_string(i), i); 17 | rd.add_data(d); 18 | } 19 | 20 | hpda::processor::split split(&rd); 21 | 22 | hpda::output::memory_output mo1(split.new_split_stream()); 23 | hpda::output::memory_output mo2(split.new_split_stream()); 24 | 25 | engine.run(); 26 | auto s = mo1.values().size(); 27 | EXPECT_EQ(s, 10); 28 | EXPECT_EQ(s, mo2.values().size()); 29 | } 30 | -------------------------------------------------------------------------------- /hpda/test/processor/test_trim.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | define_nt(hash, std::string); 5 | define_nt(value, uint64_t); 6 | typedef hpda::ntobject data_item_t; 7 | typedef hpda::ntobject value_item_t; 8 | 9 | TEST(trim, basic) { 10 | hpda::extractor::raw_data rd; 11 | 12 | hpda::engine engine; 13 | rd.set_engine(&engine); 14 | 15 | for (int i = 0; i < 1000; i++) { 16 | data_item_t d; 17 | d.set(std::to_string(i), i); 18 | rd.add_data(d); 19 | } 20 | 21 | hpda::processor::trim_t f(&rd); 22 | hpda::output::memory_output mo(&f); 23 | 24 | engine.run(); 25 | auto &s = mo.values(); 26 | EXPECT_EQ(s.size(), 1000); 27 | 28 | for (int i = 0; i < 1000; i++) { 29 | EXPECT_EQ(s[i].get<::value>(), i); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /include/hpda/algorithm/algorithm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /include/hpda/common/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef HPDA_DEBUG 12 | #include 13 | #endif 14 | 15 | #ifdef YPC_SGX 16 | #include "ypc/stbox/tsgx/log.h" 17 | #endif 18 | 19 | namespace hpda { 20 | template using ntobject = ::ff::util::ntobject; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /include/hpda/common/processor_with_output.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace internal { 7 | 8 | template 9 | class processor_with_output : virtual public functor { 10 | public: 11 | typedef OutputObjType output_type; 12 | virtual ~processor_with_output() {} 13 | virtual OutputObjType output_value() = 0; 14 | }; 15 | 16 | } // namespace internal 17 | template 18 | using processor_with_output = 19 | internal::processor_with_output>; 20 | template 21 | using processor_with_output_t = internal::processor_with_output; 22 | } // namespace hpda 23 | -------------------------------------------------------------------------------- /include/hpda/common/stream_policy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace hpda { 5 | struct lazy_eval_stream_policy {}; 6 | struct prefetch_stream_policy {}; 7 | struct fetch_all_stream_policy {}; 8 | 9 | using default_stream_policy = lazy_eval_stream_policy; 10 | } // namespace hpda 11 | 12 | -------------------------------------------------------------------------------- /include/hpda/engine/engine.h: -------------------------------------------------------------------------------- 1 | /**@file engine.h 2 | * @brief A class to represent the computing task 3 | * @details Developers can modify algorithms using templates to satisfy certain 4 | * business scenarios 5 | * @author YeeZTech 6 | * @date 2022-10-19 7 | * @version 2.0 8 | */ 9 | #pragma once 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace hpda { 16 | class engine { 17 | public: 18 | //! Notice that one functor may add to engine multiple times, and it won't 19 | //! affect. 20 | void add_functor(functor *f); 21 | 22 | void remove_functor(functor * f); 23 | 24 | void run(); 25 | 26 | protected: 27 | 28 | void build_graph(); 29 | 30 | std::vector find_outputs() const; 31 | 32 | bool contain_same_successor(functor *f1, functor *f2, functor *succ) const; 33 | 34 | bool functor_has_input(functor *f) const; 35 | 36 | bool is_output(functor *f) const; 37 | 38 | protected: 39 | std::vector m_functors; 40 | 41 | std::unordered_map> m_successors; 42 | std::unordered_map> m_predecessors; 43 | std::unordered_set m_reach_ends; 44 | }; 45 | } // namespace ypc 46 | -------------------------------------------------------------------------------- /include/hpda/engine/functor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | class engine; 7 | class functor { 8 | public: 9 | functor(); 10 | virtual ~functor(); 11 | virtual bool process() = 0; 12 | inline void reset_done_value() { m_has_value = false; } 13 | virtual void done_value(); 14 | inline bool has_value() const { return m_has_value; } 15 | inline engine *get_engine() const { return m_engine; } 16 | 17 | void set_engine(engine *e); 18 | 19 | inline void add_predecessor(functor *pred) { m_predecessors.push_back(pred); } 20 | 21 | inline const std::vector predecessors() const { 22 | return m_predecessors; 23 | } 24 | 25 | protected: 26 | bool m_has_value; 27 | std::vector m_predecessors; 28 | engine *m_engine; 29 | 30 | friend class engine; 31 | uint32_t m_status; 32 | }; 33 | } // namespace ypc 34 | -------------------------------------------------------------------------------- /include/hpda/extractor/extractor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /include/hpda/extractor/extractor_base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace extractor { 7 | namespace internal { 8 | template 9 | class extractor_base 10 | : public ::hpda::internal::processor_with_output { 11 | public: 12 | virtual ~extractor_base() {} 13 | }; 14 | } // namespace internal 15 | 16 | } // namespace extractor 17 | } // namespace hpda 18 | -------------------------------------------------------------------------------- /include/hpda/extractor/internal/https_request.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace hpda { 8 | namespace extractor { 9 | namespace internal { 10 | 11 | class https_request { 12 | public: 13 | https_request(const std::string &domain, const std::string &path); 14 | 15 | const std::string &result() const; 16 | 17 | protected: 18 | mutable boost::asio::ssl::context m_ctx; 19 | mutable boost::asio::io_service m_io_service; 20 | std::string m_domain; 21 | std::string m_path; 22 | mutable std::string m_result; 23 | }; 24 | } // namespace internal 25 | } // namespace extractor 26 | } // namespace hpda 27 | -------------------------------------------------------------------------------- /include/hpda/hpda.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | -------------------------------------------------------------------------------- /include/hpda/output/memory_output.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace output { 7 | namespace internal { 8 | template 9 | class memory_output_impl : public output_base { 10 | public: 11 | memory_output_impl( 12 | ::hpda::internal::processor_with_output *upper_stream) 13 | : output_base(upper_stream) {} 14 | 15 | virtual ~memory_output_impl() {} 16 | 17 | typedef output_base base; 18 | 19 | virtual bool process() { 20 | if (!base::has_input_value()) { 21 | return false; 22 | } 23 | m_data.push_back(output_base::input_value().make_copy()); 24 | base::consume_input_value(); 25 | return true; 26 | } 27 | 28 | std::vector &values() { return m_data; } 29 | const std::vector &values() const { return m_data; } 30 | 31 | protected: 32 | std::vector m_data; 33 | }; 34 | } // namespace internal 35 | 36 | template 37 | using memory_output = internal::memory_output_impl>; 38 | template using memory_output_t = internal::memory_output_impl; 39 | } // namespace output 40 | } // namespace hpda 41 | -------------------------------------------------------------------------------- /include/hpda/output/output.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /include/hpda/output/output_base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace output { 7 | namespace internal { 8 | 9 | template 10 | class output_base 11 | : public ::hpda::internal::processor_with_input { 12 | public: 13 | output_base( 14 | ::hpda::internal::processor_with_output *upper_stream) 15 | : ::hpda::internal::processor_with_input(upper_stream) {} 16 | 17 | virtual ~output_base() {} 18 | 19 | typedef ::hpda::internal::processor_with_input base; 20 | 21 | // inline bool next_input() { return base::next_input(); } 22 | 23 | InputObjType input_value() const { return base::input_value(); } 24 | 25 | virtual void done_value() { functor::m_has_value = false; }; 26 | }; 27 | } // namespace internal 28 | } // namespace output 29 | } // namespace hpda 30 | -------------------------------------------------------------------------------- /include/hpda/processor/processor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | -------------------------------------------------------------------------------- /include/hpda/processor/processor_base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace processor { 7 | namespace internal { 8 | template 9 | class processor_base 10 | : public ::hpda::internal::processor_with_output, 11 | public ::hpda::internal::processor_with_input { 12 | public: 13 | processor_base( 14 | ::hpda::internal::processor_with_output *upper_stream) 15 | : ::hpda::internal::processor_with_input(upper_stream) {} 16 | 17 | virtual ~processor_base() {} 18 | 19 | typedef ::hpda::internal::processor_with_input base; 20 | 21 | // inline bool next_input() { return base::next_input(); } 22 | 23 | inline InputObjType input_value() const { return base::input_value(); } 24 | }; 25 | } // namespace internal 26 | template 27 | using processor_base_t = internal::processor_base; 28 | } // namespace processor 29 | } // namespace hpda 30 | -------------------------------------------------------------------------------- /include/hpda/processor/set/helper/copy_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace hpda { 5 | namespace processor { 6 | namespace internal { 7 | 8 | template struct copy_helper { 9 | // TODO optimize for rvalue(&&) 10 | template 11 | static auto copy(T1 &target, T2 &&source) -> typename std::enable_if< 12 | (std::remove_reference::type::type_list::len > Index), void>::type { 13 | typedef typename ::ff::util::get_type_at_index_in_typelist< 14 | typename std::remove_reference::type::type_list, Index>::type 15 | c_type; 16 | target.template set(source.template get()); 17 | copy_helper::copy(target, std::forward(source)); 18 | } 19 | 20 | template 21 | static auto copy(T1 &target, const T2 &source) -> typename std::enable_if< 22 | (std::remove_reference::type::type_list::len <= Index), void>::type {} 23 | }; 24 | 25 | } // namespace internal 26 | } // namespace processor 27 | } // namespace hpda 28 | -------------------------------------------------------------------------------- /include/hpda/processor/transform/all.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace hpda { 5 | namespace processor { 6 | namespace internal { 7 | 8 | template 9 | class all_impl : public processor_base { 10 | public: 11 | all_impl(::hpda::internal::processor_with_output *upper_stream) 12 | : processor_base(upper_stream) {} 13 | 14 | virtual ~all_impl() {} 15 | 16 | typedef processor_base base; 17 | 18 | virtual bool process() { 19 | if (!base::has_input_value()) { 20 | return false; 21 | } 22 | m_data.push_back(base::input_value().make_copy()); 23 | base::consume_input_value(); 24 | return true; 25 | } 26 | 27 | virtual InputObjType output_value() { return m_data.back(); } 28 | 29 | std::vector &values() { return m_data; } 30 | const std::vector &values() const { return m_data; } 31 | 32 | protected: 33 | std::vector m_data; 34 | }; 35 | } // namespace internal 36 | template using all_t = internal::all_impl; 37 | } // namespace processor 38 | } // namespace hpda 39 | -------------------------------------------------------------------------------- /include/hpda/processor/transform/trim.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace hpda { 5 | namespace processor { 6 | namespace internal { 7 | 8 | template 9 | class trim_impl : public processor_base { 10 | public: 11 | trim_impl(::hpda::internal::processor_with_output *upper_stream) 12 | : processor_base(upper_stream) {} 13 | 14 | virtual ~trim_impl() {} 15 | 16 | typedef processor_base base; 17 | 18 | virtual bool process() { 19 | if (!base::has_input_value()) { 20 | return false; 21 | } 22 | m_data = base::input_value().make_copy(); 23 | base::consume_input_value(); 24 | return true; 25 | } 26 | 27 | virtual OutputObjType output_value() { return m_data; } 28 | 29 | protected: 30 | OutputObjType m_data; 31 | }; 32 | } // namespace internal 33 | template using trim_t = internal::trim_impl; 34 | } // namespace processor 35 | } // namespace hpda 36 | -------------------------------------------------------------------------------- /include/hpda/util/ntobject_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace hpda { 6 | namespace util { 7 | std::string convert_data_format_to_ntobject_type_file( 8 | const boost::property_tree::ptree &tree); 9 | } 10 | } // namespace hpda 11 | -------------------------------------------------------------------------------- /include/xgboost/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | *~ 15 | *txt* 16 | *conf 17 | *buffer 18 | *model 19 | xgboost -------------------------------------------------------------------------------- /include/xgboost/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Tianqi Chen 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /include/xgboost/Makefile: -------------------------------------------------------------------------------- 1 | export CC = gcc 2 | export CXX = g++ 3 | export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fopenmp 4 | 5 | # specify tensor path 6 | BIN = xgboost 7 | OBJ = 8 | .PHONY: clean all 9 | 10 | all: $(BIN) $(OBJ) 11 | export LDFLAGS= -pthread -lm 12 | 13 | xgboost: regression/xgboost_reg_main.cpp regression/*.h booster/*.h booster/*/*.hpp booster/*.hpp 14 | 15 | $(BIN) : 16 | $(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c, $^) 17 | 18 | $(OBJ) : 19 | $(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) ) 20 | 21 | install: 22 | cp -f -r $(BIN) $(INSTALL_PATH) 23 | 24 | clean: 25 | $(RM) $(OBJ) $(BIN) *~ 26 | -------------------------------------------------------------------------------- /include/xgboost/utils/xgboost_omp.h: -------------------------------------------------------------------------------- 1 | #ifndef XGBOOST_OMP_H 2 | #define XGBOOST_OMP_H 3 | /*! 4 | * \file xgboost_omp.h 5 | * \brief header to handle OpenMP compatibility issues 6 | * 7 | * \author Tianqi Chen: tianqi.tchen@gmail.com 8 | */ 9 | 10 | #if defined(_OPENMP) 11 | #include 12 | #else 13 | #warning "OpenMP is not available, compile to single thread code" 14 | inline int omp_get_thread_num() { return 0; } 15 | inline int omp_get_num_threads() { return 1; } 16 | inline void omp_set_num_threads( int nthread ) {} 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /include/ypc/common/access_policy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace utc { 6 | constexpr static uint8_t access_policy_whitelist = 1; 7 | constexpr static uint8_t access_policy_blacklist = 2; 8 | constexpr static uint8_t access_policy_signer = 3; 9 | constexpr static uint8_t access_policy_enclave = 4; 10 | 11 | } // namespace utc 12 | } // namespace ypc 13 | -------------------------------------------------------------------------------- /include/ypc/common/byte.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/byte/bytes.h" 3 | #include "ypc/common/byte/bytes_util.h" 4 | -------------------------------------------------------------------------------- /include/ypc/common/byte/base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // base64 encoding and decoding with C++. 3 | // Version: 2.rc.08 (release candidate) 4 | // 5 | 6 | #ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A 7 | #define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A 8 | 9 | #include 10 | 11 | #if __cplusplus >= 201703L 12 | #include 13 | #endif // __cplusplus >= 201703L 14 | 15 | std::string base64_encode(std::string const &s, bool url = false); 16 | std::string base64_encode_pem(std::string const &s); 17 | std::string base64_encode_mime(std::string const &s); 18 | 19 | std::string base64_decode(std::string const &s, bool remove_linebreaks = false); 20 | std::string base64_encode(unsigned char const *, size_t len, bool url = false); 21 | 22 | #if __cplusplus >= 201703L 23 | // 24 | // Interface with std::string_view rather than const std::string& 25 | // Requires C++17 26 | // Provided by Yannic Bonenberger (https://github.com/Yannic) 27 | // 28 | std::string base64_encode(std::string_view s, bool url = false); 29 | std::string base64_encode_pem(std::string_view s); 30 | std::string base64_encode_mime(std::string_view s); 31 | 32 | std::string base64_decode(std::string_view s, bool remove_linebreaks = false); 33 | #endif // __cplusplus >= 201703L 34 | 35 | #endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */ 36 | -------------------------------------------------------------------------------- /include/ypc/common/crypto_prefix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace utc { 6 | typedef uint32_t crypto_prefix_t; 7 | 8 | constexpr static uint32_t crypto_prefix_length = sizeof(uint32_t); 9 | 10 | constexpr static crypto_prefix_t crypto_prefix_forward = 0x1; 11 | constexpr static crypto_prefix_t crypto_prefix_arbitrary = 0x2; 12 | constexpr static crypto_prefix_t crypto_prefix_backup = 0x4; 13 | constexpr static crypto_prefix_t crypto_prefix_host_data = 0x6; 14 | constexpr static crypto_prefix_t crypto_prefix_host_data_private_key = 0x8; 15 | 16 | } // namespace utc 17 | } // namespace ypc 18 | -------------------------------------------------------------------------------- /include/ypc/common/ignore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ypc { 4 | struct ignore_type {}; 5 | 6 | constexpr static ignore_type ignore; 7 | } // namespace ypc 8 | -------------------------------------------------------------------------------- /include/ypc/common/limits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace utc { 6 | constexpr static uint32_t max_item_size = 64 * 1024; 7 | constexpr static uint32_t max_sample_size = 4 * 1024 * 1024; 8 | constexpr static uint32_t max_data_format_size = 1 * 1024 * 1024; 9 | constexpr static uint32_t max_keymgr_response_buf_size = 1024 * 1024; 10 | 11 | } // namespace utc 12 | } // namespace ypc 13 | -------------------------------------------------------------------------------- /include/ypc/common/parser_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace utc { 6 | 7 | constexpr static uint32_t parser_type_length = sizeof(uint32_t); 8 | 9 | constexpr static uint32_t unknown_result_parser = 0; 10 | constexpr static uint32_t onchain_result_parser = 1; 11 | constexpr static uint32_t offchain_result_parser = 2; 12 | constexpr static uint32_t local_result_parser = 0x3; 13 | constexpr static uint32_t forward_result_parser = 0x4; 14 | 15 | constexpr static uint32_t unknown_datasource_parser = 0; 16 | constexpr static uint32_t single_sealed_datasource_parser = 1; 17 | constexpr static uint32_t multi_sealed_datasource_parser = 2; 18 | constexpr static uint32_t noinput_datasource_parser = 3; 19 | constexpr static uint32_t raw_datasource_parser = 4; 20 | 21 | constexpr static uint32_t no_model_parser = 0; 22 | constexpr static uint32_t has_model_parser = 1; 23 | 24 | union parser_type_t { 25 | uint32_t value; 26 | struct _data { 27 | uint32_t result_type : 4; 28 | uint32_t data_source_type : 4; 29 | uint32_t has_model : 1; 30 | } d; 31 | }; 32 | } // namespace utc 33 | } // namespace ypc 34 | -------------------------------------------------------------------------------- /include/ypc/core/blockfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #ifdef HPDA_DEBUG 8 | #include 9 | #endif 10 | #include "ypc/corecommon/blockfile/blockfile_v1.h" 11 | #include "ypc/corecommon/blockfile/blockfile_v2.h" 12 | #include "ypc/corecommon/blockfile/traits.h" 13 | 14 | namespace ypc { 15 | 16 | template <> struct file_traits { 17 | constexpr static auto in = std::ios::in; 18 | constexpr static auto binary = std::ios::binary; 19 | constexpr static auto out = std::ios::out; 20 | constexpr static auto trunc = std::ios::trunc; 21 | constexpr static auto ate = std::ios::ate; 22 | constexpr static auto app = std::ios::app; 23 | constexpr static auto cur = std::ios::cur; 24 | constexpr static auto beg = std::ios::beg; 25 | constexpr static auto end = std::ios::end; 26 | }; 27 | 28 | template 30 | using blockfile = blockfile_v2_r; 32 | 33 | } // namespace ypc 34 | -------------------------------------------------------------------------------- /include/ypc/core/command_executor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | 6 | namespace internal { 7 | class command_executor_helper { 8 | public: 9 | static int execute_command(const std::string &cmd, std::string &output); 10 | }; 11 | } // namespace internal 12 | 13 | class command_executor { 14 | public: 15 | static int execute_command(const std::string &cmd); 16 | static int execute_command(const std::string &cmd, std::string &output); 17 | }; 18 | 19 | } // namespace ypc 20 | -------------------------------------------------------------------------------- /include/ypc/core/configuration.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "ypc/core/singleton.h" 4 | #include 5 | #include 6 | 7 | define_nt(db_url, std::string); 8 | define_nt(db_usr, std::string); 9 | define_nt(db_pass, std::string); 10 | define_nt(db_dbname, std::string); 11 | define_nt(ctrl_net_port, uint16_t); 12 | 13 | namespace ypc { 14 | 15 | using db_info_t = ::ff::util::ntobject; 16 | using net_info_t = ::ff::util::ntobject; 17 | 18 | class configuration : public singleton { 19 | public: 20 | configuration() = default; 21 | configuration(const configuration &cf) = delete; 22 | configuration &operator=(const configuration &cf) = delete; 23 | configuration &operator=(configuration &&cf) = delete; 24 | configuration(configuration &&cf) = delete; 25 | ~configuration() = default; 26 | 27 | public: 28 | static std::string create_logdir_if_not_exist(); 29 | static std::string find_db_config_file(const std::string &filename); 30 | 31 | static db_info_t read_db_config_file(const std::string &filename); 32 | static net_info_t read_net_info_from_file(const std::string &conf_file); 33 | }; 34 | 35 | } // namespace ypc 36 | -------------------------------------------------------------------------------- /include/ypc/core/db.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "ypc/core/configuration.h" 4 | #include 5 | #include 6 | 7 | namespace ypc { 8 | 9 | class db_base { 10 | public: 11 | db_base(const std::string &url, const std::string &usrname, 12 | const std::string &passwd, const std::string &dbname); 13 | virtual void create_tables() = 0; 14 | virtual void clear_tables() = 0; 15 | 16 | ::ff::sql::mysql<::ff::sql::cppconn> *db_engine_ptr(); 17 | 18 | protected: 19 | void init_db(const std::string &url, const std::string &usrname, 20 | const std::string &passwd, const std::string &dbname); 21 | 22 | protected: 23 | std::shared_ptr<::ff::sql::mysql<::ff::sql::cppconn>> m_db_engine; 24 | }; 25 | 26 | template 27 | std::shared_ptr construct_db_ptr(const std::string &filename) { 28 | db_info_t dbinfo = configuration::instance().read_db_config_file(filename); 29 | std::shared_ptr base_ptr = 30 | std::make_shared(dbinfo.get(), dbinfo.get(), 31 | dbinfo.get(), dbinfo.get()); 32 | return base_ptr; 33 | } 34 | 35 | } // namespace ypc 36 | -------------------------------------------------------------------------------- /include/ypc/core/filesystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | std::string home_directory(); 6 | std::string current_directory(); 7 | std::string complete_path(const std::string &ph, 8 | const std::string &base = current_directory()); 9 | 10 | std::string dirname(const std::string &ph); 11 | std::string join_path(const std::string &ph, const std::string &sub); 12 | 13 | bool is_portable_name(const std::string &name); 14 | 15 | bool is_dir_exists(const std::string &path); 16 | bool is_file_exists(const std::string &path); 17 | 18 | void copy_directory(const std::string &from, const std::string &to); 19 | 20 | } // namespace ypc 21 | -------------------------------------------------------------------------------- /include/ypc/core/memref.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ypc { 6 | class memref { 7 | public: 8 | inline memref() : m_data(nullptr), m_len(0), m_cap(0){}; 9 | inline size_t &size() { return m_len; } 10 | inline const size_t &size() const { return m_len; } 11 | inline uint8_t *data() { return m_data; } 12 | inline const uint8_t *data() const { return m_data; } 13 | inline size_t capacity() const { return m_cap; } 14 | 15 | inline void alloc(size_t s) { 16 | assert(!m_data); 17 | m_data = new uint8_t[s]; 18 | m_cap = s; 19 | m_len = 0; 20 | } 21 | inline void dealloc() { 22 | if (m_data != nullptr) { 23 | delete[] m_data; 24 | m_data = nullptr; 25 | m_len = 0; 26 | } 27 | } 28 | 29 | private: 30 | uint8_t *m_data; 31 | size_t m_len; 32 | size_t m_cap; 33 | }; 34 | } // namespace ypc 35 | -------------------------------------------------------------------------------- /include/ypc/core/ref.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ypc { 6 | template class ref { 7 | public: 8 | ref() : m_data(nullptr), m_len(0) {} 9 | ref(T *data, size_t len) 10 | : m_data(data), 11 | m_len(len){ 12 | m_holder = std::shared_ptr(m_data, ::ypc::ref::delete_wild_pointer); 13 | }; 14 | 15 | inline size_t &len() { return m_len; } 16 | inline const size_t &len() const { return m_len; } 17 | 18 | inline size_t &size() { return m_len; } 19 | inline const size_t &size() const { return m_len; } 20 | 21 | inline T *data() { return m_data; } 22 | inline const T *data() const { return m_data; } 23 | 24 | static void delete_wild_pointer(T *p) { free(p); } 25 | 26 | private: 27 | T *m_data; 28 | size_t m_len; 29 | std::shared_ptr m_holder; 30 | }; 31 | 32 | using bref = ref; 33 | } // namespace ypc 34 | 35 | -------------------------------------------------------------------------------- /include/ypc/core/sgx/util/cxxfile_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ypc { 4 | void init_sgx_cxxfile(); 5 | void shutdown_sgx_cxxfile(); 6 | } // namespace ypc 7 | -------------------------------------------------------------------------------- /include/ypc/core/sgx/util/kv_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | namespace ypc { 6 | void init_sgx_kv(); 7 | void shutdown_sgx_kv(); 8 | } 9 | -------------------------------------------------------------------------------- /include/ypc/core/sgx/util/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ypc { 4 | void set_sgx_file_dir(const char *directory); 5 | 6 | const char *get_sgx_file_dir(const char *directory); 7 | 8 | void init_sgx_env(); 9 | void shutdown_sgx_env(); 10 | } 11 | -------------------------------------------------------------------------------- /include/ypc/core/status.def: -------------------------------------------------------------------------------- 1 | YPC_STATUS(success, 0x00) 2 | YPC_STATUS(param_from_json_read_param_from_source_failed, 0x0101) 3 | YPC_STATUS(param_from_db_read_from_source_failed, 0x0102) 4 | YPC_STATUS(parser_return_wrong_data_hash, 0x0103) 5 | YPC_STATUS(sealed_file_cannot_open, 0x0104) 6 | YPC_STATUS(datahub_enclave_file_cannot_open, 0x0105) 7 | YPC_STATUS(parser_enclave_file_cannot_open, 0x0106) 8 | YPC_STATUS(keymgr_enclave_file_cannot_open, 0x0107) 9 | YPC_STATUS(check_data_hash_fail, 0x0108) 10 | YPC_STATUS(parser_missing_input, 0x109) 11 | YPC_STATUS(parser_unknown_result, 0x10A) 12 | -------------------------------------------------------------------------------- /include/ypc/core/status.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | enum ypc_status : uint32_t { 6 | #define YPC_STATUS(a, b) a = (b == 0 ? b : 0x20000 | b), 7 | #include "ypc/core/status.def" 8 | #undef YPC_STATUS 9 | }; 10 | const char *status_string(uint32_t status); 11 | } // namespace ypc 12 | -------------------------------------------------------------------------------- /include/ypc/core/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/version.h" 3 | 4 | namespace ypc { 5 | std::string get_ypc_version(); 6 | } 7 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/analyzer_context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | namespace ypc { 5 | class analyzer_context { 6 | public: 7 | virtual uint32_t 8 | request_private_key_for_public_key(const stbox::bytes &pubkey, 9 | stbox::bytes &private_key, 10 | stbox::bytes &dian_pkey) = 0; 11 | virtual const stbox::bytes &get_enclave_hash() const = 0; 12 | 13 | virtual const stbox::bytes &get_internal_public_key() const = 0; 14 | // virtual const stbox::bytes &get_internal_private_key() const = 0; 15 | }; 16 | } // namespace ypc 17 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/data_source.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "hpda/extractor/extractor_base.h" 3 | #include "ypc/common/limits.h" 4 | #include "ypc/core_t/ecommon/package.h" 5 | #include "ypc/corecommon/data_source.h" 6 | #include "ypc/stbox/ebyte.h" 7 | #include "ypc/stbox/stx_common.h" 8 | #include "ypc/stbox/tsgx/channel/dh_session_initiator.h" 9 | #include 10 | 11 | namespace ypc { 12 | using bytes = ::stbox::bytes; 13 | typedef ::ff::util::ntobject::data> data_source_output_t; 14 | 15 | class data_source_with_dhash : public data_source { 16 | public: 17 | inline data_source_with_dhash(const stbox::bytes &data_hash) 18 | : m_expect_data_hash(data_hash) {} 19 | 20 | virtual ~data_source_with_dhash() {} 21 | 22 | inline const bytes &expect_data_hash() const { return m_expect_data_hash; } 23 | virtual const bytes &data_hash() const = 0; 24 | 25 | inline void reset_reach_end() { m_data_reach_end = false; } 26 | 27 | protected: 28 | bytes m_expect_data_hash; 29 | bool m_data_reach_end; 30 | uint32_t m_counter; 31 | }; 32 | } // namespace ypc 33 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/helper/parser_type_traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/parser_type.h" 3 | namespace ypc { 4 | template struct result_type_traits { 5 | constexpr static uint32_t value = ypc::utc::unknown_result_parser; 6 | }; 7 | 8 | template struct datasource_type_traits { 9 | constexpr static uint32_t value = ypc::utc::unknown_datasource_parser; 10 | }; 11 | 12 | template struct model_type_traits { 13 | constexpr static uint32_t value = ypc::utc::has_model_parser; 14 | }; 15 | 16 | template <> struct model_type_traits { 17 | constexpr static uint32_t value = ypc::utc::no_model_parser; 18 | }; 19 | 20 | } // namespace ypc 21 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/data_streams/multi_data_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/helper/parser_type_traits.h" 3 | #include "ypc/core_t/analyzer/internal/is_multi_datasource.h" 4 | #include "ypc/stbox/ebyte.h" 5 | 6 | namespace ypc { 7 | namespace internal { 8 | 9 | class multi_data_stream {}; 10 | 11 | template <> struct is_multi_datasource { 12 | static constexpr bool value = true; 13 | }; 14 | 15 | } // namespace internal 16 | using multi_data_stream = internal::multi_data_stream; 17 | 18 | template <> struct datasource_type_traits { 19 | constexpr static uint32_t value = ypc::utc::multi_sealed_datasource_parser; 20 | }; 21 | 22 | } // namespace ypc 23 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/data_streams/noinput_data_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/helper/parser_type_traits.h" 3 | #include "ypc/stbox/ebyte.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | 8 | class noinput_data_stream {}; 9 | 10 | } // namespace internal 11 | using noinput_data_stream = internal::noinput_data_stream; 12 | 13 | template <> struct datasource_type_traits { 14 | constexpr static uint32_t value = ypc::utc::noinput_datasource_parser; 15 | }; 16 | } // namespace ypc 17 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/data_streams/raw_data_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/helper/parser_type_traits.h" 3 | #include "ypc/stbox/ebyte.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | 8 | class raw_data_stream {}; 9 | 10 | } // namespace internal 11 | using raw_data_stream = internal::raw_data_stream; 12 | template <> struct datasource_type_traits { 13 | constexpr static uint32_t value = ypc::utc::raw_datasource_parser; 14 | }; 15 | } // namespace ypc 16 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/data_streams/sealed_data_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/helper/parser_type_traits.h" 3 | #include "ypc/stbox/ebyte.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | 8 | class sealed_data_stream {}; 9 | 10 | } // namespace internal 11 | using sealed_data_stream = internal::sealed_data_stream; 12 | 13 | template <> struct datasource_type_traits { 14 | constexpr static uint32_t value = ypc::utc::single_sealed_datasource_parser; 15 | }; 16 | } // namespace ypc 17 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/is_multi_datasource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace ypc { 3 | namespace internal { 4 | 5 | template struct is_multi_datasource { 6 | static constexpr bool value = false; 7 | }; 8 | } // namespace internal 9 | } // namespace ypc 10 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/is_param_encrypted.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace ypc { 3 | namespace internal { 4 | 5 | template struct is_param_encrypted { 6 | static constexpr bool value = true; 7 | }; 8 | } // namespace internal 9 | } // namespace ypc 10 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/keymgr_session.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/var/enclave_hash_var.h" 3 | #include "ypc/core_t/analyzer/var/keymgr_var.h" 4 | #include "ypc/core_t/analyzer/var/request_key_var.h" 5 | #include "ypc/core_t/ecommon/package.h" 6 | #include "ypc/stbox/ebyte.h" 7 | #include "ypc/stbox/stx_status.h" 8 | #include "ypc/stbox/tsgx/channel/dh_session_initiator.h" 9 | #include "ypc/stbox/tsgx/ocall.h" 10 | 11 | namespace ypc { 12 | namespace internal { 13 | 14 | stbox::stx_status km_verify_peer_enclave_trust( 15 | sgx_dh_session_enclave_identity_t *peer_enclave_identity); 16 | 17 | class keymgr_session : virtual public enclave_hash_var, 18 | virtual public keymgr_var { 19 | protected: 20 | uint32_t init_keymgr_session(); 21 | uint32_t close_keymgr_session(); 22 | }; 23 | } // namespace internal 24 | } // namespace ypc 25 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/internal/results/local_result.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/helper/parser_type_traits.h" 3 | #include "ypc/core_t/analyzer/internal/is_param_encrypted.h" 4 | #include "ypc/core_t/analyzer/var/result_var.h" 5 | #include "ypc/stbox/ebyte.h" 6 | #include "ypc/stbox/stx_status.h" 7 | 8 | namespace ypc { 9 | namespace internal { 10 | class local_result : virtual public result_var { 11 | public: 12 | inline uint32_t generate_result() { return 0; } 13 | inline uint32_t get_analyze_result_size() { 14 | return result_var::m_result.size(); 15 | } 16 | inline uint32_t get_analyze_result(uint8_t *result, uint32_t size) { 17 | if (size != result_var::m_result.size()) { 18 | return stbox::stx_status::out_buffer_length_error; 19 | } 20 | memcpy(result, result_var::m_result.data(), size); 21 | return stbox::stx_status::success; 22 | } 23 | }; 24 | template <> struct is_param_encrypted { 25 | static constexpr bool value = false; 26 | }; 27 | } // namespace internal 28 | typedef internal::local_result local_result; 29 | template <> struct result_type_traits { 30 | constexpr static uint32_t value = ypc::utc::local_result_parser; 31 | }; 32 | } // namespace ypc 33 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/ntpackage_item_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/package.h" 3 | #include 4 | #include 5 | 6 | namespace ypc { 7 | 8 | template 9 | struct ntpackage_item_parser { 10 | static UserItemT parser(const ByteType *data, size_t len) { 11 | typedef typename cast_obj_to_package::type package_t; 12 | 13 | package_t pt; 14 | ff::net::marshaler dm((const char *)data, len, 15 | ff::net::marshaler::deserializer); 16 | pt.arch(dm); 17 | UserItemT ret(pt); 18 | return ret; 19 | } 20 | }; 21 | } // namespace ypc 22 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/data_hash_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | namespace ypc { 5 | namespace internal { 6 | class data_hash_var { 7 | protected: 8 | stbox::bytes m_data_hash; 9 | }; 10 | } // namespace internal 11 | } // namespace ypc 12 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/data_source_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/data_source.h" 3 | #include "ypc/core_t/analyzer/internal/data_streams/multi_data_stream.h" 4 | #include "ypc/core_t/analyzer/internal/data_streams/noinput_data_stream.h" 5 | #include "ypc/stbox/ebyte.h" 6 | 7 | namespace ypc { 8 | namespace internal { 9 | 10 | template class data_source_var { 11 | protected: 12 | std::shared_ptr m_datasource; 13 | stbox::bytes m_ds_use_pkey; 14 | }; 15 | 16 | template <> class data_source_var { 17 | protected: 18 | std::vector> m_datasource; 19 | std::vector m_ds_use_pkey; 20 | }; 21 | template <> class data_source_var {}; 22 | } // namespace internal 23 | } // namespace ypc 24 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/enclave_hash_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/analyzer/analyzer_context.h" 3 | #include "ypc/stbox/ebyte.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | class enclave_hash_var : virtual public analyzer_context { 8 | public: 9 | inline void set_enclave_hash(const uint8_t *hash, uint32_t hash_size) { 10 | m_enclave_hash = stbox::bytes(hash, hash_size); 11 | } 12 | 13 | virtual const stbox::bytes &get_enclave_hash() const; 14 | 15 | protected: 16 | stbox::bytes m_enclave_hash; 17 | }; 18 | } // namespace internal 19 | } // namespace ypc 20 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/encrypted_param_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | namespace ypc { 5 | namespace internal { 6 | 7 | class encrypted_param_var { 8 | protected: 9 | stbox::bytes m_encrypted_param; 10 | }; 11 | } // namespace internal 12 | } // namespace ypc 13 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/keymgr_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | #include "ypc/stbox/tsgx/channel/dh_session_initiator.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | 8 | class keymgr_var : virtual public enclave_hash_var { 9 | protected: 10 | std::unique_ptr<::stbox::dh_session_initiator> m_keymgr_session; 11 | }; 12 | } // namespace internal 13 | } // namespace ypc 14 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/model_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | namespace ypc { 5 | namespace internal { 6 | 7 | template ::value> 8 | class model_var {}; 9 | 10 | template class model_var { 11 | protected: 12 | ModelT m_model; 13 | stbox::bytes m_model_pkey; 14 | stbox::bytes m_model_hash; 15 | }; 16 | } // namespace internal 17 | 18 | } // namespace ypc 19 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/parser_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "hpda/engine/engine.h" 3 | 4 | namespace ypc { 5 | namespace internal { 6 | 7 | template class parser_var { 8 | protected: 9 | std::shared_ptr m_parser; 10 | std::shared_ptr m_engine; 11 | }; 12 | } // namespace internal 13 | } // namespace ypc 14 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/request_key_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | namespace ypc { 5 | namespace internal { 6 | 7 | template class request_key_var {}; 8 | 9 | template <> class request_key_var { 10 | protected: 11 | // should be a pair 12 | stbox::bytes m_private_key; 13 | stbox::bytes m_pkey4v; 14 | }; 15 | } // namespace internal 16 | } // namespace ypc 17 | -------------------------------------------------------------------------------- /include/ypc/core_t/analyzer/var/result_var.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | namespace ypc { 4 | namespace internal { 5 | class result_var { 6 | protected: 7 | stbox::bytes m_result; 8 | uint64_t m_cost_gas; 9 | }; 10 | } // namespace internal 11 | } // namespace ypc 12 | -------------------------------------------------------------------------------- /include/ypc/core_t/ecommon/signer_verify.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/nt_cols.h" 3 | #include "ypc/corecommon/package.h" 4 | #include "ypc/stbox/tsgx/channel/dh_session.h" 5 | 6 | namespace ypc { 7 | bool is_certified_signer( 8 | sgx_dh_session_enclave_identity_t *peer_enclave_identity, 9 | std::shared_ptr::access_list_package_t> policy = 10 | std::shared_ptr::access_list_package_t>()); 11 | } 12 | -------------------------------------------------------------------------------- /include/ypc/core_t/util/cxxfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core_t/util/file_openmode.h" 3 | #include "ypc/core_t/util/fpos.h" 4 | 5 | namespace ypc { 6 | 7 | class cxxfile { 8 | public: 9 | cxxfile(); 10 | 11 | void open(const char *filename, ypc::ios_base::openmode mode); 12 | 13 | void close(); 14 | 15 | cxxfile &seekg(int64_t pos, ios_base::seekdir dir = ios_base::beg); 16 | int64_t tellg(); 17 | 18 | cxxfile &seekp(int64_t pos, ios_base::seekdir dir = ios_base::beg); 19 | int64_t tellp(); 20 | bool is_open() const; 21 | 22 | cxxfile &flush(); 23 | inline cxxfile &read(char *s, size_t size) { 24 | return read((uint8_t *)s, size); 25 | } 26 | 27 | inline cxxfile &write(const char *s, size_t size) { 28 | return write((const uint8_t *)s, size); 29 | } 30 | cxxfile &read(uint8_t *s, size_t size); 31 | cxxfile &write(const uint8_t *s, size_t size); 32 | 33 | bool good() const; 34 | bool eof() const; 35 | bool fail() const; 36 | bool bad() const; 37 | void clear(); 38 | 39 | protected: 40 | uint32_t m_stream_id; 41 | }; 42 | } // namespace ypc 43 | -------------------------------------------------------------------------------- /include/ypc/core_t/util/file_openmode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace ypc { 4 | namespace ios_base { 5 | enum openmode { 6 | app = 0x1, 7 | ate = 0x2, 8 | binary = 0x4, 9 | in = 0x8, 10 | out = 0x10, 11 | trunc = 0x20 12 | }; 13 | inline openmode operator|(openmode a, openmode b) { 14 | typedef std::underlying_type::type UL; 15 | return openmode(static_cast
    (a) | static_cast
      (b)); 16 | } 17 | inline openmode operator&(openmode a, openmode b) { 18 | typedef std::underlying_type::type UL; 19 | return openmode(static_cast
        (a) & static_cast
          (b)); 20 | } 21 | } 22 | } // namespace ypc 23 | -------------------------------------------------------------------------------- /include/ypc/core_t/util/fpos.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ypc { 6 | // using fpos = std::array; 7 | 8 | namespace ios_base { 9 | typedef uint8_t seekdir; 10 | static constexpr seekdir beg = 0; 11 | static constexpr seekdir end = 1; 12 | static constexpr seekdir cur = 2; 13 | } // namespace ios_base 14 | 15 | } // namespace ypc 16 | -------------------------------------------------------------------------------- /include/ypc/core_t/util/kv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ypc { 6 | namespace kv { 7 | 8 | // key length must be 32 9 | bool has_key(const uint8_t *key); 10 | uint32_t remove_key(const uint8_t *key); 11 | uint32_t write(const uint8_t *key, const uint8_t *val, size_t len); 12 | uint32_t read(const uint8_t *key, uint8_t *val, size_t size); 13 | } // namespace kv 14 | } // namespace ypc 15 | -------------------------------------------------------------------------------- /include/ypc/corecommon/allowance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/crypto_prefix.h" 3 | #include "ypc/stbox/stx_status.h" 4 | 5 | namespace ypc { 6 | 7 | template struct allowance { 8 | typedef Crypto ecc; 9 | 10 | template 11 | static uint32_t check(const BytesType &private_key, const BytesType &msg, 12 | const BytesType &allowance) { 13 | //check(private_key, to_check_data, allow); 14 | BytesType pkey; 15 | auto ret = ecc::generate_pkey_from_skey(private_key, pkey); 16 | if (ret) { 17 | return ret; 18 | } 19 | ret = ecc::verify_signature(msg, allowance, pkey); 20 | return ret; 21 | } 22 | 23 | template 24 | static uint32_t generate(const BytesType &private_key, const BytesType &msg, 25 | BytesType &allowance) { 26 | uint32_t ret = ecc::sign_message(private_key, msg, allowance); 27 | return ret; 28 | } 29 | }; 30 | 31 | } // namespace ypc 32 | -------------------------------------------------------------------------------- /include/ypc/corecommon/blockfile/blockfile_interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/exceptions.h" 3 | 4 | namespace ypc { 5 | class invalid_blockfile : public std::exception { 6 | public: 7 | virtual const char *what() { return "wrong magic number"; } 8 | }; 9 | 10 | class blockfile_interface { 11 | public: 12 | virtual void reset_read_item() = 0; 13 | virtual int next_item(char *buf, size_t in_size, size_t &out_size) = 0; 14 | virtual uint64_t item_number() = 0; 15 | virtual void close() = 0; 16 | virtual int append_item(const char *data, size_t len) = 0; 17 | virtual void open_for_read(const char *file_path) = 0; 18 | virtual void open_for_write(const char *file_path) = 0; 19 | 20 | protected: 21 | struct block_info { 22 | block_info() = default; 23 | uint64_t start_item_index; 24 | uint64_t end_item_index; // not included 25 | long int start_file_pos; 26 | long int end_file_pos; 27 | }; 28 | }; 29 | } // namespace ypc 30 | -------------------------------------------------------------------------------- /include/ypc/corecommon/blockfile/blockfile_v1.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/blockfile/blockfile_base.h" 3 | #include "ypc/corecommon/blockfile/blockfile_base_r.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | struct blockfile_header_v1 { 8 | uint64_t magic_number; 9 | uint64_t version_number; 10 | uint64_t block_number; 11 | uint64_t item_number; 12 | }; 13 | 14 | } // namespace internal 15 | template 17 | using blockfile_v1 = 18 | internal::blockfile_impl; 21 | 22 | template 24 | using blockfile_v1_r = 25 | internal::blockfile_impl_r; 28 | 29 | } // namespace ypc 30 | -------------------------------------------------------------------------------- /include/ypc/corecommon/blockfile/blockfile_v2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/blockfile/blockfile_base.h" 3 | #include "ypc/corecommon/blockfile/blockfile_base_r.h" 4 | 5 | namespace ypc { 6 | namespace internal { 7 | struct blockfile_header_v2 { 8 | uint64_t magic_number; 9 | uint64_t version_number; 10 | uint64_t block_number; 11 | uint64_t item_number; 12 | char data_hash[32]; 13 | }; 14 | 15 | } // namespace internal 16 | template 18 | using blockfile_v2 = 19 | internal::blockfile_impl; 22 | 23 | template 25 | using blockfile_v2_r = 26 | internal::blockfile_impl_r; 29 | 30 | } // namespace ypc 31 | -------------------------------------------------------------------------------- /include/ypc/corecommon/blockfile/traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ypc { 4 | template struct file_traits {}; 5 | } // namespace ypc 6 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/aes_gcm_traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ypc { 4 | namespace crypto { 5 | 6 | template struct aes_gcm_traits { 7 | constexpr static bool value = false; 8 | }; 9 | } // namespace crypto 10 | } // namespace ypc 11 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/example/README.md: -------------------------------------------------------------------------------- 1 | This directory is only for example. You should not include this headers. 2 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/example/aes_gcm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | class rijndael128GCM { 6 | static uint32_t get_mac_code_size(); 7 | static inline uint32_t get_cipher_size(uint32_t data_size) { 8 | return data_size; 9 | } 10 | static inline uint32_t get_data_size(uint32_t cipher_size) { 11 | return cihper_size; 12 | } 13 | static uint32_t get_key_size(); 14 | 15 | static uint32_t encrypt_with_prefix(const uint8_t *key, uint32_t key_size, 16 | const uint8_t *data, uint32_t data_size, 17 | uint32_t prefix, uint8_t *cipher, 18 | uint32_t cipher_size, uint8_t *out_mac); 19 | static uint32_t decrypt_with_prefix(const uint8_t *key, uint32_t key_size, 20 | const uint8_t *cipher, 21 | uint32_t cipher_size, uint32_t prefix, 22 | uint8_t *data, uint32_t data_size, 23 | const uint8_t *in_mac); 24 | }; 25 | 26 | // template <> struct aes_gcm_traits { 27 | // constexpr static bool value = true; 28 | //}; 29 | 30 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/example/ecc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | 4 | struct ecc { 5 | 6 | static uint32_t get_private_key_size(); 7 | static uint32_t get_public_key_size(); 8 | static uint32_t gen_private_key(uint32_t skey_size, uint8_t *skey); 9 | 10 | static uint32_t generate_pkey_from_skey(const uint8_t *skey, 11 | uint32_t skey_size, uint8_t *pkey, 12 | uint32_t pkey_size); 13 | 14 | static uint32_t get_signature_size(); 15 | 16 | static uint32_t sign_message(const uint8_t *skey, uint32_t skey_size, 17 | const uint8_t *data, uint32_t data_size, 18 | uint8_t *sig, uint32_t sig_size); 19 | 20 | static uint32_t verify_signature(const uint8_t *data, uint32_t data_size, 21 | const uint8_t *sig, uint32_t sig_size, 22 | const uint8_t *public_key, 23 | uint32_t pkey_size); 24 | }; 25 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/example/ecdh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct secp256k1_ecdh_sgx128 { 4 | inline static uint32_t get_ecdh_shared_key_size() { return 16; } 5 | static uint32_t ecdh_shared_key(const uint8_t *skey, uint32_t skey_size, 6 | const uint8_t *public_key, uint32_t pkey_size, 7 | uint8_t *shared_key, 8 | uint32_t shared_key_size); 9 | }; 10 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/example/eth_hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class eth_hash { 4 | public: 5 | static uint32_t sha3_256(const uint8_t *msg, uint32_t msg_size, 6 | uint8_t *hash); 7 | 8 | static uint32_t get_msg_hash_size(); 9 | 10 | static uint32_t msg_hash(const uint8_t *raw_msg, uint32_t msg_size, 11 | uint8_t *hash, uint32_t hash_size); 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/gmssl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/crypto/gmssl/sm2_ecc.h" 3 | #include "ypc/corecommon/crypto/gmssl/sm3_hash.h" 4 | #include "ypc/corecommon/crypto/gmssl/sm4_aes.h" 5 | #include "ypc/corecommon/crypto/crypto_pack.h" 6 | 7 | namespace ypc { 8 | namespace crypto { 9 | typedef crypto_pack 10 | gmssl_sgx_crypto; 11 | } 12 | } // namespace ypc 13 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/gmssl/sm3_hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace crypto { 6 | 7 | class sm3_hash { 8 | public: 9 | static uint32_t hash_256(const uint8_t *msg, uint32_t msg_size, 10 | uint8_t *hash); 11 | 12 | inline static uint32_t get_msg_hash_size() { return 32; } 13 | 14 | static uint32_t msg_hash(const uint8_t *raw_msg, uint32_t msg_size, 15 | uint8_t *hash, uint32_t hash_size); 16 | }; 17 | 18 | } // namespace crypto 19 | } // namespace ypc 20 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/stdeth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/crypto/crypto_pack.h" 3 | #include "ypc/corecommon/crypto/stdeth/eth_hash.h" 4 | #include "ypc/corecommon/crypto/stdeth/rijndael128GCM.h" 5 | #include "ypc/corecommon/crypto/stdeth/secp256k1.h" 6 | #include "ypc/corecommon/crypto/stdeth/secp256k1_ecdh_sgx128.h" 7 | 8 | namespace ypc { 9 | namespace crypto { 10 | typedef crypto_pack 11 | eth_sgx_crypto; 12 | } 13 | } // namespace ypc 14 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/stdeth/eth_hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace crypto { 6 | 7 | class eth_hash { 8 | public: 9 | static uint32_t hash_256(const uint8_t *msg, uint32_t msg_size, 10 | uint8_t *hash); 11 | 12 | static uint32_t get_msg_hash_size(); 13 | 14 | static uint32_t msg_hash(const uint8_t *raw_msg, uint32_t msg_size, 15 | uint8_t *hash, uint32_t hash_size); 16 | }; 17 | 18 | } // namespace crypto 19 | } // namespace ypc 20 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/stdeth/rijndael128GCM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/corecommon/crypto/aes_gcm_traits.h" 3 | #include 4 | 5 | namespace ypc { 6 | namespace crypto { 7 | 8 | struct rijndael128GCM { 9 | static inline uint32_t get_mac_code_size() { return 16; } 10 | static uint32_t get_cipher_size(uint32_t data_size); 11 | static uint32_t get_data_size(uint32_t cipher_size); 12 | static inline uint32_t get_key_size() { return 16; } 13 | 14 | static uint32_t encrypt_with_prefix(const uint8_t *key, uint32_t key_size, 15 | const uint8_t *data, uint32_t data_size, 16 | uint32_t prefix, uint8_t *cipher, 17 | uint32_t cipher_size, uint8_t *out_mac); 18 | static uint32_t decrypt_with_prefix(const uint8_t *key, uint32_t key_size, 19 | const uint8_t *cipher, 20 | uint32_t cipher_size, uint32_t prefix, 21 | uint8_t *data, uint32_t data_size, 22 | const uint8_t *in_mac); 23 | }; 24 | 25 | template <> struct aes_gcm_traits { 26 | constexpr static bool value = true; 27 | }; 28 | } // namespace crypto 29 | } // namespace ypc 30 | 31 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/stdeth/secp256k1.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace crypto { 6 | struct secp256k1 { 7 | inline static uint32_t get_private_key_size() { return 32; } 8 | inline static uint32_t get_public_key_size() { return 64; } 9 | static uint32_t gen_private_key(uint32_t skey_size, uint8_t *skey); 10 | 11 | static uint32_t generate_pkey_from_skey(const uint8_t *skey, 12 | uint32_t skey_size, uint8_t *pkey, 13 | uint32_t pkey_size); 14 | 15 | static uint32_t get_signature_size(); 16 | 17 | static uint32_t sign_message(const uint8_t *skey, uint32_t skey_size, 18 | const uint8_t *data, uint32_t data_size, 19 | uint8_t *sig, uint32_t sig_size); 20 | 21 | static uint32_t verify_signature(const uint8_t *data, uint32_t data_size, 22 | const uint8_t *sig, uint32_t sig_size, 23 | const uint8_t *public_key, 24 | uint32_t pkey_size); 25 | }; 26 | } // namespace crypto 27 | } // namespace ypc 28 | -------------------------------------------------------------------------------- /include/ypc/corecommon/crypto/stdeth/secp256k1_ecdh_sgx128.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ypc { 5 | namespace crypto { 6 | struct secp256k1_ecdh_sgx128 { 7 | inline static uint32_t get_ecdh_shared_key_size() { return 16; } 8 | static uint32_t ecdh_shared_key(const uint8_t *skey, uint32_t skey_size, 9 | const uint8_t *public_key, uint32_t pkey_size, 10 | uint8_t *shared_key, 11 | uint32_t shared_key_size); 12 | }; 13 | 14 | } // namespace crypto 15 | } // namespace ypc 16 | 17 | -------------------------------------------------------------------------------- /include/ypc/corecommon/data_source.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "hpda/extractor/extractor_base.h" 3 | #include "ypc/corecommon/nt_cols.h" 4 | #include 5 | 6 | namespace ypc { 7 | template 8 | class data_source : public ::hpda::extractor::internal::extractor_base< 9 | ::ff::util::ntobject::data>> { 10 | public: 11 | typedef ::ff::util::ntobject::data> 12 | data_source_output_t; 13 | virtual ~data_source() {} 14 | }; 15 | } // namespace ypc 16 | -------------------------------------------------------------------------------- /include/ypc/edl/util/file.edl: -------------------------------------------------------------------------------- 1 | 2 | enclave { 3 | include "sgx_eid.h" 4 | 5 | untrusted { 6 | 7 | uint32_t fopen_ocall([in, size=len] const char * filename, size_t len, 8 | uint32_t mode); 9 | 10 | void fclose_ocall(uint32_t stream); 11 | 12 | void fflush_ocall(uint32_t stream); 13 | 14 | void fread_ocall([out, size=size]void * ptr, size_t size, 15 | uint32_t stream); 16 | 17 | void fwrite_ocall([in, size=size]const void * ptr, size_t size, 18 | uint32_t stream); 19 | 20 | void fseekg_ocall(uint32_t stream, int64_t offset, uint8_t dir); 21 | 22 | int64_t ftellg_ocall(uint32_t stream); 23 | 24 | void fseekp_ocall(uint32_t stream, int64_t offset, uint8_t dir); 25 | 26 | int64_t ftellp_ocall(uint32_t stream); 27 | 28 | uint8_t feof_ocall(uint32_t stream); 29 | uint8_t fgood_ocall(uint32_t stream); 30 | uint8_t ffail_ocall(uint32_t stream); 31 | uint8_t fbad_ocall(uint32_t stream); 32 | 33 | void clear_ocall(uint32_t stream); 34 | 35 | }; 36 | }; 37 | -------------------------------------------------------------------------------- /include/ypc/edl/util/kv.edl: -------------------------------------------------------------------------------- 1 | 2 | enclave { 3 | include "sgx_eid.h" 4 | 5 | untrusted { 6 | 7 | uint8_t has_key_ocall([in, size=32] const uint8_t * key); 8 | 9 | uint32_t remove_key_ocall([in, size=32] const uint8_t * key); 10 | 11 | uint32_t write_to_storage_ocall([in, size=32] const uint8_t * key, 12 | [in, size=len] const uint8_t * val, size_t len); 13 | 14 | uint32_t read_from_storage_ocall([in, size=32] const uint8_t * key, 15 | [out, size=data_size] uint8_t * val, size_t data_size); 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /include/ypc/edl/yaenclave.edl: -------------------------------------------------------------------------------- 1 | /* Enclave.edl - Top EDL file. */ 2 | 3 | enclave { 4 | include "sgx_eid.h" 5 | include "ypc/stbox/tsgx/channel/dh_cdef.h" 6 | from "sgx_tstdc.edl" import *; 7 | 8 | trusted { 9 | public uint64_t get_ypc_analyzer_version(); 10 | }; 11 | 12 | 13 | untrusted { 14 | /* define OCALLs here. */ 15 | uint32_t km_session_request_ocall([out] sgx_dh_msg1_t *dh_msg1,[out] uint32_t *session_id); 16 | uint32_t km_exchange_report_ocall([in] sgx_dh_msg2_t *dh_msg2, [out] sgx_dh_msg3_t *dh_msg3, uint32_t session_id); 17 | uint32_t km_send_request_ocall(uint32_t session_id, [in, size = req_message_size] secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, [out, size=resp_message_size] secure_message_t* resp_message, size_t resp_message_size); 18 | uint32_t km_end_session_ocall(uint32_t session_id); 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /include/ypc/keymgr/common/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ypc/core/byte.h" 4 | #include "ypc/core/filesystem.h" 5 | #include "ypc/corecommon/nt_cols.h" 6 | #include 7 | 8 | #define PKEY_FILE_NAME_LENGTH 40 9 | 10 | std::string create_dir_if_not_exist(const std::string &base, 11 | const std::string &dir); 12 | uint32_t 13 | write_key_pair_to_file(const std::string &filename, 14 | const ypc::nt::keymgr_key_package_t &key); 15 | 16 | uint32_t 17 | read_key_pair_from_file(const std::string &filename, 18 | ypc::nt::keymgr_key_package_t &key); 19 | 20 | extern "C" { 21 | uint32_t ocall_load_key_pair(const char *key_path_name, uint32_t path_size, 22 | uint8_t *public_key, uint32_t pkey_size, 23 | uint8_t *sealed_private_key, uint32_t sealed_size); 24 | } 25 | -------------------------------------------------------------------------------- /include/ypc/keymgr/default/enclave/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ekeymgr_t.h" /* print_string */ 4 | #include "ypc/core_t/ecommon/package.h" 5 | #include "ypc/stbox/tsgx/channel/dh_session.h" 6 | 7 | uint32_t load_and_check_key_pair(const uint8_t *pkey, uint32_t pkey_size, 8 | stbox::bytes &skey); 9 | uint32_t load_key_pair_if_not_exist(uint8_t *pkey_ptr, uint32_t pkey_size, 10 | uint8_t *skey_ptr, uint32_t *skey_size); 11 | -------------------------------------------------------------------------------- /include/ypc/stbox/ebyte.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ypc/common/byte.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace stbox { 10 | 11 | typedef uint8_t byte_t; 12 | using bytes = ::ypc::utc::bytes; 13 | using hex_bytes = bytes::hex_bytes_t; 14 | using base58_bytes = bytes::base58_bytes_t; 15 | 16 | } // namespace stbox 17 | 18 | -------------------------------------------------------------------------------- /include/ypc/stbox/exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/stx_status.h" 3 | #include 4 | #include 5 | 6 | namespace stbox { 7 | class st_error { 8 | public: 9 | explicit st_error(sgx_status_t s); 10 | 11 | virtual const char *what(); 12 | 13 | protected: 14 | sgx_status_t m_status; 15 | std::string m_message; 16 | }; 17 | } // namespace stbox 18 | -------------------------------------------------------------------------------- /include/ypc/stbox/scope_guard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace stbox { 5 | using scope_guard = ff::scope_guard; 6 | 7 | template class malloc_memory_guard { 8 | public: 9 | typedef T *ptr_type; 10 | malloc_memory_guard(ptr_type &d) : m_ptr(d) {} 11 | ~malloc_memory_guard() { 12 | if (m_ptr) { 13 | free(m_ptr); 14 | m_ptr = NULL; 15 | } 16 | } 17 | 18 | private: 19 | ptr_type &m_ptr; 20 | }; 21 | } // namespace stbox 22 | -------------------------------------------------------------------------------- /include/ypc/stbox/stbox.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | include "sgx_eid.h" 3 | 4 | trusted{ 5 | public uint64_t stbox_common_version(); 6 | }; 7 | 8 | untrusted{ 9 | void ocall_print_string([in, string] const char * buf); 10 | void ocall_log_string(uint32_t rank, [in, string] const char * buf); 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /include/ypc/stbox/stx_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace stbox { 6 | int printf(const char *fmt, ...); 7 | int sprintf(char *buf, const char *fmt, ...); 8 | void print_hex(uint8_t *data, size_t data_len); 9 | } // namespace stbox 10 | -------------------------------------------------------------------------------- /include/ypc/stbox/stx_status.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace stbox { 5 | enum stx_status : uint32_t { 6 | // 0x10000 makes sure our error code won't overlap with sgx_status_t 7 | #define ATT_STATUS(a, b) a = (b == 0 ? b : 0x10000 | b), 8 | 9 | #include "ypc/stbox/stx_status.def" 10 | 11 | #undef ATT_STATUS 12 | }; 13 | 14 | const char *status_string(uint32_t status); 15 | } // namespace stbox 16 | 17 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/channel/dh_cdef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | //#define MESSAGE_EXCHANGE 0x0 7 | #define ENCLAVE_TO_ENCLAVE_CALL 0x1 8 | 9 | #pragma pack(push, 1) 10 | typedef struct _secure_message_t { 11 | uint32_t session_id; // Session ID identifyting the session to which the 12 | // message belongs 13 | sgx_aes_gcm_data_t message_aes_gcm_data; 14 | } secure_message_t; 15 | 16 | #pragma pack(pop) 17 | 18 | //#if defined(__cplusplus) 19 | // extern "C" { 20 | //#endif 21 | 22 | // int printf(const char *fmt, ...); 23 | 24 | //#if defined(__cplusplus) 25 | //} 26 | //#endif 27 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/channel/dh_session_initiator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/stx_status.h" 3 | #include "ypc/stbox/tsgx/channel/dh_session.h" 4 | 5 | namespace stbox { 6 | class dh_session_initiator : public dh_session { 7 | public: 8 | typedef ocall 9 | session_request_func_t; 10 | 11 | typedef ocall 13 | exchange_report_func_t; 14 | 15 | typedef ocall end_session_func_t; 16 | 17 | dh_session_initiator(const session_request_func_t &ocall_session_request, 18 | const exchange_report_func_t &ocall_exchange_report, 19 | const send_request_func_t &ocall_send_request, 20 | const end_session_func_t &ocall_end_session); 21 | 22 | stx_status create_session(); 23 | 24 | stx_status close_session(); 25 | 26 | 27 | protected: 28 | // Ocall to request for a session with the destination enclave and obtain 29 | // session id and Message 1 if successful 30 | session_request_func_t m_session_request_ocall; 31 | exchange_report_func_t m_exchange_report_ocall; 32 | end_session_func_t m_end_session_ocall; 33 | }; 34 | } // namespace stbox 35 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/crypto/seal_sgx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | #include "ypc/stbox/tsgx/crypto/seal.h" 4 | namespace stbox { 5 | namespace crypto { 6 | struct intel_sgx {}; 7 | 8 | template <> struct raw_device_sealer { 9 | 10 | static uint32_t get_sealed_data_size(uint32_t data_size); 11 | 12 | static uint32_t seal_data(const uint8_t *data, uint32_t data_size, 13 | uint8_t *sealed_data, uint32_t sealed_size); 14 | 15 | static uint32_t get_unsealed_data_size(const uint8_t *sealed_data, 16 | uint32_t sealed_data_size); 17 | 18 | static uint32_t unseal_data(const uint8_t *sealed_data, 19 | uint32_t sealed_data_size, uint8_t *data, 20 | uint32_t data_size); 21 | 22 | }; 23 | } // namespace crypto 24 | } // namespace stbox 25 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | #include "ypc/stbox/stx_common.h" 4 | #include "ypc/stbox/stx_status.h" 5 | #include 6 | #include 7 | 8 | namespace stbox { 9 | 10 | typedef enum log_rank { 11 | INFO, 12 | WARNING, 13 | ERROR, 14 | FATAL 15 | 16 | } log_rank_t; 17 | 18 | class Logger { 19 | public: 20 | inline Logger(log_rank_t log_rank) : m_log_rank(log_rank){}; 21 | 22 | ~Logger(); 23 | Logger &start(const std::string &file, uint32_t line, 24 | const std::string &function); 25 | template 26 | auto operator<<(const T &t) -> 27 | typename std::enable_if::value, Logger &>::type { 28 | m_ss = m_ss + std::to_string(t); 29 | return *this; 30 | } 31 | Logger &operator<<(const std::string &t); 32 | Logger &operator<<(const bytes &t); 33 | Logger &operator<<(stx_status t); 34 | Logger &operator<<(sgx_status_t t); 35 | 36 | private: 37 | std::string m_ss; 38 | log_rank_t m_log_rank; 39 | }; 40 | 41 | } // namespace stbox 42 | 43 | #define LOG(log_rank) \ 44 | ::stbox::Logger(stbox::log_rank).start(__FILE__, __LINE__, __FUNCTION__) 45 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/memory/allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace stbox{ 5 | struct default_user_allocator_malloc_free { 6 | typedef std::size_t size_type; 7 | typedef std::ptrdiff_t difference_type; 8 | 9 | inline static void * malloc(size_type bytes){ return std::malloc(bytes); } 10 | inline static void free(char * const block){ std::free(block); } 11 | }; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/memory/memory_pool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace stbox{ 5 | 6 | class memory_pool{ 7 | public: 8 | explicit memory_pool(size_t pagesize); 9 | 10 | static void *malloc(size_t len); 11 | static void free(void *ptr); 12 | 13 | protected: 14 | size_t pagesize; 15 | }; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/memory/pool_allocator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YeeZTech/YeeZ-Privacy-Computing/b7745ae8706958bafafef957c426882e3663681d/include/ypc/stbox/tsgx/memory/pool_allocator.h -------------------------------------------------------------------------------- /include/ypc/stbox/tsgx/util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/stbox/ebyte.h" 3 | #include "ypc/stbox/stx_common.h" 4 | #include "ypc/stbox/stx_status.h" 5 | 6 | namespace stbox { 7 | stbox::bytes get_enclave_signer(); 8 | stbox::bytes get_enclave_hash(); 9 | } 10 | -------------------------------------------------------------------------------- /include/ypc/stbox/usgx/error_message.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace std { 6 | std::string to_string(sgx_status_t ret); 7 | } 8 | -------------------------------------------------------------------------------- /include/ypc/terminus/enclave_interaction.h: -------------------------------------------------------------------------------- 1 | #include "ypc/terminus/interaction.h" 2 | 3 | namespace ypc { 4 | namespace terminus { 5 | class enclave_interaction : public interaction_base { 6 | public: 7 | typedef struct _forward { 8 | inline _forward(const ypc::bytes &_encrypted_skey, const ypc::bytes &_sig) 9 | : encrypted_skey(_encrypted_skey), signature(_sig) {} 10 | 11 | ypc::bytes encrypted_skey; 12 | ypc::bytes signature; 13 | } forward_info; 14 | 15 | enclave_interaction(crypto_pack *crypto); 16 | 17 | bytes generate_allowance(const bytes &private_key, const bytes ¶m_hash, 18 | const bytes &target_enclave_hash, 19 | const bytes &dian_pkey, const bytes &dhash); 20 | 21 | forward_info forward_private_key(const bytes &private_key, 22 | const bytes &dian_pkey, 23 | const bytes &enclave_hash); 24 | }; 25 | } // namespace terminus 26 | } // namespace ypc 27 | -------------------------------------------------------------------------------- /include/ypc/terminus/interaction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/terminus/crypto_pack.h" 3 | 4 | namespace ypc { 5 | namespace terminus { 6 | class interaction_base { 7 | public: 8 | inline interaction_base(crypto_pack *crypto) : m_crypto(crypto) {} 9 | 10 | protected: 11 | crypto_pack *m_crypto; 12 | }; 13 | } // namespace terminus 14 | } // namespace ypc 15 | -------------------------------------------------------------------------------- /include/ypc/terminus/single_data_onchain_result.h: -------------------------------------------------------------------------------- 1 | #include "ypc/terminus/interaction.h" 2 | 3 | namespace ypc { 4 | namespace terminus { 5 | class single_data_onchain_result : public interaction_base { 6 | public: 7 | single_data_onchain_result(crypto_pack *crypto); 8 | 9 | bytes generate_request(const bytes ¶m, const bytes &private_key); 10 | 11 | bytes decrypt_result(const bytes &result, const bytes &private_key); 12 | }; 13 | } // namespace terminus 14 | } // namespace ypc 15 | -------------------------------------------------------------------------------- /include/ypc/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/version.h" 3 | 4 | #define YPC_CORE_T_VERSION ypc::version(0, 5, 2) 5 | #define YPC_RUNTIME_VERSION ypc::version(0, 5, 2) 6 | #define YPC_STBOX_VERSION ypc::version(0, 5, 2) 7 | #define YPC_ECC_T_VERSION ypc::version(0, 5, 2) 8 | #define YPC_KEYMGR_T_VERSION ypc::version(0, 5, 2) 9 | 10 | #define YPC_KEYMGR_RUNTIME_VERSION ypc::version(0, 5, 2) 11 | 12 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PROJECT_SOURCE_DIR}/include) 2 | include_directories(${PROJECT_SOURCE_DIR}/test/) 3 | include_directories(${FF_INCLUDE_DIR}) 4 | link_directories(${FF_LIB_DIR}) 5 | 6 | add_subdirectory(core) 7 | add_subdirectory(crypto) 8 | add_subdirectory(keymgr) 9 | add_subdirectory(toolkit) 10 | -------------------------------------------------------------------------------- /test/core/enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(T_SRCS enclave.cpp 3 | ) 4 | 5 | set(edl_path ${PROJECT_SOURCE_DIR}/include/ypc/edl:${PROJECT_SOURCE_DIR}/include/ypc/stbox/) 6 | 7 | add_enclave_library(test_ypc_enclave 8 | SRCS ${T_SRCS} 9 | EDL enclave.edl 10 | EDL_SEARCH_PATHS "${edl_path}") 11 | 12 | target_link_libraries(test_ypc_enclave PRIVATE stbox_common_t stbox_crypto_t stbox_secp256k1_t stbox_channel_t stdeth_t stdeth_ecc_t) 13 | 14 | enclave_sign(test_ypc_enclave KEY enclave_private.pem 15 | CONFIG enclave.config.xml) 16 | -------------------------------------------------------------------------------- /test/core/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /test/core/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/core/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/core/file_enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_ypc_applet(file_operator 4 | CRYPTO stdeth 5 | SRCS enclave_basic.cpp) 6 | 7 | enclave_sign(file_operator KEY enclave_private.pem 8 | CONFIG enclave.config.xml) 9 | 10 | add_ypc_applet(file_operator_read 11 | CRYPTO stdeth 12 | SRCS enclave_read.cpp) 13 | 14 | enclave_sign(file_operator_read KEY enclave_private.pem 15 | CONFIG enclave.config.xml) 16 | 17 | add_ypc_applet(file_operator_write 18 | CRYPTO stdeth 19 | SRCS enclave_write.cpp) 20 | 21 | enclave_sign(file_operator_write KEY enclave_private.pem 22 | CONFIG enclave.config.xml) 23 | -------------------------------------------------------------------------------- /test/core/file_enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /test/core/file_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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/core/file_enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/core/gtest_base64.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/common/byte/base64.h" 2 | #include 3 | 4 | TEST(test_base64, encode_decode) { 5 | std::vector in( 6 | {"", "f", "fo", "foo", "foob", "fooba", "foobar"}); 7 | std::vector out( 8 | {"", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"}); 9 | for (size_t i = 0; i < in.size(); i++) { 10 | auto ret = base64_encode(in[i]); 11 | EXPECT_EQ(ret, out[i]); 12 | } 13 | for (size_t i = 0; i < out.size(); i++) { 14 | std::string output; 15 | output = base64_decode(out[i]); 16 | EXPECT_EQ(in[i], output); 17 | } 18 | } 19 | 20 | TEST(test_base64, decode_failed) { 21 | std::string output; 22 | output = base64_decode(std::string("invalid", 7)); 23 | // EXPECT_FALSE(ret); 24 | output = base64_decode(std::string("nQB/pZw=", 8)); 25 | // EXPECT_FALSE(ret); 26 | // ret = ypc::decode_base64(std::string("nQB/pZw=\0invalid", 16), output); 27 | // EXPECT_FALSE(ret); 28 | output = base64_decode(std::string("nQB/pZw=invalid", 15)); 29 | // EXPECT_FALSE(ret); 30 | } 31 | -------------------------------------------------------------------------------- /test/core/gtest_command_executor.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/command_executor.h" 2 | #include 3 | 4 | TEST(test_command_executor, without_output) { 5 | std::string cmd = "touch xx && ls | grep xx "; 6 | auto ret = ypc::command_executor::execute_command(cmd); 7 | EXPECT_EQ(ret, 0); 8 | ypc::command_executor::execute_command("rm -rf xx"); 9 | } 10 | 11 | TEST(test_command_executor, with_output) { 12 | std::string output; 13 | std::string cmd = "touch xx && ls | grep xx "; 14 | auto ret = ypc::command_executor::execute_command(cmd, output); 15 | EXPECT_EQ(ret, 0); 16 | EXPECT_EQ(output, "xx\n"); 17 | ypc::command_executor::execute_command("rm -rf xx", output); 18 | } 19 | 20 | TEST(test_command_executor, invalid_cmd) { 21 | std::string output; 22 | std::string cmd = "xxyyzz"; 23 | auto ret = ypc::command_executor::execute_command(cmd, output); 24 | ypc::command_executor::execute_command(cmd); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /test/core/gtest_common.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest_common.h" 2 | 3 | ypc::bytes random_string(size_t len) { 4 | std::string ret(len, '0'); 5 | static std::default_random_engine generator; 6 | static std::uniform_int_distribution distribution(int('a'), int('z')); 7 | static auto rand = std::bind(distribution, generator); 8 | 9 | for (size_t i = 0; i < len; i++) { 10 | ret[i] = rand(); 11 | } 12 | return ypc::bytes(ret.data(), ret.size()); 13 | } 14 | -------------------------------------------------------------------------------- /test/core/gtest_db.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/db.h" 2 | #include 3 | 4 | TEST(test_db, constructor) {} 5 | -------------------------------------------------------------------------------- /test/core/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) { 4 | testing::InitGoogleTest(&argc, argv); 5 | return RUN_ALL_TESTS(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/core/test_ypc_module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/crypto_prefix.h" 3 | #include "ypc/core/byte.h" 4 | #include "ypc/stbox/usgx/sgx_module.h" 5 | #include 6 | 7 | using stx_status = stbox::stx_status; 8 | class test_ypc_sgx_module : public stbox::sgx_module { 9 | public: 10 | test_ypc_sgx_module(const char *mod_path); 11 | 12 | uint32_t get_encrypted_result_and_signature( 13 | const ypc::bytes &encrypted_param, const ypc::bytes &enclave_hash, 14 | const ypc::bytes &result, const ypc::bytes &private_key, 15 | const ypc::bytes &data_hash, uint64_t cost, ypc::bytes &encrypted_res, 16 | ypc::bytes &res_sig, ypc::bytes &cost_sig); 17 | 18 | uint32_t seal_data(const ypc::bytes &data, ypc::bytes &sealed_data); 19 | }; 20 | -------------------------------------------------------------------------------- /test/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${PROJECT_SOURCE_DIR}/ypc/stbox/include/ypc/stbox/) 3 | add_executable(gtest_gmssl 4 | main.cpp 5 | gtest_gmssl.cpp 6 | ) 7 | target_link_libraries(gtest_gmssl gtest core_gmssl stbox_common core) 8 | gtest_discover_tests(gtest_gmssl) 9 | AddCoverage(gtest_gmssl) 10 | 11 | if(SGX_FOUND) 12 | add_subdirectory(enclave) 13 | 14 | set(src main.cpp gtest_crypto.cpp gtest_gmssl.cpp) 15 | set(edl_path ${PROJECT_SOURCE_DIR}/include/ypc/edl/:${PROJECT_SOURCE_DIR}/include/ypc/stbox) 16 | 17 | 18 | add_untrusted_library(test_crypto_lib SHARED 19 | SRCS "test_crypto_module.cpp" 20 | EDL ./enclave/enclave.edl 21 | EDL_SEARCH_PATHS ${edl_path}) 22 | target_link_libraries(test_crypto_lib PUBLIC stbox_common core_gmssl) 23 | 24 | add_executable(test_crypto main.cpp gtest_crypto.cpp gtest_gmssl.cpp) 25 | add_dependencies(test_crypto test_crypto_enclave-sign) 26 | target_link_libraries(test_crypto test_crypto_lib core gtest) 27 | 28 | target_include_directories(test_crypto PRIVATE "${SGX_INCLUDE_DIR}") 29 | target_link_directories(test_crypto PRIVATE "${SGX_LIBRARY_DIR}") 30 | 31 | gtest_discover_tests(test_crypto) 32 | AddCoverage(test_crypto) 33 | endif() 34 | -------------------------------------------------------------------------------- /test/crypto/enclave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(T_SRCS enclave.cpp 3 | ) 4 | 5 | set(edl_path ${PROJECT_SOURCE_DIR}/include/ypc/edl:${PROJECT_SOURCE_DIR}/include/ypc/stbox) 6 | 7 | add_enclave_library(test_crypto_enclave 8 | SRCS ${T_SRCS} 9 | EDL enclave.edl 10 | EDL_SEARCH_PATHS "${edl_path}") 11 | 12 | target_link_libraries(test_crypto_enclave PRIVATE stdeth_t stdeth_ecc_t stbox_crypto_t ) 13 | 14 | enclave_sign(test_crypto_enclave KEY enclave_private.pem 15 | CONFIG enclave.config.xml) 16 | -------------------------------------------------------------------------------- /test/crypto/enclave/enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x40000 5 | 0x400000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /test/crypto/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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/crypto/enclave/enclave_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /test/crypto/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) { 4 | testing::InitGoogleTest(&argc, argv); 5 | return RUN_ALL_TESTS(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/crypto/test_crypto_module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/common/crypto_prefix.h" 3 | #include "ypc/core/byte.h" 4 | #include "ypc/stbox/usgx/sgx_module.h" 5 | #include 6 | 7 | using stx_status = stbox::stx_status; 8 | class test_crypto_sgx_module : public stbox::sgx_module { 9 | public: 10 | test_crypto_sgx_module(const char *mod_path); 11 | 12 | ypc::bytes test_generate_pkey(const ypc::bytes &skey); 13 | ypc::bytes aes_cmac_msg(const ypc::bytes &p_key, const ypc::bytes &msg); 14 | ypc::bytes test_aes_gcm_encrypt(const ypc::bytes &key, const ypc::bytes &data, 15 | ypc::bytes &cipher, const ypc::bytes &iv, 16 | const ypc::bytes &aad); 17 | ypc::bytes ecdh(const ypc::bytes &pkey, const ypc::bytes &skey); 18 | ypc::bytes encrypt(const ypc::bytes &pkey, const ypc::bytes &data, 19 | uint32_t prefix); 20 | 21 | ypc::bytes decrypt(const ypc::bytes &skey, const ypc::bytes &cipher, 22 | uint32_t prefix); 23 | ypc::bytes sign_message(const ypc::bytes &skey, const ypc::bytes &data); 24 | bool verify_message(const ypc::bytes &data, const ypc::bytes &sig, 25 | const ypc::bytes &pkey); 26 | }; 27 | -------------------------------------------------------------------------------- /test/integrate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/project.py.in" "${CMAKE_CURRENT_SOURCE_DIR}/project.py") 2 | 3 | find_program(LCOV_PATH lcov) 4 | 5 | function(AddPyTest target cmd) 6 | if(LCOV_PATH) 7 | add_custom_target(${target} 8 | COMMAND python3 ./test/integrate/${cmd} 9 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") 10 | add_dependencies(post_coverage ${target}) 11 | endif() 12 | add_test(NAME ${target} 13 | COMMAND python3 ./test/integrate/${cmd} 14 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") 15 | endfunction() 16 | 17 | AddPyTest(test_iris test_iris.py) 18 | AddPyTest(test_multi test_findperson_multi.py) 19 | 20 | -------------------------------------------------------------------------------- /test/integrate/js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ypc-js-sdk", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "node-aes-cmac": "", 6 | "secp256k1": "", 7 | "js-sha256": "", 8 | "keccak256": "", 9 | "bytebuffer": "", 10 | "n-readlines": "", 11 | "commander": "", 12 | "yargs": "" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/integrate/project.py.in: -------------------------------------------------------------------------------- 1 | 2 | def debug_postfix(): 3 | return '@CMAKE_DEBUG_POSTFIX@' 4 | -------------------------------------------------------------------------------- /test/integrate/test_findperson.py: -------------------------------------------------------------------------------- 1 | from classic_job import classic_job 2 | import os 3 | import common 4 | import sys 5 | 6 | 7 | def gen_personlist(**kwargs): 8 | cmd = os.path.join(common.bin_dir, "./personlist_gen") 9 | output = common.execute_cmd(cmd) 10 | return [cmd, output] 11 | 12 | 13 | if __name__ == "__main__": 14 | name = "findperson" 15 | gen_personlist() 16 | 17 | crypto = "stdeth" 18 | data = "person_list" 19 | parser = os.path.join(common.lib_dir, "person_first_match.signed.so") 20 | plugin = os.path.join( 21 | common.lib_dir, "libperson_reader{}.so".format(common.debug_postfix())) 22 | # input_param = "421003198607270527" 23 | input_param = "\"[{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"421003198607262936\\\"}]\"" 24 | cj = classic_job(crypto, name, data, parser, plugin, input_param, { 25 | 'request-use-js': True, 26 | 'remove-files': True if len(sys.argv) < 2 else False, 27 | }) 28 | cj.run() 29 | 30 | print("result is : ", cj.result) 31 | -------------------------------------------------------------------------------- /test/integrate/test_findperson_multi.py: -------------------------------------------------------------------------------- 1 | from multistream_job import multistream_job 2 | import os 3 | import common 4 | 5 | 6 | def gen_personlist(**kwargs): 7 | cmd = os.path.join(common.bin_dir, "./personlist_gen_multi") 8 | output = common.execute_cmd(cmd) 9 | return [cmd, output] 10 | 11 | 12 | if __name__ == "__main__": 13 | name = "findperson" 14 | gen_personlist() 15 | 16 | crypto = "stdeth" 17 | data = ["person_list1", "person_list2"] 18 | parser = os.path.join(common.lib_dir, "person_first_match_multi.signed.so") 19 | plugin = os.path.join( 20 | common.lib_dir, "libperson_reader{}.so".format(common.debug_postfix())) 21 | 22 | input_param = "" 23 | use_js = True 24 | if use_js: 25 | input_param = "\"[{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"421003198707262936\\\"}]\"" 26 | else: 27 | input_param = "421003198607270527" 28 | 29 | cj = multistream_job(crypto, name, data, parser, plugin, input_param, { 30 | 'request-use-js': use_js, 31 | }) 32 | 33 | cj.run() 34 | 35 | print("result is : ", cj.result) 36 | -------------------------------------------------------------------------------- /test/integrate/test_findperson_multi_offchain.py: -------------------------------------------------------------------------------- 1 | from multistream_job_offchain import multistream_job_offchain 2 | import os 3 | import common 4 | 5 | 6 | def gen_personlist(**kwargs): 7 | cmd = os.path.join(common.bin_dir, "./personlist_gen_multi") 8 | output = common.execute_cmd(cmd) 9 | return [cmd, output] 10 | 11 | 12 | if __name__ == "__main__": 13 | name = "findperson" 14 | gen_personlist() 15 | 16 | crypto = "stdeth" 17 | data = ["person_list1", "person_list2"] 18 | parser = os.path.join(common.lib_dir, "person_first_match_multi_offchain.signed.so") 19 | plugin = os.path.join( 20 | common.lib_dir, "libperson_reader{}.so".format(common.debug_postfix())) 21 | 22 | input_param = "" 23 | use_js = True 24 | if use_js: 25 | input_param = "\"[{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"421003198707262936\\\"}]\"" 26 | else: 27 | input_param = "421003198607270527" 28 | cj = multistream_job_offchain(crypto, name, data, parser, plugin, input_param, { 29 | 'request-use-js': use_js, 30 | }) 31 | 32 | cj.run() 33 | 34 | print("result is : ", cj.result) 35 | -------------------------------------------------------------------------------- /test/integrate/test_iris.py: -------------------------------------------------------------------------------- 1 | from data_host import classic_job 2 | import os 3 | import common 4 | # test jenkins 5 | if __name__ == "__main__": 6 | # should also set template param (Crypto) of iris_parser 7 | # and update iris_parser.signed.so by compiling the source code 8 | crypto = "stdeth" 9 | 10 | name = "iris" 11 | data = os.path.join(common.bin_dir, "iris.data") 12 | parser = os.path.join(common.lib_dir, "iris_parser.signed.so") 13 | plugin = os.path.join( 14 | common.lib_dir, "libiris_reader{}.so".format(common.debug_postfix())) 15 | input_param = "\"[{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"12\\\"}]\"" 16 | cj = classic_job(crypto, name, data, parser, plugin, input_param) 17 | cj.run() 18 | 19 | print("result is : ", cj.result) 20 | -------------------------------------------------------------------------------- /test/integrate/test_iris_classifier.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YeeZTech/YeeZ-Privacy-Computing/b7745ae8706958bafafef957c426882e3663681d/test/integrate/test_iris_classifier.py -------------------------------------------------------------------------------- /test/keymgr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(gtest_keymgr 3 | main.cpp) 4 | target_link_libraries(gtest_keymgr gtest pthread) 5 | gtest_discover_tests(gtest_keymgr) 6 | AddCoverage(gtest_keymgr) 7 | -------------------------------------------------------------------------------- /test/keymgr/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) { 4 | testing::InitGoogleTest(&argc, argv); 5 | return RUN_ALL_TESTS(); 6 | } 7 | -------------------------------------------------------------------------------- /test/toolkit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(plugins) 2 | -------------------------------------------------------------------------------- /test/toolkit/plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #add_subdirectory(csv) 2 | add_subdirectory(mysql) 3 | -------------------------------------------------------------------------------- /test/toolkit/plugins/csv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_csv main.cpp) 2 | target_link_libraries(test_csv pthread ff_net) 3 | gtest_discover_tests(test_csv) 4 | -------------------------------------------------------------------------------- /test/toolkit/plugins/csv/main.cpp: -------------------------------------------------------------------------------- 1 | #include "toolkit/plugins/csv/csv_reader.h" 2 | #include "ypc/core_t/analyzer/ntpackage_item_parser.h" 3 | #include 4 | 5 | define_nt(v1, int); 6 | define_nt(s1, std::string); 7 | define_nt(v2, double); 8 | typedef ::ff::util::ntobject mt; 9 | 10 | 11 | int main(int argc, char *argv[]) { 12 | // clang-format off 13 | std::string json("{\"file_path\":\"../test/toolkit/plugins/csv/test1.csv\"}"); 14 | // clang-format on 15 | std::cout << json << std::endl; 16 | ypc::plugins::typed_csv_reader r(json); 17 | 18 | std::cout << r.get_item_number() << std::endl; 19 | int len; 20 | r.read_item_data(nullptr, &len); 21 | char *buf = new char[len]; 22 | r.read_item_data(buf, &len); 23 | mt p = ypc::ntpackage_item_parser::parser(buf, len); 24 | std::cout << p.get() << ", " << p.get() << ", " << p.get() 25 | << std::endl; 26 | 27 | delete[] buf; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/toolkit/plugins/csv/test1.csv: -------------------------------------------------------------------------------- 1 | 100, case, 212.4 2 | 100, case, 212.4 3 | 100, case, 212.4 4 | -------------------------------------------------------------------------------- /test/toolkit/plugins/mysql/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_mysql main.cpp) 2 | target_link_libraries(test_mysql pthread ff_net mysqlcppconn) 3 | 4 | #TODO we need fix this 5 | #gtest_discover_tests(test_mysql) 6 | -------------------------------------------------------------------------------- /toolkit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(SGX_FOUND) 3 | add_subdirectory(analyzer) 4 | add_subdirectory(ydump) 5 | add_subdirectory(verifier) 6 | endif() 7 | add_subdirectory(datahub) 8 | add_subdirectory(terminus) 9 | 10 | -------------------------------------------------------------------------------- /toolkit/analyzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #include_directories(${PROJECT_SOURCE_DIR}/toolkit/analyzer/) 2 | add_executable(fid_analyzer main.cpp 3 | sgx_bridge.cpp 4 | parsers/parser.cpp 5 | ) 6 | 7 | target_link_libraries(fid_analyzer 8 | stbox_common 9 | core 10 | core_parser_module 11 | keymgr_module 12 | keymgr_utils 13 | glog 14 | ) 15 | target_include_directories(fid_analyzer PRIVATE 16 | "${PROJECT_SOURCE_DIR}/toolkit/analyzer/" 17 | "$" 18 | ) 19 | 20 | install(TARGETS fid_analyzer 21 | DESTINATION "${bin_install_dir}") 22 | AddClangTidy(fid_analyzer) 23 | EnableCoverage(fid_analyzer) 24 | -------------------------------------------------------------------------------- /toolkit/analyzer/db/db.cpp: -------------------------------------------------------------------------------- 1 | #include "db.h" 2 | 3 | namespace toolkit { 4 | namespace analyzer { 5 | 6 | request_db::request_db(const std::string &url, const std::string &usrname, 7 | const std::string &passwd, const std::string &dbname) 8 | : db_base(url, usrname, passwd, dbname) {} 9 | 10 | void request_db::create_tables() { 11 | request_data_table::create_table(m_db_engine.get()); 12 | } 13 | void request_db::clear_tables() { 14 | request_data_table::drop_table(m_db_engine.get()); 15 | } 16 | } // namespace analyzer 17 | } // namespace toolkit 18 | -------------------------------------------------------------------------------- /toolkit/analyzer/iodef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ypc/core/byte.h" 3 | #include "ypc/core/ntjson.h" 4 | #include "ypc/corecommon/nt_cols.h" 5 | #include "ypc/corecommon/package.h" 6 | 7 | using ntt = ypc::nt; 8 | 9 | define_nt(input_data_url, std::string); 10 | define_nt(input_data_hash, ypc::bytes); 11 | define_nt(enclave_hash, ypc::bytes); 12 | 13 | define_nt(shu_pkey, ypc::bytes); 14 | typedef ::ff::util::ntobject 16 | shu_info_t; 17 | 18 | define_nt(shu_info, shu_info_t); 19 | typedef ::ff::util::ntobject 21 | data_item_t; 22 | define_nt(input_data, std::vector); 23 | define_nt(parser_path, std::string); 24 | define_nt(parser_enclave_hash, ypc::bytes); 25 | define_nt(keymgr_path, std::string); 26 | define_nt(dian_pkey, ypc::bytes); 27 | 28 | typedef ::ff::util::ntobject 31 | input_param_t; 32 | -------------------------------------------------------------------------------- /toolkit/analyzer/sgx_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "parsers/parser.h" 4 | #include 5 | 6 | extern std::shared_ptr g_parser; 7 | -------------------------------------------------------------------------------- /toolkit/datahub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(data_provider main.cpp ) 2 | target_link_libraries(data_provider stbox_common core core_stdeth core_gmssl) 3 | install(TARGETS data_provider 4 | DESTINATION "${bin_install_dir}") 5 | AddClangTidy(data_provider) 6 | EnableCoverage(data_provider) 7 | 8 | add_executable(unseal_file unseal.cpp ) 9 | target_link_libraries(unseal_file stbox_common core core_stdeth core_gmssl) 10 | install(TARGETS unseal_file 11 | DESTINATION "${bin_install_dir}") 12 | AddClangTidy(unseal_file) 13 | EnableCoverage(unseal_file) 14 | -------------------------------------------------------------------------------- /toolkit/terminus/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(lib) 2 | add_subdirectory(cmd) 3 | add_subdirectory(python) 4 | -------------------------------------------------------------------------------- /toolkit/terminus/cmd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cterminus) 2 | -------------------------------------------------------------------------------- /toolkit/terminus/cmd/cterminus/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(yterminus main.cpp 2 | allowance.cpp 3 | cmd_line.cpp 4 | crypto.cpp 5 | forward.cpp 6 | gen_key.cpp 7 | helper.cpp 8 | relay.cpp 9 | request.cpp 10 | sign.cpp) 11 | target_link_libraries(yterminus terminus glog boost_program_options boost_system core) 12 | 13 | target_include_directories(yterminus PUBLIC 14 | "$" 15 | "$" 16 | ) 17 | install(TARGETS yterminus 18 | DESTINATION "${bin_install_dir}") 19 | AddClangTidy(yterminus) 20 | EnableCoverage(yterminus) 21 | -------------------------------------------------------------------------------- /toolkit/terminus/cmd/cterminus/main.cpp: -------------------------------------------------------------------------------- 1 | #include "cmd_line.h" 2 | 3 | int main(int argc, char *argv[]) { 4 | auto tp = parse_command_line(argc, argv); 5 | 6 | boost::program_options::variables_map vm = std::get<0>(tp); 7 | std::string crypto_type = "stdeth"; 8 | if (vm.count("crypto") != 0u) { 9 | crypto_type = vm["crypto"].as(); 10 | } 11 | 12 | std::unique_ptr crypto; 13 | if (crypto_type == "stdeth") { 14 | crypto = ypc::terminus::intel_sgx_and_eth_compatible(); 15 | } else if (crypto_type == "gmssl") { 16 | crypto = ypc::terminus::sm_compatible(); 17 | } else { 18 | std::cerr << "invalid crypto type!" << std::endl; 19 | return -1; 20 | } 21 | 22 | return std::get<1>(tp)(crypto.get()); 23 | } 24 | -------------------------------------------------------------------------------- /toolkit/terminus/cmd/cterminus/request.cpp: -------------------------------------------------------------------------------- 1 | #include "cmd_line.h" 2 | 3 | int generate_request(ypc::terminus::crypto_pack *crypto, 4 | const boost::program_options::variables_map &vm) { 5 | ypc::bytes pubkey = get_param_publickey(vm); 6 | 7 | std::unordered_map result; 8 | 9 | ypc::bytes param = get_param_use_param(vm); 10 | 11 | ypc::terminus::single_data_onchain_result std_interaction(crypto); 12 | 13 | result["analyzer-pkey"] = pubkey; 14 | 15 | auto request = std_interaction.generate_request(param, pubkey); 16 | if (request.empty()) { 17 | std::cerr << "failed to encrypt param" << std::endl; 18 | return -1; 19 | } 20 | 21 | result["encrypted-input"] = request; 22 | 23 | if (vm.count("output") != 0u) { 24 | std::string output_path = 25 | ypc::complete_path(vm["output"].as()); 26 | 27 | boost::property_tree::ptree pt; 28 | for (auto & it : result) { 29 | pt.put(it.first, it.second); 30 | } 31 | boost::property_tree::json_parser::write_json(output_path, pt); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | if(SGX_MODE STREQUAL "Debug") 3 | add_subdirectory(test) 4 | endif() 5 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(src 2 | crypto_pack.cpp 3 | single_data_onchain_result.cpp 4 | enclave_interaction.cpp 5 | ) 6 | 7 | add_library(terminus SHARED ${src}) 8 | 9 | target_link_libraries(terminus core_stdeth core_gmssl glog) 10 | 11 | target_include_directories(terminus PUBLIC 12 | "$" 13 | "$" 14 | "$" 15 | ) 16 | 17 | install(TARGETS terminus EXPORT mod_terminus 18 | DESTINATION "${lib_install_dir}" 19 | COMPONENT terminus) 20 | install(EXPORT mod_terminus 21 | DESTINATION "${config_install_dir}/toolkit" 22 | NAMESPACE "${namespace}" 23 | COMPONENT terminus 24 | ) 25 | 26 | AddClangTidy(terminus) 27 | EnableCoverage(terminus) 28 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/src/crypto_pack.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/terminus/crypto_pack.h" 2 | #include "ypc/corecommon/crypto/crypto_pack.h" 3 | #include "ypc/corecommon/crypto/gmssl.h" 4 | #include "ypc/corecommon/crypto/stdeth.h" 5 | 6 | namespace ypc { 7 | namespace terminus { 8 | 9 | std::unique_ptr intel_sgx_and_eth_compatible() { 10 | return std::unique_ptr( 11 | new crypto_pack_t<::ypc::crypto::eth_sgx_crypto>()); 12 | } 13 | 14 | std::unique_ptr sm_compatible() { 15 | return std::unique_ptr( 16 | new crypto_pack_t<::ypc::crypto::gmssl_sgx_crypto>()); 17 | } 18 | 19 | } // namespace terminus 20 | } // namespace ypc 21 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/src/single_data_onchain_result.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/terminus/single_data_onchain_result.h" 2 | #include "ypc/common/crypto_prefix.h" 3 | 4 | namespace ypc { 5 | namespace terminus { 6 | single_data_onchain_result::single_data_onchain_result(crypto_pack *crypto) 7 | : interaction_base(crypto) {} 8 | 9 | bytes single_data_onchain_result::generate_request(const bytes ¶m, 10 | const bytes &pubkey) { 11 | 12 | ypc::bytes encrypted_param = 13 | m_crypto->ecc_encrypt(param, pubkey, ypc::utc::crypto_prefix_arbitrary); 14 | 15 | if (encrypted_param.empty()) { 16 | LOG(ERROR) << "encrypt param failed"; 17 | return ypc::bytes(); 18 | } 19 | return encrypted_param; 20 | } 21 | 22 | ypc::bytes 23 | single_data_onchain_result::decrypt_result(const bytes &result, 24 | const bytes &private_key) { 25 | return m_crypto->ecc_decrypt(result, private_key, 26 | ypc::utc::crypto_prefix_arbitrary); 27 | } 28 | } // namespace terminus 29 | } // namespace ypc 30 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(gtest_terminus 2 | main.cpp 3 | gtest_intel_sgx.cpp 4 | ) 5 | find_package (Threads REQUIRED) 6 | 7 | target_include_directories(gtest_terminus PUBLIC 8 | "$" 9 | "$" 10 | "$" 11 | ) 12 | target_link_libraries(gtest_terminus gtest terminus 13 | ${CMAKE_THREAD_LIBS_INIT} 14 | boost_system 15 | ) 16 | 17 | gtest_discover_tests(gtest_terminus) 18 | AddCoverage(gtest_terminus) 19 | -------------------------------------------------------------------------------- /toolkit/terminus/lib/test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) { 4 | testing::InitGoogleTest(&argc, argv); 5 | return RUN_ALL_TESTS(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /toolkit/terminus/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | pybind11_add_module(pyterminus module.cpp) 3 | target_link_libraries(pyterminus PRIVATE boost_system terminus glog core) 4 | install(TARGETS pyterminus 5 | DESTINATION "${lib_install_dir}" 6 | COMPONENT c_yterminus OPTIONAL) 7 | -------------------------------------------------------------------------------- /toolkit/verifier/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES dian_pubkey_verifier 2 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE 3 | DESTINATION "${bin_install_dir}") 4 | -------------------------------------------------------------------------------- /toolkit/verifier/dian_pubkey_verifier: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ $# -ne 3 ]; then 3 | echo "Invalid number of parameters!" 4 | echo "Usage: dian_pubkey_verifier \$DIAN_PKEY \$YPC_INSTALL_DIR \$DCAP_SERVICE_URL" 5 | echo "The default value of \$YPC_INSTALL_DIR is: /usr/local" 6 | exit 7 | fi 8 | 9 | dian_pkey=$1 10 | ypc_install_dir=$2 11 | dcap_url=$3 12 | 13 | # 1. generate quote 14 | dianshu_key_verify=${ypc_install_dir}/bin/dianshu_key_verify 15 | if [ ! -f "$dianshu_key_verify" ]; then 16 | echo "Invalid directory of \"$YPC_INSTALL_DIR\"!" 17 | echo "${dianshu_key_verify}: no such file!" 18 | exit 19 | fi 20 | export LD_LIBRARY_PATH=$ypc_install_dir/lib:$LD_LIBRARY_PATH 21 | echo "" 22 | echo "Generate quote..." 23 | $dianshu_key_verify --pkey $dian_pkey --output quote.output 24 | 25 | # 2. verify quote 26 | echo "" 27 | echo "Verify quote..." 28 | curl -s -X POST -H "Content-Type:multipart/form-data" -F "quote=@quote.output" $dcap_url 29 | -------------------------------------------------------------------------------- /toolkit/ydump/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ydump 2 | main.cpp 3 | nouse_bridge.cpp) 4 | target_link_libraries(ydump core stbox_common keymgr_utils keymgr_module core_parser_module ) 5 | install(TARGETS ydump 6 | DESTINATION "${bin_install_dir}") 7 | 8 | AddClangTidy(ydump) 9 | -------------------------------------------------------------------------------- /ypc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(common) 2 | add_subdirectory(core) 3 | add_subdirectory(keymgr) 4 | add_subdirectory(stbox) 5 | -------------------------------------------------------------------------------- /ypc/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(src byte/base58.cpp byte/base64.cpp version.cpp) 2 | 3 | if(SGX_FOUND) 4 | add_sgx_library(common_t 5 | common_t 6 | SRCS ${src}) 7 | 8 | target_include_directories(common_t PUBLIC 9 | "$" 10 | "$") 11 | 12 | install(TARGETS common_t EXPORT mod_common_t 13 | DESTINATION "${lib_install_dir}" 14 | COMPONENT common_t) 15 | 16 | install(EXPORT mod_common_t 17 | DESTINATION "${config_install_dir}/common" 18 | NAMESPACE "${namespace}" 19 | COMPONENT common_t) 20 | endif() 21 | 22 | add_library(common SHARED ${src}) 23 | 24 | target_include_directories(common PUBLIC 25 | "$" 26 | "$" 27 | ) 28 | 29 | install(TARGETS common EXPORT mod_common 30 | DESTINATION "${lib_install_dir}" 31 | COMPONENT common) 32 | 33 | install(EXPORT mod_common 34 | DESTINATION "${config_install_dir}/common" 35 | NAMESPACE "${namespace}" 36 | COMPONENT common) 37 | 38 | add_version(common) 39 | 40 | -------------------------------------------------------------------------------- /ypc/common/README.md: -------------------------------------------------------------------------------- 1 | This directory contains only header file, and all are compatiable to both 2 | SGX trusted and untrusted environment. 3 | Thus, we use namespace ypc::utc, for Untrusted-Trust-Compatiable 4 | code. 5 | -------------------------------------------------------------------------------- /ypc/common/version.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/common/version.h" 2 | #ifndef YPC_SGX 3 | #include 4 | #endif 5 | #include 6 | 7 | #ifndef YPC_SGX 8 | std::ostream &operator<<(std::ostream &stream, const ypc::version &v) { 9 | stream << v.major_version() << '.' << v.minor_version() << '.' 10 | << v.patch_version(); 11 | return stream; 12 | } 13 | 14 | std::istream &operator>>(std::istream &stream, ypc::version &v) { 15 | uint32_t major; 16 | uint16_t minor; 17 | uint16_t patch; 18 | char c; 19 | stream >> major >> c; 20 | if (c != '.') { 21 | throw std::runtime_error("invalid sep in version, expect '.'"); 22 | } 23 | stream >> minor >> c; 24 | if (c != '.') { 25 | throw std::runtime_error("invalid sep in version, expect '.'"); 26 | } 27 | stream >> patch; 28 | v = ypc::version(major, minor, patch); 29 | return stream; 30 | } 31 | 32 | #endif 33 | 34 | namespace std { 35 | std::string to_string(const ypc::version &v) { 36 | return std::to_string(v.major_version()) + "." + 37 | std::to_string(v.minor_version()) + "." + 38 | std::to_string(v.patch_version()); 39 | } 40 | } // namespace std 41 | 42 | -------------------------------------------------------------------------------- /ypc/core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /ypc/core/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(core) 2 | if(SGX_FOUND) 3 | add_subdirectory(core_t) 4 | endif() 5 | -------------------------------------------------------------------------------- /ypc/core/src/core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(SGX_FOUND) 2 | add_subdirectory(sgx) 3 | endif() 4 | 5 | add_subdirectory(crypto) 6 | find_package (Threads REQUIRED) 7 | 8 | add_library(core SHARED 9 | poption_require.cpp 10 | db.cpp 11 | configuration.cpp 12 | sealed_file.cpp 13 | command_executor.cpp 14 | filesystem.cpp 15 | privacy_data_reader.cpp 16 | status.cpp 17 | version.cpp 18 | ${FF_PATH}/src/net/common/archive.cpp) 19 | 20 | target_include_directories(core PUBLIC 21 | "$" 22 | "$" 23 | "$") 24 | 25 | target_link_libraries(core PUBLIC 26 | mysqlcppconn 27 | boost_program_options 28 | boost_filesystem 29 | glog 30 | boost_system 31 | ${CMAKE_THREAD_LIBS_INIT} 32 | common 33 | ) 34 | #target_link_libraries(core INTERFACE stbox_common) 35 | #target_link_libraries(core INTERFACE core_parser_module) 36 | 37 | install(TARGETS core EXPORT mod_core 38 | DESTINATION "${lib_install_dir}" 39 | COMPONENT core) 40 | 41 | install(EXPORT mod_core 42 | DESTINATION "${config_install_dir}/core" 43 | NAMESPACE "${namespace}" 44 | COMPONENT core 45 | ) 46 | AddClangTidy(core) 47 | EnableCoverage(core) 48 | add_version(core) 49 | 50 | -------------------------------------------------------------------------------- /ypc/core/src/core/command_executor.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/command_executor.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ypc { 7 | 8 | namespace internal { 9 | int command_executor_helper::execute_command(const std::string &command, 10 | std::string &output) { 11 | FILE *stream; 12 | const int max_buffer = 256; 13 | char buffer[max_buffer]; 14 | std::string cmd = command; 15 | cmd.append(" 2>&1"); 16 | 17 | stream = popen(cmd.c_str(), "r"); 18 | if (stream != nullptr) { 19 | while (!feof(stream)) { // NOLINT 20 | if (fgets(buffer, max_buffer, stream) != NULL) { 21 | output.append(buffer); 22 | } 23 | } 24 | pclose(stream); 25 | } 26 | return 0; 27 | } 28 | } // namespace internal 29 | 30 | int command_executor::execute_command(const std::string &cmd) { 31 | std::string output; 32 | return execute_command(cmd, output); 33 | } 34 | 35 | int command_executor::execute_command(const std::string &cmd, 36 | std::string &output) { 37 | return internal::command_executor_helper::execute_command(cmd, output); 38 | } 39 | } // namespace ypc 40 | -------------------------------------------------------------------------------- /ypc/core/src/core/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(stdeth) 2 | add_subdirectory(gmssl) 3 | -------------------------------------------------------------------------------- /ypc/core/src/core/crypto/gmssl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(OpenSSL REQUIRED) 2 | #include_directories(${OPENSSL_INCLUDE_DIR}) 3 | #link_directories(${OPENSSL_LIB}) 4 | 5 | set(gmssl_src sm2_ecc.cpp ../../../corecommon/crypto/sm3_hash.cpp sm4_aes.cpp) 6 | 7 | add_library(core_gmssl SHARED ${gmssl_src}) 8 | target_include_directories(core_gmssl PUBLIC 9 | "${OPENSSL_INCLUDE_DIR}" 10 | "$" 11 | "$" 12 | "$") 13 | 14 | target_link_directories(core_gmssl PUBLIC ${OPENSSL_LIB}) 15 | 16 | target_link_libraries(core_gmssl PUBLIC ${OPENSSL_CRYPTO_LIBRARY} stbox_gmssl) 17 | 18 | install(TARGETS core_gmssl EXPORT mod_core_gmssl 19 | DESTINATION "${lib_install_dir}" 20 | COMPONENT gmssl) 21 | 22 | install(EXPORT mod_core_gmssl 23 | DESTINATION "${config_install_dir}/core" 24 | NAMESPACE "${namespace}" 25 | COMPONENT gmssl 26 | ) 27 | 28 | AddClangTidy(core_gmssl) 29 | EnableCoverage(core_gmssl) 30 | add_version(core_gmssl) 31 | -------------------------------------------------------------------------------- /ypc/core/src/core/crypto/stdeth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(OpenSSL REQUIRED) 2 | 3 | set(stdeth_src ../../../corecommon/crypto/eth_hash.cpp rijndael128GCM.cpp secp256k1.cpp secp256k1_ecdh_sgx128.cpp openssl.cpp) 4 | 5 | add_library(core_stdeth SHARED ${stdeth_src}) 6 | #target_link_libraries(ypc_stdeth_u ${OPENSSL_CRYPTO_LIBRARY} stbox_keccak_u secp256k1) 7 | #install(TARGETS ypc_stdeth_u DESTINATION lib COMPONENT c_ypc_core OPTIONAL) 8 | 9 | target_include_directories(core_stdeth PUBLIC 10 | "${OPENSSL_INCLUDE_DIR}" 11 | "$" 12 | "$" 13 | "$") 14 | 15 | 16 | target_link_libraries(core_stdeth PUBLIC ${OPENSSL_CRYPTO_LIBRARY} stbox_keccak stbox_secp256k1) 17 | 18 | install(TARGETS core_stdeth EXPORT mod_core_stdeth 19 | DESTINATION "${lib_install_dir}" 20 | COMPONENT stdeth) 21 | 22 | install(EXPORT mod_core_stdeth 23 | DESTINATION "${config_install_dir}/core" 24 | NAMESPACE "${namespace}" 25 | COMPONENT stdeth 26 | ) 27 | 28 | AddClangTidy(core_stdeth) 29 | EnableCoverage(core_stdeth) 30 | add_version(core_stdeth) 31 | -------------------------------------------------------------------------------- /ypc/core/src/core/crypto/stdeth/secp256k1.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/corecommon/crypto/stdeth/secp256k1.h" 2 | #include "ypc/corecommon/crypto/stdeth/secp256k1.ipp" 3 | #include 4 | 5 | namespace ypc { 6 | namespace crypto { 7 | uint32_t secp256k1::gen_private_key(uint32_t skey_size, uint8_t *skey) { 8 | secp256k1_context *ctx = init_secp256k1_context(); 9 | 10 | if (ctx == nullptr) { 11 | LOG(ERROR) << "Context or Secret key or Public key is null"; 12 | return stbox::stx_status::ecc_invalid_ctx_or_skey; 13 | } 14 | int counter = 0; 15 | do { 16 | auto rc = RAND_bytes(skey, skey_size); 17 | if (rc != 1) { 18 | throw std::runtime_error("RAND_bytes key failed"); 19 | } 20 | counter++; 21 | if (counter > 0xFFFF) { 22 | throw std::runtime_error( 23 | "secp256k1::gen_private_key too many times, you may retry"); 24 | } 25 | } while (secp256k1_ec_seckey_verify(ctx, skey) == 0); 26 | return stbox::stx_status::success; 27 | } 28 | } // namespace crypto 29 | } // namespace ypc 30 | -------------------------------------------------------------------------------- /ypc/core/src/core/db.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/db.h" 2 | 3 | namespace ypc { 4 | 5 | db_base::db_base(const std::string &url, const std::string &usrname, 6 | const std::string &passwd, const std::string &dbname) { 7 | init_db(url, usrname, passwd, dbname); 8 | } 9 | 10 | void db_base::init_db(const std::string &url, const std::string &usrname, 11 | const std::string &passwd, const std::string &dbname) { 12 | m_db_engine = std::make_shared<::ff::sql::mysql<::ff::sql::cppconn>>( 13 | url, usrname, passwd, dbname); 14 | } 15 | 16 | ::ff::sql::mysql<::ff::sql::cppconn> *db_base::db_engine_ptr() { // NOLINT 17 | return m_db_engine.get(); 18 | } 19 | } // namespace ypc 20 | -------------------------------------------------------------------------------- /ypc/core/src/core/poption_require.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/poption_require.h" 2 | namespace ypc { 3 | namespace internal { 4 | bool opt::check(const boost::program_options::variables_map &vm, // NOLINT 5 | bool exit_if_fail) const { 6 | if (exit_if_fail && !vm.count(m_value)) { // NOLINT 7 | std::cerr << "missing '" << m_value << "'" << std::endl; 8 | exit(-1); 9 | } 10 | return vm.count(m_value); // NOLINT 11 | } 12 | 13 | } // namespace internal 14 | } // namespace ypc 15 | -------------------------------------------------------------------------------- /ypc/core/src/core/sgx/util/util.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/sgx/util/util.h" 2 | #include "ypc/core/sgx/util/cxxfile_bridge.h" 3 | #include "ypc/core/sgx/util/kv_bridge.h" 4 | #include 5 | 6 | namespace ypc { 7 | std::string g_sgx_file_directory("/tmp/"); 8 | 9 | void set_sgx_file_dir(const char *directory) { 10 | g_sgx_file_directory = std::string(directory); 11 | } 12 | 13 | const char *get_sgx_file_dir(const char *directory) { 14 | return g_sgx_file_directory.c_str(); 15 | } 16 | 17 | void init_sgx_env() { 18 | init_sgx_cxxfile(); 19 | init_sgx_kv(); 20 | } 21 | void shutdown_sgx_env() { 22 | shutdown_sgx_cxxfile(); 23 | shutdown_sgx_kv(); 24 | } 25 | } // namespace ypc 26 | -------------------------------------------------------------------------------- /ypc/core/src/core/status.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/status.h" 2 | #include "ypc/stbox/stx_status.h" 3 | 4 | namespace ypc { 5 | const char *status_string(uint32_t status) { 6 | if (0U == status) { 7 | return "success"; 8 | } 9 | if (0U == (status & 0x20000)) { 10 | #define YPC_STATUS(a, b) \ 11 | case 0x20000 | b: \ 12 | return #a; 13 | 14 | switch (status) { 15 | #include "ypc/core/status.def" 16 | default: 17 | return "unknown ypc status"; 18 | } 19 | 20 | #undef YPC_STATUS 21 | } else { 22 | // defined in stbox status 23 | return "unknown ypc status"; 24 | // return ::stbox::status_string(status); 25 | } 26 | } 27 | } // namespace ypc 28 | -------------------------------------------------------------------------------- /ypc/core/src/core/version.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core/version.h" 2 | #include "ypc/version.h" 3 | 4 | namespace ypc { 5 | std::string get_ypc_version() { return std::to_string(YPC_RUNTIME_VERSION); } 6 | } 7 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(analyzer) 2 | add_subdirectory(crypto) 3 | add_subdirectory(sgx_ecc) 4 | add_subdirectory(util) 5 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/analyzer/analyzer_version.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core_t/analyzer/yaenclave_t_interface.h" 2 | #include "ypc/version.h" 3 | uint64_t get_ypc_analyzer_version() { return YPC_CORE_T_VERSION.data(); } 4 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/analyzer/var/enclave_hash_var.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core_t/analyzer/var/enclave_hash_var.h" 2 | 3 | namespace ypc { 4 | namespace internal { 5 | const stbox::bytes &enclave_hash_var::get_enclave_hash() const { 6 | return m_enclave_hash; 7 | } 8 | } // namespace internal 9 | } // namespace ypc 10 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(stdeth) 2 | add_subdirectory(gmssl) 3 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/crypto/gmssl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(gmssl_src sm2_ecc.cpp ../../../corecommon/crypto/sm3_hash.cpp sm4_aes.cpp) 3 | 4 | add_trusted_library(gmssl_t 5 | gmssl_t 6 | SRCS "${gmssl_src}" 7 | EDL ${PROJECT_SOURCE_DIR}/include/ypc/edl/ecc.edl 8 | EDL_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/include/ypc/stbox/) 9 | 10 | target_include_directories(gmssl_t PUBLIC 11 | "$" 12 | "$" 13 | "$") 14 | target_link_libraries(gmssl_t PUBLIC stbox_common_t stbox_gmssl_t) 15 | install(TARGETS gmssl_t EXPORT mod_gmssl_t 16 | DESTINATION "${lib_install_dir}" 17 | COMPONENT gmssl_t) 18 | 19 | install(EXPORT mod_gmssl_t 20 | DESTINATION "${config_install_dir}/core" 21 | NAMESPACE "${namespace}" 22 | COMPONENT gmssl_t) 23 | 24 | AddClangTidy(gmssl_t) 25 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/crypto/stdeth/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(stdeth_src ../../../corecommon/crypto/eth_hash.cpp rijndael128GCM.cpp secp256k1.cpp secp256k1_ecdh_sgx128.cpp) 3 | 4 | add_trusted_library(stdeth_t 5 | stdeth_t 6 | SRCS "${stdeth_src}" 7 | EDL ${PROJECT_SOURCE_DIR}/include/ypc/edl/ecc.edl 8 | EDL_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/include/ypc/stbox/) 9 | 10 | target_include_directories(stdeth_t PUBLIC 11 | "$" 12 | "$" 13 | "$") 14 | target_link_libraries(stdeth_t PUBLIC stbox_common_t stbox_secp256k1_t stbox_keccak_t) 15 | install(TARGETS stdeth_t EXPORT mod_stdeth_t 16 | DESTINATION "${lib_install_dir}" 17 | COMPONENT stdeth_t) 18 | 19 | install(EXPORT mod_stdeth_t 20 | DESTINATION "${config_install_dir}/core" 21 | NAMESPACE "${namespace}" 22 | COMPONENT stdeth_t) 23 | 24 | 25 | AddClangTidy(stdeth_t) 26 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/crypto/stdeth/secp256k1.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/corecommon/crypto/stdeth/secp256k1.h" 2 | #include "ypc/corecommon/crypto/stdeth/secp256k1.ipp" 3 | #include 4 | 5 | namespace ypc { 6 | namespace crypto { 7 | uint32_t secp256k1::gen_private_key(uint32_t skey_size, uint8_t *skey) { 8 | secp256k1_context *ctx = init_secp256k1_context(); 9 | 10 | if (ctx == nullptr) { 11 | LOG(ERROR) << "Context or Secret key or Public key is null"; 12 | return stbox::stx_status::ecc_invalid_ctx_or_skey; 13 | } 14 | sgx_status_t se_ret; 15 | do { 16 | se_ret = sgx_read_rand(skey, skey_size); 17 | if (se_ret != SGX_SUCCESS) { 18 | LOG(ERROR) << "call sgx_read_rand failed"; 19 | return se_ret; 20 | } 21 | } while (0 == secp256k1_ec_seckey_verify(ctx, skey)); 22 | return se_ret; 23 | } 24 | } // namespace crypto 25 | } // namespace ypc 26 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/ecommon/package.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core_t/ecommon/package.h" 2 | #include "ypc/stbox/stx_common.h" 3 | 4 | // namespace ypc { 5 | void sgx_package_handler::handle_pkg(const uint8_t *buf, size_t len) { 6 | uint32_t type_id; 7 | ::ff::net::deserialize((const char *)buf, type_id); 8 | auto it = m_all_handlers.find(type_id); 9 | if (it == m_all_handlers.end()) { 10 | throw std::runtime_error("no handler for type id"); 11 | } 12 | it->second(buf, len); 13 | } 14 | //} // namespace ypc 15 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/sgx_ecc/gmssl_ecc_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "ecc_t.h" 2 | #include "ypc/common/crypto_prefix.h" 3 | #include "ypc/corecommon/crypto/gmssl.h" 4 | #include "ypc/stbox/tsgx/crypto/seal.h" 5 | #include "ypc/stbox/tsgx/crypto/seal_sgx.h" 6 | #include "ypc/stbox/tsgx/log.h" 7 | #include "ypc/version.h" 8 | 9 | using ecc = ypc::crypto::gmssl_sgx_crypto; 10 | using sealer = stbox::crypto::raw_device_sealer; 11 | 12 | #include "ecc_impl.ipp" 13 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/sgx_ecc/stdeth_ecc_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "ecc_t.h" 2 | #include "ypc/common/crypto_prefix.h" 3 | #include "ypc/corecommon/crypto/stdeth.h" 4 | #include "ypc/stbox/tsgx/crypto/seal.h" 5 | #include "ypc/stbox/tsgx/crypto/seal_sgx.h" 6 | #include "ypc/stbox/tsgx/log.h" 7 | #include "ypc/version.h" 8 | 9 | using ecc = ypc::crypto::eth_sgx_crypto; 10 | using sealer = stbox::crypto::raw_device_sealer; 11 | 12 | #include "ecc_impl.ipp" 13 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs cxxfile.cpp 2 | kv.cpp) 3 | add_trusted_library(core_util_t 4 | core_util_t 5 | SRCS ${srcs} 6 | EDL ${PROJECT_SOURCE_DIR}/include/ypc/edl/eparser.edl 7 | EDL_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/include/ypc/edl/:${PROJECT_SOURCE_DIR}/include/ypc/stbox/:${PROJECT_SOURCE_DIR}/include/ypc/edl/util/") 8 | 9 | target_include_directories(core_util_t-edlobj PUBLIC 10 | "$" 11 | "$") 12 | target_include_directories(core_util_t PUBLIC 13 | "$" 14 | "$" 15 | "$" 16 | "$") 17 | target_link_libraries(core_util_t PUBLIC stbox_common_t) 18 | 19 | install(TARGETS core_util_t EXPORT mod_core_util_t 20 | DESTINATION "${lib_install_dir}" 21 | COMPONENT core_t) 22 | install(EXPORT mod_core_util_t 23 | DESTINATION "${config_install_dir}/core" 24 | NAMESPACE "${namespace}" 25 | COMPONENT core_t) 26 | 27 | AddClangTidy(core_util_t) 28 | -------------------------------------------------------------------------------- /ypc/core/src/core_t/util/kv.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/core_t/util/kv.h" 2 | #include "eparser_t.h" 3 | #include "ypc/stbox/tsgx/ocall.h" 4 | namespace ypc { 5 | namespace kv { 6 | 7 | // key length must be 32 8 | bool has_key(const uint8_t *key) { 9 | return stbox::ocall_cast(has_key_ocall)(key) != 0; 10 | } 11 | uint32_t remove_key(const uint8_t *key) { 12 | return stbox::ocall_cast(remove_key_ocall)(key); 13 | } 14 | uint32_t write(const uint8_t *key, const uint8_t *val, std::size_t len) { 15 | return stbox::ocall_cast(write_to_storage_ocall)(key, val, len); 16 | } 17 | uint32_t read(const uint8_t *key, uint8_t *val, std::size_t size) { 18 | return stbox::ocall_cast(read_from_storage_ocall)(key, val, size); 19 | } 20 | } // namespace kv 21 | } // namespace ypc 22 | -------------------------------------------------------------------------------- /ypc/core/src/corecommon/crypto/sm3_hash.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/corecommon/crypto/gmssl/sm3_hash.h" 2 | #include "ypc/common/byte.h" 3 | #include "ypc/stbox/gmssl/sha2.h" 4 | #include "ypc/stbox/gmssl/sm3.h" 5 | #include "ypc/stbox/stx_status.h" 6 | 7 | namespace ypc { 8 | namespace crypto { 9 | 10 | uint32_t sm3_hash::hash_256(const uint8_t *msg, uint32_t msg_size, 11 | uint8_t *hash) { 12 | SM3_CTX ctx; 13 | sm3_init(&ctx); 14 | sm3_update(&ctx, msg, msg_size); 15 | sm3_finish(&ctx, hash); 16 | return stbox::stx_status::success; 17 | } 18 | 19 | uint32_t sm3_hash::msg_hash(const uint8_t *raw_msg, uint32_t msg_size, 20 | uint8_t *hash, uint32_t hash_size) { 21 | return hash_256(raw_msg, msg_size, hash); 22 | } 23 | } // namespace crypto 24 | } // namespace ypc 25 | -------------------------------------------------------------------------------- /ypc/keymgr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(common) 3 | if(SGX_FOUND) 4 | add_subdirectory(default) 5 | endif() 6 | 7 | -------------------------------------------------------------------------------- /ypc/keymgr/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(keymgr_utils SHARED 2 | util.cpp) 3 | 4 | target_include_directories(keymgr_utils PUBLIC 5 | "$" 6 | "$" 7 | ) 8 | 9 | target_link_libraries(keymgr_utils PUBLIC core) 10 | 11 | install(TARGETS keymgr_utils 12 | EXPORT mod_keymgr_utils 13 | DESTINATION "${lib_install_dir}" 14 | COMPONENT keymgr) 15 | 16 | install(EXPORT mod_keymgr_utils 17 | DESTINATION "${config_install_dir}/keymgr" 18 | NAMESPACE "${namespace}" 19 | COMPONENT keymgr 20 | ) 21 | 22 | add_version(keymgr_utils) 23 | AddClangTidy(keymgr_utils) 24 | EnableCoverage(keymgr_utils) 25 | -------------------------------------------------------------------------------- /ypc/keymgr/default/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(enclave) 2 | add_subdirectory(gmssl) 3 | 4 | set(edl_path ${PROJECT_SOURCE_DIR}/include/ypc/edl/:${PROJECT_SOURCE_DIR}/include/ypc/stbox) 5 | 6 | add_untrusted_library(keymgr_module SHARED 7 | SRCS "keymgr_sgx_module.cpp" 8 | EDL ${PROJECT_SOURCE_DIR}/include/ypc/keymgr/default/enclave/ekeymgr.edl 9 | EDL_SEARCH_PATHS ${edl_path}) 10 | target_include_directories(keymgr_module INTERFACE 11 | ${SGX_INCLUDE_DIR} 12 | ) 13 | target_link_libraries(keymgr_module PUBLIC stbox_common keymgr_utils) 14 | 15 | install(TARGETS keymgr_module EXPORT mod_keymgr_module 16 | DESTINATION "${lib_install_dir}" 17 | COMPONENT keymgr) 18 | 19 | install(EXPORT mod_keymgr_module 20 | DESTINATION "${config_install_dir}/keymgr" 21 | NAMESPACE "${namespace}" 22 | COMPONENT keymgr 23 | ) 24 | 25 | add_sgx_executable(keymgr_tool 26 | SRCS main.cpp no_use_extra_data_bridge.cpp) 27 | add_dependencies(keymgr_tool keymgr-sign) 28 | target_link_libraries(keymgr_tool PUBLIC keymgr_module common) 29 | install(TARGETS keymgr_tool 30 | DESTINATION "${bin_install_dir}") 31 | 32 | AddClangTidy(keymgr_module) 33 | AddClangTidy(keymgr_tool) 34 | add_version(keymgr) 35 | -------------------------------------------------------------------------------- /ypc/keymgr/default/enclave/ekeymgr.config.debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x4000000 5 | 0x4000000 6 | 10 7 | 1 8 | 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /ypc/keymgr/default/enclave/ekeymgr.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 0 4 | 0x4000000 5 | 0x4000000 6 | 10 7 | 1 8 | 9 | 1 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /ypc/keymgr/default/enclave/ekeymgr.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/corecommon/crypto/stdeth.h" 2 | 3 | using ecc = ypc::crypto::eth_sgx_crypto; 4 | 5 | #ifdef DEBUG 6 | #define KEY_PATH ".yeez.stdeth_key.debug" 7 | #else 8 | #define KEY_PATH ".yeez.stdeth_key" 9 | #endif 10 | 11 | #include "ypc/keymgr/default/ekeymgr.ipp" 12 | -------------------------------------------------------------------------------- /ypc/keymgr/default/enclave/ekeymgr.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /ypc/keymgr/default/enclave/ekeymgr_debug.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 | g_peak_rsrv_mem_committed; 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /ypc/keymgr/default/gmssl/ekeymgr.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/corecommon/crypto/gmssl.h" 2 | 3 | using ecc = ypc::crypto::gmssl_sgx_crypto; 4 | 5 | #ifdef DEBUG 6 | #define KEY_PATH ".yeez.gmssl_key.debug" 7 | #else 8 | #define KEY_PATH ".yeez.gmssl_key" 9 | #endif 10 | 11 | #include "ypc/keymgr/default/ekeymgr.ipp" 12 | -------------------------------------------------------------------------------- /ypc/keymgr/default/no_use_extra_data_bridge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | extern "C" { 3 | uint32_t ocall_read_next_extra_data_item(uint8_t *data_hash, 4 | uint32_t hash_size); 5 | uint32_t ocall_get_next_extra_data_item_size(); 6 | uint32_t ocall_get_next_extra_data_item_data(uint8_t *item_data, 7 | uint32_t ndi_size); 8 | } 9 | 10 | uint32_t ocall_read_next_extra_data_item(uint8_t *data_hash, 11 | uint32_t hash_size) { 12 | return 0; 13 | } 14 | uint32_t ocall_get_next_extra_data_item_size() { return 0; } 15 | uint32_t ocall_get_next_extra_data_item_data(uint8_t *item_data, 16 | uint32_t ndi_size) { 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /ypc/stbox/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /ypc/stbox/src/exception.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/stbox/exception.h" 2 | 3 | namespace stbox { 4 | st_error::st_error(sgx_status_t s) : m_status(s) {} 5 | const char *st_error::what() { 6 | if (m_message.empty()) { 7 | m_message = std::string(status_string(m_status)); 8 | } 9 | return m_message.c_str(); 10 | } 11 | } // namespace stbox 12 | -------------------------------------------------------------------------------- /ypc/stbox/src/keccak/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(src keccak.c) 3 | add_library(stbox_keccak SHARED ${src}) 4 | 5 | target_include_directories(stbox_keccak PUBLIC 6 | "$" 7 | "$" 8 | ) 9 | 10 | install(TARGETS stbox_keccak EXPORT mod_keccak 11 | DESTINATION "${lib_install_dir}" 12 | COMPONENT stdeth) 13 | 14 | install(EXPORT mod_keccak 15 | DESTINATION "${config_install_dir}/stbox" 16 | NAMESPACE "${namespace}") 17 | 18 | add_version(stbox_keccak) 19 | 20 | if(SGX_FOUND) 21 | add_sgx_library(stbox_keccak_t SRCS ${src}) 22 | 23 | target_include_directories(stbox_keccak_t PUBLIC 24 | "$" 25 | "$" 26 | ) 27 | 28 | install(TARGETS stbox_keccak_t EXPORT mod_keccak_t 29 | DESTINATION "${lib_install_dir}" 30 | COMPONENT stdeth_t) 31 | 32 | install(EXPORT mod_keccak_t 33 | DESTINATION "${config_install_dir}/stbox" 34 | NAMESPACE "${namespace}") 35 | endif() 36 | -------------------------------------------------------------------------------- /ypc/stbox/src/stx_common.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/stbox/stx_common.h" 2 | #include 3 | #include 4 | 5 | namespace stbox { 6 | void print_hex(uint8_t *data, size_t data_len) { 7 | for (size_t i = 0; i < data_len; i++) { 8 | printf("%02x", data[i]); 9 | } 10 | printf("\r\n"); 11 | } 12 | } // namespace stbox 13 | -------------------------------------------------------------------------------- /ypc/stbox/src/stx_status.cpp: -------------------------------------------------------------------------------- 1 | #ifdef YPC_ENABLE_SGX 2 | #include "ypc/stbox/stx_status.h" 3 | #include 4 | #endif 5 | 6 | #include 7 | 8 | namespace stbox { 9 | const char *status_string(uint32_t status) { 10 | if (0U == (status & 0x10000)) { 11 | #define ATT_STATUS(a, b) \ 12 | case b | 0x10000: \ 13 | return #a; 14 | 15 | switch (status) { 16 | #include "ypc/stbox/stx_status.def" 17 | default: 18 | return "unknown stx status"; 19 | } 20 | 21 | #undef ATT_STATUS 22 | } else { 23 | switch (status) { 24 | #ifdef YPC_ENABLE_SGX 25 | #define SGX_STATUS(n) \ 26 | case n: \ 27 | return #n; 28 | #include "ypc/stbox/sgx_status.def" 29 | #undef SGX_STATUS 30 | #endif 31 | default: 32 | return "unknown sgx status"; 33 | } 34 | return "unknown sgx status"; 35 | } 36 | } 37 | } // namespace stbox 38 | 39 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(secp256k1) 2 | if(SGX_FOUND) 3 | add_subdirectory(channel) 4 | add_subdirectory(crypto) 5 | endif() 6 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/channel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(t_channel_src 2 | dh_session.cpp 3 | dh_session_responder.cpp 4 | dh_session_initiator.cpp 5 | ) 6 | 7 | add_sgx_library(stbox_channel_t 8 | stbox_channel 9 | SRCS "${t_channel_src}" 10 | ) 11 | 12 | target_link_libraries(stbox_channel_t PUBLIC stbox_common_t) 13 | 14 | target_include_directories(stbox_channel_t PUBLIC 15 | "$" 16 | "$" 17 | "$" 18 | "$" 19 | ) 20 | 21 | install(TARGETS stbox_channel_t EXPORT mod_channel_t 22 | DESTINATION "${lib_install_dir}" 23 | COMPONENT core_t) 24 | 25 | install(EXPORT mod_channel_t 26 | DESTINATION "${config_install_dir}/stbox" 27 | NAMESPACE "${namespace}") 28 | 29 | AddClangTidy(stbox_channel_t) 30 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #add_definitions(-DSTBOX_CRYPTO_VERBOSE) 3 | 4 | 5 | set(crypto_src 6 | seal_sgx.cpp 7 | ) 8 | 9 | add_sgx_library(stbox_crypto_t 10 | SRCS "${crypto_src}") 11 | target_link_libraries(stbox_crypto_t PUBLIC stbox_common_t) 12 | 13 | target_include_directories(stbox_crypto_t PUBLIC 14 | "$" 15 | "$" 16 | "$" 17 | "$" 18 | ) 19 | 20 | install(TARGETS stbox_crypto_t EXPORT mod_crypto_t 21 | DESTINATION "${lib_install_dir}" 22 | COMPONENT core_t) 23 | 24 | install(EXPORT mod_crypto_t 25 | DESTINATION "${config_install_dir}/stbox" 26 | NAMESPACE "${namespace}") 27 | 28 | AddClangTidy(stbox_crypto_t) 29 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/log.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/stbox/tsgx/log.h" 2 | #include "stbox_t.h" 3 | 4 | namespace stbox { 5 | Logger::~Logger() { 6 | ocall_log_string(m_log_rank, m_ss.c_str()); 7 | } 8 | 9 | Logger &Logger::start(const std::string &file, uint32_t line, 10 | const std::string &function) { 11 | std::string::size_type pos = file.find_last_of("/"); 12 | std::string f = file.substr(pos + 1); 13 | 14 | m_ss = f + std::string(":") + std::to_string(line) + std::string(":") + 15 | function + std::string(", "); 16 | return *this; 17 | } 18 | Logger &Logger::operator<<(const std::string &t) { 19 | m_ss = m_ss + t; 20 | return *this; 21 | } 22 | Logger &Logger::operator<<(const bytes &t) { 23 | hex_bytes r = t.as(); 24 | m_ss = m_ss + std::string((const char *)r.data(), r.size()); 25 | return *this; 26 | } 27 | Logger &Logger::operator<<(stx_status t) { 28 | m_ss = m_ss + std::to_string(t); 29 | return *this; 30 | } 31 | Logger &Logger::operator<<(sgx_status_t t) { 32 | m_ss = m_ss + std::string(status_string(t)); 33 | return *this; 34 | } 35 | } // namespace stbox 36 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/basic-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_BASIC_CONFIG_H 8 | #define SECP256K1_BASIC_CONFIG_H 9 | 10 | #ifdef USE_BASIC_CONFIG 11 | 12 | #undef USE_ASM_X86_64 13 | #undef USE_ENDOMORPHISM 14 | #undef USE_FIELD_10X26 15 | #undef USE_FIELD_5X52 16 | #undef USE_FIELD_INV_BUILTIN 17 | #undef USE_FIELD_INV_NUM 18 | #undef USE_NUM_GMP 19 | #undef USE_NUM_NONE 20 | #undef USE_SCALAR_4X64 21 | #undef USE_SCALAR_8X32 22 | #undef USE_SCALAR_INV_BUILTIN 23 | #undef USE_SCALAR_INV_NUM 24 | 25 | #define USE_NUM_NONE 1 26 | #define USE_FIELD_INV_BUILTIN 1 27 | #define USE_SCALAR_INV_BUILTIN 1 28 | #define USE_FIELD_10X26 1 29 | #define USE_SCALAR_8X32 1 30 | 31 | #endif /* USE_BASIC_CONFIG */ 32 | 33 | #endif /* SECP256K1_BASIC_CONFIG_H */ 34 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECDSA_H 8 | #define SECP256K1_ECDSA_H 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif /* SECP256K1_ECDSA_H */ 22 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_ECMULT_CONST_H 8 | #define SECP256K1_ECMULT_CONST_H 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | /* Here `bits` should be set to the maximum bitlength of the _absolute value_ of `q`, plus 14 | * one because we internally sometimes add 2 to the number during the WNAF conversion. */ 15 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q, int bits); 16 | 17 | #endif /* SECP256K1_ECMULT_CONST_H */ 18 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/java/.deps/libsecp256k1_jni_la-org_bitcoin_NativeSecp256k1.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/java/.deps/libsecp256k1_jni_la-org_bitcoin_Secp256k1Context.Plo: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/java/org_bitcoin_Secp256k1Context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "org_bitcoin_Secp256k1Context.h" 4 | #include "include/secp256k1.h" 5 | 6 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 7 | (JNIEnv* env, jclass classObject) 8 | { 9 | secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 10 | 11 | (void)classObject;(void)env; 12 | 13 | return (uintptr_t)ctx; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/java/org_bitcoin_Secp256k1Context.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_Secp256k1Context */ 5 | 6 | #ifndef _Included_org_bitcoin_Secp256k1Context 7 | #define _Included_org_bitcoin_Secp256k1Context 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_Secp256k1Context 13 | * Method: secp256k1_init_context 14 | * Signature: ()J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 17 | (JNIEnv *, jclass); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_ecdh 6 | bench_ecdh_SOURCES = src/bench_ecdh.c 7 | bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_recover 6 | bench_recover_SOURCES = src/bench_recover.c 7 | bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_NUM_REPR_H 8 | #define SECP256K1_NUM_REPR_H 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num; 19 | 20 | #endif /* SECP256K1_NUM_REPR_H */ 21 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_NUM_IMPL_H 8 | #define SECP256K1_NUM_IMPL_H 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif /* SECP256K1_NUM_IMPL_H */ 25 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif /* SECP256K1_SCALAR_REPR_H */ 20 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif /* SECP256K1_SCALAR_REPR_H */ 20 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/scalar_low.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef SECP256K1_SCALAR_REPR_H 8 | #define SECP256K1_SCALAR_REPR_H 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef uint32_t secp256k1_scalar; 14 | 15 | #endif /* SECP256K1_SCALAR_REPR_H */ 16 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/secp256k1/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for src/libsecp256k1-config.h 2 | -------------------------------------------------------------------------------- /ypc/stbox/src/tsgx/util.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/stbox/tsgx/util.h" 2 | #include 3 | #include 4 | namespace stbox { 5 | 6 | stbox::bytes get_enclave_signer() { 7 | stbox::bytes signer(sizeof(sgx_measurement_t)); 8 | memcpy(signer.data(), sgx_self_report()->body.mr_signer.m, 9 | sizeof(sgx_measurement_t)); 10 | return signer; 11 | } 12 | 13 | stbox::bytes get_enclave_hash() { 14 | stbox::bytes hash(sizeof(sgx_measurement_t)); 15 | memcpy(hash.data(), sgx_self_report()->body.mr_enclave.m, 16 | sizeof(sgx_measurement_t)); 17 | return hash; 18 | } 19 | } // namespace stbox 20 | -------------------------------------------------------------------------------- /ypc/stbox/src/usgx/sgx_module.cpp: -------------------------------------------------------------------------------- 1 | #include "ypc/stbox/usgx/sgx_module.h" 2 | #include "sgx_urts.h" 3 | #include "ypc/stbox/usgx/error_message.h" 4 | #include 5 | #include 6 | 7 | namespace stbox { 8 | namespace internal { 9 | 10 | void buffer_length_traits::call(sgx_module_base &m) { 11 | //*m_len = m.ecall(m_func); 12 | *m_len = m_func->call(m); 13 | *m_mem = (uint8_t *)malloc(*m_len); 14 | } 15 | 16 | } // namespace internal 17 | sgx_module::sgx_module(const char *mod_path) 18 | : internal::sgx_module_base(mod_path) { 19 | sgx_status_t ret = SGX_ERROR_UNEXPECTED; 20 | 21 | LOG(INFO) << "SGX_DEBUG_FLAG: " << SGX_DEBUG_FLAG; 22 | /* Call sgx_create_enclave to initialize an enclave instance */ 23 | /* Debug Support: set 2nd parameter to 1 */ 24 | ret = sgx_create_enclave(mod_path, SGX_DEBUG_FLAG, NULL, NULL, &m_sgx_eid, 25 | NULL); 26 | if (ret != SGX_SUCCESS) { 27 | std::cerr << "sgx_create_enclave fail " << status_string(ret) 28 | << ", for file: " << mod_path << std::endl; 29 | throw std::runtime_error(std::to_string(ret)); 30 | } 31 | } 32 | 33 | sgx_module::~sgx_module() { sgx_destroy_enclave(m_sgx_eid); } 34 | 35 | } // namespace stbox 36 | --------------------------------------------------------------------------------