Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/oram #16

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1eb0353
release v0.5.2
xchmwang Apr 21, 2023
c84b21f
Merge branch 'develop' of https://github.com/YeeZTech/YeeZ-Privacy-Co…
xchmwang May 26, 2023
0d54837
fix cmakelist for debug and release mode
xchmwang May 26, 2023
f4130dc
add hpda transform trim
xchmwang May 30, 2023
2f2118c
add hpda processor for get all values
xchmwang Jun 4, 2023
2eb769c
hpda processor get all values test impl
xchmwang Jun 4, 2023
58872e7
oram update
lmjdusanzis Jun 26, 2023
0859eb0
oram update
lmjdusanzis Jun 26, 2023
19337cb
privacy_data_reader error
lmjdusanzis Jul 5, 2023
60d6439
ORAM finish single file query
lmjdusanzis Jul 25, 2023
ca0e68a
oram introduction
lmjdusanzis Jul 25, 2023
1452f8f
merkle modify
lmjdusanzis Jul 27, 2023
5fae496
merkle update2
lmjdusanzis Jul 31, 2023
b98af0f
merkle tree update 3
lmjdusanzis Jul 31, 2023
648a141
merkle tree update4
lmjdusanzis Aug 1, 2023
b35b650
finish merkle tree
lmjdusanzis Aug 10, 2023
37da0e6
finish merkle tree
lmjdusanzis Aug 10, 2023
69f2ee7
finish assembly function
lmjdusanzis Sep 1, 2023
914d99a
index to be changed
lmjdusanzis Feb 2, 2024
76e4c7c
change pre
lmjdusanzis Apr 16, 2024
a29ec3c
toolkit/analyzer/parsers/convert_parser.cpp
lmjdusanzis Jun 2, 2024
10fdf74
test/integrate/job_step.py
lmjdusanzis Jun 3, 2024
e0686bb
toolkit/analyzer/sgx_bridge.cpp
lmjdusanzis Jun 3, 2024
cdba3e0
include/ypc/core_t/analyzer/interface/data_interface.h
lmjdusanzis Jun 3, 2024
5a227be
enclave/convert_parser.h,enclave2/convert_parser2.h
lmjdusanzis Jun 4, 2024
eca2f72
example/convert/enclave/convert_parser.h
lmjdusanzis Jun 5, 2024
68d2c8a
example/convert/enclave2/convert_parser2.h
lmjdusanzis Jun 5, 2024
bc8d88e
finish convert
lmjdusanzis Jun 6, 2024
c6dfe9e
finish convert2
lmjdusanzis Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ bin
*.env
generate

test/integrate
test/integrate/person_list
test/integrate/project.py
test/project_path.h
test/integrate/__pycache__/
test/integrate/js/
.vscode/
hash_hex/
hash_hex/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

cmake_minimum_required(VERSION 3.12)
project(YPC VERSION 0.5.1)
project(YPC VERSION 0.5.2)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ create_signed_so() {
["person_first_match"]="example/personlist/first_match/enclave/enclave.config.xml"
["person_first_match_multi"]="example/multi_personlist/first_match/enclave/enclave.config.xml"
["person_first_match_multi_offchain"]="example/multi_personlist/first_match/enclave_for_offchain/enclave.config.xml"
["convert_sealed_file"]="example/convert/enclave/enclave.config.xml"
)

for filename in ${!enclave_libs[@]}; do
Expand Down
2 changes: 2 additions & 0 deletions example/convert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(enclave)
add_subdirectory(enclave2)
7 changes: 7 additions & 0 deletions example/convert/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "common_t.h"
#include "ypc/core/blockfile.h"
#include "ypc/core/byte.h"
#include "ypc/corecommon/package.h"
typedef ypc::blockfile<0x82, 1024 * 1024, 256 * 64 * 1024> file_t;

36 changes: 36 additions & 0 deletions example/convert/common_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include <ff/net/middleware/ntpackage.h>
#include <ff/util/ntobject.h>

define_nt(RYXXBZ, std::string, "RYXXBZ");
define_nt(XM, std::string, "XM");
define_nt(CYM, std::string, "CYM");
define_nt(XBDM, std::string, "XBDM");
define_nt(FWXXBZ, std::string, "FWXXBZ");
define_nt(XP, std::string, "XP");
define_nt(DWMC, std::string, "DWMC");
define_nt(ZJHM, std::string, "ZJHM");
define_nt(GJDM, std::string, "GJDM");
define_nt(MZDM, std::string, "MZDM");
define_nt(JGSSXDM, std::string, "JGSSXDM");
define_nt(HKXZFLYDM, std::string, "HKXZFLYDM");
define_nt(HLXDM, std::string, "HLXDM");
define_nt(HJDZ_XZQHDM, std::string, "HJDZXZQHDM");
define_nt(SJJZD_XZQHDM, std::string, "SJJZDXZQHDM");
define_nt(SJJZD_QHNXXDZ, std::string, "SJJZDQHNXXDZ");
define_nt(XLDM, std::string, "XLDM");
define_nt(TSSFDM, std::string, "TSSFDM");
define_nt(CSQR, std::string, "CSQR");
define_nt(LXDH, std::string, "LXDH");
define_nt(HYZKDM, std::string, "HYZKDM");
define_nt(DJR_XM, std::string, "DJR_XM");
define_nt(DJR_GMSFZHM, std::string, "DJRGMSFZHM");
define_nt(DJR_LXDH, std::string, "DJRLXDH");
define_nt(GXSJ, std::string, "GXSJ");
define_nt(SJZT, std::string, "SJZT");

typedef ff::util::ntobject<
RYXXBZ, XM, CYM, XBDM, FWXXBZ, XP, DWMC, ZJHM, GJDM, MZDM, JGSSXDM,
HKXZFLYDM, HLXDM, HJDZ_XZQHDM, SJJZD_XZQHDM, SJJZD_QHNXXDZ, XLDM, TSSFDM,
CSQR, LXDH, HYZKDM, DJR_XM, DJR_GMSFZHM, DJR_LXDH, GXSJ, SJZT>
row_t;
13 changes: 13 additions & 0 deletions example/convert/enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(T_SRCS eparser.cpp)

add_ypc_applet(convert_sealed_file
CRYPTO stdeth
SRCS ${T_SRCS})

if(SGX_MODE STREQUAL "Debug")
enclave_sign(convert_sealed_file KEY enclave_private.pem
CONFIG enclave.config.debug.xml)
else()
enclave_sign(convert_sealed_file KEY enclave_private.pem
CONFIG enclave.config.xml)
endif()
193 changes: 193 additions & 0 deletions example/convert/enclave/convert_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#include "ypc/corecommon/package.h"
#include "ypc/stbox/ebyte.h"
#include "ypc/stbox/stx_common.h"
#ifdef EXAMPLE_FM_NORMAL
#include <glog/logging.h>
typedef ypc::bytes bytes;
#else
#include "ypc/core_t/analyzer/data_source.h"
#include "ypc/stbox/tsgx/log.h"
typedef stbox::bytes bytes;
#endif
#include "user_type.h"
#include "ypc/corecommon/data_source.h"
#include "ypc/corecommon/to_type.h"
#include <hpda/extractor/raw_data.h>
#include <hpda/output/memory_output.h>
#include <hpda/processor/query/filter.h>
#include <string.h>


#include "ypc/core_t/analyzer/eparser_t_interface.h"
#include "ypc/common/crypto_prefix.h"
#include "ypc/corecommon/crypto/gmssl.h"
#include "ypc/corecommon/crypto/stdeth.h"
#include "ypc/corecommon/oram_types.h"
#include <random>
#include <hpda/processor/transform/split.h>


using oram_ntt = ypc::oram::nt<bytes>;
using ntt = ypc::nt<bytes>;





define_nt(input_buf, std::string);
typedef ff::net::ntpackage<0, input_buf> input_buf_t;


class crypto_base {
public:
virtual uint32_t encrypt_message_with_prefix(const bytes &public_key,
const bytes &data,
uint32_t prefix,
bytes &cipher) = 0;
virtual uint32_t hash_256(const bytes &msg, bytes &hash) = 0;
};
using crypto_ptr_t = std::shared_ptr<crypto_base>;
template <typename Crypto> class crypto_tool : public crypto_base {
public:
using crypto_t = Crypto;
virtual uint32_t encrypt_message_with_prefix(const bytes &public_key,
const bytes &data,
uint32_t prefix,
bytes &cipher) {
return crypto_t::encrypt_message_with_prefix(public_key, data, prefix,
cipher);
}
virtual uint32_t hash_256(const bytes &msg, bytes &hash) {
return crypto_t::hash_256(msg, hash);
}
};


class convert_parser {
public:
convert_parser() {}
convert_parser(ypc::data_source<bytes> *source) : m_source(source){};

inline bytes do_parse(const bytes &param) {
bytes result;

LOG(INFO) << "do convert_parse";
ypc::to_type<bytes, user_item_t> converter(m_source);

crypto_ptr_t crypto_ptr = std::make_shared<crypto_tool<ypc::crypto::eth_sgx_crypto>>();
bytes pub_key(param);



LOG(INFO) << "create id_map";

size_t batch_size = 0;
size_t item_size = 0;
uint64_t batch_num = 0; // the number of batch
uint64_t full_num = 0;
uint64_t last_num = 0;
uint64_t item_num = 0;

std::vector<oram_ntt::id_map_pair> id_map_array;
uint32_t batch_id = 1;

hpda::processor::internal::filter_impl<user_item_t> match2(
&converter, [&](const user_item_t &v) {
if(item_size == 0) {
typename ypc::cast_obj_to_package<user_item_t>::type pt = v;
auto item_data = ypc::make_bytes<bytes>::for_package(pt);
item_size = item_data.size();
}

std::string item_index_field = v.get<ZJHM>();

input_buf_t item_index_field_pkg;
item_index_field_pkg.set<input_buf>(item_index_field);
bytes item_index_field_bytes = ypc::make_bytes<bytes>::for_package(item_index_field_pkg);
bytes item_index_field_hash;
crypto_ptr->hash_256(item_index_field_bytes, item_index_field_hash);

std::shared_ptr<oram_ntt::id_map_pair> k_v(new oram_ntt::id_map_pair());
k_v->set<oram_ntt::item_index_field_hash, oram_ntt::block_id>(item_index_field_hash, batch_id);
id_map_array.push_back(*k_v);

++item_num;

batch_size += item_size;
if (batch_size >= ypc::utc::max_item_size) {

if(full_num == 0) {
full_num = item_num;
}

item_num = 0;
batch_size = 0;

++batch_id;
++batch_num;
}

return false;
});
match2.get_engine()->run();

if(item_num > 0) {
last_num = item_num;
++batch_num;
}

oram_ntt::id_map_t id_map_pkg;
id_map_pkg.set<oram_ntt::id_map>(id_map_array);
id_map_array.clear();
bytes id_map_bytes = ypc::make_bytes<bytes>::for_package(id_map_pkg);


LOG(INFO) << "write header";

ypc::oram::header osf_header{};
osf_header.block_num = batch_num;
uint32_t real_bucket_num = ceil(static_cast<double>(osf_header.block_num) / ypc::oram::BucketSizeZ);
osf_header.level_num_L = ceil(log2(real_bucket_num + 1)) - 1;
osf_header.bucket_num_N = (1 << (osf_header.level_num_L + 1)) - 1;
osf_header.id_map_filepos = sizeof(osf_header);
osf_header.oram_tree_filepos = osf_header.id_map_filepos + id_map_bytes.size();

osf_header.item_size = item_size;
if(full_num > 0) {
osf_header.item_num_each_batch = full_num;
} else {
osf_header.item_num_each_batch = last_num;
}

auto ret = stbox::ocall_cast<uint32_t>(write_convert_data_structure)
(0, (uint8_t *)&osf_header, sizeof(osf_header));
if (ret != stbox::stx_status::success) {
LOG(ERROR) << "write_convert_data_structure ocall fail!";
return result;
}

LOG(INFO) << "write id map";

int32_t id_map_size = 8000000;
for(int i = 0; i <= id_map_bytes.size(); i += id_map_size) {
if(i + id_map_size <= id_map_bytes.size()) {
ret = stbox::ocall_cast<uint32_t>(write_convert_data_structure)
(osf_header.id_map_filepos + i, id_map_bytes.data() + i, id_map_size);
} else {
ret = stbox::ocall_cast<uint32_t>(write_convert_data_structure)
(osf_header.id_map_filepos + i, id_map_bytes.data() + i, id_map_bytes.size() - i);
}

if (ret != stbox::stx_status::success) {
LOG(ERROR) << "write_convert_data_structure ocall fail!";
return result;
}
}


return result;
}

protected:
ypc::data_source<bytes> *m_source;
};
12 changes: 12 additions & 0 deletions example/convert/enclave/enclave.config.debug.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x50000</StackMaxSize>
<HeapMaxSize>0x80000000</HeapMaxSize>
<TCSNum>10</TCSNum>
<TCSPolicy>1</TCSPolicy>
<!-- Recommend changing 'DisableDebug' to 1 to make the enclave undebuggable for enclave release -->
<DisableDebug>0</DisableDebug>
<MiscSelect>0</MiscSelect>
<MiscMask>0xFFFFFFFF</MiscMask>
</EnclaveConfiguration>
12 changes: 12 additions & 0 deletions example/convert/enclave/enclave.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x50000</StackMaxSize>
<HeapMaxSize>0x80000000</HeapMaxSize>
<TCSNum>10</TCSNum>
<TCSPolicy>1</TCSPolicy>
<!-- Recommend changing 'DisableDebug' to 1 to make the enclave undebuggable for enclave release -->
<DisableDebug>1</DisableDebug>
<MiscSelect>0</MiscSelect>
<MiscMask>0xFFFFFFFF</MiscMask>
</EnclaveConfiguration>
11 changes: 11 additions & 0 deletions example/convert/enclave/enclave.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enclave.so
{
global:
g_global_data_sim;
g_global_data;
enclave_entry;
g_peak_heap_used;
g_peak_rsrv_mem_committed;
local:
*;
};
11 changes: 11 additions & 0 deletions example/convert/enclave/enclave_debug.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enclave.so
{
global:
g_global_data_sim;
g_global_data;
enclave_entry;
g_peak_heap_used;
g_peak_rsrv_mem_committed;
local:
*;
};
39 changes: 39 additions & 0 deletions example/convert/enclave/enclave_private.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-----BEGIN RSA PRIVATE KEY-----
MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ
AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ
ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr
nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b
3zk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=
-----END RSA PRIVATE KEY-----
13 changes: 13 additions & 0 deletions example/convert/enclave/eparser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "ypc/core_t/analyzer/algo_wrapper.h"
#include "ypc/core_t/analyzer/macro.h"
#include "ypc/corecommon/crypto/stdeth.h"
#include "ypc/corecommon/crypto/gmssl.h"

#include "convert_parser.h"

ypc::algo_wrapper<ypc::crypto::eth_sgx_crypto, ypc::convert_sealed_data_stream,
convert_parser,
ypc::onchain_result<ypc::crypto::eth_sgx_crypto>>
pw;

YPC_PARSER_IMPL(pw);
Loading