Skip to content

Instantly share code, notes, and snippets.

@bl4ck5un
Last active May 14, 2019 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bl4ck5un/75005ae8ab2d225a529925044e521954 to your computer and use it in GitHub Desktop.
Save bl4ck5un/75005ae8ab2d225a529925044e521954 to your computer and use it in GitHub Desktop.
integer <> binary
#include "emp-sh2pc/emp-sh2pc.h"
using namespace emp;
using namespace std;
const string circuit_file_location = macro_xstr(EMP_CIRCUIT_PATH);
int port, party;
string file = circuit_file_location+"/AES-non-expanded.txt";//adder_32bit.txt";
CircuitFile cf(file.c_str());
// test vector
const char *_key = "2b7e151628aed2a6abf7158809cf4f3c";
const char *_pla = "6bc1bee22e409f96e93d7e117393172a";
const char *_cph = "3ad77bb40d7a3660a89ecaf32466ef97";
auto key_bin = hex_to_binary(_key);
auto plain_bin = hex_to_binary(_pla);
auto cipher_bin = hex_to_binary(_cph);
void test() {
auto start = clock_start();
Integer a(128, 2, ALICE);
Integer b(128, 3, BOB);
Integer ref(128, 0, PUBLIC);
for (int i = 0; i < 128; i++) {
a[i] = key_bin[i] == '1';
b[i] = plain_bin[i] == '1';
ref[i] = cipher_bin[i] == '1';
}
Integer c(128, 1, PUBLIC);
for(int i = 0; i < 10000; ++i) {
cf.compute((block*)c.bits, (block*)a.bits, (block*)b.bits);
}
cout << time_from(start)<<" "<<party<<" "<<c.reveal<string>(BOB)<<endl;
cout << "ref " << ref.reveal<string>(PUBLIC) << endl;
}
int main(int argc, char** argv) {
parse_party_and_port(argv, &party, &port);
NetIO* io = new NetIO(party==ALICE?nullptr:"127.0.0.1", port);
setup_semi_honest(io, party);
test();
delete io;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment