├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── applications ├── balance-checker │ ├── App │ │ ├── App.cpp │ │ ├── App.h │ │ └── TrustedLibrary │ │ │ ├── Libcxx.cpp │ │ │ ├── attest.hpp │ │ │ ├── db_updater.hpp │ │ │ ├── kv_db.hpp │ │ │ └── lock_utils.hpp │ ├── Enclave │ │ ├── Enclave.config.xml │ │ ├── Enclave.cpp │ │ ├── Enclave.edl │ │ ├── Enclave.h │ │ ├── Enclave.lds │ │ ├── Enclave_debug.lds │ │ ├── TrustedLibrary │ │ │ ├── crypt.hpp │ │ │ ├── omap.cpp │ │ │ └── omap.edl │ │ └── bearssl │ │ │ ├── include │ │ │ ├── bearssl.h │ │ │ ├── bearssl_aead.h │ │ │ ├── bearssl_block.h │ │ │ ├── bearssl_ec.h │ │ │ ├── bearssl_hash.h │ │ │ ├── bearssl_hmac.h │ │ │ ├── bearssl_kdf.h │ │ │ ├── bearssl_pem.h │ │ │ ├── bearssl_prf.h │ │ │ ├── bearssl_rand.h │ │ │ ├── bearssl_rsa.h │ │ │ ├── bearssl_ssl.h │ │ │ └── bearssl_x509.h │ │ │ └── src │ │ │ ├── bearssl │ │ │ ├── aead │ │ │ │ └── gcm.c │ │ │ ├── codec │ │ │ │ ├── dec32be.c │ │ │ │ └── enc32be.c │ │ │ ├── config.h │ │ │ ├── hash │ │ │ │ ├── ghash_pclmul.c │ │ │ │ ├── sha1.c │ │ │ │ └── sha2small.c │ │ │ ├── inner.h │ │ │ ├── mac │ │ │ │ └── hmac.c │ │ │ ├── rand │ │ │ │ ├── aesctr_drbg.c │ │ │ │ ├── hmac_drbg.c │ │ │ │ └── sysrng.c │ │ │ └── symcipher │ │ │ │ ├── aes_x86ni.c │ │ │ │ └── aes_x86ni_ctr.c │ │ │ ├── cmockery.c │ │ │ ├── curve25519-donna-c64.c │ │ │ ├── sgx-tcrypto-stub.c │ │ │ ├── sgxsd-enclave-test.c │ │ │ └── sgxsd-enclave.c │ ├── Makefile │ ├── README.txt │ ├── algo_runner.sh │ ├── client.js │ ├── common.hpp │ ├── httplib.h │ ├── initDB.sh │ ├── init_db_balance │ ├── init_db_balance.cpp │ ├── integration_test.py │ ├── mock_server_runner.sh │ ├── rcc_balance.txt │ ├── retrieveTransfers.py │ ├── retrieveTransfersState.json │ └── update_balance.py ├── cexample │ ├── README.txt │ └── src │ │ ├── CMakeLists.txt │ │ └── test.c ├── goexample │ ├── .gitignore │ ├── README.txt │ ├── go.mod │ ├── go.sum │ └── odsl │ │ ├── CMakeLists.txt │ │ ├── cmake │ │ ├── bearssl.cmake │ │ └── boost.cmake │ │ ├── gen_binding.sh │ │ ├── odsl.i │ │ └── odsl_test.go ├── omap │ ├── App │ │ ├── App.cpp │ │ ├── App.h │ │ └── TrustedLibrary │ │ │ └── Libcxx.cpp │ ├── Enclave │ │ ├── Enclave.config.xml │ │ ├── Enclave.cpp │ │ ├── Enclave.edl │ │ ├── Enclave.h │ │ ├── Enclave.lds │ │ ├── Enclave_debug.lds │ │ ├── TrustedLibrary │ │ │ ├── omap.edl │ │ │ └── omap_test.cpp │ │ └── bearssl │ │ │ ├── include │ │ │ ├── bearssl.h │ │ │ ├── bearssl_aead.h │ │ │ ├── bearssl_block.h │ │ │ ├── bearssl_ec.h │ │ │ ├── bearssl_hash.h │ │ │ ├── bearssl_hmac.h │ │ │ ├── bearssl_kdf.h │ │ │ ├── bearssl_pem.h │ │ │ ├── bearssl_prf.h │ │ │ ├── bearssl_rand.h │ │ │ ├── bearssl_rsa.h │ │ │ ├── bearssl_ssl.h │ │ │ └── bearssl_x509.h │ │ │ └── src │ │ │ ├── bearssl │ │ │ ├── aead │ │ │ │ └── gcm.c │ │ │ ├── codec │ │ │ │ ├── dec32be.c │ │ │ │ └── enc32be.c │ │ │ ├── config.h │ │ │ ├── hash │ │ │ │ ├── ghash_pclmul.c │ │ │ │ ├── sha1.c │ │ │ │ └── sha2small.c │ │ │ ├── inner.h │ │ │ ├── mac │ │ │ │ └── hmac.c │ │ │ ├── rand │ │ │ │ ├── aesctr_drbg.c │ │ │ │ ├── hmac_drbg.c │ │ │ │ └── sysrng.c │ │ │ └── symcipher │ │ │ │ ├── aes_x86ni.c │ │ │ │ └── aes_x86ni_ctr.c │ │ │ ├── cmockery.c │ │ │ ├── curve25519-donna-c64.c │ │ │ ├── sgx-tcrypto-stub.c │ │ │ ├── sgxsd-enclave-test.c │ │ │ └── sgxsd-enclave.c │ ├── Makefile │ ├── README.txt │ ├── algo_runner.sh │ └── perf_tests │ │ ├── erc20DeferWrite │ │ ├── Init_Time.jpg │ │ ├── Throughput_MapSize_100000.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_200000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_200000000.jpg │ │ ├── Throughput_MapSize_500000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ └── omapPerf200g.txt │ │ ├── erc20DeferWriteParBitonic │ │ ├── Actual_Throughput_MapSize_100000.jpg │ │ ├── Actual_Throughput_MapSize_1000000.jpg │ │ ├── Actual_Throughput_MapSize_10000000.jpg │ │ ├── Actual_Throughput_MapSize_100000000.jpg │ │ ├── Actual_Throughput_MapSize_200000.jpg │ │ ├── Actual_Throughput_MapSize_2000000.jpg │ │ ├── Actual_Throughput_MapSize_20000000.jpg │ │ ├── Actual_Throughput_MapSize_200000000.jpg │ │ ├── Actual_Throughput_MapSize_500000.jpg │ │ ├── Actual_Throughput_MapSize_5000000.jpg │ │ ├── Actual_Throughput_MapSize_50000000.jpg │ │ ├── Init_Time.jpg │ │ ├── Throughput_MapSize_100000.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_200000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_200000000.jpg │ │ ├── Throughput_MapSize_500000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ └── omapPerf200g.txt │ │ ├── erc20FromEmpty │ │ ├── Init_Time.jpg │ │ ├── Throughput_MapSize_100000.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_200000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_200000000.jpg │ │ ├── Throughput_MapSize_500000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ ├── omapPerf16g.txt │ │ └── omapPerf200g.txt │ │ ├── erc20FromExist │ │ ├── Init_Time.jpg │ │ ├── Throughput_MapSize_100000.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_200000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_500000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ └── omapPerf200g.txt │ │ ├── erc20SingleThread │ │ ├── Init_Time.jpg │ │ ├── Throughput.jpg │ │ └── omapPerf200g.txt │ │ ├── parcuckoo │ │ ├── Init_Time.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ └── omapPerf200g.txt │ │ ├── pardisk │ │ ├── Init_Time.jpg │ │ ├── Latency1000.jpg │ │ ├── Latency1000.pdf │ │ ├── Latency100000.jpg │ │ └── Latency100000.pdf │ │ ├── pipeline │ │ ├── Init_Time.jpg │ │ ├── Latency1.jpg │ │ └── Latency1.pdf │ │ ├── plotLatency.py │ │ ├── plotPerf.py │ │ └── signalFromEmpty │ │ ├── Init_Time.jpg │ │ ├── Init_Time_Signal.jpg │ │ ├── Throughput_MapSize_100000.jpg │ │ ├── Throughput_MapSize_1000000.jpg │ │ ├── Throughput_MapSize_10000000.jpg │ │ ├── Throughput_MapSize_100000000.jpg │ │ ├── Throughput_MapSize_200000.jpg │ │ ├── Throughput_MapSize_2000000.jpg │ │ ├── Throughput_MapSize_20000000.jpg │ │ ├── Throughput_MapSize_500000.jpg │ │ ├── Throughput_MapSize_5000000.jpg │ │ ├── Throughput_MapSize_50000000.jpg │ │ └── omapPerf200g.txt └── rustexample │ ├── .gitignore │ ├── Cargo.toml │ ├── README.txt │ ├── build.rs │ ├── makestaticbearssl.sh │ ├── src │ └── lib.rs │ └── wrapper.h ├── cmake ├── bearssl.cmake ├── boost.cmake ├── buildtype.cmake ├── clangformat.cmake ├── colors.cmake ├── cppcheck.cmake ├── faster.cmake └── searchfiles.cmake ├── omap ├── CMakeLists.txt ├── algorithm │ ├── bitonic.hpp │ ├── edge_rec.hpp │ ├── element.hpp │ ├── merge_split.hpp │ ├── or_compact_shuffle.hpp │ ├── param_select.hpp │ └── static_sort.hpp ├── common │ ├── cmp_intrinsics.hpp │ ├── cpp_extended.hpp │ ├── defs.hpp │ ├── dmcache.hpp │ ├── dummy.hpp │ ├── encrypted.hpp │ ├── encutils.cpp │ ├── encutils.hpp │ ├── lock_util.hpp │ ├── lrucache.hpp │ ├── mov_intrinsics.hpp │ ├── tracing │ │ ├── perf.hpp │ │ ├── perf_counters.hpp │ │ ├── perf_counters.hxx │ │ ├── perf_counters_release.hxx │ │ ├── tracer.cpp │ │ ├── tracer.hpp │ │ ├── tracer_events.hxx │ │ └── trackers │ │ │ ├── max_tracker.hpp │ │ │ ├── profiler.hpp │ │ │ └── time_tracker.hpp │ └── utils.hpp ├── external_memory │ ├── cachefrontvector.hpp │ ├── extemvector.hpp │ ├── rw_concepts.hpp │ ├── server │ │ ├── cached.hpp │ │ ├── enclaveFileServer_untrusted.hpp │ │ ├── enclaveMemServer_untrusted.hpp │ │ ├── enclaveMmapFileServer_untrusted.hpp │ │ ├── serverAllocator.hpp │ │ ├── serverBackend.cpp │ │ ├── serverBackend.hpp │ │ └── serverFrontend.hpp │ ├── stdvector.hpp │ └── virtualvector.hpp ├── interface │ ├── common_impl.hpp │ ├── common_interface.hpp │ ├── interface.cpp │ ├── omap_c.cpp │ ├── omap_c.h │ ├── omap_declare.cfg │ ├── omap_generic_impl.hpp │ ├── omap_generic_interface.hpp │ ├── omap_spec_impl.hpp │ ├── omap_spec_interface.hpp │ ├── par_omap_impl.hpp │ ├── par_omap_interface.hpp │ ├── recoram_impl.hpp │ └── recoram_interface.hpp └── odsl │ ├── adaptive_oram.hpp │ ├── block.hpp │ ├── bucket.hpp │ ├── circuit_oram.hpp │ ├── heap_tree.hpp │ ├── linear_oram.hpp │ ├── omap.hpp │ ├── omap_short_kv.hpp │ ├── oram_common.hpp │ ├── page_oram.hpp │ ├── par_omap.hpp │ └── recursive_oram.hpp ├── tests ├── CMakeLists.txt ├── basic.cpp ├── cuckoo.cpp ├── oram.cpp ├── par_omap.cpp └── testutils.hpp └── tools ├── docker └── cppbuilder │ ├── Dockerfile │ └── rocksDBInstall.sh └── test-sgx └── test-sgx.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | *.gch 10 | *.pch 11 | *.so 12 | *.dylib 13 | *.dll 14 | *.lai 15 | *.la 16 | *.a 17 | *.lib 18 | *.exe 19 | *.out 20 | *.app 21 | *.bin 22 | *.elf 23 | 24 | # pycache 25 | __pycache__/ 26 | 27 | # CmakeFolders 28 | CMakeCache.txt 29 | CMakeFiles/ 30 | cmake_install.cmake 31 | build/ 32 | codebuild/ 33 | 34 | # tex stuff: 35 | *.log 36 | *.synctex.gz 37 | *.dvi 38 | *.aux 39 | *.blg 40 | *.bbl 41 | *.fdb_latexmk 42 | *.fls 43 | */.ipynb_checkpoints/ 44 | */*.synctex 45 | */*.synctex(busy) 46 | 47 | # vscode stuff 48 | .vscode/ 49 | 50 | # perf data 51 | perf.data* 52 | 53 | # SGX enclave stuff 54 | Enclave_t.h 55 | Enclave_t.c 56 | Enclave_u.h 57 | Enclave_u.c 58 | .config_HW_PRERELEASE_x64 59 | .config_SIM_DEBUG_x64 60 | .config_SIM_RELEASE_x64 61 | *.pem 62 | *.key 63 | 64 | scripts/ 65 | db/ 66 | usdt_balance.txt 67 | updated_usdt_balances.txt 68 | mock_balance.txt 69 | db_usdt/ 70 | db_rcc/ 71 | mock_db/ 72 | tx.log 73 | temp/ 74 | 75 | applications/balance-checker/Enclave/TrustedLibrary/encutils.cpp 76 | applications/omap/Enclave/TrustedLibrary/encutils.cpp 77 | applications/rustexample/BearSSL/ 78 | 79 | tools/test-sgx/SGX-hardware 80 | mvp-pox-node/ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | project("Oblivious Sorting and Shuffling" LANGUAGES C CXX) 3 | 4 | include(cmake/buildtype.cmake) 5 | include(cmake/faster.cmake) 6 | 7 | set(PROJECT_TRDPARTY_DIR "thirdparty") 8 | 9 | # gtest is currently buggy with clang and interprocess optimization, we needded to remove this flag: -Werror 10 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0 -DNDEBUG -g -ggdb -fno-inline -no-pie") 11 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ") 12 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -ggdb -fno-inline -no-pie") 13 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native") 14 | include(cmake/colors.cmake) 15 | 16 | # Includes: 17 | # 18 | include(FetchContent) 19 | FetchContent_Declare( 20 | googletest 21 | URL https://github.com/google/googletest/archive/3ea587050da9447536d0b55fece0a240273d9927.zip 22 | ) 23 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 24 | FetchContent_MakeAvailable(googletest) 25 | 26 | find_package (Boost REQUIRED) 27 | find_package(OpenMP REQUIRED) 28 | 29 | include(cmake/searchfiles.cmake) 30 | include(cmake/boost.cmake) 31 | include(cmake/bearssl.cmake) 32 | 33 | 34 | 35 | add_subdirectory(omap) 36 | 37 | 38 | enable_testing() 39 | add_subdirectory(tests) 40 | 41 | add_subdirectory(applications/cexample/src) 42 | 43 | 44 | include(cmake/cppcheck.cmake) 45 | include(cmake/clangformat.cmake) 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2024 obliviouslabs 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. -------------------------------------------------------------------------------- /applications/balance-checker/App/App.cpp: -------------------------------------------------------------------------------- 1 | #include "App.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Enclave_u.h" 18 | #include "TrustedLibrary/attest.hpp" 19 | #include "sgx_dcap_ql_wrapper.h" 20 | #include "sgx_eid.h" /* sgx_enclave_id_t */ 21 | #include "sgx_error.h" /* sgx_status_t */ 22 | #include "sgx_quote_3.h" 23 | #include "sgx_urts.h" 24 | 25 | /* Global EID shared by multiple threads */ 26 | sgx_enclave_id_t global_eid = 0; 27 | 28 | typedef struct _sgx_errlist_t { 29 | sgx_status_t err; 30 | const char *msg; 31 | const char *sug; /* Suggestion */ 32 | } sgx_errlist_t; 33 | 34 | /* Error code returned by sgx_create_enclave */ 35 | static sgx_errlist_t sgx_errlist[] = { 36 | {SGX_ERROR_UNEXPECTED, "Unexpected error occurred.", NULL}, 37 | {SGX_ERROR_INVALID_PARAMETER, "Invalid parameter.", NULL}, 38 | {SGX_ERROR_OUT_OF_MEMORY, "Out of memory.", NULL}, 39 | {SGX_ERROR_ENCLAVE_LOST, "Power transition occurred.", 40 | "Please refer to the sample \"PowerTransition\" for details."}, 41 | {SGX_ERROR_INVALID_ENCLAVE, "Invalid enclave image.", NULL}, 42 | {SGX_ERROR_INVALID_ENCLAVE_ID, "Invalid enclave identification.", NULL}, 43 | {SGX_ERROR_INVALID_SIGNATURE, "Invalid enclave signature.", NULL}, 44 | {SGX_ERROR_OUT_OF_EPC, "Out of EPC memory.", NULL}, 45 | {SGX_ERROR_NO_DEVICE, "Invalid SGX device.", 46 | "Please make sure SGX module is enabled in the BIOS, and install SGX " 47 | "driver afterwards."}, 48 | {SGX_ERROR_MEMORY_MAP_CONFLICT, "Memory map conflicted.", NULL}, 49 | {SGX_ERROR_INVALID_METADATA, "Invalid enclave metadata.", NULL}, 50 | {SGX_ERROR_DEVICE_BUSY, "SGX device was busy.", NULL}, 51 | {SGX_ERROR_INVALID_VERSION, "Enclave version was invalid.", NULL}, 52 | {SGX_ERROR_INVALID_ATTRIBUTE, "Enclave was not authorized.", NULL}, 53 | {SGX_ERROR_ENCLAVE_FILE_ACCESS, "Can't open enclave file.", NULL}, 54 | {SGX_ERROR_NDEBUG_ENCLAVE, 55 | "The enclave is signed as product enclave, and can not be created as " 56 | "debuggable enclave.", 57 | NULL}, 58 | }; 59 | 60 | /* Check error conditions for loading enclave */ 61 | void print_error_message(sgx_status_t ret) { 62 | size_t idx = 0; 63 | size_t ttl = sizeof sgx_errlist / sizeof sgx_errlist[0]; 64 | 65 | for (idx = 0; idx < ttl; idx++) { 66 | if (ret == sgx_errlist[idx].err) { 67 | if (NULL != sgx_errlist[idx].sug) 68 | printf("Info: %s\n", sgx_errlist[idx].sug); 69 | printf("Error: %s\n", sgx_errlist[idx].msg); 70 | break; 71 | } 72 | } 73 | 74 | if (idx == ttl) printf("Error: Unexpected error occurred.\n"); 75 | } 76 | 77 | /* Initialize the enclave: 78 | * Call sgx_create_enclave to initialize an enclave instance 79 | */ 80 | int initialize_enclave(void) { 81 | sgx_status_t ret = SGX_ERROR_UNEXPECTED; 82 | 83 | /* Call sgx_create_enclave to initialize an enclave instance */ 84 | /* Debug Support: set 2nd parameter to 1 */ 85 | ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, NULL, NULL, 86 | &global_eid, NULL); 87 | if (ret != SGX_SUCCESS) { 88 | print_error_message(ret); 89 | return -1; 90 | } 91 | 92 | return 0; 93 | } 94 | 95 | /* OCall functions */ 96 | void ocall_print_string(const char *str) { 97 | /* Proxy/Bridge will check the length and null-terminate 98 | * the input string to prevent buffer overflow. 99 | */ 100 | printf("%s", str); 101 | } 102 | 103 | void ocall_FAIL() { 104 | printf("Called FAIL oCall\n"); 105 | exit(-1); 106 | } 107 | 108 | #include 109 | 110 | uint64_t ocall_measure_time(void) { 111 | // returns linux-epoch-time in nanoseconds. 112 | auto now_c = std::chrono::system_clock::now(); 113 | uint64_t ret = now_c.time_since_epoch().count(); 114 | return ret; 115 | } 116 | 117 | /* Application entry */ 118 | int SGX_CDECL main(int argc, char *argv[]) { 119 | (void)(argc); 120 | (void)(argv); 121 | /* Initialize the enclave */ 122 | if (initialize_enclave() < 0) { 123 | printf("Enter a character before exit ...\n"); 124 | getchar(); 125 | return -1; 126 | } 127 | if (argc != 2) { 128 | printf("Usage: %s \n", argv[0]); 129 | return 1; 130 | } 131 | 132 | /* Utilize trusted libraries */ 133 | ActualMain(argv[1]); 134 | 135 | /* Destroy the enclave */ 136 | sgx_destroy_enclave(global_eid); 137 | 138 | return 0; 139 | } -------------------------------------------------------------------------------- /applications/balance-checker/App/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "sgx_eid.h" 11 | #include "sgx_error.h" 12 | 13 | #ifndef TRUE 14 | #define TRUE 1 15 | #endif 16 | 17 | #ifndef FALSE 18 | #define FALSE 0 19 | #endif 20 | 21 | #if defined(__GNUC__) 22 | #define TOKEN_FILENAME "enclave.token" 23 | #define ENCLAVE_FILENAME "enclave.signed.so" 24 | #endif 25 | 26 | extern sgx_enclave_id_t global_eid; /* global enclave id */ 27 | 28 | #if defined(__cplusplus) 29 | extern "C" { 30 | #endif 31 | 32 | std::string GetPublicKeyBase64(void); 33 | void ActualMain(const char* dbPath); 34 | 35 | #if defined(__cplusplus) 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /applications/balance-checker/App/TrustedLibrary/kv_db.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "rocksdb/write_batch.h" 11 | 12 | template 13 | class KV_DB { 14 | public: 15 | KV_DB(const std::string& db_path) { 16 | rocksdb::Options options; 17 | options.create_if_missing = true; 18 | rocksdb::DB* rawDbPointer; 19 | rocksdb::Status status = rocksdb::DB::Open(options, db_path, &rawDbPointer); 20 | db_.reset(rawDbPointer); 21 | if (!status.ok()) { 22 | throw std::runtime_error("Unable to open/create database: " + 23 | status.ToString()); 24 | } 25 | 26 | // add a json meta data file under db_path to record the number of keys 27 | } 28 | 29 | void put(const K& key, const V& value) { 30 | rocksdb::Status status = 31 | db_->Put(rocksdb::WriteOptions(), serialize(key), serialize(value)); 32 | if (!status.ok()) { 33 | throw std::runtime_error("Write failed: " + status.ToString()); 34 | } 35 | } 36 | 37 | bool get(const K& key, V& value) { 38 | std::string valueStr; 39 | rocksdb::Status status = 40 | db_->Get(rocksdb::ReadOptions(), serialize(key), &valueStr); 41 | if (status.ok()) { 42 | value = deserialize(valueStr); 43 | return true; 44 | } else if (status.IsNotFound()) { 45 | return false; 46 | } else { 47 | throw std::runtime_error("Read failed: " + status.ToString()); 48 | } 49 | } 50 | 51 | bool get(const K& key, V& value, const V& defaultValue) { 52 | bool found = get(key, value); 53 | if (!found) { 54 | value = defaultValue; 55 | } 56 | return found; 57 | } 58 | 59 | bool del(const K& key) { 60 | rocksdb::Status status = db_->Delete(rocksdb::WriteOptions(), key); 61 | if (status.ok()) { 62 | return true; 63 | } else if (status.IsNotFound()) { 64 | return false; 65 | } else { 66 | throw std::runtime_error("Delete failed: " + status.ToString()); 67 | } 68 | } 69 | 70 | rocksdb::WriteBatch newWriteBatch() { return rocksdb::WriteBatch(); } 71 | 72 | void writeBatch(rocksdb::WriteBatch& batch) { 73 | rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch); 74 | if (!status.ok()) { 75 | throw std::runtime_error("Write failed: " + status.ToString()); 76 | } 77 | } 78 | 79 | class Iterator { 80 | public: 81 | Iterator(){}; 82 | 83 | Iterator(rocksdb::Iterator* it) : it_(it) {} 84 | 85 | bool isValid() const { return it_.get() && it_->Valid(); } 86 | 87 | void seekToFirst() { it_->SeekToFirst(); } 88 | 89 | void next() { it_->Next(); } 90 | 91 | K key() const { return deserialize(it_->key().ToString()); } 92 | 93 | V value() const { return deserialize(it_->value().ToString()); } 94 | 95 | void reset() { it_.reset(); } 96 | 97 | private: 98 | std::unique_ptr it_; 99 | }; 100 | 101 | Iterator getIterator() { 102 | return Iterator(db_->NewIterator(rocksdb::ReadOptions())); 103 | } 104 | 105 | private: 106 | std::unique_ptr db_; 107 | 108 | template 109 | std::string serialize(const T& value) { 110 | if constexpr (std::is_same_v) { 111 | return value; 112 | } 113 | std::ostringstream oss; 114 | oss << value; 115 | return oss.str(); 116 | } 117 | 118 | template 119 | static T deserialize(const std::string& str) { 120 | if constexpr (std::is_same_v) { 121 | return str; 122 | } 123 | std::istringstream iss(str); 124 | T value; 125 | iss >> value; 126 | return value; 127 | } 128 | }; -------------------------------------------------------------------------------- /applications/balance-checker/App/TrustedLibrary/lock_utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | bool lockFile(int fd) { 9 | struct flock fl; 10 | fl.l_type = F_WRLCK; // Write lock 11 | fl.l_whence = SEEK_SET; 12 | fl.l_start = 0; 13 | fl.l_len = 0; // Lock the whole file 14 | 15 | if (fcntl(fd, F_SETLKW, &fl) == -1) { 16 | std::cerr << "Error locking file: " << strerror(errno) << std::endl; 17 | return false; 18 | } 19 | 20 | return true; 21 | } 22 | 23 | bool unlockFile(int fd) { 24 | struct flock fl; 25 | fl.l_type = F_UNLCK; 26 | fl.l_whence = SEEK_SET; 27 | fl.l_start = 0; 28 | fl.l_len = 0; // Unlock the whole file 29 | 30 | if (fcntl(fd, F_SETLK, &fl) == -1) { 31 | std::cerr << "Error unlocking file: " << strerror(errno) << std::endl; 32 | return false; 33 | } 34 | 35 | return true; 36 | } 37 | 38 | // RAII wrapper for file locking 39 | class FileLocker { 40 | public: 41 | FileLocker(const std::string& path) : path_(path) { 42 | fd_ = open(path_.c_str(), O_RDWR); 43 | if (fd_ == -1) { 44 | std::cerr << "Error opening file: " << path << " " << strerror(errno) 45 | << std::endl; 46 | throw std::runtime_error("Error opening file"); 47 | } 48 | if (!lockFile(fd_)) { 49 | throw std::runtime_error("Error locking file"); 50 | } 51 | } 52 | 53 | int getFd() const { return fd_; } 54 | 55 | ~FileLocker() { 56 | if (!unlockFile(fd_)) { 57 | std::cerr << "Error unlocking file" << std::endl; 58 | } 59 | close(fd_); 60 | } 61 | 62 | private: 63 | std::string path_; 64 | int fd_; 65 | }; 66 | 67 | bool clearFile(int fileDescriptor) { 68 | if (ftruncate(fileDescriptor, 0) == -1) { 69 | std::cerr << "Failed to clear the file." << std::endl; 70 | return false; 71 | } 72 | return true; 73 | } 74 | 75 | #include 76 | class SemaphoreLock { 77 | public: 78 | explicit SemaphoreLock(std::counting_semaphore<>& semaphore) 79 | : sem(semaphore) { 80 | // Acquire a semaphore slot 81 | sem.acquire(); 82 | } 83 | 84 | ~SemaphoreLock() { 85 | // Release the semaphore slot 86 | sem.release(); 87 | } 88 | 89 | // Delete copy constructor and copy assignment operator 90 | SemaphoreLock(const SemaphoreLock&) = delete; 91 | SemaphoreLock& operator=(const SemaphoreLock&) = delete; 92 | 93 | // Define move constructor and move assignment operator, if needed 94 | 95 | private: 96 | std::counting_semaphore<>& sem; 97 | }; -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/Enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 0x4000000 6 | 0x1e8480000 7 | 1 8 | 1 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/Enclave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Enclave.h" 5 | #include "Enclave_t.h" 6 | 7 | void printf(const char *fmt, ...) 8 | { 9 | char buf[BUFSIZ] = {'\0'}; 10 | va_list ap; 11 | va_start(ap, fmt); 12 | vsnprintf(buf, BUFSIZ, fmt, ap); 13 | va_end(ap); 14 | ocall_print_string(buf); 15 | } 16 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/Enclave.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | from "TrustedLibrary/omap.edl" import *; 3 | from "sgx_tstdc.edl" import *; 4 | }; 5 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/Enclave.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #ifndef ENCLAVE_MODE_ENCLAVE 6 | #define ENCLAVE_MODE_ENCLAVE 7 | #endif 8 | #if defined(__cplusplus) 9 | extern "C" { 10 | #endif 11 | 12 | void printf(const char *fmt, ...); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/Enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /applications/balance-checker/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 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/TrustedLibrary/crypt.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../../common.hpp" 5 | #include "sgx_tcrypto.h" 6 | #include "sgx_tseal.h" 7 | sgx_status_t generate_key_pair(sgx_ec256_private_t* p_private, 8 | sgx_ec256_public_t* p_public) { 9 | sgx_ecc_state_handle_t ecc_handle; 10 | sgx_status_t status = sgx_ecc256_open_context(&ecc_handle); 11 | if (status != SGX_SUCCESS) { 12 | return status; 13 | } 14 | 15 | status = sgx_ecc256_create_key_pair(p_private, p_public, ecc_handle); 16 | sgx_ecc256_close_context(ecc_handle); 17 | 18 | return status; 19 | } 20 | 21 | sgx_status_t compute_shared_key(const sgx_ec256_private_t* p_private_b, 22 | const sgx_ec256_public_t* p_public_a, 23 | sgx_ec256_dh_shared_t* p_shared_key) { 24 | sgx_ecc_state_handle_t ecc_handle; 25 | sgx_status_t status = sgx_ecc256_open_context(&ecc_handle); 26 | if (status != SGX_SUCCESS) { 27 | return status; 28 | } 29 | 30 | status = sgx_ecc256_compute_shared_dhkey(p_private_b, p_public_a, 31 | p_shared_key, ecc_handle); 32 | sgx_ecc256_close_context(ecc_handle); 33 | 34 | return status; 35 | } 36 | 37 | ec256_public_t convert_to_ec256_public_t(const sgx_ec256_public_t& public_key) { 38 | ec256_public_t res; 39 | for (int i = 0; i < 32; ++i) { 40 | res.gx[i] = public_key.gx[31 - i]; 41 | res.gy[i] = public_key.gy[31 - i]; 42 | } 43 | return res; 44 | } 45 | 46 | sgx_ec256_public_t convert_to_sgx_ec256_public_t( 47 | const ec256_public_t& public_key_big_endian) { 48 | sgx_ec256_public_t res; 49 | for (int i = 0; i < 32; ++i) { 50 | res.gx[i] = public_key_big_endian.gx[31 - i]; 51 | res.gy[i] = public_key_big_endian.gy[31 - i]; 52 | } 53 | return res; 54 | } 55 | 56 | typedef sgx_ec256_private_t private_key_t; 57 | 58 | sgx_status_t seal_private_key(const private_key_t* private_key, 59 | uint8_t** sealed_blob_out, 60 | size_t* sealed_size_out) { 61 | sgx_status_t status; 62 | 63 | // Specify the key policy (e.g., MRENCLAVE or MRSIGNER) and the enclave's 64 | // execution attributes 65 | uint16_t key_policy = SGX_KEYPOLICY_MRENCLAVE; 66 | sgx_attributes_t attribute_mask = {SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG, 0}; 67 | sgx_misc_select_t misc_mask = 0; 68 | size_t private_key_size = sizeof(private_key_t); 69 | 70 | // Calculate the size of the sealed data 71 | uint32_t sealed_data_size = sgx_calc_sealed_data_size(0, private_key_size); 72 | if (sealed_data_size == UINT32_MAX) { 73 | return SGX_ERROR_UNEXPECTED; 74 | } 75 | 76 | // Allocate space for the sealed data 77 | sgx_sealed_data_t* sealed_data = (sgx_sealed_data_t*)malloc(sealed_data_size); 78 | if (!sealed_data) { 79 | return SGX_ERROR_OUT_OF_MEMORY; 80 | } 81 | 82 | // Seal the private key 83 | status = sgx_seal_data_ex(key_policy, attribute_mask, misc_mask, 0, NULL, 84 | private_key_size, (uint8_t*)private_key, 85 | sealed_data_size, sealed_data); 86 | if (status != SGX_SUCCESS) { 87 | free(sealed_data); 88 | return status; 89 | } 90 | 91 | // Set the output parameters 92 | *sealed_blob_out = (uint8_t*)sealed_data; 93 | *sealed_size_out = sealed_data_size; 94 | 95 | return SGX_SUCCESS; 96 | } 97 | 98 | sgx_status_t unseal_private_key(const uint8_t* sealed_data, 99 | size_t sealed_data_size, private_key_t* key) { 100 | sgx_status_t sgx_status; 101 | const sgx_sealed_data_t* sealed_blob = (const sgx_sealed_data_t*)sealed_data; 102 | uint32_t decrypted_data_len = sgx_get_encrypt_txt_len(sealed_blob); 103 | 104 | if (decrypted_data_len != sizeof(private_key_t)) return SGX_ERROR_UNEXPECTED; 105 | 106 | // Unseal the private key 107 | sgx_status = sgx_unseal_data(sealed_blob, NULL, NULL, (uint8_t*)key, 108 | &decrypted_data_len); 109 | if (SGX_SUCCESS != sgx_status) { 110 | return sgx_status; 111 | } 112 | 113 | return SGX_SUCCESS; 114 | } -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/TrustedLibrary/omap.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | include "sgx_report.h" 3 | trusted { 4 | public void ecall_omap_init(uint64_t N, uint64_t initSize); 5 | public int ecall_omap_find([in, count=keyLength] uint8_t* key, [out, count=valLength] uint8_t* val, uint32_t keyLength, uint32_t valLength); 6 | public int ecall_omap_insert([in, count=keyLength] uint8_t* key, [in, count=valLength] uint8_t* val, uint32_t keyLength, uint32_t valLength); 7 | public int ecall_omap_update([in, count=keyLength] uint8_t* key, [in, count=valLength] uint8_t* val, uint32_t keyLength, uint32_t valLength); 8 | public void ecall_set_last_block(uint64_t lastBlock); 9 | public int ecall_omap_delete([in, count=keyLength] uint8_t* key, uint32_t keyLength); 10 | public uint32_t ecall_gen_key_pair([out] uint8_t pubkey[64], [out] uint8_t sealedPrivKey[1024]); 11 | public int ecall_set_private_key([in, count=sealedPrivKeySize] uint8_t* sealedPrivKey, uint32_t sealedPrivKeySize); 12 | public void ecall_handle_encrypted_query([in, count=encryptedQueryLength] uint8_t* encryptedQuery, [out, count=encryptedResponseLength] uint8_t* encryptedResponse, uint32_t encryptedQueryLength, uint32_t encryptedResponseLength); 13 | public uint32_t enclave_create_report([in]const sgx_target_info_t* p_qe3_target, 14 | [in]const sgx_report_data_t* p_data, 15 | [out]sgx_report_t* p_report); 16 | }; 17 | 18 | untrusted { 19 | void ocall_FAIL(); 20 | void ocall_print_string([in, string] const char *str); 21 | uint64_t ocall_measure_time(); 22 | uint8_t* ocall_InitServer(uint64_t sizeOfT, uint64_t N_); 23 | void ocall_DeleteServer(); 24 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, uint64_t totalBytes, [in, count=batchSize] uint64_t* offsets, [out, count=totalBytes] uint8_t* buffer); 25 | void ocall_Read(uint64_t pos, uint64_t length, [out, count=length] uint8_t* page); 26 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, uint64_t totalBytes, [in, count=batchSize] uint64_t* offsets, [in, count=totalBytes] uint8_t* buffer); 27 | void ocall_Write(uint64_t pos, uint64_t length, [in, count=length] const uint8_t* page); 28 | uint64_t ocall_Fetch_Next_KV_Batch([out, count=batchBytes]uint8_t* data, uint64_t batchBytes); 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/bearssl/src/bearssl/codec/dec32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec32be(uint32_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec32be(buf); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/bearssl/src/bearssl/codec/enc32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc32be(void *dst, const uint32_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc32be(buf, *v ++); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/bearssl/src/bearssl/mac/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | static inline size_t 28 | block_size(const br_hash_class *dig) 29 | { 30 | unsigned ls; 31 | 32 | ls = (unsigned)(dig->desc >> BR_HASHDESC_LBLEN_OFF) 33 | & BR_HASHDESC_LBLEN_MASK; 34 | return (size_t)1 << ls; 35 | } 36 | 37 | static void 38 | process_key(const br_hash_class **hc, void *ks, 39 | const void *key, size_t key_len, unsigned bb) 40 | { 41 | unsigned char tmp[256]; 42 | size_t blen, u; 43 | 44 | blen = block_size(*hc); 45 | memcpy(tmp, key, key_len); 46 | for (u = 0; u < key_len; u ++) { 47 | tmp[u] ^= (unsigned char)bb; 48 | } 49 | memset(tmp + key_len, bb, blen - key_len); 50 | (*hc)->init(hc); 51 | (*hc)->update(hc, tmp, blen); 52 | (*hc)->state(hc, ks); 53 | } 54 | 55 | /* see bearssl.h */ 56 | void 57 | br_hmac_key_init(br_hmac_key_context *kc, 58 | const br_hash_class *dig, const void *key, size_t key_len) 59 | { 60 | br_hash_compat_context hc; 61 | unsigned char kbuf[64]; 62 | 63 | kc->dig_vtable = dig; 64 | hc.vtable = dig; 65 | if (key_len > block_size(dig)) { 66 | dig->init(&hc.vtable); 67 | dig->update(&hc.vtable, key, key_len); 68 | dig->out(&hc.vtable, kbuf); 69 | key = kbuf; 70 | key_len = br_digest_size(dig); 71 | } 72 | process_key(&hc.vtable, kc->ksi, key, key_len, 0x36); 73 | process_key(&hc.vtable, kc->kso, key, key_len, 0x5C); 74 | } 75 | 76 | /* see bearssl.h */ 77 | void 78 | br_hmac_init(br_hmac_context *ctx, 79 | const br_hmac_key_context *kc, size_t out_len) 80 | { 81 | const br_hash_class *dig; 82 | size_t blen, hlen; 83 | 84 | dig = kc->dig_vtable; 85 | blen = block_size(dig); 86 | dig->init(&ctx->dig.vtable); 87 | dig->set_state(&ctx->dig.vtable, kc->ksi, (uint64_t)blen); 88 | memcpy(ctx->kso, kc->kso, sizeof kc->kso); 89 | hlen = br_digest_size(dig); 90 | if (out_len > 0 && out_len < hlen) { 91 | hlen = out_len; 92 | } 93 | ctx->out_len = hlen; 94 | } 95 | 96 | /* see bearssl.h */ 97 | void 98 | br_hmac_update(br_hmac_context *ctx, const void *data, size_t len) 99 | { 100 | ctx->dig.vtable->update(&ctx->dig.vtable, data, len); 101 | } 102 | 103 | /* see bearssl.h */ 104 | size_t 105 | br_hmac_out(const br_hmac_context *ctx, void *out) 106 | { 107 | const br_hash_class *dig; 108 | br_hash_compat_context hc; 109 | unsigned char tmp[64]; 110 | size_t blen, hlen; 111 | 112 | dig = ctx->dig.vtable; 113 | dig->out(&ctx->dig.vtable, tmp); 114 | blen = block_size(dig); 115 | dig->init(&hc.vtable); 116 | dig->set_state(&hc.vtable, ctx->kso, (uint64_t)blen); 117 | hlen = br_digest_size(dig); 118 | dig->update(&hc.vtable, tmp, hlen); 119 | dig->out(&hc.vtable, tmp); 120 | memcpy(out, tmp, ctx->out_len); 121 | return ctx->out_len; 122 | } 123 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/bearssl/src/bearssl/rand/sysrng.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #define BR_ENABLE_INTRINSICS 1 26 | #include "inner.h" 27 | 28 | #if BR_USE_URANDOM 29 | #include 30 | #include 31 | #include 32 | #include 33 | #endif 34 | 35 | #if BR_USE_WIN32_RAND 36 | #include 37 | #include 38 | #pragma comment(lib, "advapi32") 39 | #endif 40 | 41 | #if BR_RDRAND 42 | BR_TARGETS_X86_UP 43 | BR_TARGET("rdrnd") 44 | static int 45 | seeder_rdrand(const br_prng_class **ctx) 46 | { 47 | unsigned char tmp[32]; 48 | size_t u; 49 | 50 | for (u = 0; u < sizeof tmp; u += sizeof(uint32_t)) { 51 | int j; 52 | uint32_t x; 53 | 54 | /* 55 | * We use the 32-bit intrinsic so that code is compatible 56 | * with both 32-bit and 64-bit architectures. 57 | * 58 | * Intel recommends trying at least 10 times in case of 59 | * failure. 60 | */ 61 | for (j = 0; j < 10; j ++) { 62 | if (_rdrand32_step(&x)) { 63 | goto next_word; 64 | } 65 | } 66 | return 0; 67 | next_word: 68 | br_enc32le(tmp + u, x); 69 | } 70 | (*ctx)->update(ctx, tmp, sizeof tmp); 71 | return 1; 72 | } 73 | BR_TARGETS_X86_DOWN 74 | 75 | static int 76 | rdrand_supported(void) 77 | { 78 | /* 79 | * The RDRND support is bit 30 of ECX, as returned by CPUID. 80 | */ 81 | return br_cpuid(0, 0, 0x40000000, 0); 82 | } 83 | 84 | #endif 85 | 86 | #if BR_USE_URANDOM 87 | static int 88 | seeder_urandom(const br_prng_class **ctx) 89 | { 90 | int f; 91 | 92 | f = open("/dev/urandom", O_RDONLY); 93 | if (f >= 0) { 94 | unsigned char tmp[32]; 95 | size_t u; 96 | 97 | for (u = 0; u < sizeof tmp;) { 98 | ssize_t len; 99 | 100 | len = read(f, tmp + u, (sizeof tmp) - u); 101 | if (len < 0) { 102 | if (errno == EINTR) { 103 | continue; 104 | } 105 | break; 106 | } 107 | u += (size_t)len; 108 | } 109 | close(f); 110 | if (u == sizeof tmp) { 111 | (*ctx)->update(ctx, tmp, sizeof tmp); 112 | return 1; 113 | } 114 | } 115 | return 0; 116 | } 117 | #endif 118 | 119 | #if BR_USE_WIN32_RAND 120 | static int 121 | seeder_win32(const br_prng_class **ctx) 122 | { 123 | HCRYPTPROV hp; 124 | 125 | if (CryptAcquireContext(&hp, 0, 0, PROV_RSA_FULL, 126 | CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 127 | { 128 | BYTE buf[32]; 129 | BOOL r; 130 | 131 | r = CryptGenRandom(hp, sizeof buf, buf); 132 | CryptReleaseContext(hp, 0); 133 | if (r) { 134 | (*ctx)->update(ctx, buf, sizeof buf); 135 | return 1; 136 | } 137 | } 138 | return 0; 139 | } 140 | #endif 141 | 142 | /* see bearssl_rand.h */ 143 | br_prng_seeder 144 | br_prng_seeder_system(const char **name) 145 | { 146 | #if BR_RDRAND 147 | if (rdrand_supported()) { 148 | if (name != NULL) { 149 | *name = "rdrand"; 150 | } 151 | return &seeder_rdrand; 152 | } 153 | #endif 154 | #if BR_USE_URANDOM 155 | if (name != NULL) { 156 | *name = "urandom"; 157 | } 158 | return &seeder_urandom; 159 | #elif BR_USE_WIN32_RAND 160 | if (name != NULL) { 161 | *name = "win32"; 162 | } 163 | return &seeder_win32; 164 | #endif 165 | if (name != NULL) { 166 | *name = "none"; 167 | } 168 | return 0; 169 | } 170 | -------------------------------------------------------------------------------- /applications/balance-checker/Enclave/bearssl/src/sgx-tcrypto-stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Open Whisper Systems 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * @author Jeff Griffin 20 | */ 21 | 22 | #include 23 | 24 | #include "sgx_error.h" 25 | 26 | sgx_status_t sgx_init_crypto_lib(uint64_t cpu_feature_indicator, uint32_t *cpuinfo_table) { 27 | return SGX_SUCCESS; 28 | } 29 | -------------------------------------------------------------------------------- /applications/balance-checker/README.txt: -------------------------------------------------------------------------------- 1 | --------------------------------------------- 2 | How to Build/Execute the Balance Checker sample program 3 | --------------------------------------------- 4 | 1. Install Intel(R) Software Guard Extensions (Intel(R) SGX) SDK for Linux* OS 5 | 2. Make sure your environment is set: 6 | $ source ${sgx-sdk-install-path}/environment 7 | 3. Build the project with the prepared Makefile: 8 | a. Simulation Mode, Debug build: 9 | $ make 10 | b. Hardware Mode, Pre-release build: 11 | $ make SGX_MODE=HW SGX_PRERELEASE=1 SGX_DEBUG=0 12 | c. Hardware Mode, Release build: 13 | $ make SGX_MODE=HW SGX_DEBUG=0 14 | d. Simulation Mode, Debug build: 15 | $ make SGX_MODE=SIM 16 | e. Simulation Mode, Pre-release build: 17 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 18 | f. Simulation Mode, Release build: 19 | $ make SGX_MODE=SIM SGX_DEBUG=0 20 | 4. Execute the binary directly: 21 | $ ./map.elf 22 | 5. Remember to "make clean" before switching build mode 23 | 6. To compile the client, run "make client" 24 | ------------------------------------------------- 25 | Launch token initialization 26 | ------------------------------------------------- 27 | If using libsgx-enclave-common or sgxpsw under version 2.4, an initialized variable launch_token needs to be passed as the 3rd parameter of API sgx_create_enclave. For example, 28 | 29 | sgx_launch_token_t launch_token = {0}; 30 | sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, launch_token, NULL, &global_eid, NULL); 31 | 32 | ------------------------------------------------- 33 | Run Example Testcases for Balance Checker application 34 | ------------------------------------------------- 35 | To launch the server, run: 36 | ./algo_runner.sh 37 | or to output directly to terminal 38 | ./algo_runner.sh 1 39 | 40 | To launch the client, run: 41 | ./client -------------------------------------------------------------------------------- /applications/balance-checker/algo_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source /startsgxenv.sh 3 | export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH 4 | 5 | cp ../../omap/common/encutils.cpp ./Enclave/TrustedLibrary/encutils.cpp 6 | 7 | 8 | SGX_MODE=HW # HW or SIM 9 | # g++ init_db_balance.cpp -o init_db_balance -L/usr/local/lib -lrocksdb 10 | # ./init_db_balance ./db ./rcc_balance.txt 11 | # ./init_db_balance ./db_usdt ./usdt_balance.txt 12 | # Algorithms: 13 | MIN_ENCLAVE_SIZE=16384 # enclave size in MB 14 | MAX_ENCLAVE_SIZE=16384 15 | TCS_NUM=2 16 | CORE_ID=0 # the cpu core id to run the program 17 | DISK_IO=0 # 0: no disk IO, 1: disk IO 18 | DB_PATH=./db_usdt 19 | 20 | if [ $SGX_MODE = HW ] 21 | then 22 | SGX_PRERELEASE=1 23 | else 24 | SGX_PRERELEASE=0 25 | fi 26 | 27 | if [ $DISK_IO = 1 ] 28 | then 29 | DISK_TAG=_DISK 30 | fi 31 | 32 | if [ $MAX_ENCLAVE_SIZE != 128 ] 33 | then 34 | ENCLAVE_SIZE_TAG=_${MIN_ENCLAVE_SIZE}_${MAX_ENCLAVE_SIZE} 35 | fi 36 | 37 | FILENAME=OMap${DISK_TAG}${ENCLAVE_SIZE_TAG}.out 38 | if [ -z "$1" ]; then 39 | rm -f $FILENAME 40 | echo "output to "${FILENAME} 41 | fi 42 | for (( encsize=$MIN_ENCLAVE_SIZE; encsize<=$MAX_ENCLAVE_SIZE; encsize*=2 )) 43 | do 44 | heapsizeB=$(( encsize * 1000000 )) 45 | hex_encsize=$(printf '%x\n' $heapsizeB) 46 | 47 | sed -i "/.*0x"${hex_encsize}"" ./Enclave/Enclave.config.xml 48 | 49 | make clean 50 | make SGX_MODE=$SGX_MODE SGX_PRERELEASE=$SGX_PRERELEASE DISK_IO=$DISK_IO ENCLAVE_SIZE=$encsize 51 | if [[ $1 = 1 ]]; then 52 | taskset -c ${CORE_ID} ./omap.elf $DB_PATH 53 | sleep 1 54 | else 55 | taskset -c ${CORE_ID} stdbuf -oL nohup ./omap.elf $DB_PATH &>> $FILENAME < /dev/null 56 | fi 57 | done 58 | 59 | sed -i '/.*0x7A00000' ./Enclave/Enclave.config.xml -------------------------------------------------------------------------------- /applications/balance-checker/initDB.sh: -------------------------------------------------------------------------------- 1 | export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH 2 | DBPath=db_usdt 3 | BalancePath=updated_usdt_balances.txt 4 | rm -r $DBPath 5 | g++ init_db_balance.cpp -o init_db_balance -L/usr/local/lib -lrocksdb 6 | ./init_db_balance $DBPath $BalancePath -------------------------------------------------------------------------------- /applications/balance-checker/init_db_balance: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/balance-checker/init_db_balance -------------------------------------------------------------------------------- /applications/balance-checker/init_db_balance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "App/TrustedLibrary/kv_db.hpp" 4 | 5 | using DB_ = KV_DB; 6 | 7 | void initFromBalanceFile(const char* DBPath, const char* balancePath) { 8 | DB_* db = new DB_(DBPath); 9 | std::ifstream balanceFile(balancePath); 10 | std::string line; 11 | uint64_t lastBlock = 0, lastTxIdx = 0, recordCount = 0; 12 | std::getline(balanceFile, line); 13 | std::cout << line << std::endl; 14 | std::istringstream iss(line); 15 | if (!(iss >> lastBlock >> lastTxIdx >> recordCount)) { 16 | printf("Error reading balance file meta data\n"); 17 | abort(); 18 | } 19 | printf("lastBlock = %lu, recordCount = %lu\n", lastBlock, recordCount); 20 | while (std::getline(balanceFile, line)) { 21 | std::istringstream iss(line); 22 | std::string addr; 23 | std::string balance; 24 | if (!(iss >> addr >> balance)) { 25 | printf("Error reading balance file\n"); 26 | abort(); 27 | } 28 | if (addr.size() != 42) { 29 | int padLen = 42 - addr.size(); 30 | addr.insert(2, padLen, '0'); 31 | } 32 | db->put(addr, balance); 33 | } 34 | db->put("lastBlock", std::to_string(lastBlock + 10)); 35 | db->put("lastTxIdx", std::to_string(lastTxIdx)); 36 | db->put("recordCount", std::to_string(recordCount)); 37 | delete db; 38 | } 39 | 40 | int main(int argc, char** argv) { 41 | if (argc != 3) { 42 | printf("Usage: %s \n", argv[0]); 43 | return 1; 44 | } 45 | initFromBalanceFile(argv[1], argv[2]); 46 | return 0; 47 | } -------------------------------------------------------------------------------- /applications/balance-checker/mock_server_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source /startsgxenv.sh 3 | export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH 4 | SGX_MODE=SIM # HW or SIM 5 | # g++ init_db_balance.cpp -o init_db_balance -L/usr/local/lib -lrocksdb 6 | # ./init_db_balance ./db ./rcc_balance.txt 7 | # ./init_db_balance ./db_usdt ./usdt_balance.txt 8 | # Algorithms: 9 | MIN_ENCLAVE_SIZE=8192 # enclave size in MB 10 | MAX_ENCLAVE_SIZE=8192 11 | TCS_NUM=1 12 | CORE_ID=0 # the cpu core id to run the program 13 | DISK_IO=0 # 0: no disk IO, 1: disk IO 14 | DB_PATH=./mock_db 15 | 16 | 17 | if [ $DISK_IO = 1 ] 18 | then 19 | DISK_TAG=_DISK 20 | fi 21 | 22 | if [ $MAX_ENCLAVE_SIZE != 128 ] 23 | then 24 | ENCLAVE_SIZE_TAG=_${MIN_ENCLAVE_SIZE}_${MAX_ENCLAVE_SIZE} 25 | fi 26 | 27 | 28 | FILENAME=OMap${IO_TAG}${DISK_TAG}${ENCLAVE_SIZE_TAG}.out 29 | if [ -z "$1" ]; then 30 | rm -f $FILENAME 31 | echo "output to "${FILENAME} 32 | fi 33 | for (( encsize=$MIN_ENCLAVE_SIZE; encsize<=$MAX_ENCLAVE_SIZE; encsize*=2 )) 34 | do 35 | heapsizeB=$(( encsize * 1000000 )) 36 | hex_encsize=$(printf '%x\n' $heapsizeB) 37 | 38 | sed -i "/.*0x"${hex_encsize}"" ./Enclave/Enclave.config.xml 39 | 40 | make clean 41 | make SGX_MODE=$SGX_MODE SGX_PRERELEASE=0 DISK_IO=$DISK_IO ENCLAVE_SIZE=$encsize 42 | if [[ $1 = 1 ]]; then 43 | ./omap.elf $DB_PATH 44 | sleep 1 45 | else 46 | stdbuf -o0 nohup ./omap.elf $DB_PATH &>> $FILENAME < /dev/null 47 | fi 48 | done 49 | 50 | sed -i '/.*0x7A00000' ./Enclave/Enclave.config.xml -------------------------------------------------------------------------------- /applications/balance-checker/retrieveTransfersState.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_scanned_block": 19983874, 3 | "blocks": {} 4 | } -------------------------------------------------------------------------------- /applications/balance-checker/update_balance.py: -------------------------------------------------------------------------------- 1 | # Read a txt file of erc20 balance till a certain block number and transaction id 2 | # Then read multiple log files of erc20 transfer events and update the balance 3 | # Finally, write the updated balance to a new txt file 4 | 5 | # The balance file should be in the following format: 6 | # 18784420 230 5574 7 | # 0xb0255cc0ad302545bd1dad0b39af5b1492f7a4b3 4348029885273000000000000 8 | # 0xab697d998be7d4a215b241a31b7fa8615cccea6a 1533670505197973256865817 9 | # ... 10 | # The first line is the block number, transaction id and the number of addresses 11 | # The following lines are the addresses and the balance 12 | 13 | # Each line of the log files should be in the following format: 14 | # 19094970 0x7822aa2b164b4b7dbb0a49dc8bde35b7275c30a23f59ad335a027dbb02a42e13 79 0x974caa59e49682cda0ad2bbe82983419a2ecc400 0x08ccadb7724eef6fa927796a120b87cd0c82addb 1159000000 2024-01-27T02:34:47 15 | # The first column is the block number, the second column is the transaction id, the third column is the log index, the fourth column is the from address, the fifth column is the to address, the sixth column is the amount, the seventh column is the timestamp 16 | # The log files are sorted by block number and transaction id 17 | # There could be duplicate lines in the log files, so if the block number is smaller than a previous line, the line should be ignored (if the block number is the same, compare the transaction id) 18 | 19 | # The updated balance file should be in the same format as the original balance file 20 | # The log files could be very large, so the program should be efficient (don't store the logs in memory, update the balance in a streaming fashion) 21 | 22 | def read_initial_balances(balance_file): 23 | with open(balance_file, 'r') as f: 24 | lines = f.readlines() 25 | 26 | metadata = lines[0].strip().split() 27 | balances = {} 28 | 29 | for line in lines[1:]: 30 | address, balance = line.strip().split() 31 | balances[int(address, 16)] = int(balance) 32 | 33 | return int(metadata[0]), int(metadata[1]), int(metadata[2]), balances 34 | 35 | def update_balances_from_logs(balance_file, log_files, updated_balance_file): 36 | # Read initial balances 37 | last_block_number, last_log_index, num_addresses, balances = read_initial_balances(balance_file) 38 | 39 | for log_file in log_files: 40 | with open(log_file, 'r') as f: 41 | for line in f: 42 | log_block_number, transaction_id, log_index, from_address, to_address, amount, timestamp = line.strip().split() 43 | from_address = int(from_address, 16) 44 | to_address = int(to_address, 16) 45 | log_block_number = int(log_block_number) 46 | log_index = int(log_index) 47 | # transaction_id = int(transaction_id) 48 | amount = int(amount) 49 | # Check if the log entry is relevant (i.e., after the last processed block/transaction) 50 | if log_block_number < last_block_number or (log_block_number == last_block_number and log_index <= last_log_index): 51 | continue 52 | 53 | # Update balances 54 | if from_address in balances: 55 | balances[from_address] -= amount 56 | else: 57 | balances[from_address] = -amount 58 | 59 | if to_address in balances: 60 | balances[to_address] += amount 61 | else: 62 | balances[to_address] = amount 63 | 64 | # Update last processed block and transaction ID 65 | last_block_number = log_block_number 66 | last_log_index = log_index 67 | 68 | # remove addresses with zero balance 69 | balances = {address: balance for address, balance in balances.items() if balance != 0} 70 | 71 | # Write updated balances to a new file, sorted by balance (descending) 72 | with open(updated_balance_file, 'w') as f: 73 | f.write(f"{last_block_number} {last_log_index} {len(balances)}\n") 74 | for address, balance in sorted(balances.items(), key=lambda x: x[1], reverse=True): 75 | f.write(f"{hex(address)} {balance}\n") 76 | 77 | # Example usage: 78 | balance_file = 'usdt_balance.txt' 79 | log_files = ['usdt_tx.log', 'usdt_tx2.log'] # List of log file paths 80 | updated_balance_file = 'updated_usdt_balances2.txt' 81 | 82 | update_balances_from_logs(balance_file, log_files, updated_balance_file) 83 | -------------------------------------------------------------------------------- /applications/cexample/README.txt: -------------------------------------------------------------------------------- 1 | # A simple example of linking our C++ library with the a C program 2 | 3 | Run at the root directory: 4 | 5 | ninja -C build 6 | ./build/applications/cexample/src/main -------------------------------------------------------------------------------- /applications/cexample/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(COMAP LANGUAGES C) 3 | 4 | set(CMAKE_C_STANDARD 99) 5 | 6 | # Add the executable 7 | add_executable(main test.c) 8 | 9 | # Link against the C++ library 10 | target_link_libraries(main PRIVATE oraminterface 11 | common) -------------------------------------------------------------------------------- /applications/cexample/src/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "interface/omap_c.h" 5 | 6 | void testOMap() { 7 | OblivMap omap = NewOblivMap(20, 32); 8 | InitEmpty(omap, 100); 9 | StartInit(omap, 100); 10 | uint8_t key[20] = {0}; 11 | uint8_t val[32] = {0}; 12 | memcpy(key, "key1", 4); 13 | memcpy(val, "val1", 4); 14 | Insert(omap, key, val); 15 | FinishInit(omap); 16 | memcpy(key, "key2", 4); 17 | memcpy(val, "val2", 4); 18 | Insert(omap, key, val); 19 | memcpy(key, "key1", 4); 20 | uint8_t val1[32] = {0}; 21 | Find(omap, key, val1); 22 | printf("val1: %s\n", val1); 23 | uint8_t val2[32] = {0}; 24 | memcpy(key, "key2", 4); 25 | Find(omap, key, val2); 26 | printf("val2: %s\n", val2); 27 | Destroy(omap); 28 | } 29 | 30 | int main() { 31 | testOMap(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /applications/goexample/.gitignore: -------------------------------------------------------------------------------- 1 | odsl/odsl.go -------------------------------------------------------------------------------- /applications/goexample/README.txt: -------------------------------------------------------------------------------- 1 | ------------------------------- 2 | Go Binding Example 3 | ------------------------------- 4 | This example shows how to compile the C++ codes into a shared library, and called by a Go program. Wrapper codes are generated using the Swig tool. 5 | 6 | 1. Make sure Go and Swig are installed. Change go.mod with the correct Go version. 7 | 2. Switch to the odsl folder. 8 | 3. Run $ source gen_binding.sh (you may need to run with sudo) 9 | 4. Run $ go test -------------------------------------------------------------------------------- /applications/goexample/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gty929/oram 2 | 3 | go 1.22 4 | 5 | require github.com/stretchr/testify v1.9.0 6 | 7 | require ( 8 | github.com/davecgh/go-spew v1.1.1 // indirect 9 | github.com/pmezard/go-difflib v1.0.0 // indirect 10 | gopkg.in/yaml.v3 v3.0.1 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /applications/goexample/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 6 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 7 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 8 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 9 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 10 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 11 | -------------------------------------------------------------------------------- /applications/goexample/odsl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(gobinding) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | # Find SWIG 7 | find_package(SWIG REQUIRED) 8 | include(${SWIG_USE_FILE}) 9 | include(cmake/bearssl.cmake) 10 | include(cmake/boost.cmake) 11 | 12 | # Set SWIG module and include directories 13 | set_source_files_properties(odsl.i PROPERTIES CPLUSPLUS ON) 14 | include_directories("../../../omap") 15 | set(CMAKE_SWIG_FLAGS "-c++" "-go" "-cgo" "-intgosize" "64") 16 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ") 17 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -ggdb -fno-inline -no-pie") 18 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native") 19 | 20 | 21 | 22 | set(CPP_PARENT_PATH "../../../omap") 23 | 24 | 25 | set(SOURCES odsl.i ${CPP_PARENT_PATH}/common/encutils.cpp ${CPP_PARENT_PATH}/common/tracing/tracer.cpp ${CPP_PARENT_PATH}/external_memory/server/serverBackend.cpp) 26 | 27 | # Add SWIG module 28 | swig_add_library(mylib TYPE SHARED LANGUAGE go SOURCES ${SOURCES}) 29 | 30 | # Set output name 31 | set_target_properties(mylib PROPERTIES OUTPUT_NAME "libodsl") 32 | 33 | # Set output directory 34 | set_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go) 35 | 36 | target_include_directories(mylib PUBLIC ${BEARSSL_INCLUDE_DIRS} ${BEARSSL_INCLUDE_DIRS}/bearssl) 37 | 38 | # Link SWIG module and additional sources 39 | target_link_libraries(mylib INTERFACE dl ${BEARSSL_LIBRARY}) 40 | 41 | # Generate Ninja build files 42 | set_property(TARGET mylib PROPERTY SWIG_GENERATED TRUE) 43 | set_property(SOURCE odsl.i PROPERTY GENERATED TRUE) 44 | -------------------------------------------------------------------------------- /applications/goexample/odsl/cmake/bearssl.cmake: -------------------------------------------------------------------------------- 1 | find_path(BEARSSL_INCLUDE_DIRS bearssl.h) 2 | 3 | find_library(BEARSSL_LIBRARY bearssl) 4 | 5 | include(FindPackageHandleStandardArgs) 6 | find_package_handle_standard_args(BEARSSL DEFAULT_MSG 7 | BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY) 8 | 9 | mark_as_advanced(BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY) -------------------------------------------------------------------------------- /applications/goexample/odsl/cmake/boost.cmake: -------------------------------------------------------------------------------- 1 | find_library(BOOST_STACKTRACE_BACKTRACE_LIBRARY NAMES boost_stacktrace_backtrace) 2 | 3 | include (GNUInstallDirs) 4 | 5 | macro(linkstacktrace arg0) 6 | if (UNIX) 7 | message(STATUS "Using Boost::stacktrace/addr2line") 8 | target_compile_definitions(${arg0} PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 9 | target_link_libraries(${arg0} PRIVATE dl) 10 | elseif (MINGW AND BOOST_STACKTRACE_BACKTRACE_LIBRARY) 11 | message(STATUS "Using Boost::stacktrace/backtrace") 12 | target_compile_definitions(${arg0} PRIVATE BOOST_STACKTRACE_USE_BACKTRACE) 13 | target_link_libraries(${arg0} PRIVATE boost_stacktrace_backtrace backtrace) 14 | else () 15 | message(STATUS "Using Boost::stacktrace/basic") 16 | endif () 17 | endmacro() 18 | -------------------------------------------------------------------------------- /applications/goexample/odsl/gen_binding.sh: -------------------------------------------------------------------------------- 1 | rm -rf build # Needed after the CC/CXX export or after changing the CMAKE_BUILD_TYPE 2 | export CC=/usr/bin/gcc 3 | export CXX=/usr/bin/g++ 4 | cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release 5 | ninja -C build 6 | cp build/odsl.go odsl.go 7 | LD_PATH=/usr/local/lib/ 8 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LD_PATH 9 | sudo cp go/libodsl.so $LD_PATH 10 | cp go/libodsl.so $LD_PATH -------------------------------------------------------------------------------- /applications/goexample/odsl/odsl.i: -------------------------------------------------------------------------------- 1 | %module odsl 2 | %{ 3 | #include "stdint.h" 4 | #include "interface/common_impl.hpp" 5 | #include "interface/omap_generic_impl.hpp" 6 | #include "interface/par_omap_impl.hpp" 7 | #include "interface/recoram_impl.hpp" 8 | %} 9 | 10 | /* Let's just grab the original header file here */ 11 | %include 12 | %include "interface/common_interface.hpp" 13 | %include "interface/omap_generic_interface.hpp" 14 | %include "interface/par_omap_interface.hpp" 15 | %include "interface/recoram_interface.hpp" 16 | %template(OMapBinding) OMapGenericBinding<8, 8>; 17 | %insert(cgo_comment_typedefs) %{ 18 | #cgo LDFLAGS: -lodsl -lbearssl -lstdc++ 19 | %} -------------------------------------------------------------------------------- /applications/goexample/odsl/odsl_test.go: -------------------------------------------------------------------------------- 1 | package odsl 2 | 3 | import ( 4 | "testing" 5 | "unsafe" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestORAM(t *testing.T) { 11 | var oram ORAMBinding 12 | oram = NewORAMBinding() 13 | oram.InitORAM(1000) 14 | oram.Write(1, 2) 15 | val := oram.Read(1) 16 | assert.Equal(t, uint64(2), val) 17 | } 18 | 19 | func getUintPtr(num *uint64) uintptr { 20 | return uintptr(unsafe.Pointer(num)) 21 | } 22 | 23 | func TestOMap(t *testing.T) { 24 | var omap OMapBinding 25 | omap = NewOMapBinding() 26 | omap.InitEmpty(1000) 27 | key := uint64(1) 28 | val := uint64(2) 29 | omap.Insert(getUintPtr(&key), getUintPtr(&val)) 30 | var findRes uint64 31 | foundFlag := omap.Find(getUintPtr(&key), getUintPtr(&findRes)) 32 | assert.Equal(t, true, foundFlag) 33 | assert.Equal(t, uint64(2), findRes) 34 | } 35 | 36 | func TestParOMap(t *testing.T) { 37 | var paromap ParOMapBinding 38 | paromap = NewParOMapBinding() 39 | paromap.InitEmpty(1000, 4) 40 | keys := []uint64{1, 2, 3, 4, 5} 41 | vals := []uint64{10, 20, 30, 40, 50} 42 | foundFlags := []bool{false, false, false, false, false} 43 | paromap.InsertBatch(5, &keys[0], &vals[0], &foundFlags[0]) 44 | for i := 0; i < 5; i++ { 45 | assert.Equal(t, false, foundFlags[i]) 46 | } 47 | searchKeys := []uint64{3, 6, 5} 48 | searchVals := []uint64{0, 0, 0} 49 | foundFlags = []bool{false, false, false} 50 | paromap.FindBatch(3, &searchKeys[0], &searchVals[0], &foundFlags[0]) 51 | assert.Equal(t, true, foundFlags[0]) 52 | assert.Equal(t, uint64(30), searchVals[0]) 53 | assert.Equal(t, false, foundFlags[1]) 54 | assert.Equal(t, true, foundFlags[2]) 55 | assert.Equal(t, uint64(50), searchVals[2]) 56 | } 57 | -------------------------------------------------------------------------------- /applications/omap/App/App.cpp: -------------------------------------------------------------------------------- 1 | #include "App.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Enclave_u.h" 10 | #include "sgx_urts.h" 11 | 12 | /* Global EID shared by multiple threads */ 13 | sgx_enclave_id_t global_eid = 0; 14 | 15 | typedef struct _sgx_errlist_t { 16 | sgx_status_t err; 17 | const char *msg; 18 | const char *sug; /* Suggestion */ 19 | } sgx_errlist_t; 20 | 21 | /* Error code returned by sgx_create_enclave */ 22 | static sgx_errlist_t sgx_errlist[] = { 23 | {SGX_ERROR_UNEXPECTED, "Unexpected error occurred.", NULL}, 24 | {SGX_ERROR_INVALID_PARAMETER, "Invalid parameter.", NULL}, 25 | {SGX_ERROR_OUT_OF_MEMORY, "Out of memory.", NULL}, 26 | {SGX_ERROR_ENCLAVE_LOST, "Power transition occurred.", 27 | "Please refer to the sample \"PowerTransition\" for details."}, 28 | {SGX_ERROR_INVALID_ENCLAVE, "Invalid enclave image.", NULL}, 29 | {SGX_ERROR_INVALID_ENCLAVE_ID, "Invalid enclave identification.", NULL}, 30 | {SGX_ERROR_INVALID_SIGNATURE, "Invalid enclave signature.", NULL}, 31 | {SGX_ERROR_OUT_OF_EPC, "Out of EPC memory.", NULL}, 32 | {SGX_ERROR_NO_DEVICE, "Invalid SGX device.", 33 | "Please make sure SGX module is enabled in the BIOS, and install SGX " 34 | "driver afterwards."}, 35 | {SGX_ERROR_MEMORY_MAP_CONFLICT, "Memory map conflicted.", NULL}, 36 | {SGX_ERROR_INVALID_METADATA, "Invalid enclave metadata.", NULL}, 37 | {SGX_ERROR_DEVICE_BUSY, "SGX device was busy.", NULL}, 38 | {SGX_ERROR_INVALID_VERSION, "Enclave version was invalid.", NULL}, 39 | {SGX_ERROR_INVALID_ATTRIBUTE, "Enclave was not authorized.", NULL}, 40 | {SGX_ERROR_ENCLAVE_FILE_ACCESS, "Can't open enclave file.", NULL}, 41 | {SGX_ERROR_NDEBUG_ENCLAVE, 42 | "The enclave is signed as product enclave, and can not be created as " 43 | "debuggable enclave.", 44 | NULL}, 45 | }; 46 | 47 | /* Check error conditions for loading enclave */ 48 | void print_error_message(sgx_status_t ret) { 49 | size_t idx = 0; 50 | size_t ttl = sizeof sgx_errlist / sizeof sgx_errlist[0]; 51 | 52 | for (idx = 0; idx < ttl; idx++) { 53 | if (ret == sgx_errlist[idx].err) { 54 | if (NULL != sgx_errlist[idx].sug) 55 | printf("Info: %s\n", sgx_errlist[idx].sug); 56 | printf("Error: %s\n", sgx_errlist[idx].msg); 57 | break; 58 | } 59 | } 60 | 61 | if (idx == ttl) printf("Error: Unexpected error occurred.\n"); 62 | } 63 | 64 | /* Initialize the enclave: 65 | * Call sgx_create_enclave to initialize an enclave instance 66 | */ 67 | int initialize_enclave(void) { 68 | sgx_status_t ret = SGX_ERROR_UNEXPECTED; 69 | 70 | /* Call sgx_create_enclave to initialize an enclave instance */ 71 | /* Debug Support: set 2nd parameter to 1 */ 72 | ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, NULL, NULL, 73 | &global_eid, NULL); 74 | if (ret != SGX_SUCCESS) { 75 | print_error_message(ret); 76 | return -1; 77 | } 78 | 79 | return 0; 80 | } 81 | 82 | /* OCall functions */ 83 | void ocall_print_string(const char *str) { 84 | /* Proxy/Bridge will check the length and null-terminate 85 | * the input string to prevent buffer overflow. 86 | */ 87 | printf("%s", str); 88 | } 89 | 90 | void ocall_FAIL() { 91 | printf("Called FAIL oCall\n"); 92 | exit(-1); 93 | } 94 | 95 | #include 96 | 97 | uint64_t ocall_measure_time(void) { 98 | // returns linux-epoch-time in nanoseconds. 99 | auto now_c = std::chrono::system_clock::now(); 100 | uint64_t ret = now_c.time_since_epoch().count(); 101 | return ret; 102 | } 103 | 104 | /* Application entry */ 105 | int SGX_CDECL main(int argc, char *argv[]) { 106 | (void)(argc); 107 | (void)(argv); 108 | 109 | /* Initialize the enclave */ 110 | if (initialize_enclave() < 0) { 111 | printf("Enter a character before exit ...\n"); 112 | getchar(); 113 | return -1; 114 | } 115 | 116 | /* Utilize trusted libraries */ 117 | ActualMain(); 118 | 119 | /* Destroy the enclave */ 120 | sgx_destroy_enclave(global_eid); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /applications/omap/App/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sgx_eid.h" 9 | #include "sgx_error.h" 10 | 11 | #ifndef TRUE 12 | #define TRUE 1 13 | #endif 14 | 15 | #ifndef FALSE 16 | #define FALSE 0 17 | #endif 18 | 19 | #if defined(__GNUC__) 20 | #define TOKEN_FILENAME "enclave.token" 21 | #define ENCLAVE_FILENAME "enclave.signed.so" 22 | #endif 23 | 24 | extern sgx_enclave_id_t global_eid; /* global enclave id */ 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | void ActualMain(void); 31 | 32 | #if defined(__cplusplus) 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /applications/omap/App/TrustedLibrary/Libcxx.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "../App.h" 6 | #include "Enclave_u.h" 7 | #ifdef DISK_IO 8 | #include "external_memory/server/enclaveFileServer_untrusted.hpp" 9 | #else 10 | #include "external_memory/server/enclaveMemServer_untrusted.hpp" 11 | #endif 12 | 13 | void ActualMain(void) { 14 | sgx_status_t ret = SGX_ERROR_UNEXPECTED; 15 | 16 | ret = ecall_omap_perf(global_eid); 17 | 18 | if (ret != SGX_SUCCESS) abort(); 19 | 20 | // printf("Did not abort\n"); 21 | } 22 | -------------------------------------------------------------------------------- /applications/omap/Enclave/Enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 0x500000 6 | 0x7A00000 7 | 1 8 | 1 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /applications/omap/Enclave/Enclave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Enclave.h" 5 | #include "Enclave_t.h" 6 | 7 | void printf(const char *fmt, ...) 8 | { 9 | char buf[BUFSIZ] = {'\0'}; 10 | va_list ap; 11 | va_start(ap, fmt); 12 | vsnprintf(buf, BUFSIZ, fmt, ap); 13 | va_end(ap); 14 | ocall_print_string(buf); 15 | } 16 | -------------------------------------------------------------------------------- /applications/omap/Enclave/Enclave.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | from "TrustedLibrary/omap.edl" import *; 3 | from "sgx_tstdc.edl" import *; 4 | from "sgx_pthread.edl" import *; 5 | from "sgx_tswitchless.edl" import *; 6 | }; 7 | -------------------------------------------------------------------------------- /applications/omap/Enclave/Enclave.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #ifndef ENCLAVE_MODE_ENCLAVE 6 | #define ENCLAVE_MODE_ENCLAVE 7 | #endif 8 | #if defined(__cplusplus) 9 | extern "C" { 10 | #endif 11 | 12 | void printf(const char *fmt, ...); 13 | 14 | #if defined(__cplusplus) 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /applications/omap/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 | -------------------------------------------------------------------------------- /applications/omap/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 | -------------------------------------------------------------------------------- /applications/omap/Enclave/TrustedLibrary/omap.edl: -------------------------------------------------------------------------------- 1 | enclave { 2 | trusted { 3 | public void ecall_omap(void); 4 | public void ecall_omap_perf(void); 5 | }; 6 | 7 | untrusted { 8 | void ocall_FAIL(); 9 | void ocall_print_string([in, string] const char *str); 10 | uint64_t ocall_measure_time(); 11 | uint8_t* ocall_InitServer(uint64_t sizeOfT, uint64_t N_); 12 | void ocall_DeleteServer(); 13 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, uint64_t totalBytes, [in, count=batchSize] uint64_t* offsets, [out, count=totalBytes] uint8_t* buffer); 14 | void ocall_Read(uint64_t pos, uint64_t length, [out, count=length] uint8_t* page); 15 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, uint64_t totalBytes, [in, count=batchSize] uint64_t* offsets, [in, count=totalBytes] uint8_t* buffer); 16 | void ocall_Write(uint64_t pos, uint64_t length, [in, count=length] const uint8_t* page); 17 | }; 18 | }; 19 | -------------------------------------------------------------------------------- /applications/omap/Enclave/bearssl/src/bearssl/codec/dec32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_dec32be(uint32_t *v, size_t num, const void *src) 30 | { 31 | const unsigned char *buf; 32 | 33 | buf = src; 34 | while (num -- > 0) { 35 | *v ++ = br_dec32be(buf); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /applications/omap/Enclave/bearssl/src/bearssl/codec/enc32be.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | /* see inner.h */ 28 | void 29 | br_range_enc32be(void *dst, const uint32_t *v, size_t num) 30 | { 31 | unsigned char *buf; 32 | 33 | buf = dst; 34 | while (num -- > 0) { 35 | br_enc32be(buf, *v ++); 36 | buf += 4; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /applications/omap/Enclave/bearssl/src/bearssl/mac/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "inner.h" 26 | 27 | static inline size_t 28 | block_size(const br_hash_class *dig) 29 | { 30 | unsigned ls; 31 | 32 | ls = (unsigned)(dig->desc >> BR_HASHDESC_LBLEN_OFF) 33 | & BR_HASHDESC_LBLEN_MASK; 34 | return (size_t)1 << ls; 35 | } 36 | 37 | static void 38 | process_key(const br_hash_class **hc, void *ks, 39 | const void *key, size_t key_len, unsigned bb) 40 | { 41 | unsigned char tmp[256]; 42 | size_t blen, u; 43 | 44 | blen = block_size(*hc); 45 | memcpy(tmp, key, key_len); 46 | for (u = 0; u < key_len; u ++) { 47 | tmp[u] ^= (unsigned char)bb; 48 | } 49 | memset(tmp + key_len, bb, blen - key_len); 50 | (*hc)->init(hc); 51 | (*hc)->update(hc, tmp, blen); 52 | (*hc)->state(hc, ks); 53 | } 54 | 55 | /* see bearssl.h */ 56 | void 57 | br_hmac_key_init(br_hmac_key_context *kc, 58 | const br_hash_class *dig, const void *key, size_t key_len) 59 | { 60 | br_hash_compat_context hc; 61 | unsigned char kbuf[64]; 62 | 63 | kc->dig_vtable = dig; 64 | hc.vtable = dig; 65 | if (key_len > block_size(dig)) { 66 | dig->init(&hc.vtable); 67 | dig->update(&hc.vtable, key, key_len); 68 | dig->out(&hc.vtable, kbuf); 69 | key = kbuf; 70 | key_len = br_digest_size(dig); 71 | } 72 | process_key(&hc.vtable, kc->ksi, key, key_len, 0x36); 73 | process_key(&hc.vtable, kc->kso, key, key_len, 0x5C); 74 | } 75 | 76 | /* see bearssl.h */ 77 | void 78 | br_hmac_init(br_hmac_context *ctx, 79 | const br_hmac_key_context *kc, size_t out_len) 80 | { 81 | const br_hash_class *dig; 82 | size_t blen, hlen; 83 | 84 | dig = kc->dig_vtable; 85 | blen = block_size(dig); 86 | dig->init(&ctx->dig.vtable); 87 | dig->set_state(&ctx->dig.vtable, kc->ksi, (uint64_t)blen); 88 | memcpy(ctx->kso, kc->kso, sizeof kc->kso); 89 | hlen = br_digest_size(dig); 90 | if (out_len > 0 && out_len < hlen) { 91 | hlen = out_len; 92 | } 93 | ctx->out_len = hlen; 94 | } 95 | 96 | /* see bearssl.h */ 97 | void 98 | br_hmac_update(br_hmac_context *ctx, const void *data, size_t len) 99 | { 100 | ctx->dig.vtable->update(&ctx->dig.vtable, data, len); 101 | } 102 | 103 | /* see bearssl.h */ 104 | size_t 105 | br_hmac_out(const br_hmac_context *ctx, void *out) 106 | { 107 | const br_hash_class *dig; 108 | br_hash_compat_context hc; 109 | unsigned char tmp[64]; 110 | size_t blen, hlen; 111 | 112 | dig = ctx->dig.vtable; 113 | dig->out(&ctx->dig.vtable, tmp); 114 | blen = block_size(dig); 115 | dig->init(&hc.vtable); 116 | dig->set_state(&hc.vtable, ctx->kso, (uint64_t)blen); 117 | hlen = br_digest_size(dig); 118 | dig->update(&hc.vtable, tmp, hlen); 119 | dig->out(&hc.vtable, tmp); 120 | memcpy(out, tmp, ctx->out_len); 121 | return ctx->out_len; 122 | } 123 | -------------------------------------------------------------------------------- /applications/omap/Enclave/bearssl/src/bearssl/rand/sysrng.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Thomas Pornin 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #define BR_ENABLE_INTRINSICS 1 26 | #include "inner.h" 27 | 28 | #if BR_USE_URANDOM 29 | #include 30 | #include 31 | #include 32 | #include 33 | #endif 34 | 35 | #if BR_USE_WIN32_RAND 36 | #include 37 | #include 38 | #pragma comment(lib, "advapi32") 39 | #endif 40 | 41 | #if BR_RDRAND 42 | BR_TARGETS_X86_UP 43 | BR_TARGET("rdrnd") 44 | static int 45 | seeder_rdrand(const br_prng_class **ctx) 46 | { 47 | unsigned char tmp[32]; 48 | size_t u; 49 | 50 | for (u = 0; u < sizeof tmp; u += sizeof(uint32_t)) { 51 | int j; 52 | uint32_t x; 53 | 54 | /* 55 | * We use the 32-bit intrinsic so that code is compatible 56 | * with both 32-bit and 64-bit architectures. 57 | * 58 | * Intel recommends trying at least 10 times in case of 59 | * failure. 60 | */ 61 | for (j = 0; j < 10; j ++) { 62 | if (_rdrand32_step(&x)) { 63 | goto next_word; 64 | } 65 | } 66 | return 0; 67 | next_word: 68 | br_enc32le(tmp + u, x); 69 | } 70 | (*ctx)->update(ctx, tmp, sizeof tmp); 71 | return 1; 72 | } 73 | BR_TARGETS_X86_DOWN 74 | 75 | static int 76 | rdrand_supported(void) 77 | { 78 | /* 79 | * The RDRND support is bit 30 of ECX, as returned by CPUID. 80 | */ 81 | return br_cpuid(0, 0, 0x40000000, 0); 82 | } 83 | 84 | #endif 85 | 86 | #if BR_USE_URANDOM 87 | static int 88 | seeder_urandom(const br_prng_class **ctx) 89 | { 90 | int f; 91 | 92 | f = open("/dev/urandom", O_RDONLY); 93 | if (f >= 0) { 94 | unsigned char tmp[32]; 95 | size_t u; 96 | 97 | for (u = 0; u < sizeof tmp;) { 98 | ssize_t len; 99 | 100 | len = read(f, tmp + u, (sizeof tmp) - u); 101 | if (len < 0) { 102 | if (errno == EINTR) { 103 | continue; 104 | } 105 | break; 106 | } 107 | u += (size_t)len; 108 | } 109 | close(f); 110 | if (u == sizeof tmp) { 111 | (*ctx)->update(ctx, tmp, sizeof tmp); 112 | return 1; 113 | } 114 | } 115 | return 0; 116 | } 117 | #endif 118 | 119 | #if BR_USE_WIN32_RAND 120 | static int 121 | seeder_win32(const br_prng_class **ctx) 122 | { 123 | HCRYPTPROV hp; 124 | 125 | if (CryptAcquireContext(&hp, 0, 0, PROV_RSA_FULL, 126 | CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 127 | { 128 | BYTE buf[32]; 129 | BOOL r; 130 | 131 | r = CryptGenRandom(hp, sizeof buf, buf); 132 | CryptReleaseContext(hp, 0); 133 | if (r) { 134 | (*ctx)->update(ctx, buf, sizeof buf); 135 | return 1; 136 | } 137 | } 138 | return 0; 139 | } 140 | #endif 141 | 142 | /* see bearssl_rand.h */ 143 | br_prng_seeder 144 | br_prng_seeder_system(const char **name) 145 | { 146 | #if BR_RDRAND 147 | if (rdrand_supported()) { 148 | if (name != NULL) { 149 | *name = "rdrand"; 150 | } 151 | return &seeder_rdrand; 152 | } 153 | #endif 154 | #if BR_USE_URANDOM 155 | if (name != NULL) { 156 | *name = "urandom"; 157 | } 158 | return &seeder_urandom; 159 | #elif BR_USE_WIN32_RAND 160 | if (name != NULL) { 161 | *name = "win32"; 162 | } 163 | return &seeder_win32; 164 | #endif 165 | if (name != NULL) { 166 | *name = "none"; 167 | } 168 | return 0; 169 | } 170 | -------------------------------------------------------------------------------- /applications/omap/Enclave/bearssl/src/sgx-tcrypto-stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Open Whisper Systems 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Affero General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Affero General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * @author Jeff Griffin 20 | */ 21 | 22 | #include 23 | 24 | #include "sgx_error.h" 25 | 26 | sgx_status_t sgx_init_crypto_lib(uint64_t cpu_feature_indicator, uint32_t *cpuinfo_table) { 27 | return SGX_SUCCESS; 28 | } 29 | -------------------------------------------------------------------------------- /applications/omap/README.txt: -------------------------------------------------------------------------------- 1 | --------------------------------------------- 2 | How to Build/Execute the OMap sample program 3 | --------------------------------------------- 4 | 1. Install Intel(R) Software Guard Extensions (Intel(R) SGX) SDK for Linux* OS 5 | 2. Make sure your environment is set: 6 | $ source ${sgx-sdk-install-path}/environment 7 | 3. Build the project with the prepared Makefile: 8 | a. Simulation Mode, Debug build: 9 | $ make 10 | b. Hardware Mode, Pre-release build: 11 | $ make SGX_MODE=HW SGX_PRERELEASE=1 SGX_DEBUG=0 12 | c. Hardware Mode, Release build: 13 | $ make SGX_MODE=HW SGX_DEBUG=0 14 | d. Simulation Mode, Debug build: 15 | $ make SGX_MODE=SIM 16 | e. Simulation Mode, Pre-release build: 17 | $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 18 | f. Simulation Mode, Release build: 19 | $ make SGX_MODE=SIM SGX_DEBUG=0 20 | 4. Execute the binary directly: 21 | $ ./sort.elf 22 | 5. Remember to "make clean" before switching build mode 23 | 24 | ------------------------------------------------- 25 | Launch token initialization 26 | ------------------------------------------------- 27 | If using libsgx-enclave-common or sgxpsw under version 2.4, an initialized variable launch_token needs to be passed as the 3rd parameter of API sgx_create_enclave. For example, 28 | 29 | sgx_launch_token_t launch_token = {0}; 30 | sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, launch_token, NULL, &global_eid, NULL); 31 | 32 | ------------------------------------------------- 33 | Run Example Testcases for OMap algorithms 34 | ------------------------------------------------- 35 | ./algo_runner.sh 36 | or to output directly to terminal 37 | ./algo_runner.sh 1 -------------------------------------------------------------------------------- /applications/omap/algo_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source /startsgxenv.sh 3 | 4 | cp ../../omap/common/encutils.cpp ./Enclave/TrustedLibrary/encutils.cpp 5 | 6 | SGX_MODE=SIM # HW or SIM 7 | 8 | # Algorithms: 9 | MIN_ENCLAVE_SIZE=8192 # enclave size in MB 10 | MAX_ENCLAVE_SIZE=8192 11 | CORE_ID=5 # the cpu core id to run the program 12 | DISK_IO=0 # 0: no disk IO, 1: disk IO 13 | TCS_NUM=2 14 | 15 | if [ $SGX_MODE = HW ] 16 | then 17 | SGX_PRERELEASE=1 18 | else 19 | SGX_PRERELEASE=0 20 | fi 21 | 22 | if [ $DISK_IO = 1 ] 23 | then 24 | DISK_TAG=_DISK 25 | fi 26 | 27 | if [ $MAX_ENCLAVE_SIZE != 128 ] 28 | then 29 | ENCLAVE_SIZE_TAG=_${MIN_ENCLAVE_SIZE}_${MAX_ENCLAVE_SIZE} 30 | fi 31 | 32 | 33 | FILENAME=OMap${IO_TAG}${DISK_TAG}${ENCLAVE_SIZE_TAG}.out 34 | if [ -z "$1" ]; then 35 | rm -f $FILENAME 36 | echo "output to "${FILENAME} 37 | fi 38 | for (( encsize=$MIN_ENCLAVE_SIZE; encsize<=$MAX_ENCLAVE_SIZE; encsize*=2 )) 39 | do 40 | heapsizeB=$(( encsize * 1048576 )) 41 | hex_encsize=$(printf '%x\n' $heapsizeB) 42 | 43 | sed -i "/.*0x"${hex_encsize}"" ./Enclave/Enclave.config.xml 44 | 45 | sed -i "/.*"${TCS_NUM}"" ./Enclave/Enclave.config.xml 46 | 47 | make clean 48 | make SGX_MODE=$SGX_MODE SGX_PRERELEASE=$SGX_PRERELEASE DISK_IO=$DISK_IO ENCLAVE_SIZE=$encsize TCS_NUM=$TCS_NUM 49 | if [[ $1 = 1 ]]; then 50 | ./omap.elf 51 | sleep 1 52 | else 53 | stdbuf -oL nohup ./omap.elf &>> $FILENAME < /dev/null 54 | fi 55 | done 56 | 57 | sed -i '/.*0x7A00000' ./Enclave/Enclave.config.xml 58 | sed -i "/.*1" ./Enclave/Enclave.config.xml -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_200000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_200000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWrite/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_200000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_200000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Actual_Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_200000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_200000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20DeferWriteParBitonic/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_200000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_200000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromEmpty/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20FromExist/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20SingleThread/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20SingleThread/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20SingleThread/Throughput.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/erc20SingleThread/Throughput.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/erc20SingleThread/omapPerf200g.txt: -------------------------------------------------------------------------------- 1 | mapSize = 100000, threadCount = 1, batchSize = 1 2 | oram init time 0.312021 s 3 | oram insert time 22.741879 us 4 | oram find time 21.776734 us 5 | oram erase time 21.599045 us 6 | mapSize = 200000, threadCount = 1, batchSize = 1 7 | oram init time 0.655446 s 8 | oram insert time 22.767815 us 9 | oram find time 22.909287 us 10 | oram erase time 22.690901 us 11 | mapSize = 500000, threadCount = 1, batchSize = 1 12 | oram init time 1.763373 s 13 | oram insert time 24.734756 us 14 | oram find time 24.869702 us 15 | oram erase time 24.621800 us 16 | mapSize = 1000000, threadCount = 1, batchSize = 1 17 | oram init time 3.645635 s 18 | oram insert time 26.320362 us 19 | oram find time 26.680198 us 20 | oram erase time 26.231365 us 21 | mapSize = 2000000, threadCount = 1, batchSize = 1 22 | oram init time 7.509643 s 23 | oram insert time 32.431116 us 24 | oram find time 32.399544 us 25 | oram erase time 32.403806 us 26 | mapSize = 5000000, threadCount = 1, batchSize = 1 27 | oram init time 19.739165 s 28 | oram insert time 35.207169 us 29 | oram find time 35.274760 us 30 | oram erase time 35.149657 us 31 | mapSize = 10000000, threadCount = 1, batchSize = 1 32 | oram init time 40.123137 s 33 | oram insert time 36.571680 us 34 | oram find time 36.713813 us 35 | oram erase time 36.576261 us 36 | mapSize = 20000000, threadCount = 1, batchSize = 1 37 | oram init time 83.697901 s 38 | oram insert time 43.833172 us 39 | oram find time 44.035137 us 40 | oram erase time 43.886472 us 41 | mapSize = 50000000, threadCount = 1, batchSize = 1 42 | oram init time 214.035604 s 43 | oram insert time 46.871881 us 44 | oram find time 46.990704 us 45 | oram erase time 46.668854 us 46 | mapSize = 100000000, threadCount = 1, batchSize = 1 47 | oram init time 453.496285 s 48 | oram insert time 56.359480 us 49 | oram find time 56.403967 us 50 | oram erase time 56.210470 us 51 | mapSize = 200000000, threadCount = 1, batchSize = 1 52 | oram init time 933.659245 s 53 | oram insert time 59.811109 us 54 | oram find time 59.682155 us 55 | oram erase time 59.375235 us -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/parcuckoo/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/parcuckoo/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pardisk/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pardisk/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pardisk/Latency1000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pardisk/Latency1000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pardisk/Latency1000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pardisk/Latency1000.pdf -------------------------------------------------------------------------------- /applications/omap/perf_tests/pardisk/Latency100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pardisk/Latency100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pardisk/Latency100000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pardisk/Latency100000.pdf -------------------------------------------------------------------------------- /applications/omap/perf_tests/pipeline/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pipeline/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pipeline/Latency1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pipeline/Latency1.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/pipeline/Latency1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/pipeline/Latency1.pdf -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Init_Time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Init_Time.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Init_Time_Signal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Init_Time_Signal.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_100000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_100000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_1000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_1000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_10000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_10000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_100000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_100000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_200000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_200000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_2000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_2000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_20000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_20000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_500000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_500000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_5000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_5000000.jpg -------------------------------------------------------------------------------- /applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_50000000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obliviouslabs/oram/bbab52166942eecb604ca86c710b5ecbe592ba26/applications/omap/perf_tests/signalFromEmpty/Throughput_MapSize_50000000.jpg -------------------------------------------------------------------------------- /applications/rustexample/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | Cargo.lock -------------------------------------------------------------------------------- /applications/rustexample/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "omap" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [build-dependencies] 9 | bindgen = "0.69.4" 10 | cmake = "0.1.50" 11 | cxx = { version = "1.0.118", features = ["c++14", "c++17", "c++20"] } 12 | 13 | [dependencies] 14 | rand = "0.8.5" -------------------------------------------------------------------------------- /applications/rustexample/README.txt: -------------------------------------------------------------------------------- 1 | ------------------------------- 2 | Go Binding Example 3 | ------------------------------- 4 | This example shows how to call the C++ codes from Rust. 5 | 6 | 1. Build the example with $ rm -r target && cargo build 7 | 2. Run unit tests with $ cargo test 8 | 9 | ------------------------------- 10 | 11 | For efficiency and obliviousness consideration, the lengths of keys and values in the oblivious map are fixed at compile time. Since the Rust compiler cannot compile C++ code, user needs to declare the desired lengths in omap/interface/omap_declare.cfg. For instance, to define an omap with 20-byte key and 32-byte value, add 12 | DECLARE_OMAP(20, 32) 13 | to omap_declare.cfg, and the omap can be referred to as OMapBinding_20_32 in the rust program. 14 | -------------------------------------------------------------------------------- /applications/rustexample/build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | extern crate cmake; 3 | 4 | use cmake::Config; 5 | use std::{env, path::PathBuf}; 6 | 7 | fn main() { 8 | let dst = Config::new("../../") 9 | .generator("Ninja") 10 | .define("CMAKE_BUILD_TYPE", "Release") 11 | .build(); 12 | 13 | let bindings = bindgen::Builder::default() 14 | .header("wrapper.h") 15 | .clang_arg("-x") 16 | .clang_arg("c++") 17 | .clang_arg("-std=c++20") 18 | .clang_arg("-I../../omap") 19 | .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) 20 | .generate() 21 | .expect("Failed to generate bindings"); 22 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 23 | bindings 24 | .write_to_file(out_path.join("bindings.rs")) 25 | .expect("Failed to write bindings"); 26 | 27 | // To compile this, you need openssl static libs. 28 | // They exist on most distros, but you probably need to install them. 29 | // 30 | println!("cargo:rustc-link-search=native=/usr/lib"); 31 | println!("cargo:rustc-link-search=native=/usr/lib/gcc/x86_64-linux-gnu/11/"); 32 | println!("cargo:rustc-link-lib=static=stdc++"); 33 | println!("cargo:rustc-link-lib=boost_system"); 34 | println!("cargo:rustc-link-search=native=./BearSSL/build/"); 35 | println!("cargo:rustc-link-lib=static=bearssl"); 36 | println!("cargo:rustc-link-lib=crypto"); 37 | println!("cargo:rustc-link-lib=static=gomp"); 38 | 39 | println!( 40 | "cargo:rustc-link-search=native={}/build/omap", 41 | dst.display() 42 | ); 43 | println!("cargo:rustc-link-lib=static=common"); 44 | println!("cargo:rustc-link-lib=static=oraminterface"); 45 | } 46 | -------------------------------------------------------------------------------- /applications/rustexample/makestaticbearssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git clone https://www.bearssl.org/git/BearSSL 3 | cd BearSSL 4 | make -j32 5 | cd .. 6 | -------------------------------------------------------------------------------- /applications/rustexample/wrapper.h: -------------------------------------------------------------------------------- 1 | #include "interface/common_interface.hpp" 2 | #include "interface/omap_spec_interface.hpp" 3 | #include "interface/par_omap_interface.hpp" 4 | #include "interface/recoram_interface.hpp" -------------------------------------------------------------------------------- /cmake/bearssl.cmake: -------------------------------------------------------------------------------- 1 | find_path(BEARSSL_INCLUDE_DIRS bearssl.h) 2 | 3 | find_library(BEARSSL_LIBRARY bearssl) 4 | 5 | include(FindPackageHandleStandardArgs) 6 | find_package_handle_standard_args(BEARSSL DEFAULT_MSG 7 | BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY) 8 | 9 | mark_as_advanced(BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY) -------------------------------------------------------------------------------- /cmake/boost.cmake: -------------------------------------------------------------------------------- 1 | find_library(BOOST_STACKTRACE_BACKTRACE_LIBRARY NAMES boost_stacktrace_backtrace) 2 | 3 | include (GNUInstallDirs) 4 | 5 | macro(linkstacktrace arg0) 6 | if (UNIX) 7 | message(STATUS "Using Boost::stacktrace/addr2line") 8 | target_compile_definitions(${arg0} PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 9 | target_link_libraries(${arg0} PRIVATE dl) 10 | elseif (MINGW AND BOOST_STACKTRACE_BACKTRACE_LIBRARY) 11 | message(STATUS "Using Boost::stacktrace/backtrace") 12 | target_compile_definitions(${arg0} PRIVATE BOOST_STACKTRACE_USE_BACKTRACE) 13 | target_link_libraries(${arg0} PRIVATE boost_stacktrace_backtrace backtrace) 14 | else () 15 | message(STATUS "Using Boost::stacktrace/basic") 16 | endif () 17 | endmacro() 18 | -------------------------------------------------------------------------------- /cmake/buildtype.cmake: -------------------------------------------------------------------------------- 1 | set(default_build_type "Debug") 2 | # set(default_build_type "Release") 3 | # if(EXISTS "${CMAKE_SOURCE_DIR}/.git") 4 | # set(default_build_type "Debug") 5 | # endif() 6 | 7 | if(ENCLAVE_BUILD AND ENCLAVE_BUILD EQUAL "1") 8 | # We only do enclave builds in Release mode 9 | # 10 | # We build in CXX20 mode, but in actual builds we will use stl from sgx, which 11 | # is c++14 stl minus all functions that cannot exists inside an enclave. 12 | # 13 | set(CMAKE_CXX_STANDARD 20) 14 | set(default_build_type "Release") 15 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DENCLAVE_MODE") 16 | else() 17 | set(CMAKE_CXX_STANDARD 20) 18 | endif() 19 | 20 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 21 | message(STATUS "Setting build type to '${default_build_type}' as none was specified.") 22 | set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE 23 | STRING "Choose the type of build." FORCE) 24 | # Set the possible values of build type for cmake-gui 25 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 26 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 27 | endif() 28 | 29 | 30 | if("${CMAKE_BUILD_TYPE}" EQUAL "Release") 31 | # This flag breaks addr2line: 32 | # 33 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) 34 | endif() 35 | 36 | message(STATUS "Build type is ${CMAKE_BUILD_TYPE} (default is '${default_build_type}').") -------------------------------------------------------------------------------- /cmake/clangformat.cmake: -------------------------------------------------------------------------------- 1 | get_property(INCLUDE_FILES GLOBAL PROPERTY INCLUDE_FILES_G) 2 | get_property(SOURCE_FILES_NM GLOBAL PROPERTY SOURCE_FILES_NM_G) 3 | 4 | add_custom_target( 5 | clangformat 6 | COMMAND /usr/bin/clang-format 7 | -style=LLVM 8 | -i 9 | ${SOURCE_FILES_NM} 10 | ) -------------------------------------------------------------------------------- /cmake/colors.cmake: -------------------------------------------------------------------------------- 1 | option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE) 2 | 3 | if (${FORCE_COLORED_OUTPUT}) 4 | message(${CMAKE_CXX_COMPILER_ID}) 5 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") 6 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fdiagnostics-color") 7 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fdiagnostics-color") 8 | elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") 10 | endif () 11 | endif () -------------------------------------------------------------------------------- /cmake/cppcheck.cmake: -------------------------------------------------------------------------------- 1 | get_property(INCLUDE_FILES GLOBAL PROPERTY INCLUDE_FILES_G) 2 | get_property(SOURCE_FILES_NM GLOBAL PROPERTY SOURCE_FILES_NM_G) 3 | 4 | add_custom_target( 5 | cppcheck 6 | COMMAND cppcheck 7 | --enable=warning,performance,portability,style,information,missingInclude 8 | --std=c++20 9 | --library=googletest.cfg 10 | # --template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)" 11 | -I../omap/ -I../tests/ 12 | --verbose 13 | --quiet 14 | ${SOURCE_FILES_NM} 15 | ) 16 | 17 | add_custom_target( 18 | cppcheck-builder 19 | COMMAND cppcheck 20 | --xml --xml-version=2 21 | --enable=all 22 | -I../omap/ -I../tests/ 23 | --std=c++20 24 | --library=googletest.cfg 25 | -DBOOST_STACKTRACE_USE_ADDR2LINE 26 | ${SOURCE_FILES_NM} --suppress=missingIncludeSystem 27 | --check-config 28 | 2> quality/cppcheck.xml 29 | COMMAND 30 | cppcheck-codequality 31 | --input-file=quality/cppcheck.xml 32 | --output-file=quality/cppcheck.json 33 | ) -------------------------------------------------------------------------------- /cmake/faster.cmake: -------------------------------------------------------------------------------- 1 | find_program(MOLD_FOUND "mold") 2 | find_program(LLD_FOUND "lld") 3 | find_program(CCACHE_FOUND "ccache") 4 | 5 | if(MOLD_FOUND) 6 | message("Found mold") 7 | set(CMAKE_LINKER mold) 8 | elseif (LLD_FOUND) 9 | message("Found lld!") 10 | set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld") 11 | set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld") 12 | set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld") 13 | else () 14 | message("No custom linker found, using GNU ld.") 15 | endif(MOLD_FOUND) 16 | 17 | 18 | if(CCACHE_FOUND) 19 | message("Found ccache!") 20 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 21 | else () 22 | message("No ccache found.") 23 | endif(CCACHE_FOUND) -------------------------------------------------------------------------------- /cmake/searchfiles.cmake: -------------------------------------------------------------------------------- 1 | set_property( GLOBAL PROPERTY INCLUDE_FILES_G "") 2 | set_property( GLOBAL PROPERTY SOURCE_FILES_NM_G "") 3 | 4 | macro(searchfiles) 5 | get_property(INCLUDE_FILES GLOBAL PROPERTY INCLUDE_FILES_G) 6 | get_property(SOURCE_FILES_NM GLOBAL PROPERTY SOURCE_FILES_NM_G) 7 | file(GLOB INCLUDE_FILES_A *.hpp) 8 | list(APPEND INCLUDE_FILES "${INCLUDE_FILES_A}") 9 | file(GLOB SOURCE_FILES_NM_A *.cpp) 10 | list(APPEND SOURCE_FILES_NM "${SOURCE_FILES_NM_A}") 11 | set_property( GLOBAL PROPERTY INCLUDE_FILES_G "${INCLUDE_FILES}") 12 | set_property( GLOBAL PROPERTY SOURCE_FILES_NM_G "${SOURCE_FILES_NM}") 13 | endmacro() -------------------------------------------------------------------------------- /omap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | searchfiles() 2 | 3 | add_library (common common/encutils.cpp common/tracing/tracer.cpp external_memory/server/serverBackend.cpp) 4 | target_compile_definitions(common PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 5 | target_include_directories(common PUBLIC .) 6 | # HACK: in ubuntu bearssl is included as /bearsslrootdir whereas in other distros it is included as /bearsslrootdir/bearssl. This makes it work on both even though we will only use one of the includes on each distro: 7 | target_include_directories(common PUBLIC ${BEARSSL_INCLUDE_DIRS} ${BEARSSL_INCLUDE_DIRS}/bearssl) 8 | target_link_libraries (common dl ${BEARSSL_LIBRARY}) 9 | 10 | add_library (oraminterface interface/interface.cpp interface/omap_c.cpp common) 11 | target_compile_definitions(oraminterface PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 12 | target_include_directories(oraminterface PUBLIC .) 13 | target_link_libraries (oraminterface dl OpenMP::OpenMP_CXX) -------------------------------------------------------------------------------- /omap/algorithm/edge_rec.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/utils.hpp" 3 | /// @brief EdgeRec is a bitset that records the edges in a graph 4 | /// @tparam Bits the type of the bitset, default is uint64_t 5 | template 6 | struct EdgeRec { 7 | Bits edges; 8 | uint16_t k; 9 | 10 | public: 11 | explicit EdgeRec(uint16_t k) : k(k) { // k is number of vertices 12 | static_assert(std::is_same::value, 13 | "unrecognized type for recording edge"); 14 | edges = 0; 15 | } 16 | // map vertex to edge offset in Edge Rec 17 | // it's ordered by 0-0, 1-0, 1-1, 2-0, 2-1, ... 18 | INLINE static constexpr uint16_t getEdgeOffset(uint16_t v0, uint16_t v1) { 19 | return (v0 << 3) | v1; 20 | } 21 | 22 | INLINE static constexpr Bits getEdgesMask(uint16_t v0, uint16_t v1) { 23 | if constexpr (std::is_same::value) { 24 | return (1UL << getEdgeOffset(v0, v1)) | (1UL << getEdgeOffset(v1, v0)); 25 | } 26 | return 0; 27 | } 28 | 29 | INLINE void flipEdge(Bits mask) { 30 | if constexpr (std::is_same::value) { 31 | edges ^= mask; 32 | } 33 | } 34 | 35 | INLINE void flipEdge(uint16_t v0, uint16_t v1) { 36 | flipEdge(getEdgesMask(v0, v1)); 37 | } 38 | 39 | INLINE bool retrieveEdge(uint16_t edgeOffset) const { 40 | return (edges >> edgeOffset) & 1UL; 41 | } 42 | 43 | INLINE bool retrieveEdge(uint16_t v0, uint16_t v1) const { 44 | uint16_t offset = getEdgeOffset(v0, v1); 45 | return retrieveEdge(offset); 46 | } 47 | 48 | // retrieve the direction of v0->v1 and flip the direction 49 | INLINE bool retrieveAndFlipEdge(uint16_t v0, uint16_t v1) { 50 | Bits mask = getEdgesMask(v0, v1); 51 | Bits v0_to_v1_mask = 1UL << getEdgeOffset(v0, v1); 52 | Bits v1_to_v0_mask = 1UL << getEdgeOffset(v1, v0); 53 | edges ^= v0_to_v1_mask | v1_to_v0_mask; 54 | return !(edges & v0_to_v1_mask); 55 | } 56 | 57 | void print() { 58 | for (uint16_t i = 0; i < k; ++i) { 59 | for (uint16_t j = i + 1; j < k; ++j) { 60 | if (retrieveEdge(i, j)) { 61 | printf("%d - %d\n", i, j); 62 | } 63 | } 64 | } 65 | } 66 | 67 | void printPath(const EdgeRec& path) { 68 | Assert(k == path.k); 69 | for (uint16_t i = 0; i < k; ++i) { 70 | for (uint16_t j = i + 1; j < k; ++j) { 71 | if (retrieveEdge(i, j)) { 72 | if (path.retrieveEdge(i, j)) { 73 | printf("%d -> %d\n", i, j); 74 | } else { 75 | printf("%d -> %d\n", j, i); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | INLINE EdgeRec EulerPath(uint64_t numEdge) { 83 | numEdge = std::min(numEdge, (uint64_t)(k * (k - 1) / 2)); 84 | // an edge is set to 1 if it's direction is from small vertex to larger 85 | EdgeRec path(k); 86 | // for edges appearing even number of times, set direction according to 87 | // their order 88 | path.edges = (~edges) & 0xFF7F3F1F0F070301UL; 89 | static constexpr Bits simpleMask = ~0x8040201008040201UL; 90 | // filtering out edges pointing to itself 91 | edges &= simpleMask; 92 | uint16_t v8 = 0; 93 | for (uint16_t r = 0; r != numEdge; ++r) { 94 | // clear bits for less than v0 95 | uint64_t choices = edges & ((-1UL) << v8); 96 | uint16_t trailingZeros = std::countr_zero(choices); 97 | // case 1: there's an edge v0->next 98 | // case 2: next is a vertex connected to the smallest uncovered vertex 99 | // case 3: all is done and next = 0 100 | uint16_t next = trailingZeros & 7; 101 | uint16_t v0 = trailingZeros >> 3; 102 | Bits v0_to_next_mask = 1UL << trailingZeros; 103 | v8 = next << 3; 104 | Bits next_to_v0_mask = 1UL << (v8 | v0); 105 | // set this edge as done (could be that it's already done in case 2) 106 | edges &= ~(v0_to_next_mask | next_to_v0_mask); 107 | // set direction v0->next if it's in case 1 108 | path.edges |= v0_to_next_mask; 109 | } 110 | return path; 111 | } 112 | }; -------------------------------------------------------------------------------- /omap/algorithm/element.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/cmp_intrinsics.hpp" 3 | #include "common/defs.hpp" 4 | #include "common/dummy.hpp" 5 | #include "common/mov_intrinsics.hpp" 6 | #include "common/utils.hpp" 7 | 8 | /// This file defines some macros and data structures for sorting and shuffling 9 | /// algorithms. 10 | 11 | // size of each element in bytes 12 | #ifndef ELEMENT_SIZE 13 | #define ELEMENT_SIZE 128 14 | #endif 15 | 16 | namespace Algorithm { 17 | /// @brief Wrapper for flex-way butterfly o-sort 18 | /// @tparam T type of elements 19 | template 20 | struct TaggedT { 21 | #if defined(__AVX512VL__) || defined(__AVX2__) 22 | static constexpr size_t paddingSize = sizeof(T) % 32 == 16 ? 8 : 0; 23 | #else 24 | static constexpr size_t paddingSize = 0; 25 | #endif 26 | uint64_t tag; // random label except that the most significant bit is the 27 | // flag to mark if the element is dummy 28 | T v; 29 | char padding[paddingSize]; 30 | 31 | inline void setData(const T& _data) { 32 | v = _data; 33 | tag = UniformRandom() & 0x7fff'ffff'ffff'ffffUL; 34 | } 35 | 36 | inline const T& getData() const { return v; } 37 | 38 | inline bool IsDummy() const { return tag >> 63; } 39 | 40 | inline void setDummy() { tag |= 0x8000'0000'0000'0000UL; } 41 | 42 | inline void setTag(uint64_t _tag) { tag = _tag & 0x7fff'ffff'ffff'ffffUL; } 43 | 44 | inline bool setAndGetMarked(uint64_t bitMask) const { // same as isMarked 45 | return isMarked(bitMask); 46 | } 47 | 48 | inline bool isMarked(uint64_t bitMask) const { return !(tag & bitMask); } 49 | 50 | inline void condChangeMark(bool cond, uint64_t bitMask) { 51 | obliMove(cond, tag, tag ^ bitMask); 52 | } 53 | 54 | inline uint8_t getMarkAndUpdate(uint64_t k) { 55 | uint64_t realTag = tag & 0x7fff'ffff'ffff'ffffUL; 56 | tag &= 0x8000'0000'0000'0000UL; 57 | tag |= realTag / k; 58 | uint8_t mark = realTag % k; 59 | return mark; 60 | } 61 | }; 62 | } // namespace Algorithm 63 | 64 | /// @brief Example of a sort element 65 | struct TestElement { 66 | uint64_t key; // key for comparison 67 | uint8_t payload[ELEMENT_SIZE - 68 | sizeof(key)]; // a payload that is typically longer 69 | static consteval inline TestElement DUMMY() { 70 | return TestElement{static_cast(-1), {}}; 71 | } 72 | bool operator==(const TestElement& other) const { return key == other.key; } 73 | bool operator<(const TestElement& other) const { return key < other.key; } 74 | #ifndef ENCLAVE_MODE 75 | friend std::ostream& operator<<(std::ostream& o, const TestElement& x) { 76 | o << x.key; 77 | return o; 78 | } 79 | #endif 80 | }; 81 | 82 | template 83 | struct Bytes { 84 | uint8_t data[size]; 85 | 86 | Bytes() = default; 87 | 88 | explicit Bytes(const void* _data) { memcpy(data, _data, size); } 89 | 90 | bool operator==(const Bytes& other) const { 91 | return obliCheckEqual(data, other.data); 92 | } 93 | 94 | bool operator!=(const Bytes& other) const { return !(*this == other); } 95 | 96 | bool operator<(const Bytes& other) const { 97 | return obliCheckLess(data, other.data); 98 | } 99 | 100 | void SetRand() { read_rand(data, size); } 101 | 102 | const uint8_t* GetData() const { return data; } 103 | 104 | static consteval inline Bytes DUMMY() { 105 | Bytes ret; 106 | for (size_t i = 0; i < size; ++i) { 107 | ret.data[i] = 0xff; 108 | } 109 | return ret; 110 | } 111 | 112 | // out stream 113 | #ifndef ENCLAVE_MODE 114 | friend std::ostream& operator<<(std::ostream& o, const Bytes& x) { 115 | for (size_t i = 0; i < size; ++i) { 116 | o << std::hex << std::setw(2) << std::setfill('0') << (int)x.data[i] 117 | << std::dec; 118 | } 119 | return o; 120 | } 121 | #endif 122 | }; 123 | 124 | namespace std { 125 | template 126 | struct hash> { 127 | std::size_t operator()(const Bytes& bytes) const { 128 | return std::hash()( 129 | std::string_view((const char*)bytes.GetData(), size)); 130 | } 131 | }; 132 | } // namespace std -------------------------------------------------------------------------------- /omap/algorithm/param_select.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include "element.hpp" 7 | 8 | /// This file contains some utility functions to help calculate parameters given 9 | /// a desired success probability. 10 | 11 | namespace Algorithm { 12 | 13 | /// @brief add two numbers in log space 14 | static double addLogs(double logA, double logB) { 15 | double bigger = std::max(logA, logB); 16 | double smaller = std::min(logA, logB); 17 | if (std::isinf(bigger)) { 18 | return bigger; 19 | } 20 | if (bigger - smaller > 100) { 21 | return bigger; 22 | } 23 | return bigger + log2(1.0 + pow(2, (smaller - bigger))); 24 | } 25 | 26 | /// @brief log of the binomial coefficient 27 | static double logCombin(uint64_t k, uint64_t n) { 28 | Assert(k <= n); 29 | if (k * 2 > n) { 30 | k = n - k; 31 | } 32 | 33 | double res = (lgamma(n + 1) - lgamma(n - k + 1) - lgamma(k + 1)) / log(2); 34 | return res; 35 | } 36 | 37 | /// @brief log of the binomial pmf 38 | static double binomLogPmf(uint64_t k, uint64_t n, double p) { 39 | double logCkn = logCombin(k, n); 40 | 41 | if (p > 1e-5) { 42 | return logCkn + (double)k * log2(p) + (double)(n - k) * log2(1 - p); 43 | } 44 | return logCkn + (double)k * log2(p) - 45 | (double)(n - k) / log(2) * (p + p * p / 2 + p * p * p / 3); 46 | } 47 | 48 | /// @brief log of the binomial survival function 49 | static double binomLogSf(uint64_t k, uint64_t n, double p) { 50 | double sf = -INFINITY; 51 | double pmf = binomLogPmf(k, n, p); 52 | double eps = pmf - 40; 53 | while (pmf > eps && k < n) { 54 | ++k; 55 | pmf += log2((double)(n - k + 1) / (double)k) + log2(p / (1 - p)); 56 | sf = addLogs(sf, pmf); 57 | } 58 | return sf; 59 | } 60 | 61 | /// @brief calculate lower bound 62 | /// @tparam T type of the value 63 | /// @tparam type of the lambda function 64 | /// @param left left bound 65 | /// @param right right bound 66 | /// @param satisfy lambda function that checks the condition 67 | /// @param prec precision 68 | /// @return the smallest value in the range [left, right) that satisfies the 69 | /// condition 70 | template 71 | static T lowerBound(T left, T right, const Check& satisfy, T prec = 1) { 72 | while (true) { 73 | T mid = (left + right) / 2; 74 | if (satisfy(mid)) { 75 | right = mid; 76 | if (right - left <= prec) { 77 | return mid; 78 | } 79 | } else { 80 | left = mid; 81 | if (right - left <= prec) { 82 | return right; 83 | } 84 | } 85 | } 86 | } 87 | } // namespace Algorithm -------------------------------------------------------------------------------- /omap/algorithm/static_sort.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "element.hpp" 3 | 4 | /// This file contains a static sort class that uses a compile time generated, 5 | /// adapted from: 6 | /// https://stackoverflow.com/questions/19790522/very-fast-sorting-of-fixed-length-arrays-using-comparator-networks 7 | 8 | namespace Algorithm { 9 | 10 | /// This class is a functor that sorts a fixed size array or container using a 11 | /// compile time generated Bose-Nelson sorting network, which is slightly faster 12 | /// than bitonic sort for small arrays. 13 | template 14 | class StaticSort { 15 | template 16 | struct Swap { 17 | inline Swap(const A &a, const int &i0, const int &i1) { 18 | bool cond = Compare()(*(a + i0), *(a + i1)); 19 | obliSwap(cond, *(a + i0), *(a + i1)); 20 | } 21 | }; 22 | 23 | template 24 | struct Swap { 25 | inline Swap(const A &a, const int &i0, const int &i1) { 26 | bool cond = *(a.second + i0) > *(a.second + i1); 27 | obliSwap(cond, *(a.first + i0), *(a.first + i1)); 28 | obliSwap(cond, *(a.second + i0), *(a.second + i1)); 29 | } 30 | }; 31 | 32 | template 33 | struct PB { 34 | inline PB(const A &a) { 35 | enum { 36 | L = X >> 1, 37 | M = (X & 1 ? Y : Y + 1) >> 1, 38 | IAddL = I + L, 39 | XSubL = X - L 40 | }; 41 | PB p0(a); 42 | PB p1(a); 43 | PB p2(a); 44 | } 45 | }; 46 | 47 | template 48 | struct PB { 49 | inline PB(const A &a) { Swap s(a, I - 1, J - 1); } 50 | }; 51 | 52 | template 53 | struct PB { 54 | inline PB(const A &a) { 55 | Swap s0(a, I - 1, J); 56 | Swap s1(a, I - 1, J - 1); 57 | } 58 | }; 59 | 60 | template 61 | struct PB { 62 | inline PB(const A &a) { 63 | Swap s0(a, I - 1, J - 1); 64 | Swap s1(a, I, J - 1); 65 | } 66 | }; 67 | 68 | template 69 | struct PS { 70 | inline PS(const A &a) { 71 | enum { L = M >> 1, IAddL = I + L, MSubL = M - L }; 72 | PS ps0(a); 73 | PS ps1(a); 74 | PB pb(a); 75 | } 76 | }; 77 | 78 | template 79 | struct PS { 80 | inline PS(const A &a) {} 81 | }; 82 | 83 | public: 84 | /** 85 | * Sorts the array/container arr. 86 | * \param arr The array/container to be sorted. 87 | */ 88 | template 89 | inline void operator()(Container &arr) const { 90 | PS ps(arr); 91 | }; 92 | }; 93 | } // namespace Algorithm -------------------------------------------------------------------------------- /omap/common/cmp_intrinsics.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "cpp_extended.hpp" 10 | 11 | template 12 | INLINE bool CE_internal(const uint8_t* a, const uint8_t* b) { 13 | static_assert(sz <= 8); 14 | if constexpr (sz == 8) { 15 | return *reinterpret_cast(a) == 16 | *reinterpret_cast(b); 17 | } else if constexpr (sz == 4) { 18 | return *reinterpret_cast(a) == 19 | *reinterpret_cast(b); 20 | } else if constexpr (sz == 2) { 21 | return *reinterpret_cast(a) == 22 | *reinterpret_cast(b); 23 | } else if constexpr (sz == 1) { 24 | return *reinterpret_cast(a) == 25 | *reinterpret_cast(b); 26 | } else { 27 | uint64_t aCopy = 0; 28 | uint64_t bCopy = 0; 29 | memcpy(&aCopy, a, sz); 30 | memcpy(&bCopy, b, sz); 31 | return aCopy == bCopy; 32 | } 33 | } 34 | 35 | template 36 | INLINE bool CL_internal(const uint8_t* a, const uint8_t* b) { 37 | static_assert(sz <= 8); 38 | if constexpr (sz == 8) { 39 | return *reinterpret_cast(a) < 40 | *reinterpret_cast(b); 41 | } else if constexpr (sz == 4) { 42 | return *reinterpret_cast(a) < 43 | *reinterpret_cast(b); 44 | } else if constexpr (sz == 2) { 45 | return *reinterpret_cast(a) < 46 | *reinterpret_cast(b); 47 | } else if constexpr (sz == 1) { 48 | return *reinterpret_cast(a) < 49 | *reinterpret_cast(b); 50 | } else { 51 | uint64_t aCopy = 0; 52 | uint64_t bCopy = 0; 53 | memcpy(&aCopy, a, sz); 54 | memcpy(&bCopy, b, sz); 55 | return aCopy < bCopy; 56 | } 57 | } 58 | 59 | template 60 | INLINE bool obliCheckEqual(const uint8_t* a, const uint8_t* b) { 61 | bool res = true; 62 | 63 | for (uint64_t i = 0; i + 8 <= sz; i += 8) { 64 | res &= CE_internal<8>(a + i, b + i); 65 | } 66 | static constexpr uint64_t rem = sz % 8; 67 | if constexpr (rem) { 68 | static constexpr uint64_t last = sz - rem; 69 | res &= CE_internal(a + last, b + last); 70 | } 71 | return res; 72 | } 73 | 74 | // Check if a is less than b, if the system is big-endian, the result is 75 | // lexicographical order, otherwise, it only guarantees to follows a 76 | // deterministic ordering. 77 | template 78 | INLINE bool obliCheckLess(const uint8_t* a, const uint8_t* b) { 79 | bool eq = true; 80 | bool less = false; 81 | 82 | for (uint64_t i = 0; i + 8 < sz; i += 8) { 83 | less |= eq & CL_internal<8>(a + i, b + i); 84 | eq &= CE_internal<8>(a + i, b + i); 85 | } 86 | static constexpr uint64_t rem = (sz - 1) % 8 + 1; 87 | static constexpr uint64_t last = sz - rem; 88 | return less | (eq & CL_internal(a + last, b + last)); 89 | } -------------------------------------------------------------------------------- /omap/common/defs.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/cpp_extended.hpp" 3 | 4 | #ifndef SERVER__CACHE_SIZE 5 | #define SERVER__CACHE_SIZE 8192 6 | #endif 7 | 8 | #define ORAM_USE_INRAM_SERVER true 9 | 10 | #ifndef ENCLAVE_SIZE 11 | #define ENCLAVE_SIZE 1000000 12 | #endif 13 | #ifndef DEFAULT_HEAP_SIZE 14 | #define DEFAULT_HEAP_SIZE ((uint64_t)ENCLAVE_SIZE * 0xD0000UL) 15 | #endif 16 | 17 | #define FLAMEGRAPHS_BASE_FOLDER "./quality/flamegraphs/" -------------------------------------------------------------------------------- /omap/common/dmcache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include "common/defs.hpp" 7 | 8 | namespace CACHE { 9 | template 10 | struct DMCache { 11 | typedef uint64_t IndexType; 12 | struct CacheEntry { 13 | T val; 14 | IndexType idx; 15 | bool dirty; 16 | }; 17 | 18 | uint64_t size; 19 | std::vector data; 20 | 21 | DMCache() { 22 | size = cache_size; 23 | data.resize(cache_size); 24 | } 25 | 26 | bool CheckContains(const IndexType& rootIdx) { 27 | return data[rootIdx % cache_size].idx == rootIdx; 28 | } 29 | 30 | void Insert(const IndexType& newIndex, const T& val) { 31 | data[newIndex % cache_size] = {val, newIndex, false}; 32 | } 33 | 34 | T& Access(const IndexType& accessedIndex, bool dirty = true, 35 | bool writeBack = true) { 36 | auto& data_to_access = data[accessedIndex % cache_size]; 37 | data_to_access.dirty = (data_to_access.dirty || dirty) && writeBack; 38 | 39 | return data_to_access.val; 40 | } 41 | 42 | const T& AccessReadOnly(const IndexType& accessedIndex) { 43 | return Access(accessedIndex, false); 44 | } 45 | 46 | const T& AccessNoWriteBack(const IndexType& accessedIndex) { 47 | return Access(accessedIndex, false, false); 48 | } 49 | 50 | CacheEntry& GetMappedSlot(IndexType indexToEvict) { 51 | return data[indexToEvict % cache_size]; 52 | } 53 | 54 | const CacheEntry& GetMappedSlot(IndexType indexToEvict) const { 55 | return data[indexToEvict % cache_size]; 56 | } 57 | }; 58 | } // namespace CACHE -------------------------------------------------------------------------------- /omap/common/dummy.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/cpp_extended.hpp" 3 | 4 | template 5 | INLINE consteval T DUMMY() { 6 | return T::DUMMY(); 7 | } 8 | 9 | template <> 10 | INLINE consteval uint8_t DUMMY() { 11 | return static_cast(-1); 12 | } 13 | 14 | template <> 15 | INLINE consteval uint16_t DUMMY() { 16 | return static_cast(-1); 17 | } 18 | 19 | template <> 20 | INLINE consteval uint32_t DUMMY() { 21 | return static_cast(-1); 22 | } 23 | 24 | template <> 25 | INLINE consteval uint64_t DUMMY() { 26 | return static_cast(-1); 27 | } -------------------------------------------------------------------------------- /omap/common/lock_util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef ENCLAVE_MODE 3 | #ifndef TCS_NUM 4 | #define TCS_NUM 1 5 | #endif 6 | #if TCS_NUM > 1 7 | #include "sgx_spinlock.h" 8 | #include "sgx_thread.h" 9 | struct Lock { 10 | sgx_spinlock_t _lock = SGX_SPINLOCK_INITIALIZER; 11 | void lock() { sgx_spin_lock(&_lock); } 12 | void unlock() { sgx_spin_unlock(&_lock); } 13 | }; 14 | 15 | struct Mutex { 16 | sgx_thread_mutex_t _lock = SGX_THREAD_MUTEX_INITIALIZER; 17 | void lock() { sgx_thread_mutex_lock(&_lock); } 18 | void unlock() { sgx_thread_mutex_unlock(&_lock); } 19 | }; 20 | 21 | #else 22 | struct Lock { 23 | void lock() {} 24 | void unlock() {} 25 | }; 26 | 27 | struct Mutex { 28 | void lock() {} 29 | void unlock() {} 30 | }; 31 | #endif 32 | 33 | #else 34 | #include 35 | // TTASSpinlock 36 | struct Lock { 37 | public: 38 | Lock() : flag(false) {} 39 | Lock(const Lock&) {} 40 | 41 | void lock() { 42 | // First, test in a non-atomic way 43 | while (flag.load(std::memory_order_relaxed)) { 44 | // Spin without attempting to set the flag 45 | // Optionally, use std::this_thread::yield() to reduce contention 46 | } 47 | // Now attempt to set the flag atomically 48 | while (flag.exchange(true, std::memory_order_acquire)) { 49 | // If exchange returns true, the flag was already set, so keep spinning 50 | } 51 | } 52 | 53 | void unlock() { flag.store(false, std::memory_order_release); } 54 | 55 | private: 56 | std::atomic flag; 57 | }; 58 | 59 | struct Mutex { 60 | void lock() { _lock.lock(); } 61 | void unlock() { _lock.unlock(); } 62 | Mutex() {} 63 | Mutex(const Mutex&) {} 64 | 65 | private: 66 | std::mutex _lock; 67 | }; 68 | #endif 69 | 70 | template 71 | struct Critical { 72 | LockType& _lock; 73 | explicit Critical(LockType& _lock) : _lock(_lock) { _lock.lock(); } 74 | ~Critical() { _lock.unlock(); } 75 | }; -------------------------------------------------------------------------------- /omap/common/lrucache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include "common/defs.hpp" 7 | 8 | namespace CACHE { 9 | template 11 | struct LRUCache { 12 | struct CacheEntry { 13 | T val; 14 | bool dirty; 15 | }; 16 | typedef uint64_t IndexType; 17 | uint64_t size; 18 | std::unordered_map data; 19 | std::unordered_map::iterator> dataRefs; 20 | std::list LRU; 21 | 22 | struct TLB_entry { 23 | IndexType idx; 24 | uint64_t counter = 0; // 0 stands for invalid 25 | CacheEntry* pentry; // rehashing should not invalidate pointer to value 26 | }; 27 | 28 | uint64_t TLB_global_counter; 29 | std::vector TLB; 30 | 31 | void sortTLBByCounter() { 32 | auto cmp = [](const TLB_entry& entry1, const TLB_entry& entry2) { 33 | return entry1.counter > entry2.counter; 34 | }; 35 | std::sort(TLB.begin(), TLB.end(), cmp); 36 | } 37 | 38 | void resetTLBCounters() { 39 | sortTLBByCounter(); 40 | TLB_global_counter = tlb_size + 1; 41 | uint64_t counter = tlb_size + 1; 42 | for (TLB_entry& entry : TLB) { 43 | entry.counter = --counter; 44 | } 45 | } 46 | 47 | // if write back is false, reset dirty to false 48 | T* AccessTLB(const IndexType& accessedIndex, bool dirty = true, 49 | bool writeBack = true) { 50 | if (++TLB_global_counter == UINT64_MAX) { 51 | // to prevent overflow 52 | resetTLBCounters(); 53 | } 54 | for (TLB_entry& entry : TLB) { 55 | if (entry.idx == accessedIndex && entry.counter) { 56 | entry.counter = TLB_global_counter; 57 | entry.pentry->dirty = (entry.pentry->dirty || dirty) && writeBack; 58 | T* pval = &entry.pentry->val; 59 | return pval; 60 | } 61 | } 62 | return NULL; 63 | } 64 | 65 | const T* AccessTLBReadOnly(const IndexType& accessedIndex) { 66 | return AccessTLB(accessedIndex, false); 67 | } 68 | 69 | const T* AccessTLBNoWriteBack(const IndexType& accessedIndex) { 70 | return AccessTLB(accessedIndex, false, false); 71 | } 72 | 73 | T& UpdateTLB(const IndexType& accessedIndex, CacheEntry& entry) { 74 | uint64_t minCounter = UINT64_MAX; 75 | auto minIt = TLB.begin(); 76 | for (auto it = TLB.begin(); it != TLB.end(); ++it) { 77 | if (it->counter < minCounter) { 78 | minCounter = it->counter; 79 | minIt = it; 80 | } 81 | } 82 | *minIt = {accessedIndex, TLB_global_counter, &entry}; 83 | sortTLBByCounter(); // speed up future lookups 84 | return entry.val; 85 | } 86 | 87 | LRUCache() { 88 | size = 0; 89 | data.reserve(cache_size); 90 | dataRefs.reserve(cache_size); 91 | TLB_global_counter = 0; 92 | TLB.resize(tlb_size); 93 | } 94 | 95 | bool CheckContains(const IndexType& rootIdx) { 96 | return data.count(rootIdx) > 0; 97 | } 98 | 99 | bool IsFull() { return size == cache_size; } 100 | 101 | CacheEntry& GetNextToEvict(IndexType& indexToEvict) { 102 | Assert(size > 0); 103 | Assert(size == cache_size); 104 | indexToEvict = LRU.back(); 105 | Assert(data.count(indexToEvict) > 0); 106 | return data[indexToEvict]; 107 | } 108 | 109 | void EvictLRU(const IndexType& evictedIndex) { 110 | #ifndef NDEBUG 111 | Assert(size > 0); 112 | Assert(size == cache_size); 113 | Assert(evictedIndex == LRU.back()); 114 | Assert(data.count(evictedIndex) > 0); 115 | #endif 116 | size--; 117 | LRU.pop_back(); 118 | data.erase(evictedIndex); 119 | dataRefs.erase(evictedIndex); 120 | } 121 | 122 | void Insert(const IndexType& newIndex, const T& val) { 123 | Assert(size < cache_size); 124 | Assert(data.count(newIndex) == 0); 125 | size++; 126 | LRU.push_front(newIndex); 127 | 128 | data[newIndex] = {val, false}; 129 | dataRefs[newIndex] = (LRU.begin()); 130 | 131 | // return data[newIndex].val; 132 | } 133 | 134 | T& Access(const IndexType& accessedIndex, bool dirty = true, 135 | bool writeBack = true) { 136 | Assert(size > 0); 137 | Assert(data.count(accessedIndex) > 0); 138 | 139 | LRU.erase(dataRefs[accessedIndex]); 140 | LRU.push_front(accessedIndex); 141 | dataRefs[accessedIndex] = LRU.begin(); 142 | auto& data_to_access = data[accessedIndex]; 143 | data_to_access.dirty = (data_to_access.dirty || dirty) && writeBack; 144 | 145 | return UpdateTLB(accessedIndex, data_to_access); 146 | } 147 | 148 | const T& AccessReadOnly(const IndexType& accessedIndex) { 149 | return Access(accessedIndex, false); 150 | } 151 | 152 | const T& AccessNoWriteBack(const IndexType& accessedIndex) { 153 | return Access(accessedIndex, false, false); 154 | } 155 | }; 156 | } // namespace CACHE -------------------------------------------------------------------------------- /omap/common/tracing/perf.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifndef ENCLAVE_MODE 5 | // #define ENABLE_PERF_COUNTERS 1 6 | #endif 7 | 8 | struct PerfCounters { 9 | #ifdef ENABLE_PERF_COUNTERS 10 | #define F(_, name, ...) uint64_t name = 0; 11 | #include "common/tracing/perf_counters.hpp" 12 | 13 | void Reset() { 14 | #define F(_, name, ...) this->name = 0; 15 | #include "common/tracing/perf_counters.hpp" 16 | } 17 | 18 | void Log(std::ostream& ofs) { 19 | #define F(iscomputed, name, description, expression) \ 20 | if constexpr (iscomputed) { \ 21 | ofs << description << ": " << (expression) << std::endl; \ 22 | } else { \ 23 | ofs << description << ": " << (name) << std::endl; \ 24 | } 25 | #include "common/tracing/perf_counters.hpp" 26 | } 27 | #endif 28 | }; 29 | 30 | #ifdef ENABLE_PERF_COUNTERS 31 | #define PERFCTR_RESET() g_PerfCounters.Reset() 32 | #define PERFCTR_LOG() g_PerfCounters.Log(std::cout) 33 | #define PERFCTR_LOG_TO(to) g_PerfCounters.Log(to) 34 | #define PERFCTR_INCREMENT(name) g_PerfCounters.name++; 35 | #define PERFCTR_INCREMENT_BY(name, by) g_PerfCounters.name += (by); 36 | #else 37 | #define PERFCTR_RESET() 38 | #define PERFCTR_LOG() 39 | #define PERFCTR_LOG_TO(...) 40 | #define PERFCTR_INCREMENT(...) 41 | #define PERFCTR_INCREMENT_BY(...) 42 | #endif 43 | 44 | extern PerfCounters g_PerfCounters; -------------------------------------------------------------------------------- /omap/common/tracing/perf_counters.hpp: -------------------------------------------------------------------------------- 1 | #ifndef F 2 | #error Define F before including this file 3 | #endif 4 | #define _PERF_COUNTERS_CALLGUARD_ 1 5 | 6 | #ifndef NDEBUG 7 | #include "perf_counters.hxx" 8 | #endif 9 | 10 | #include "perf_counters_release.hxx" 11 | 12 | #undef _PERF_COUNTERS_CALLGUARD_ 13 | #undef F -------------------------------------------------------------------------------- /omap/common/tracing/perf_counters.hxx: -------------------------------------------------------------------------------- 1 | #ifndef _PERF_COUNTERS_CALLGUARD_ 2 | #error Include "perf_counter.hpp" instead 3 | #endif 4 | // The perf counteres defines here are not present in release builds. 5 | // 6 | 7 | 8 | // F(iscomputed, name, description, expression) 9 | F(false, readCount, "Read pages", 0) 10 | F(false, writeCount, "Write pages", 0) 11 | F(false, accessCount, "Access count", 0) 12 | F(false, swapCount, "Swap count", 0) 13 | F(false, tlbHitCount, "TLB hit count", 0) 14 | F(true, tlbHitRate, "TLB hit rate", static_cast(tlbHitCount) / static_cast(accessCount)) 15 | -------------------------------------------------------------------------------- /omap/common/tracing/perf_counters_release.hxx: -------------------------------------------------------------------------------- 1 | #ifndef _PERF_COUNTERS_CALLGUARD_ 2 | #error Include "perf_counter.hpp" instead 3 | #endif 4 | 5 | // F(iscomputed, name, description, expression) 6 | F(false, CIRCUITORAM_OVERFLOW, "Number of times ORAM stash was leaked due to overflow", 0) 7 | F(false, OHMAP_DEAMORT_OVERFLOW, "Number of times OHMAP stash size was leaked due to OHMAP deamortization stash overflow", 0) 8 | -------------------------------------------------------------------------------- /omap/common/tracing/tracer.cpp: -------------------------------------------------------------------------------- 1 | #include "common/tracing/tracer.hpp" 2 | 3 | #ifndef ENCLAVE_MODE 4 | 5 | void print_stacktrace(int signum) { 6 | ::signal(signum, SIG_DFL); 7 | std::cerr << "Stack trace:\n" << boost::stacktrace::stacktrace() << '\n'; 8 | Profiler::g_Tracker.Reset(); 9 | TimeTracker::g_Tracker.Reset(); 10 | g_MaxTracker.Reset(); 11 | ::raise(SIGABRT); 12 | } 13 | 14 | TimeTracker TimeTracker::g_Tracker; 15 | Profiler Profiler::g_Tracker; 16 | 17 | MaxTracker g_MaxTracker; 18 | bool g_disableTracing = false; 19 | bool g_disableProfiling = true; 20 | OnExitHandlerInstaller g_OnExit; 21 | 22 | #endif 23 | 24 | PerfCounters g_PerfCounters; 25 | -------------------------------------------------------------------------------- /omap/common/tracing/tracer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common/defs.hpp" 12 | 13 | #ifndef ENCLAVE_MODE 14 | #include 15 | 16 | extern bool g_disableTracing; 17 | 18 | 19 | enum class EventId : int { 20 | #define F(name) name, 21 | #include "./tracer_events.hxx" 22 | LAST_EVENT 23 | }; 24 | 25 | consteval EventId CE_GetFuncEventId(const char* funcName = SOURCE_LOCATION::current().function_name()) { 26 | #define F(name) if (CE_StringEquals(funcName, # name)) return EventId::name; 27 | #include "./tracer_events.hxx" 28 | return EventId::LAST_EVENT; 29 | } 30 | 31 | // BlockTracer: 32 | // 33 | template 34 | struct BlockTracer { 35 | Metadata metadata; 36 | EventId eventId; 37 | 38 | BlockTracer() = default; 39 | BlockTracer( const BlockTracer& ) = delete; // non construction-copyable 40 | BlockTracer& operator=( const BlockTracer& ) = delete; // non copyable 41 | 42 | INLINE BlockTracer(const EventId eventId) : eventId(eventId) { 43 | Assert(eventId != EventId::LAST_EVENT); 44 | T::g_Tracker.BeginBlock(*this); 45 | } 46 | 47 | INLINE void Finish() { 48 | Assert(eventId != EventId::LAST_EVENT); 49 | T::g_Tracker.Measure(eventId, metadata); 50 | eventId = EventId::LAST_EVENT; 51 | } 52 | 53 | INLINE ~BlockTracer() { 54 | if (eventId != EventId::LAST_EVENT) { 55 | T::g_Tracker.EndBlock(); 56 | } 57 | } 58 | }; 59 | 60 | constexpr uint64_t TOTAL_TRACKERS = static_cast >(EventId::LAST_EVENT); 61 | constexpr uint64_t MAX_TRACKER_REC = 128; 62 | 63 | 64 | /// Code related to initialization 65 | // 66 | extern void print_stacktrace(int signum); 67 | struct OnExitHandlerInstaller { 68 | int theStart; 69 | 70 | void Init() { 71 | theStart = 10; 72 | std::cerr << "Installing signal handler" << std::endl; 73 | ::signal(SIGSEGV, &print_stacktrace); 74 | ::signal(SIGABRT, &print_stacktrace); 75 | ::signal(SIGFPE, &print_stacktrace); 76 | } 77 | 78 | OnExitHandlerInstaller() { 79 | Init(); 80 | } 81 | }; 82 | extern OnExitHandlerInstaller g_OnExit; 83 | // 84 | // 85 | 86 | 87 | #include "trackers/time_tracker.hpp" 88 | #include "trackers/max_tracker.hpp" 89 | #include "trackers/profiler.hpp" 90 | 91 | #endif 92 | 93 | #ifdef ENCLAVE_MODE 94 | #ifdef ENABLE_PROFILING 95 | #undef ENABLE_PROFILING 96 | #endif 97 | #endif 98 | 99 | #ifdef ENABLE_PROFILING 100 | #define PROFILER_SET(val) g_disableProfiling = !val; 101 | #define PROFILER_RESET(...) Profiler::g_Tracker.Reset(__VA_ARGS__); 102 | #define PROFILE_F() typename Profiler::BlockProfiler_t _CONCAT_LINE(profiler)(CE_GetFuncEventId(__FUNCTION__)); 103 | #define PROFILE_B(name) typename Profiler::BlockProfiler_t _CONCAT_LINE(_profiler_##name)(EventId::name); 104 | #define END_PROFILE_B() Profiler::g_Tracker.EndBlock(); 105 | #define SWITCH_PROFILE_B(name) END_PROFILE_B(); PROFILE_B(name); 106 | #else 107 | #define PROFILER_SET(val) 108 | #define PROFILER_RESET(...) 109 | #define PROFILE_F() 110 | #define PROFILE_B(name) 111 | #define END_PROFILE_B() 112 | #define SWITCH_PROFILE_B(name) 113 | #endif 114 | 115 | #if defined ENABLE_PROFILING || defined ENABLE_VALUE_TRACKING 116 | #define PROFILE_V(varName, val) Profiler::g_Tracker.TrackValue(EventId::varName, val) 117 | #else 118 | #define PROFILE_V(varName, val) 119 | #endif 120 | 121 | #if defined ENABLE_TRACING 122 | #define TRACER_SET(val) g_disableTracing = !val 123 | #define TRACER_RESET() TimeTracker::g_Tracker.Reset(); g_MaxTracker.Reset(); 124 | #define TRACE_MAX(varName, val) g_MaxTracker.Update(EventId::varName, val); 125 | #define TRACE_F() typename TimeTracker::BlockTracer_t _CONCAT_LINE(tracer)(CE_GetFuncEventId(__FUNCTION__)); 126 | #define TRACE_B(name) typename TimeTracker::BlockTracer_t _CONCAT_LINE(_tracer_##name)(EventId::name); 127 | #define END_TRACE_B() TimeTracker::g_Tracker.EndBlock(); 128 | #define SWITCH_TRACE_B(name) END_TRACE_B(); TRACE_B(name); 129 | #else 130 | #define TRACER_SET(val) 131 | #define TRACER_RESET() 132 | #define TRACE_F() 133 | #define TRACE_B(name) 134 | #define END_TRACE_B() 135 | #define SWITCH_TRACE_B(name) 136 | #define TRACE_MAX(varName, val) 137 | #endif 138 | 139 | #include "common/tracing/perf.hpp" -------------------------------------------------------------------------------- /omap/common/tracing/tracer_events.hxx: -------------------------------------------------------------------------------- 1 | #ifndef F 2 | #error Define F before including this file 3 | #endif 4 | 5 | F(Encrypt) 6 | F(Decrypt) 7 | F(FileServer) 8 | F(MemServer) 9 | F(FileServerBackend) 10 | F(MemServerBackend) 11 | 12 | #undef F -------------------------------------------------------------------------------- /omap/common/tracing/trackers/max_tracker.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/tracing/tracer.hpp" 3 | 4 | struct MaxTracker { 5 | using eint_t = std::underlying_type_t; 6 | 7 | uint64_t maxes[TOTAL_TRACKERS]; 8 | uint64_t counts[TOTAL_TRACKERS]; 9 | uint64_t totals[TOTAL_TRACKERS]; 10 | 11 | MaxTracker() { 12 | std::cout << "Building MaxTracker" << std::endl; 13 | for (int i=0; i(eventId); 23 | maxes[eid] = std::max(maxes[eid], val); 24 | totals[eid] += val; 25 | counts[eid] ++; 26 | } 27 | 28 | ~MaxTracker() { 29 | Reset(); 30 | } 31 | 32 | void Log() { 33 | #define F(name) { \ 34 | eint_t i = static_cast(EventId::name); \ 35 | if (counts[i] != 0) { \ 36 | std::cout << (#name) \ 37 | << " " << maxes[i] \ 38 | << " " << totals[i] / (double)counts[i]\ 39 | << std::endl; \ 40 | }} 41 | #include "../tracer_events.hxx" 42 | } 43 | 44 | void Reset() { 45 | Log(); 46 | for (int i=0; i; 6 | using eint_t = std::underlying_type_t; 7 | static TimeTracker g_Tracker; 8 | 9 | double totals[TOTAL_TRACKERS]; 10 | uint64_t count[TOTAL_TRACKERS]; 11 | uint64_t blockRecCount; 12 | BlockTracer_t* stack[MAX_TRACKER_REC]; 13 | 14 | explicit TimeTracker() : stack{0} { 15 | std::cout << "Building tracker with " << TOTAL_TRACKERS << " total tracers." << std::endl; 16 | for (int i=0; iFinish(); 33 | } 34 | 35 | INLINE void Measure(const EventId eventId, const std::chrono::_V2::system_clock::time_point& start) { 36 | auto end = std::chrono::system_clock::now(); 37 | if (g_disableTracing) return; 38 | const eint_t eid = static_cast(eventId); 39 | std::chrono::duration diff = end - start; 40 | count[eid]++; 41 | totals[eid] += diff.count(); 42 | } 43 | 44 | ~TimeTracker() { 45 | Reset(); 46 | } 47 | 48 | void Log() { 49 | std::cout << "TimeTracker::Log:" << std::endl; 50 | #define F(name) { \ 51 | eint_t i = static_cast(EventId::name); \ 52 | if (count[i] != 0) { \ 53 | std::cout << (#name) \ 54 | << " " << totals[i] / (std::max((uint64_t)1,count[i])) \ 55 | << " " << totals[i] \ 56 | << " " << count[i] \ 57 | << std::endl; \ 58 | }} 59 | #include "../tracer_events.hxx" 60 | } 61 | 62 | void Reset(bool log=true) { 63 | if (log) { 64 | Log(); 65 | } 66 | for (int i=0; i 4 | 5 | #include "common/defs.hpp" 6 | #include "common/encutils.hpp" 7 | #include "common/mov_intrinsics.hpp" 8 | 9 | constexpr INLINE uint64_t GetNextPowerOfTwo(uint64_t n) { 10 | Assert(n <= 0x8000'0000'0000'0000); 11 | n = n - 1; 12 | n |= n >> 1; 13 | n |= n >> 2; 14 | n |= n >> 4; 15 | n |= n >> 8; 16 | n |= n >> 16; 17 | n |= n >> 32; 18 | n = n + 1; 19 | return n; 20 | } 21 | 22 | INLINE int GetLogBaseTwo(uint64_t n) { 23 | const uint64_t masks[6] = {0x2, 0xC, 0xF0, 24 | 0xFF00, 0xFFFF'0000, 0xFFFF'FFFF'0000'0000}; 25 | int c = 32; 26 | int r = 0; 27 | for (int32_t i = 5; i >= 0; i--) { 28 | const bool cond = n & masks[i]; 29 | obliMove(cond, n, n >> c); 30 | obliMove(cond, r, r | c); 31 | c >>= 1; 32 | } 33 | return r; 34 | } 35 | 36 | constexpr INLINE int GetLogBaseTwoConstexpr(uint64_t n) { 37 | const uint64_t masks[6] = {0x2, 0xC, 0xF0, 38 | 0xFF00, 0xFFFF'0000, 0xFFFF'FFFF'0000'0000}; 39 | int c = 32; 40 | int r = 0; 41 | for (int32_t i = 5; i >= 0; i--) { 42 | const bool cond = n & masks[i]; 43 | if (cond) { 44 | n >>= c; 45 | r |= c; 46 | } 47 | c >>= 1; 48 | } 49 | return r; 50 | } 51 | 52 | INLINE uint64_t CeilLog2(uint64_t x) { 53 | static const uint64_t t[6] = {0xFFFFFFFF00000000ull, 0x00000000FFFF0000ull, 54 | 0x000000000000FF00ull, 0x00000000000000F0ull, 55 | 0x000000000000000Cull, 0x0000000000000002ull}; 56 | 57 | uint64_t y = (((x & (x - 1)) == 0) ? 0 : 1); 58 | int j = 32; 59 | int i; 60 | 61 | for (i = 0; i < 6; i++) { 62 | int k = (((x & t[i]) == 0) ? 0 : j); 63 | y += k; 64 | x >>= k; 65 | j >>= 1; 66 | } 67 | 68 | return y; 69 | } 70 | 71 | extern RandGen default_rand; 72 | 73 | // [left, right] 74 | template 75 | inline T UniformRandom(T left, T right) { 76 | return (T)(default_rand.rand64() % (right - left + 1) + left); 77 | } 78 | 79 | inline uint32_t UniformRandom32(uint32_t left, uint32_t right) { 80 | return default_rand.rand32() % (right - left + 1) + left; 81 | } 82 | 83 | inline bool UniformRandomBit() { return default_rand.rand1(); } 84 | 85 | // [0,right] 86 | template 87 | INLINE T UniformRandom(T right) { 88 | return UniformRandom((T)0, right); 89 | } 90 | 91 | // [0,right] 92 | INLINE uint64_t UniformRandom() { return default_rand.rand64(); } 93 | 94 | INLINE uint32_t UniformRandom32(uint32_t right) { 95 | return UniformRandom32(0, right); 96 | } 97 | 98 | // [0,right] 99 | INLINE uint32_t UniformRandom32() { return default_rand.rand32(); } 100 | 101 | INLINE void GetRandIV(uint8_t* out) { 102 | *(uint64_t*)out = UniformRandom(); 103 | *(uint32_t*)(out + 8) = UniformRandom32(); 104 | } 105 | 106 | // x/y round up 107 | template 108 | INLINE constexpr xT divRoundUp(xT x, yT y) { 109 | return (xT)((x + y - 1) / y); 110 | } 111 | 112 | /** 113 | * Note: this function is not oblivious 114 | */ 115 | template 116 | void fisherYatesShuffle(Iterator begin, Iterator end) { 117 | size_t N = end - begin; 118 | for (size_t n = N - 1; n; --n) { 119 | size_t randPos = UniformRandom(n); 120 | std::swap(*(begin + randPos), *(--end)); 121 | } 122 | } 123 | 124 | size_t reverseBits(size_t num, int bits) { 125 | size_t reverse_num = 0; 126 | for (int i = 0; i < bits; ++i) { 127 | reverse_num |= ((num >> i) & 1) << ((bits - 1) - i); 128 | } 129 | return reverse_num; 130 | } -------------------------------------------------------------------------------- /omap/external_memory/rw_concepts.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * @brief This file defines the concepts for reader and writer. 6 | * 7 | */ 8 | 9 | template 10 | concept _any_of = std::disjunction_v...>; 11 | 12 | template 13 | concept Readable = requires(Reader reader) { 14 | { reader.read() } -> _any_of; 15 | { reader.eof() } -> std::same_as; 16 | { reader.size() } -> std::same_as; 17 | }; 18 | 19 | template 20 | concept Writable = requires(Writer writer, T value) { 21 | { writer.write(value) }; 22 | { writer.eof() } -> std::same_as; 23 | { writer.size() } -> std::same_as; 24 | { writer.flush() }; 25 | }; -------------------------------------------------------------------------------- /omap/external_memory/server/enclaveFileServer_untrusted.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "common/cpp_extended.hpp" 6 | 7 | #define DEFAULT_FILENAME "/ssdmount/storage.bin" 8 | 9 | static uint64_t N; 10 | static std::unique_ptr lbios(nullptr); 11 | 12 | uint8_t* ocall_InitServer(uint64_t sizeOfT, uint64_t N_) { 13 | lbios.reset(new std::fstream()); 14 | N = N_; 15 | lbios->open(DEFAULT_FILENAME, std::fstream::in | std::fstream::out | 16 | std::fstream::binary | std::fstream::trunc); 17 | Assert(lbios->is_open()); 18 | return NULL; 19 | } 20 | 21 | void ocall_Read(size_t pos, uint64_t length, uint8_t* page) { 22 | std::ifstream file(DEFAULT_FILENAME, std::ios::binary); 23 | std::streampos filePos = pos; 24 | file.seekg(filePos, std::ios::beg); 25 | file.read((char*)page, length); 26 | if (!file) { 27 | throw std::runtime_error("read failed"); 28 | } 29 | } 30 | 31 | void ocall_Write(uint64_t pos, uint64_t length, const uint8_t* page) { 32 | std::ofstream file(DEFAULT_FILENAME, 33 | std::ios::binary | std::ios::in | std::ios::out); 34 | std::streampos filePos = pos; 35 | file.seekp(filePos, std::ios::beg); 36 | file.write((char*)page, length); 37 | if (!file) { 38 | throw std::runtime_error("write failed"); 39 | } 40 | } 41 | 42 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, 43 | uint64_t totalBytes, uint64_t* offsets, uint8_t* buffer) { 44 | // printf("batch read %ld chunks of total size %ld\n", batchSize, totalBytes); 45 | uint8_t* pos = buffer; 46 | for (uint64_t i = 0; i < batchSize; ++i) { 47 | uint64_t offset = *(offsets + i); 48 | ocall_Read(offset, pageBytes, pos); 49 | pos += pageBytes; 50 | } 51 | } 52 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, 53 | uint64_t totalBytes, uint64_t* offsets, 54 | uint8_t* buffer) { 55 | // printf("batch write %ld chunks of total size %ld\n", batchSize, 56 | // totalBytes); 57 | uint8_t* pos = buffer; 58 | for (uint64_t i = 0; i < batchSize; ++i) { 59 | uint64_t offset = *(offsets + i); 60 | ocall_Write(offset, pageBytes, pos); 61 | pos += pageBytes; 62 | } 63 | } 64 | 65 | void ocall_DeleteServer() { lbios->close(); } -------------------------------------------------------------------------------- /omap/external_memory/server/enclaveMemServer_untrusted.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #ifndef ENCLAVE_MODE 5 | // #warning Defining enclave mode 6 | #define ENCLAVE_MODE 7 | // #define NDEBUG 8 | #endif 9 | 10 | #include "common/cpp_extended.hpp" 11 | 12 | static uint64_t N; 13 | uint8_t* data; 14 | 15 | uint8_t* ocall_InitServer(uint64_t sizeOfT, uint64_t N_) { 16 | // printf("init mem server\n"); 17 | data = new uint8_t[sizeOfT * N_]; 18 | N = N_; 19 | return data; 20 | } 21 | 22 | void ocall_Read(size_t pos, uint64_t length, uint8_t* page) { 23 | std::memcpy(page, &data[pos], length); 24 | } 25 | 26 | void ocall_Write(uint64_t pos, uint64_t length, const uint8_t* page) { 27 | std::memcpy(&data[pos], page, length); 28 | } 29 | 30 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, 31 | uint64_t totalBytes, uint64_t* offsets, uint8_t* buffer) { 32 | // printf("batch read %ld chunks of total size %ld\n", batchSize, totalBytes); 33 | uint8_t* pos = buffer; 34 | for (uint64_t i = 0; i < batchSize; ++i) { 35 | uint64_t offset = *(offsets + i); 36 | ocall_Read(offset, pageBytes, pos); 37 | pos += pageBytes; 38 | } 39 | } 40 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, 41 | uint64_t totalBytes, uint64_t* offsets, 42 | uint8_t* buffer) { 43 | // printf("batch write %ld chunks of total size %ld\n", batchSize, 44 | // totalBytes); 45 | uint8_t* pos = buffer; 46 | for (uint64_t i = 0; i < batchSize; ++i) { 47 | uint64_t offset = *(offsets + i); 48 | ocall_Write(offset, pageBytes, pos); 49 | pos += pageBytes; 50 | } 51 | } 52 | 53 | void ocall_DeleteServer() { 54 | if (data) { 55 | delete[] data; 56 | } 57 | data = NULL; 58 | } -------------------------------------------------------------------------------- /omap/external_memory/server/enclaveMmapFileServer_untrusted.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common/cpp_extended.hpp" 13 | 14 | #define DEFAULT_FILENAME "/ssdmount/storage.bin" 15 | 16 | static uint64_t N; 17 | int fd; 18 | uint8_t* data; 19 | uint8_t* ocall_InitServer(uint64_t sizeOfT, uint64_t N_) { 20 | N = N_; 21 | int fd = open(DEFAULT_FILENAME, O_RDWR | O_CREAT | O_TRUNC, 0644); 22 | int allocRes = fallocate64(fd, 0, 0, N * sizeOfT); 23 | if (allocRes != 0) { 24 | std::cerr << "Error allocating space for the file." << std::endl; 25 | close(fd); 26 | return NULL; 27 | } 28 | if (fd == -1) { 29 | std::cerr << "Error opening file for writing." << std::endl; 30 | return NULL; 31 | } 32 | data = static_cast( 33 | mmap(nullptr, N * sizeOfT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); 34 | if (data == MAP_FAILED) { 35 | std::cerr << "Error memory mapping the file." << std::endl; 36 | close(fd); 37 | return NULL; 38 | } 39 | return NULL; 40 | } 41 | 42 | void ocall_Read(size_t pos, uint64_t length, uint8_t* page) { 43 | std::memcpy(page, data + pos, length); 44 | } 45 | 46 | void ocall_Write(uint64_t pos, uint64_t length, const uint8_t* page) { 47 | std::memcpy(data + pos, page, length); 48 | } 49 | 50 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, 51 | uint64_t totalBytes, uint64_t* offsets, uint8_t* buffer) { 52 | // printf("batch read %ld chunks of total size %ld\n", batchSize, totalBytes); 53 | uint8_t* pos = buffer; 54 | for (uint64_t i = 0; i < batchSize; ++i) { 55 | uint64_t offset = *(offsets + i); 56 | ocall_Read(offset, pageBytes, pos); 57 | pos += pageBytes; 58 | } 59 | } 60 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, 61 | uint64_t totalBytes, uint64_t* offsets, 62 | uint8_t* buffer) { 63 | // printf("batch write %ld chunks of total size %ld\n", batchSize, 64 | // totalBytes); 65 | uint8_t* pos = buffer; 66 | for (uint64_t i = 0; i < batchSize; ++i) { 67 | uint64_t offset = *(offsets + i); 68 | ocall_Write(offset, pageBytes, pos); 69 | pos += pageBytes; 70 | } 71 | } 72 | 73 | void ocall_DeleteServer() { 74 | if (munmap(data, N) == -1) { 75 | std::cerr << "Error unmapping the file." << std::endl; 76 | } 77 | close(fd); 78 | } -------------------------------------------------------------------------------- /omap/external_memory/server/serverAllocator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "common/lock_util.hpp" 7 | 8 | namespace EM { 9 | // LargeBlockAllocator 10 | // This is a slow allocator used only in oblivious structures constructors. 11 | // This is not optimized for speed, it is meant to not be used very frequently 12 | // to connect oblivious structure memory managers to the external server 13 | // singleton. 14 | // 15 | struct LargeBlockAllocator { 16 | typedef uint64_t Size_t; 17 | struct AllocatorSlot { 18 | Size_t base; 19 | Size_t size; 20 | }; 21 | 22 | Size_t size; 23 | Lock lock; 24 | 25 | // $Invariant: IsSorted(freeList) 26 | // 27 | std::vector freeList; 28 | 29 | explicit LargeBlockAllocator(Size_t _size) 30 | : size(_size), freeList({AllocatorSlot{.base = 0, .size = _size}}) { 31 | freeList.reserve(1000); 32 | } 33 | 34 | const AllocatorSlot Allocate(Size_t _size) { 35 | Critical section(lock); 36 | TRACE_FUNCTION(_size); 37 | 38 | uint64_t bestIdx = -1; 39 | uint64_t bestSize = -1; 40 | for (uint64_t i = 0; i < freeList.size(); i++) { 41 | if (freeList[i].size >= _size) { 42 | if (freeList[i].size < bestSize) { 43 | bestSize = freeList[i].size; 44 | bestIdx = i; 45 | if (bestSize == _size) break; 46 | } 47 | } 48 | } 49 | 50 | // Assert(bestIdx != (uint64_t)-1); 51 | if (bestIdx == (uint64_t)-1) { 52 | throw std::runtime_error("LargeBlockAllocator: Out of memory"); 53 | } 54 | AllocatorSlot ret = freeList[bestIdx]; 55 | ret.size = _size; 56 | freeList[bestIdx].size -= _size; 57 | freeList[bestIdx].base += _size; 58 | if (freeList[bestIdx].size == 0) { 59 | freeList.erase(freeList.begin() + bestIdx); 60 | } 61 | return ret; 62 | } 63 | 64 | void Free(const AllocatorSlot& slot) { 65 | Critical section(lock); 66 | TRACE_FUNCTION(slot.base, slot.size); 67 | 68 | if (slot.size == 0) return; 69 | 70 | AllocatorSlot tmp = slot; 71 | // In place insert: 72 | // 73 | for (uint64_t i = 0; i < freeList.size(); i++) { 74 | if (freeList[i].base > tmp.base) { 75 | std::swap(freeList[i], tmp); 76 | } 77 | } 78 | freeList.push_back(tmp); 79 | 80 | // Now we should coallesce the blocks: 81 | // 82 | uint64_t j = 0; 83 | for (uint64_t i = 1; i < freeList.size(); i++) { 84 | if (freeList[j].base + freeList[j].size == freeList[i].base) { 85 | freeList[j].size += freeList[i].size; 86 | } else { 87 | j++; 88 | if (i != j) { 89 | freeList[j] = freeList[i]; 90 | } 91 | } 92 | } 93 | freeList.resize(j + 1); 94 | } 95 | }; 96 | } // namespace EM -------------------------------------------------------------------------------- /omap/external_memory/server/serverBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "external_memory/server/serverBackend.hpp" 2 | // #include "external_memory/server/batchBackend.hpp" 3 | 4 | EM::Backend::MemServerBackend* EM::Backend::g_DefaultBackend = nullptr; 5 | 6 | struct MemServerInstaller { 7 | MemServerInstaller() { 8 | // EM::Backend::g_DefaultBackend = new EM::Backend::MemServerBackend(1<<28); 9 | EM::Backend::g_DefaultBackend = new EM::Backend::MemServerBackend(1 << 28); 10 | } 11 | }; 12 | MemServerInstaller g_MemServerInstaller; 13 | -------------------------------------------------------------------------------- /omap/external_memory/server/serverBackend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common/lrucache.hpp" 8 | #include "common/tracing/tracer.hpp" 9 | #include "external_memory/server/serverAllocator.hpp" 10 | 11 | namespace EM { 12 | enum PageSlotState { EMPTY_PAGE, PENDING_PAGE, DONE_PAGE }; 13 | namespace Backend { 14 | 15 | template 16 | concept BackendServer = requires( 17 | FS fs, uint64_t indexType, const EM::LargeBlockAllocator::AllocatorSlot cas, 18 | uint8_t* u8p, const uint8_t* cu8p) { 19 | { FS(indexType) }; 20 | { 21 | fs.Allocate(indexType) 22 | } -> std::same_as; 23 | { fs.Free(cas) }; 24 | { fs.Write(indexType, indexType, cu8p) }; 25 | { fs.Read(indexType, indexType, u8p) }; 26 | }; 27 | 28 | #define SERVER_SIZE (1 << 16) 29 | 30 | struct ServerBackend : EM::LargeBlockAllocator { 31 | // Read and Write bytes, contains an allocator. 32 | // 33 | using typename EM::LargeBlockAllocator::AllocatorSlot; 34 | using typename EM::LargeBlockAllocator::Size_t; 35 | 36 | explicit ServerBackend(uint64_t _size) : EM::LargeBlockAllocator(_size) {} 37 | }; 38 | 39 | struct MemServerBackend : ServerBackend { 40 | uint8_t* data; 41 | #ifndef ENCLAVE_MODE 42 | void ocall_InitServer(uint8_t** data_ptr, uint64_t pageBytes, 43 | uint64_t numPage) { 44 | *data_ptr = new uint8_t[pageBytes * numPage]; 45 | } 46 | 47 | void ocall_DeleteServer() { delete[] (data); } 48 | #endif 49 | 50 | #ifndef DISK_IO 51 | void ocall_Read(uint64_t offset, uint64_t sz, uint8_t* buffer) { 52 | std::memcpy(buffer, &data[offset], sz); 53 | } 54 | void ocall_Write(uint64_t offset, uint64_t sz, const uint8_t* buffer) { 55 | std::memcpy(&data[offset], buffer, sz); 56 | } 57 | #endif 58 | 59 | explicit MemServerBackend(uint64_t _size) : ServerBackend(_size) { 60 | ocall_InitServer(&data, 4096, (size - 1) / 4096 + 1); 61 | } 62 | 63 | ~MemServerBackend() { ocall_DeleteServer(); } 64 | 65 | void Read(uint64_t offset, uint64_t sz, uint8_t* to) { 66 | ocall_Read(offset, sz, to); 67 | } 68 | 69 | void Write(uint64_t offset, uint64_t sz, const uint8_t* from) { 70 | ocall_Write(offset, sz, from); 71 | } 72 | 73 | #ifndef DISK_IO 74 | void ocall_Read_Batch(uint64_t batchSize, uint64_t pageBytes, 75 | uint64_t totalBytes, uint64_t* offsets, 76 | uint8_t* buffer) { 77 | uint8_t* pos = buffer; 78 | for (uint64_t i = 0; i < batchSize; ++i) { 79 | uint64_t offset = *(offsets + i); 80 | ocall_Read(offset, pageBytes, pos); 81 | pos += pageBytes; 82 | } 83 | } 84 | void ocall_Write_Batch(uint64_t batchSize, uint64_t pageBytes, 85 | uint64_t totalBytes, uint64_t* offsets, 86 | uint8_t* buffer) { 87 | uint8_t* pos = buffer; 88 | for (uint64_t i = 0; i < batchSize; ++i) { 89 | uint64_t offset = *(offsets + i); 90 | ocall_Write(offset, pageBytes, pos); 91 | pos += pageBytes; 92 | } 93 | } 94 | #endif 95 | void ReadBatch(uint64_t batchSize, uint64_t pageBytes, uint64_t* offsets, 96 | uint8_t* out) { 97 | ocall_Read_Batch(batchSize, pageBytes, pageBytes * batchSize, offsets, out); 98 | } 99 | 100 | void WriteBatch(uint64_t batchSize, uint64_t pageBytes, uint64_t* offsets, 101 | uint8_t* in) { 102 | ocall_Write_Batch(batchSize, pageBytes, pageBytes * batchSize, offsets, in); 103 | } 104 | }; 105 | extern MemServerBackend* g_DefaultBackend; 106 | } // namespace Backend 107 | } // namespace EM -------------------------------------------------------------------------------- /omap/external_memory/stdvector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "common/defs.hpp" 5 | /** 6 | * A wrapper for std::vector with the same interface as the other vector 7 | * containers 8 | * */ 9 | template 10 | struct StdVector : public std::vector { 11 | struct Iterator : public std::vector::iterator { 12 | using vector_type = StdVector; 13 | using iterator_category = std::random_access_iterator_tag; 14 | 15 | Iterator() : std::vector::iterator() {} 16 | 17 | // Constructor to initialize the base iterator and custom attribute 18 | explicit Iterator(const typename std::vector::iterator& it) 19 | : std::vector::iterator(it) {} 20 | 21 | friend Iterator operator+(const Iterator& it, size_t size) { 22 | return Iterator(typename std::vector::iterator(it) + size); 23 | } 24 | 25 | friend Iterator operator-(const Iterator& it, size_t size) { 26 | return Iterator(typename std::vector::iterator(it) - size); 27 | } 28 | 29 | friend Iterator operator+(const Iterator& it, int64_t size) { 30 | return Iterator(typename std::vector::iterator(it) + size); 31 | } 32 | 33 | friend Iterator operator-(const Iterator& it, int64_t size) { 34 | return Iterator(typename std::vector::iterator(it) - size); 35 | } 36 | 37 | friend Iterator operator+(const Iterator& it, int32_t size) { 38 | return Iterator(typename std::vector::iterator(it) + size); 39 | } 40 | 41 | friend Iterator operator-(const Iterator& it, int32_t size) { 42 | return Iterator(typename std::vector::iterator(it) - size); 43 | } 44 | 45 | friend Iterator operator+(const Iterator& it, uint32_t size) { 46 | return Iterator(typename std::vector::iterator(it) + size); 47 | } 48 | 49 | friend Iterator operator-(const Iterator& it, uint32_t size) { 50 | return Iterator(typename std::vector::iterator(it) - size); 51 | } 52 | }; 53 | StdVector() : std::vector() {} 54 | explicit StdVector(uint64_t N) : std::vector(N) {} 55 | StdVector(Iterator begin, Iterator end) : std::vector(begin, end) {} 56 | 57 | StdVector(uint64_t N, const T& val) : std::vector(N, val) {} 58 | StdVector(const StdVector& other) : std::vector(other) {} 59 | StdVector(StdVector&& other) : std::vector(std::move(other)) {} 60 | 61 | Iterator begin() { return Iterator(std::vector::begin()); } 62 | 63 | Iterator end() { return Iterator(std::vector::end()); } 64 | 65 | void resize(uint64_t N) { std::vector::resize(N); } 66 | void SetSize(uint64_t N, uint64_t _ignore1 = 0, uint64_t _ignore2 = 0) { 67 | resize(N); 68 | } 69 | INLINE size_t size() { return std::vector::size(); } 70 | 71 | struct Reader { 72 | using value_type = T; 73 | using iterator_type = Iterator; 74 | Iterator it; 75 | Iterator end; 76 | 77 | Reader() {} 78 | 79 | Reader(Iterator _begin, Iterator _end) : it(_begin), end(_end) {} 80 | 81 | void init(Iterator _begin, Iterator _end) { 82 | it = _begin; 83 | end = _end; 84 | } 85 | 86 | INLINE T& get() { 87 | Assert(!eof()); 88 | return *it; 89 | } 90 | 91 | INLINE const T& read() { 92 | const T& val = get(); 93 | ++it; 94 | return val; 95 | } 96 | 97 | INLINE bool eof() { return end <= it; } 98 | 99 | size_t size() { return end - it; } 100 | }; 101 | 102 | struct Writer { 103 | using value_type = T; 104 | using iterator_type = Iterator; 105 | Iterator it; 106 | Iterator end; 107 | Writer() {} 108 | 109 | Writer(Iterator _begin, Iterator _end) : it(_begin), end(_end) {} 110 | 111 | void init(Iterator _begin, Iterator _end) { 112 | it = _begin; 113 | end = _end; 114 | } 115 | 116 | INLINE void write(const T& element) { 117 | *it = element; 118 | ++it; 119 | } 120 | 121 | INLINE bool eof() { return end <= it; } 122 | 123 | size_t size() { return end - it; } 124 | 125 | INLINE void flush() {} 126 | }; 127 | }; -------------------------------------------------------------------------------- /omap/interface/common_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "omap_generic_interface.hpp" 6 | void HelloWorld(uint32_t num) { printf("Hello, world %u!\n", num); } 7 | 8 | #include "external_memory/server/serverBackend.hpp" 9 | #include "interface/common_interface.hpp" 10 | void ResetBackend(uint64_t size) { 11 | if (EM::Backend::g_DefaultBackend) { 12 | delete EM::Backend::g_DefaultBackend; 13 | } 14 | EM::Backend::g_DefaultBackend = new EM::Backend::MemServerBackend(size); 15 | } 16 | 17 | void DeleteBackend() { 18 | if (EM::Backend::g_DefaultBackend) { 19 | delete EM::Backend::g_DefaultBackend; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /omap/interface/common_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | void ResetBackend(uint64_t size); 5 | void DeleteBackend(); 6 | 7 | void HelloWorld(uint32_t num); 8 | 9 | template 10 | struct TestKey { 11 | K key; 12 | uint32_t val; 13 | }; -------------------------------------------------------------------------------- /omap/interface/interface.cpp: -------------------------------------------------------------------------------- 1 | #include "common_impl.hpp" 2 | #include "recoram_impl.hpp" 3 | // #include "omap_impl.hpp" 4 | #include "omap_spec_impl.hpp" 5 | #include "par_omap_impl.hpp" -------------------------------------------------------------------------------- /omap/interface/omap_c.h: -------------------------------------------------------------------------------- 1 | #ifndef OMAP_C_H 2 | #define OMAP_C_H 3 | 4 | #include 5 | // A pure C header file for C binding 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define OMAP_TYPE(KS, VS) OMapType##_##KS##_##VS 11 | 12 | enum OMapEnum { 13 | #undef DECLARE_OMAP 14 | #define DECLARE_OMAP(KS, VS) OMAP_TYPE(KS, VS) = KS * 65536 + VS, 15 | #include "omap_declare.cfg" 16 | #undef DECLARE_OMAP 17 | }; 18 | 19 | struct OblivMap { 20 | void* omap; 21 | enum OMapEnum type; 22 | }; 23 | 24 | typedef struct OblivMap OblivMap; 25 | 26 | OblivMap NewOblivMap(int keySize, int valSize); 27 | void InitEmpty(OblivMap omap, uint32_t size); 28 | void InitEmptyExternal(OblivMap omap, uint32_t size, uint64_t cacheBytes); 29 | void StartInit(OblivMap omap, uint32_t size); 30 | void StartInitExternal(OblivMap omap, uint32_t size, uint64_t cacheBytes); 31 | void FinishInit(OblivMap omap); 32 | uint8_t Insert(OblivMap omap, const void* keyPtr, const void* valPtr); 33 | uint8_t OInsert(OblivMap omap, const void* keyPtr, const void* valPtr); 34 | uint8_t Erase(OblivMap omap, const void* keyPtr); 35 | uint8_t OErase(OblivMap omap, const void* keyPtr); 36 | uint8_t Find(OblivMap omap, const void* keyPtr, void* valPtr); 37 | void Destroy(OblivMap omap); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif -------------------------------------------------------------------------------- /omap/interface/omap_declare.cfg: -------------------------------------------------------------------------------- 1 | DECLARE_OMAP(8, 8) 2 | DECLARE_OMAP(20, 32) -------------------------------------------------------------------------------- /omap/interface/omap_generic_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef void* omap_t; 5 | typedef void* initializer_t; 6 | 7 | /** 8 | * @brief Binds to OMap implementation. 9 | * 10 | */ 11 | template 12 | struct OMapGenericBinding { 13 | omap_t omap; // pointer to the OMap object 14 | initializer_t initializer; // pointer to the OMap initializer 15 | OMapGenericBinding(); 16 | 17 | /** 18 | * @brief Initializes an empty OMap. Assumes sufficiently large enclave size. 19 | * 20 | * @param size The maximum number of key-value pairs the map can hold. 21 | */ 22 | void InitEmpty(uint32_t size); 23 | 24 | /** 25 | * @brief Initializes an empty OMap. Uses at most cacheBytes bytes of EPC 26 | * memory. 27 | * 28 | * @param size The maximum number of key-value pairs the map can hold. 29 | * @param cacheBytes The maximum number of bytes to use for caching. 30 | */ 31 | void InitEmptyExternal(uint32_t size, uint64_t cacheBytes); 32 | 33 | /** 34 | * @brief Inserts a key-value pair into the map. The method can be called 35 | * either during initialization or after initialization. The method leaks 36 | * whether the key already exists. 37 | * 38 | * @param key The key to insert. 39 | * @param val The value to insert. 40 | * @return Always false if called during initialization. Otherwise, returns 41 | * true if the key already exists, false otherwise. 42 | */ 43 | bool Insert(const void* keyPtr, const void* valPtr); 44 | 45 | /** 46 | * @brief Inserts a key-value pair into the map obliviously. The method can be 47 | * called either during initialization or after initialization. If the method 48 | * is called during initialization, it is same as Insert. Otherwise, the 49 | * insertion is fully oblivious, and is about 3x slower than Insert. 50 | * 51 | * @param key 52 | * @param val 53 | * @return true 54 | * @return false 55 | */ 56 | bool OInsert(const void* keyPtr, const void* valPtr); 57 | 58 | /** 59 | * @brief Finds a key in the map. The method is oblivious. 60 | * 61 | * @param key The key to find. 62 | * @param val Outputs the value corresponding to the key. 63 | * @return true if the key is found, false otherwise. 64 | */ 65 | bool Find(const void* keyPtr, void* valPtr); 66 | 67 | /** 68 | * @brief Erases a key from the map. The method is not oblivious, and can leak 69 | * if the key exists. 70 | * 71 | * @param key The key to erase. 72 | * @return true if the key existed in the map, false otherwise. 73 | */ 74 | bool Erase(const void* keyPtr); 75 | 76 | /** 77 | * @brief Erases a key from the map obliviously. 1~2x slower than Erase. 78 | * 79 | * @param key The key to erase. 80 | * @return true if the key existed in the map, false otherwise. 81 | */ 82 | bool OErase(const void* keyPtr); 83 | 84 | /** 85 | * @brief Start initializing the OMap. Assumes sufficiently large EPC. Cannot 86 | * be called together with InitEmpty or InitEmptyExternal. Only Insert or 87 | * OInsert can be called during initialization. 88 | * 89 | * @param size The maximum number of key-value pairs the map can hold. 90 | */ 91 | void StartInit(uint32_t size); 92 | 93 | /** 94 | * @brief Start initializing the OMap using at most cacheBytes bytes of EPC 95 | * memory. Cannot be called together with InitEmpty or InitEmptyExternal. Only 96 | * Insert or OInsert can be called during initialization. 97 | * 98 | * @param size The maximum number of key-value pairs the map can hold. 99 | */ 100 | void StartInitExternal(uint32_t size, uint64_t cacheBytes); 101 | 102 | /** 103 | * @brief Finish the initialization. Must be called after StartInit or 104 | * StartInitExternal. 105 | * 106 | */ 107 | void FinishInit(); 108 | 109 | void Destroy(); 110 | 111 | ~OMapGenericBinding(); 112 | }; 113 | -------------------------------------------------------------------------------- /omap/interface/omap_spec_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "omap_generic_impl.hpp" 3 | #include "omap_spec_interface.hpp" 4 | 5 | #define DECLARE_OMAP_BINDING_IMPL(KS, VS) \ 6 | OMapBinding(KS, VS)::OMapBinding(KS, VS)() {} \ 7 | void OMapBinding(KS, VS)::InitEmpty(uint32_t size) { omap.InitEmpty(size); } \ 8 | void OMapBinding(KS, VS)::InitEmptyExternal(uint32_t size, \ 9 | uint64_t cacheBytes) { \ 10 | omap.InitEmptyExternal(size, cacheBytes); \ 11 | } \ 12 | void OMapBinding(KS, VS)::StartInit(uint32_t size) { omap.StartInit(size); } \ 13 | void OMapBinding(KS, VS)::StartInitExternal(uint32_t size, \ 14 | uint64_t cacheBytes) { \ 15 | omap.StartInitExternal(size, cacheBytes); \ 16 | } \ 17 | void OMapBinding(KS, VS)::FinishInit() { omap.FinishInit(); } \ 18 | bool OMapBinding(KS, VS)::Insert(const void* keyPtr, const void* valPtr) { \ 19 | return omap.Insert(keyPtr, valPtr); \ 20 | } \ 21 | bool OMapBinding(KS, VS)::OInsert(const void* keyPtr, const void* valPtr) { \ 22 | return omap.OInsert(keyPtr, valPtr); \ 23 | } \ 24 | bool OMapBinding(KS, VS)::Erase(const void* keyPtr) { \ 25 | return omap.Erase(keyPtr); \ 26 | } \ 27 | bool OMapBinding(KS, VS)::OErase(const void* keyPtr) { \ 28 | return omap.OErase(keyPtr); \ 29 | } \ 30 | bool OMapBinding(KS, VS)::Find(const void* keyPtr, void* valPtr) { \ 31 | return omap.Find(keyPtr, valPtr); \ 32 | } \ 33 | void OMapBinding(KS, VS)::Destroy() { omap.Destroy(); } \ 34 | OMapBinding(KS, VS)::~OMapBinding(KS, VS)() {} 35 | 36 | #undef DECLARE_OMAP 37 | #define DECLARE_OMAP(KS, VS) DECLARE_OMAP_BINDING_IMPL(KS, VS) 38 | #include "omap_declare.cfg" -------------------------------------------------------------------------------- /omap/interface/omap_spec_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "omap_generic_interface.hpp" 5 | 6 | #define OMapBinding(OMAP_KEY_SIZE, OMAP_VAL_SIZE) \ 7 | OMapBinding##_##OMAP_KEY_SIZE##_##OMAP_VAL_SIZE 8 | 9 | #define DECLARE_OMAP_BINDING(OMAP_KEY_SIZE, OMAP_VAL_SIZE) \ 10 | struct OMapBinding(OMAP_KEY_SIZE, OMAP_VAL_SIZE) { \ 11 | OMapGenericBinding omap; \ 12 | OMapBinding(OMAP_KEY_SIZE, OMAP_VAL_SIZE)(); \ 13 | void InitEmpty(uint32_t size); \ 14 | void InitEmptyExternal(uint32_t size, uint64_t cacheBytes); \ 15 | void StartInit(uint32_t size); \ 16 | void StartInitExternal(uint32_t size, uint64_t cacheBytes); \ 17 | void FinishInit(); \ 18 | bool Insert(const void* keyPtr, const void* valPtr); \ 19 | bool OInsert(const void* keyPtr, const void* valPtr); \ 20 | bool Erase(const void* keyPtr); \ 21 | bool OErase(const void* keyPtr); \ 22 | bool Find(const void* keyPtr, void* valPtr); \ 23 | void Destroy(); \ 24 | ~OMapBinding(OMAP_KEY_SIZE, OMAP_VAL_SIZE)(); \ 25 | }; 26 | 27 | #define DECLARE_OMAP(KS, VS) DECLARE_OMAP_BINDING(KS, VS) 28 | #include "omap_declare.cfg" 29 | #undef DECLARE_OMAP -------------------------------------------------------------------------------- /omap/interface/par_omap_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "odsl/par_omap.hpp" 3 | #include "par_omap_interface.hpp" 4 | 5 | using ParMapType = ODSL::ParOMap; 6 | using ParInitializerType = typename ParMapType::InitContext; 7 | 8 | ParOMapBinding::ParOMapBinding() { 9 | omap = nullptr; 10 | initializer = nullptr; 11 | } 12 | 13 | void ParOMapBinding::InitEmpty(uint32_t size, uint32_t numCores) { 14 | uint32_t shardCount = ParMapType::GetSuitableShardCount(numCores, true); 15 | omap = (void*)(new ParMapType(size, shardCount)); 16 | ((ParMapType*)omap)->Init(); 17 | } 18 | 19 | void ParOMapBinding::InitEmptyExternal(uint32_t size, uint32_t numCores, 20 | uint64_t cacheBytes) { 21 | uint32_t shardCount = ParMapType::GetSuitableShardCount(numCores, true); 22 | omap = (void*)(new ParMapType(size, shardCount)); 23 | ((ParMapType*)omap)->Init(cacheBytes); 24 | } 25 | 26 | void ParOMapBinding::StartInit(uint32_t size, uint32_t initSize, 27 | uint32_t numCores) { 28 | uint32_t shardCount = ParMapType::GetSuitableShardCount(numCores, false); 29 | omap = (void*)(new ParMapType(size, shardCount)); 30 | initializer = (void*)(((ParMapType*)omap)->NewInitContext(initSize)); 31 | } 32 | 33 | void ParOMapBinding::StartInitExternal(uint32_t size, uint32_t initSize, 34 | uint32_t numCores, uint64_t cacheBytes) { 35 | uint32_t shardCount = ParMapType::GetSuitableShardCount(numCores, false); 36 | omap = (void*)(new ParMapType(size, shardCount)); 37 | initializer = 38 | (void*)(((ParMapType*)omap)->NewInitContext(initSize, cacheBytes)); 39 | } 40 | 41 | void ParOMapBinding::FinishInit() { 42 | Assert(initializer, "FinishInit without StartInit"); 43 | ((ParInitializerType*)initializer)->Finalize(); 44 | delete (ParInitializerType*)initializer; 45 | initializer = nullptr; 46 | } 47 | 48 | void ParOMapBinding::InsertBatch(uint32_t batchSize, const K* keys, 49 | const V* vals, bool* existFlags) { 50 | if (initializer) { 51 | for (uint32_t i = 0; i < batchSize; ++i) { 52 | ((ParInitializerType*)initializer)->Insert(keys[i], vals[i]); 53 | } 54 | return; 55 | } 56 | std::vector resFlags = 57 | ((ParMapType*)omap)->InsertBatch(keys, keys + batchSize, vals); 58 | for (uint32_t i = 0; i < batchSize; ++i) { 59 | existFlags[i] = resFlags[i]; 60 | } 61 | } 62 | 63 | void ParOMapBinding::FindBatch(uint32_t batchSize, const K* keys, V* vals, 64 | bool* existFlags) { 65 | Assert(!initializer, "Find during initialization"); 66 | std::vector resFlags = 67 | ((ParMapType*)omap)->FindBatch(keys, keys + batchSize, vals); 68 | for (uint32_t i = 0; i < batchSize; ++i) { 69 | existFlags[i] = resFlags[i]; 70 | } 71 | } 72 | 73 | void ParOMapBinding::FindBatchDeferMaintain(uint32_t batchSize, const K* keys, 74 | V* vals, bool* existFlags) { 75 | Assert(!initializer, "Find during initialization"); 76 | std::vector resFlags = 77 | ((ParMapType*)omap) 78 | ->FindBatchDeferWriteBack(keys, keys + batchSize, vals); 79 | for (uint32_t i = 0; i < batchSize; ++i) { 80 | existFlags[i] = resFlags[i]; 81 | } 82 | } 83 | 84 | void ParOMapBinding::FindBatchMaintain() { 85 | Assert(!initializer, "Find during initialization"); 86 | ((ParMapType*)omap)->WriteBack(); 87 | } 88 | 89 | void ParOMapBinding::EraseBatch(uint32_t batchSize, const K* keys, 90 | bool* existFlags) { 91 | Assert(!initializer, "Erase during initialization"); 92 | std::vector resFlags = 93 | ((ParMapType*)omap)->EraseBatch(keys, keys + batchSize); 94 | for (uint32_t i = 0; i < batchSize; ++i) { 95 | existFlags[i] = resFlags[i]; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /omap/interface/recoram_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "odsl/recursive_oram.hpp" 3 | #include "recoram_interface.hpp" 4 | 5 | ORAMBinding::ORAMBinding() { oram = nullptr; } 6 | 7 | using ORAMType = ODSL::RecursiveORAM; 8 | 9 | void ORAMBinding::InitORAM(uint32_t size) { 10 | Assert(oram == nullptr); 11 | oram = (void*)(new ORAMType(size)); 12 | ((ORAMType*)oram)->InitDefault(T()); 13 | } 14 | 15 | void ORAMBinding::InitORAMExternal(uint32_t size, uint64_t cacheBytes) { 16 | Assert(oram == nullptr); 17 | oram = (void*)(new ORAMType(size, cacheBytes)); 18 | ((ORAMType*)oram)->InitDefault(T()); 19 | } 20 | 21 | void ORAMBinding::Write(uint32_t addr, T val) { 22 | ((ORAMType*)oram)->Write(addr, val); 23 | } 24 | 25 | T ORAMBinding::Read(uint32_t addr) { 26 | T ret; 27 | ((ORAMType*)oram)->Read(addr, ret); 28 | return ret; 29 | } 30 | 31 | ORAMBinding::~ORAMBinding() { 32 | if (oram) { 33 | delete (ORAMType*)oram; 34 | } 35 | } -------------------------------------------------------------------------------- /omap/interface/recoram_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef void* oram_t; 5 | typedef uint64_t T; 6 | 7 | struct ORAMBinding { 8 | oram_t oram; // pointer to the ORAM object 9 | ORAMBinding(); 10 | 11 | /** 12 | * @brief Initializes an empty ORAM. Assumes sufficiently large enclave size. 13 | * 14 | * @param size The maximum number of elements the ORAM can hold. 15 | */ 16 | void InitORAM(uint32_t size); 17 | 18 | /** 19 | * @brief Initializes an empty ORAM using at most cacheBytes bytes of EPC 20 | * memory. 21 | * 22 | * @param size The maximum number of elements the ORAM can hold. 23 | * @param cacheBytes The maximum number of bytes to use for caching. 24 | */ 25 | void InitORAMExternal(uint32_t size, uint64_t cacheBytes); 26 | 27 | /** 28 | * @brief Writes a value to the ORAM. 29 | * 30 | * @param addr The address to write to. 31 | * @param val The value to write. 32 | */ 33 | void Write(uint32_t addr, T val); 34 | 35 | /** 36 | * @brief Reads a value from the ORAM. 37 | * 38 | * @param addr The address to read from. 39 | * @return The value at the address. 40 | */ 41 | T Read(uint32_t addr); 42 | 43 | ~ORAMBinding(); 44 | }; -------------------------------------------------------------------------------- /omap/odsl/block.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common/cpp_extended.hpp" 3 | #include "common/dummy.hpp" 4 | #include "common/mov_intrinsics.hpp" 5 | /// @brief This file contains the definition of the blocks used in oram. 6 | 7 | namespace ODSL { 8 | 9 | /// @brief A block is a wrapper around a data element, with a position and a 10 | /// unique id. 11 | /// @tparam T The type of the data 12 | /// @tparam PositionType The type of the position, default to uint64_t 13 | /// @tparam UidType The type of the unique id, default to uint64_t 14 | template 16 | struct Block { 17 | T data; 18 | PositionType position; 19 | UidType uid = DUMMY(); 20 | Block() = default; 21 | Block(const T& data, PositionType position, UidType uid) 22 | : data(data), position(position), uid(uid) {} 23 | 24 | Block(PositionType position, UidType uid) 25 | : uid(uid), position(position), data(DUMMY()) {} 26 | Block(const Block& other) = default; 27 | Block(Block&& other) = default; 28 | Block& operator=(const Block& other) = default; 29 | Block& operator=(Block&& other) = default; 30 | bool operator==(const Block& other) const { return uid == other.uid; } 31 | bool operator!=(const Block& other) const { return !(*this == other); } 32 | static_assert(std::is_trivially_copyable_v, 33 | "T must be trivially copyable"); 34 | 35 | INLINE bool ReadAndRemove(const UidType& uid, T& out) { 36 | bool match = this->uid == uid; 37 | obliMove(match, this->uid, DUMMY()); 38 | obliMove(match, out, data); 39 | return match; 40 | } 41 | 42 | INLINE bool Insert(bool cond, const Block& data) { 43 | return obliMove(cond & IsDummy(), *this, data); 44 | } 45 | 46 | INLINE bool IsDummy() const { return uid == DUMMY(); } 47 | 48 | #ifndef ENCLAVE_MODE 49 | friend std::ostream& operator<<(std::ostream& os, const Block& block) { 50 | os << "Block{data: " << block.data << ", position: " << block.position 51 | << ", uid: "; 52 | if (block.IsDummy()) { 53 | os << "-1"; 54 | } else { 55 | os << block.uid; 56 | } 57 | os << "}"; 58 | return os; 59 | } 60 | #endif 61 | }; 62 | 63 | /// @brief A block with a unique id, but no position. Useful for linear oram. 64 | /// @tparam T The type of the data 65 | /// @tparam UidType The type of the unique id, default to uint64_t 66 | template 67 | struct UidBlock { 68 | T data; 69 | UidType uid = DUMMY(); 70 | UidBlock() = default; 71 | UidBlock(const T& data, UidType uid) : data(data), uid(uid) {} 72 | 73 | explicit UidBlock(UidType uid) : uid(uid), data(DUMMY()) {} 74 | UidBlock(const UidBlock& other) = default; 75 | UidBlock(UidBlock&& other) = default; 76 | UidBlock& operator=(const UidBlock& other) = default; 77 | UidBlock& operator=(UidBlock&& other) = default; 78 | bool operator==(const UidBlock& other) const { return uid == other.uid; } 79 | bool operator!=(const UidBlock& other) const { return !(*this == other); } 80 | 81 | // define less 82 | bool operator<(const UidBlock& other) const { return uid < other.uid; } 83 | 84 | INLINE bool IsDummy() const { return uid == DUMMY(); } 85 | }; 86 | 87 | }; // namespace ODSL -------------------------------------------------------------------------------- /omap/odsl/bucket.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "block.hpp" 3 | 4 | /// @brief This file contains the definition of bucket used in oram. 5 | 6 | namespace ODSL { 7 | 8 | /// @brief A bucket is a wrapper around a set of blocks. 9 | template 11 | struct Bucket { 12 | using BlockType = Block; 13 | static_assert(std::is_trivially_copyable_v, 14 | "T must be trivially copyable"); 15 | static_assert(std::is_trivially_copyable_v, 16 | "Block must be trivially copyable"); 17 | BlockType blocks[Z]; 18 | Bucket() = default; 19 | Bucket(const Bucket& other) = default; 20 | Bucket(Bucket&& other) = default; 21 | Bucket& operator=(const Bucket& other) = default; 22 | Bucket& operator=(Bucket&& other) = default; 23 | static inline Bucket DUMMY() { 24 | Bucket b; 25 | for (int i = 0; i < Z; i++) { 26 | b.blocks[i] = BlockType(); 27 | } 28 | return b; 29 | } 30 | 31 | #ifndef ENCLAVE_MODE 32 | // cout 33 | friend std::ostream& operator<<(std::ostream& os, const Bucket& b) { 34 | os << "[ "; 35 | for (int i = 0; i < Z; i++) { 36 | os << b.blocks[i] << " "; 37 | } 38 | os << "]"; 39 | return os; 40 | } 41 | #endif 42 | }; 43 | 44 | template 45 | struct FreshORAMNode { 46 | BucketType bucket; 47 | uint64_t leftNonce = 0; 48 | uint64_t rightNonce = 0; 49 | static inline FreshORAMNode DUMMY() { 50 | FreshORAMNode node; 51 | node.bucket = BucketType::DUMMY(); 52 | return node; 53 | } 54 | }; 55 | 56 | template 57 | struct NonFreshORAMNode { 58 | BucketType bucket; 59 | static inline NonFreshORAMNode DUMMY() { 60 | NonFreshORAMNode node; 61 | node.bucket = BucketType::DUMMY(); 62 | return node; 63 | } 64 | }; 65 | }; // namespace ODSL -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | searchfiles() 2 | 3 | include_directories (${PROJECT_SOURCE_DIR}/omap) 4 | 5 | add_executable( 6 | test_par_omap 7 | par_omap.cpp 8 | ) 9 | target_compile_definitions(test_par_omap PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 10 | target_link_libraries( 11 | test_par_omap 12 | dl 13 | gtest_main 14 | common 15 | OpenMP::OpenMP_CXX 16 | ) 17 | 18 | add_executable( 19 | test_cuckoo 20 | cuckoo.cpp 21 | ) 22 | target_compile_definitions(test_cuckoo PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 23 | target_link_libraries( 24 | test_cuckoo 25 | dl 26 | gtest_main 27 | common 28 | OpenMP::OpenMP_CXX 29 | ) 30 | 31 | add_executable( 32 | test_basic 33 | basic.cpp 34 | ) 35 | target_compile_definitions(test_basic PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 36 | target_link_libraries( 37 | test_basic 38 | dl 39 | gtest_main 40 | common 41 | ) 42 | 43 | add_executable( 44 | test_oram 45 | oram.cpp 46 | ) 47 | target_compile_definitions(test_oram PRIVATE BOOST_STACKTRACE_USE_ADDR2LINE) 48 | target_link_libraries( 49 | test_oram 50 | dl 51 | gtest_main 52 | common 53 | OpenMP::OpenMP_CXX 54 | ) 55 | 56 | include(GoogleTest) 57 | gtest_discover_tests(test_basic) 58 | gtest_discover_tests(test_oram) 59 | gtest_discover_tests(test_cuckoo) 60 | gtest_discover_tests(test_par_omap) -------------------------------------------------------------------------------- /tests/testutils.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common/tracing/tracer.hpp" 3 | #ifdef NDEBUG 4 | #define ISDEBUG false 5 | #else 6 | #define ISDEBUG true 7 | #endif 8 | 9 | #define DEBUG_ONLY_TEST() if (!ISDEBUG) { GTEST_SKIP(); } 10 | #define RELEASE_ONLY_TEST() if (ISDEBUG) { GTEST_SKIP(); } 11 | 12 | class FooEnvironment : public ::testing::Environment { 13 | public: 14 | ~FooEnvironment() override {} 15 | 16 | // Override this to define how to set up the environment. 17 | void SetUp() override { 18 | g_OnExit.Init(); 19 | } 20 | 21 | // Override this to define how to tear down the environment. 22 | void TearDown() override {} 23 | }; 24 | 25 | ::testing::Environment* const foo_env = ::testing::AddGlobalTestEnvironment(new FooEnvironment); 26 | -------------------------------------------------------------------------------- /tools/docker/cppbuilder/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | ENV TZ=Europe/Lisbon 3 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 4 | 5 | RUN apt update -y && apt upgrade -y 6 | RUN apt install -y wget gnupg 7 | 8 | RUN echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu jammy main' | tee /etc/apt/sources.list.d/intel-sgx.list 9 | RUN wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add - 10 | 11 | RUN apt update -y && apt upgrade -y \ 12 | && apt install -y build-essential lld make git wget unzip cmake ninja-build gdb \ 13 | ocaml ocamlbuild automake autoconf libtool wget python-is-python3 libssl-dev git cmake perl \ 14 | python3 python3-pip lcov gcovr cppcheck \ 15 | && apt install -y clang clang-13 libc++-13-dev libc++abi-13-dev clang-format clang-format-13 \ 16 | libx86-dev libclang-common-13-dev libclang-common-14-dev \ 17 | && apt install -y libgtest-dev libboost-dev \ 18 | && apt install -y doxygen \ 19 | && apt install -y python3-matplotlib python3-numpy bc \ 20 | && apt install -y libcurl4-openssl-dev protobuf-compiler libprotobuf-dev \ 21 | debhelper reprepro pkgconf libboost-system-dev libboost-thread-dev \ 22 | protobuf-c-compiler libprotobuf-c-dev lsb-release libsystemd0 \ 23 | libbearssl-dev cargo libstdc++-11-dev \ 24 | build-essential lld make git wget unzip cmake ninja-build gdb \ 25 | ocaml ocamlbuild automake autoconf libtool wget python-is-python3 libssl-dev git cmake perl \ 26 | python3 python3-pip lcov gcovr cppcheck \ 27 | clang clang-13 libc++-13-dev libc++abi-13-dev clang-format clang-format-13 \ 28 | libx86-dev libclang-common-13-dev libclang-common-14-dev libgtest-dev libboost-dev libssl-dev doxygen python3-matplotlib python3-numpy libssl-dev libcurl4-openssl-dev protobuf-compiler libprotobuf-dev \ 29 | debhelper cmake reprepro unzip pkgconf libboost-dev libboost-system-dev libboost-thread-dev \ 30 | protobuf-c-compiler libprotobuf-c-dev lsb-release libsystemd0 \ 31 | golang swig librocksdb-dev 32 | 33 | RUN pip install cppcheck-codequality 34 | RUN pip install requests 35 | RUN pip install web3 36 | RUN pip install tqdm 37 | 38 | RUN apt-get install -y libsgx-urts libsgx-launch libsgx-enclave-common 39 | RUN apt-get install -y libsgx-epid libsgx-quote-ex libsgx-dcap-ql libsgx-dcap-ql-dev libsgx-enclave-common-dbgsym libsgx-urts-dbgsym 40 | 41 | 42 | RUN wget 'https://github.com/boyter/scc/releases/download/v3.0.0/scc-3.0.0-x86_64-unknown-linux.zip' 43 | RUN unzip 'scc-3.0.0-x86_64-unknown-linux.zip' -d / 44 | RUN chmod +x /scc 45 | 46 | RUN mkdir /dockerfiles 47 | RUN cd /dockerfiles && wget https://download.01.org/intel-sgx/latest/linux-latest/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.23.100.2.bin \ 48 | && chmod +x ./* \ 49 | && echo yes | ./sgx_linux_x64_sdk_2.23.100.2.bin 50 | RUN echo "source /dockerfiles/sgxsdk/environment" > /startsgxenv.sh 51 | RUN chmod +x /startsgxenv.sh 52 | 53 | # Installing rocksdb takes a long time, uncomment to run the balance checker example 54 | # COPY rocksDBInstall.sh /rocksDBInstall.sh 55 | # RUN chmod +x /rocksDBInstall.sh && \ 56 | # /rocksDBInstall.sh 57 | 58 | SHELL ["/bin/bash", "-c"] 59 | RUN ln -s /usr/lib/libsgx_urts.so /usr/lib/libsgx_urts.so.2 60 | 61 | WORKDIR /builder/ 62 | CMD ["bash"] 63 | -------------------------------------------------------------------------------- /tools/docker/cppbuilder/rocksDBInstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ROCKSDB_VERSION=8.10.0 4 | 5 | #Run as a root user 6 | if [ "$EUID" -ne 0 ] 7 | then echo "Please run as root (with sudo command)" 8 | exit 9 | fi 10 | 11 | if ! command -v wget &> /dev/null 12 | then 13 | echo "wget command could not be found. installing..." 14 | apt install -y wget 15 | fi 16 | 17 | if ! command -v make &> /dev/null 18 | then 19 | echo "make command could not be found. installing..." 20 | apt install -y cmake 21 | fi 22 | 23 | if ! command -v g++ &> /dev/null 24 | then 25 | echo "g++ command could not be found. installing..." 26 | apt install -y g++ 27 | fi 28 | 29 | echo "installing required dependancies..." 30 | sudo apt install -y libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev 31 | 32 | echo "downloading rocksdb..." 33 | pushd /tmp || return 34 | wget https://github.com/facebook/rocksdb/archive/refs/tags/v${ROCKSDB_VERSION}.tar.gz 35 | tar -xvf v${ROCKSDB_VERSION}.tar.gz && cd rocksdb-${ROCKSDB_VERSION} || return 36 | 37 | # Ignore GCC warnings 38 | export CXXFLAGS='-Wno-error=deprecated-copy -Wno-error=pessimizing-move -Wno-error=class-memaccess' 39 | 40 | # Build as a shared library 41 | make shared_lib 42 | 43 | # The following command installs the shared library in /usr/lib/ and the header files in /usr/include/rocksdb/: 44 | make install-shared INSTALL_PATH=/usr 45 | popd || return 46 | 47 | # cleanup 48 | rm -rf /tmp/rocksdb-${ROCKSDB_VERSION} /tmp/v${ROCKSDB_VERSION}.tar.gz 49 | 50 | echo "installation successful" 51 | 52 | # To uninstall 53 | #make uninstall INSTALL_PATH=/usr -------------------------------------------------------------------------------- /tools/test-sgx/test-sgx.sh: -------------------------------------------------------------------------------- 1 | git clone git@github.com:ayeks/SGX-hardware.git 2 | cd SGX-hardware 3 | make 4 | ./test-sgx 5 | cd .. --------------------------------------------------------------------------------