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

Flatbuffers serialization, aggregation optimization, build improvements #9

Merged
merged 52 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8666789
DEBUGGING
Oct 20, 2020
befa362
DEBUGGING
Oct 20, 2020
7603ca4
removing redundant directory
Oct 20, 2020
f9696d5
client wrapper code
Oct 20, 2020
98ae93a
removing extraneous files
Oct 21, 2020
41c4881
adding installation option (non-cython)
Oct 21, 2020
dd69b24
fixing non-cython install
Oct 21, 2020
b012d6f
fix non-cython install
Oct 21, 2020
1118955
fixing noncython install
Oct 21, 2020
a7dcf69
fixing noncython install
Oct 21, 2020
27b13ee
updating client and server wrappers, implementing NVIDIA functions in…
Oct 22, 2020
b8bba38
deleting unnecessary build files
Oct 22, 2020
09bd9d3
removing test build files
Oct 22, 2020
1b456af
slight modifications
Oct 27, 2020
13e1e41
changes to crypto constants
Oct 27, 2020
c068ea3
server wrapper changes
Oct 27, 2020
e3105d1
adding test
Oct 27, 2020
c07a865
changing return parameters of host_modelaggregator
Oct 27, 2020
68a81ee
preparing for import
Oct 29, 2020
c33e914
preparing for import
kvah Oct 29, 2020
1aa7407
Adding aggregation python tests
kvah Nov 3, 2020
7a963e1
Updating aggregation test
kvah Nov 3, 2020
26cf44b
Cleanup and fixes
podcastinator Nov 3, 2020
f4551d0
Free allocated memory
podcastinator Nov 3, 2020
1983997
Adding support for n dimensional arrays
Nov 4, 2020
48b7331
Merge branch 'master' of github.com:kvah/secure-aggregation
kvah Nov 4, 2020
320970c
cleaning files
kvah Nov 4, 2020
ea80e4d
removing unnecessary files
kvah Nov 4, 2020
981e9a6
Fix c++ integration test
chester-leung Nov 5, 2020
5d5987b
pushing nvidia test functions
podcastinator Nov 5, 2020
b63fb8a
Merge branch 'master' of https://github.com/kvah/secure-aggregation
podcastinator Nov 5, 2020
3be5490
Adding flatbuffer serialization
podcastinator Nov 10, 2020
dc5a609
Adding Flatbuffer Serialization Changes
podcastinator Nov 10, 2020
d61c11b
debugging with fake enclave
podcastinator Nov 10, 2020
4d46f94
debugging custom code
podcastinator Nov 11, 2020
cb51ab9
optimization
podcastinator Nov 11, 2020
e4c74cd
Docker start scripts
podcastinator Nov 11, 2020
ac911be
Run enclave code as well
podcastinator Nov 11, 2020
069950a
Increase enclave size
podcastinator Nov 11, 2020
b7b40c7
Checkpoint
podcastinator Nov 12, 2020
a2aeda9
Debugging Protobuf Issues
kvah Nov 12, 2020
529e4cd
Checkpoint
podcastinator Nov 19, 2020
f3a25d2
Merge pull request #1 from kvah/rishabh
podcastinator Nov 23, 2020
67525d4
adding .gitignore, removing autogenerated cython files
kvah Nov 24, 2020
e5d34a0
Remove python changes to merge into master
chester-leung Dec 2, 2020
a7795a4
Clean up
chester-leung Dec 2, 2020
2eac36c
Merge branch 'master' into cpp-changes
chester-leung Dec 2, 2020
cd8c0c3
Revert enclave path
chester-leung Dec 2, 2020
0959e89
Delete empty file
podcastinator Dec 2, 2020
2c834e0
Address PR comments
chester-leung Dec 2, 2020
5be573e
Merge branch 'cpp-changes' of https://github.com/chester-leung/secure…
chester-leung Dec 2, 2020
8e2e812
Add back readme
chester-leung Dec 2, 2020
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
32 changes: 0 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
Empty file modified README.md
100644 → 100755
Empty file.
Empty file removed client/README.md
Empty file.
Empty file removed common/README.md
Empty file.
9 changes: 0 additions & 9 deletions common/encryption/CMakeLists.txt

This file was deleted.

49 changes: 9 additions & 40 deletions common/encryption/encrypt.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
#ifndef ENCRYPT_H_
podcastinator marked this conversation as resolved.
Show resolved Hide resolved
#define ENCRYPT_H_

#define CIPHER_KEY_SIZE 16
#define CIPHER_IV_SIZE 12
#define CIPHER_TAG_SIZE 16
#define SHA_DIGEST_SIZE 32
#define CIPHER_PK_SIZE 512
#define SIG_ALLOC_SIZE 1024

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <string.h>
#include <stdio.h>
#include "serialization.h"
#include "crypto.h"

#include "mbedtls/config.h"
#include "mbedtls/gcm.h"
#include "mbedtls/entropy.h" // mbedtls_entropy_context
#include "mbedtls/ctr_drbg.h" // mbedtls_ctr_drbg_context
#include "mbedtls/cipher.h" // MBEDTLS_CIPHER_ID_AES
#include "mbedtls/gcm.h" // mbedtls_gcm_context
#include "mbedtls/pk.h"
#include "mbedtls/rsa.h"
#include "mbedtls/sha256.h"
#include "mbedtls/x509_crt.h"
#include "mbedtls/error.h"

void encrypt_bytes(unsigned char* model_data, size_t data_len, unsigned char** ciphertext) {

void encrypt_bytes(uint8_t* model_data, size_t data_len, uint8_t** ciphertext) {
mbedtls_gcm_context gcm;
mbedtls_gcm_init(&gcm);

unsigned char key[] = "abcdefghijklmnop";
// FIXME: hardcoded key
uint8_t key[] = "abcdefghijklmnop";

unsigned char* output = new unsigned char[data_len * sizeof(unsigned char)];
unsigned char* iv = new unsigned char[CIPHER_IV_SIZE * sizeof(unsigned char)];
unsigned char* tag = new unsigned char[CIPHER_TAG_SIZE * sizeof(unsigned char)];
uint8_t* output = ciphertext[0];
uint8_t* iv = ciphertext[1];
uint8_t* tag = ciphertext[2];

int ret = encrypt_symm(
key,
Expand All @@ -50,19 +24,14 @@ void encrypt_bytes(unsigned char* model_data, size_t data_len, unsigned char** c
iv,
tag
);

*ciphertext = output;
*(ciphertext + 1) = iv;
*(ciphertext + 2) = tag;
}

void decrypt_bytes(unsigned char* model_data, unsigned char* iv, unsigned char* tag, size_t data_len, unsigned char** text) {

void decrypt_bytes(uint8_t* model_data, uint8_t* iv, uint8_t* tag, size_t data_len, uint8_t** text) {
mbedtls_gcm_context gcm;
mbedtls_gcm_init(&gcm);

unsigned char key[] = "abcdefghijklmnop";
unsigned char* out = new unsigned char[data_len];
// FIXME: hardcoded key
uint8_t key[] = "abcdefghijklmnop";

decrypt_symm(
key,
Expand Down
46 changes: 0 additions & 46 deletions common/encryption/main.cpp

This file was deleted.

89 changes: 35 additions & 54 deletions common/encryption/serialization.h
Original file line number Diff line number Diff line change
@@ -1,73 +1,54 @@
#ifndef SERIALIZATION_H_
#define SERIALIZATION_H_

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <string.h>
#include <stdio.h>
#include "flatbuffers/model_generated.h"

std::string serialize(std::map<std::string, std::vector<double>> model) {
// Serialize string:float[] map into SSSS:[VVVVVVVV]

std::vector<unsigned char> serialized;
uint8_t* serialize(std::map<std::string, std::vector<double>> model,
int* serialized_buffer_size) {
flatbuffers::FlatBufferBuilder builder;
std::vector<flatbuffers::Offset<secagg::KVPair>> features;

for (const auto &[name, values]: model) {
for (char const &c: name) {
serialized.push_back(c);
}
serialized.push_back(':');
serialized.push_back('[');
for (const double &val: values) {
std::string val_string = std::to_string(val);
for (char const &c: val_string) {
serialized.push_back(c);
}
serialized.push_back(',');
}
serialized.push_back(']');
serialized.push_back('/');
auto key = builder.CreateString(name);
auto value = builder.CreateVector(values);
auto kvpair = secagg::CreateKVPair(builder, key, value);
features.push_back(kvpair);
}
auto model_features = builder.CreateVector(features);
auto model_offset = secagg::CreateModel(builder, model_features);
builder.Finish(model_offset);

std::string s(serialized.begin(), serialized.end());
return s;
}

std::map<std::string, std::vector<double>> deserialize(std::string serialized_str) {
// Splits each entry on '/'
std::vector<std::string> entries;
std::string delimitEntries = "/";
size_t pos = 0;
uint8_t* model_buffer = builder.GetBufferPointer();
int model_buffer_size = builder.GetSize();

while ((pos = serialized_str.find(delimitEntries)) != std::string::npos) {
std:: string token = serialized_str.substr(0, pos);
entries.push_back(token);
serialized_str.erase(0, pos+delimitEntries.length());
}
uint8_t* ret_buffer = new uint8_t[model_buffer_size];
memcpy(ret_buffer, model_buffer, sizeof(uint8_t) * model_buffer_size);
*serialized_buffer_size = model_buffer_size;
return ret_buffer;
}

// Recreate the original map entries
std::map<std::string, std::vector<double>> deserialize(uint8_t* serialized_buffer) {
std::map<std::string, std::vector<double>> demodel;
for (const std::string &entry: entries) {
std::string delimiter = ":";
std::string key = entry.substr(0, entry.find(delimiter));
std::string values = entry.substr(entry.find(delimiter), entry.length());
// values.length()-3 to remove trailing characters at the end (:[ and ])
values = values.substr(2, values.length()-3);
std::vector<double> newValues;
pos = 0;
std::string delimitValues = ",";
while ((pos = values.find(",")) != std::string::npos) {
std::string value = values.substr(0, pos);
double valueDouble = ::atof(value.c_str());
newValues.push_back(valueDouble);
values.erase(0, pos+delimitValues.length());

auto model = secagg::GetModel(serialized_buffer);
auto kvpairs = model->kv();
auto num_kvs = kvpairs->size();
for (int i = 0; i < num_kvs; i++) {
std::vector<double> feature_values;
auto pair = kvpairs->Get(i);

// Key is a string
auto key = pair->key()->str();
auto value = pair->value();
for (int j = 0; j < value->size(); j++) {
auto feature_value = value->Get(j);
feature_values.push_back(feature_value);
}
demodel.insert({key, newValues});
demodel.insert({key, feature_values});
}

return demodel;
// END DESERIALIZATION

}

Expand Down
13 changes: 13 additions & 0 deletions common/flatbuffers/model.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Example IDL file for our monster's schema.
namespace secagg;

table KVPair {
key:string;
value:[double];
}

table Model {
kv:[KVPair];
}

root_type Model;
Loading