|
@@ -7,9 +7,9 @@
|
|
|
|
|
|
#define PROFILE_STORAGE
|
|
|
|
|
|
-StgClient *clients;
|
|
|
-uint8_t *epoch_tokens;
|
|
|
-uint8_t *epoch_mailboxes;
|
|
|
+static std::vector<StgClient> clients;
|
|
|
+static uint8_t *epoch_tokens;
|
|
|
+static uint8_t *epoch_mailboxes;
|
|
|
|
|
|
static struct {
|
|
|
uint32_t max_users;
|
|
@@ -24,19 +24,17 @@ static struct {
|
|
|
bool *pub_selected;
|
|
|
} storage_state;
|
|
|
|
|
|
-bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
- uint16_t num_priv_channels = g_teems_config.m_priv_in;
|
|
|
- uint16_t msg_size = g_teems_config.msg_size;
|
|
|
- uint32_t pt_msgbundle_size = num_priv_channels * msg_size;
|
|
|
+static bool storage_generateClientKeys(uint32_t num_clients,
|
|
|
+ uint32_t my_stg_no) {
|
|
|
|
|
|
- clients = new StgClient[num_clients];
|
|
|
+ clients.resize(num_clients);
|
|
|
|
|
|
for(uint32_t i =0; i < num_clients; i++) {
|
|
|
uint32_t mid = storage_state.my_storage_node_id + i;
|
|
|
clients[i].my_id = mid;
|
|
|
- clients[i].priv_friends = new clientid_t[g_teems_config.m_priv_out];
|
|
|
+ clients[i].priv_friends.resize(g_teems_config.m_priv_out);
|
|
|
// Initialize this client's private channel friends as themself
|
|
|
- for(int j =0; j <g_teems_config.m_priv_out; j++) {
|
|
|
+ for(int j = 0; j < g_teems_config.m_priv_out; j++) {
|
|
|
(clients[i].priv_friends)[j] = mid;
|
|
|
}
|
|
|
}
|
|
@@ -57,7 +55,8 @@ bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
|
|
|
sgx_status_t ret = SGX_SUCCESS;
|
|
|
ret = sgx_rijndael128GCM_encrypt(pESK, zeroes, SGX_AESGCM_KEY_SIZE,
|
|
|
- (uint8_t*) (clients[i].key), iv, SGX_AESGCM_IV_SIZE, NULL, 0, &tag);
|
|
|
+ (uint8_t*) (clients[i].key), iv, SGX_AESGCM_IV_SIZE,
|
|
|
+ NULL, 0, &tag);
|
|
|
if(ret!=SGX_SUCCESS) {
|
|
|
printf("stg_generateClientKeys FAIL\n");
|
|
|
return false;
|
|
@@ -73,7 +72,6 @@ bool storage_generateClientKeys(uint32_t num_clients, uint32_t my_stg_no) {
|
|
|
}
|
|
|
*/
|
|
|
c_simid+=num_stg_nodes;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -121,8 +119,10 @@ static void* generate_all_tokens_launch(void *voidargs)
|
|
|
for(int i = 0; i<g_teems_config.m_priv_out; i++)
|
|
|
{
|
|
|
memcpy(ptr, (&(clients[lcid].my_id)), sizeof(clientid_t));
|
|
|
- memcpy(ptr + sizeof(clientid_t), (&(clients[lcid].priv_friends[i])), sizeof(clientid_t));
|
|
|
- memcpy(ptr + 2 * sizeof(clientid_t), &epoch_val, sizeof(epoch_val));
|
|
|
+ memcpy(ptr + sizeof(clientid_t),
|
|
|
+ (&(clients[lcid].priv_friends[i])), sizeof(clientid_t));
|
|
|
+ memcpy(ptr + 2 * sizeof(clientid_t),
|
|
|
+ &epoch_val, sizeof(epoch_val));
|
|
|
|
|
|
ret = sgx_rijndael128_cmac_msg(pTSK, ptr, pt_tokens_size,
|
|
|
(sgx_cmac_128bit_tag_t*) tkn_body_ptr);
|
|
@@ -148,7 +148,8 @@ static void* generate_all_tokens_launch(void *voidargs)
|
|
|
*/
|
|
|
|
|
|
unsigned char *cl_iv = clients[lcid].iv;
|
|
|
- ret = (sgx_rijndael128GCM_encrypt(&(clients[lcid].key), token_body, pt_tokens_size,
|
|
|
+ ret = (sgx_rijndael128GCM_encrypt(&(clients[lcid].key),
|
|
|
+ token_body, pt_tokens_size,
|
|
|
(uint8_t*) tkn_ptr, cl_iv, SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
(sgx_aes_gcm_128bit_tag_t*) tkn_tag));
|
|
|
if(ret!=SGX_SUCCESS) {
|
|
@@ -181,7 +182,7 @@ static bool launch_all_users(void *(*launch)(void *)) {
|
|
|
|
|
|
// Special-case nthread=1 for efficiency
|
|
|
if (nthreads <= 1) {
|
|
|
- UserRange args = { 0, storage_state.max_users };
|
|
|
+ UserRange args = { 0, storage_state.max_users, false };
|
|
|
return launch(&args);
|
|
|
}
|
|
|
UserRange args[nthreads];
|
|
@@ -190,7 +191,7 @@ static bool launch_all_users(void *(*launch)(void *)) {
|
|
|
uint32_t last = 0;
|
|
|
for (threadid_t i=0; i<nthreads; ++i) {
|
|
|
uint32_t num = inc + (i < extra);
|
|
|
- args[i] = { last, num };
|
|
|
+ args[i] = { last, num, false };
|
|
|
last += num;
|
|
|
}
|
|
|
|
|
@@ -228,16 +229,15 @@ static void *processMsgs_launch(void *voidargs) {
|
|
|
uint32_t user_start = args->start;
|
|
|
uint32_t user_end = args->start + args->num;
|
|
|
|
|
|
- uint32_t mailbox_size, num_expected_msgs;
|
|
|
+ uint32_t mailbox_size;
|
|
|
if (g_teems_config.private_routing) {
|
|
|
mailbox_size = g_teems_config.m_priv_in * g_teems_config.msg_size;
|
|
|
- num_expected_msgs = g_teems_config.m_priv_in * storage_state.max_users;
|
|
|
} else {
|
|
|
mailbox_size = g_teems_config.m_pub_in * g_teems_config.msg_size;
|
|
|
- num_expected_msgs = g_teems_config.m_pub_in * storage_state.max_users;
|
|
|
}
|
|
|
|
|
|
- uint32_t enc_mailbox_size = mailbox_size + SGX_AESGCM_IV_SIZE + SGX_AESGCM_MAC_SIZE;
|
|
|
+ uint32_t enc_mailbox_size = mailbox_size + SGX_AESGCM_IV_SIZE +
|
|
|
+ SGX_AESGCM_MAC_SIZE;
|
|
|
unsigned char *epoch_buf_ptr = epoch_mailboxes +
|
|
|
enc_mailbox_size * user_start;
|
|
|
unsigned char *stg_buf_ptr = storage_state.stg_buf.buf +
|
|
@@ -248,8 +248,9 @@ static void *processMsgs_launch(void *voidargs) {
|
|
|
|
|
|
for(uint32_t lcid = user_start; lcid < user_end; lcid++) {
|
|
|
memcpy(epoch_buf_ptr, clients[lcid].iv, SGX_AESGCM_IV_SIZE);
|
|
|
- ret = sgx_rijndael128GCM_encrypt(&(clients[lcid].key), stg_buf_ptr, mailbox_size,
|
|
|
- (uint8_t*) epoch_buf_ct_ptr, epoch_buf_ptr, SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
+ ret = sgx_rijndael128GCM_encrypt(&(clients[lcid].key), stg_buf_ptr,
|
|
|
+ mailbox_size, (uint8_t*) epoch_buf_ct_ptr, epoch_buf_ptr,
|
|
|
+ SGX_AESGCM_IV_SIZE, NULL, 0,
|
|
|
(sgx_aes_gcm_128bit_tag_t*) epoch_buf_tag_ptr);
|
|
|
if(ret!=SGX_SUCCESS) {
|
|
|
printf("processMsgs: Encrypting msgs FAIL\n");
|
|
@@ -297,7 +298,8 @@ bool storage_init(uint32_t max_users, uint32_t msg_buf_size)
|
|
|
for (nodenum_t i=0; i<g_teems_config.num_nodes; ++i) {
|
|
|
if (g_teems_config.roles[i] & ROLE_STORAGE) {
|
|
|
if (i == g_teems_config.my_node_num) {
|
|
|
- storage_state.my_storage_node_id = my_storage_node_id << DEST_UID_BITS;
|
|
|
+ storage_state.my_storage_node_id =
|
|
|
+ my_storage_node_id << DEST_UID_BITS;
|
|
|
my_stg_pos = my_storage_node_id;
|
|
|
} else {
|
|
|
++my_storage_node_id;
|
|
@@ -408,14 +410,17 @@ void storage_received(MsgBuffer &storage_buf)
|
|
|
prev_uid = uid;
|
|
|
}
|
|
|
#ifdef PROFILE_STORAGE
|
|
|
- unsigned long start_compaction = printf_with_rtclock("begin public-channel compaction (%u)\n", num_msgs);
|
|
|
+ unsigned long start_compaction =
|
|
|
+ printf_with_rtclock("begin public-channel compaction (%u)\n",
|
|
|
+ num_msgs);
|
|
|
#endif
|
|
|
TightCompact_parallel<OSWAP_16X>(
|
|
|
(unsigned char *) storage_state.stg_buf.buf,
|
|
|
num_msgs, msg_size, storage_state.pub_selected,
|
|
|
g_teems_config.nthreads);
|
|
|
#ifdef PROFILE_STORAGE
|
|
|
- printf_with_rtclock_diff(start_compaction, "end public-channel compaction (%u)\n", num_msgs);
|
|
|
+ printf_with_rtclock_diff(start_compaction,
|
|
|
+ "end public-channel compaction (%u)\n", num_msgs);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -433,8 +438,9 @@ void storage_received(MsgBuffer &storage_buf)
|
|
|
// Obliviously set the dest array
|
|
|
uint32_t *dests = storage_state.dest.data();
|
|
|
uint32_t stg_size = storage_state.stg_buf.bufsize;
|
|
|
- const uint8_t *buf = storage_state.stg_buf.buf;
|
|
|
- uint32_t m_in = g_teems_config.private_routing ? g_teems_config.m_priv_in : g_teems_config.m_pub_in;
|
|
|
+ uint8_t *buf = storage_state.stg_buf.buf;
|
|
|
+ uint32_t m_in = g_teems_config.private_routing ?
|
|
|
+ g_teems_config.m_priv_in : g_teems_config.m_pub_in;
|
|
|
|
|
|
uint32_t uid = *(uint32_t*)(buf);
|
|
|
uid &= uid_mask;
|