diff --git a/README.md b/README.md index 15be7c8b..6387e54a 100644 --- a/README.md +++ b/README.md @@ -209,9 +209,9 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github. `bin/` inside the build directory. * To locally execute an application, run the created executable from **two different terminals** and pass all required parameters accordingly. * By default applications are tested locally (via sockets on `localhost`). You can run them on two different machines by specifying IP addresses and ports as parameters. - * **Example:** The Millionaire's problem requires to specify the role of the executing party. All other parameters will use default values if they are not set. You execute it locally with: `./millionaire_prob.exe -r 0` and `./millionaire_prob.exe -r 1`, each in a separate terminal. + * **Example:** The Millionaire's problem requires to specify the role of the executing party. All other parameters will use default values if they are not set. You execute it locally with: `./millionaire_prob_test -r 0` and `./millionaire_prob_test -r 1`, each in a separate terminal. * You should get some debug output for you to verify the correctness of the computation. - * Performance statistics can be turned on setting `#define PRINT_PERFORMANCE_STATS 1` in `src/abycore/ABY_utils/ABYconstants.h` in [line 32](https://github.com/encryptogroup/ABY/blob/public/src/abycore/ABY_utils/ABYconstants.h#L32). + * Performance statistics can be turned on setting `#define PRINT_PERFORMANCE_STATS 1` in `src/abycore/ABY_utils/ABYconstants.h` in [line 33](https://github.com/encryptogroup/ABY/blob/public/src/abycore/ABY_utils/ABYconstants.h#L33). #### Creating and Building your own ABY Application * To get an idea how to create a simple ABY application, you can follow the diff --git a/src/abycore/ABY_utils/ABYconstants.h b/src/abycore/ABY_utils/ABYconstants.h index 3f86da44..306ed2e2 100644 --- a/src/abycore/ABY_utils/ABYconstants.h +++ b/src/abycore/ABY_utils/ABYconstants.h @@ -64,6 +64,10 @@ #define USE_MULTI_MUX_GATES +// default directory containing ABY circuit files. +// can also be passed to ABYParty constructor at runtime +#define ABY_CIRCUIT_DIR "../../bin/circ/" + /** \enum e_role \brief Defines the role of the party or the source / target for certain operations (e.g., input/output) @@ -279,7 +283,7 @@ typedef enum op_t{ ADD, MUL, SUB, DIV, SIN, SQRT, EXP, EXP2, CMP, LN, LOG2, COS, SQR }op_t; -// Floating point operation cinfiguration. +// Floating point operation cinfiguration. typedef enum fp_op_setting{ ieee, no_status }fp_op_setting; diff --git a/src/abycore/aby/abyparty.cpp b/src/abycore/aby/abyparty.cpp index 586260f8..7dccae25 100644 --- a/src/abycore/aby/abyparty.cpp +++ b/src/abycore/aby/abyparty.cpp @@ -65,7 +65,7 @@ class ABYParty::CPartyWorkerThread: public CThread { ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl seclvl, uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mg_algo, - uint32_t reservegates) + uint32_t reservegates, const std::string& abycircdir) : m_cCrypt(std::make_unique(seclvl.symbits)), glock(std::make_unique()), m_eMTGenAlg(mg_algo), m_eRole(pid), m_nNumOTThreads(nthreads), m_tComm(std::make_unique()), @@ -97,7 +97,7 @@ ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl se std::cout << "Generating circuit" << std::endl; #endif StartWatch("Generating circuit", P_CIRCUIT); - if (!InitCircuit(bitlen, reservegates)) { + if (!InitCircuit(bitlen, reservegates, abycircdir)) { std::cout << "There was an while initializing the circuit, ending! " << std::endl; std::exit(EXIT_FAILURE); } @@ -268,19 +268,19 @@ void ABYParty::ExecCircuit() { } -BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates) { +BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& abycircdir) { // Default reserved gates in abyparty.h constructur m_pCircuit = new ABYCircuit(reservegates); m_vSharings.resize(S_LAST); - m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get()); + m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir); if (m_eRole == SERVER) { - m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get()); - m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get()); + m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir); + m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir); } else { - m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get()); - m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get()); + m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir); + m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir); } switch (bitlen) { case 8: @@ -299,7 +299,7 @@ BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates) { m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg); break; } - m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get()); + m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir); m_vGates = &(m_pCircuit->GatesVec()); diff --git a/src/abycore/aby/abyparty.h b/src/abycore/aby/abyparty.h index ddceae36..406de880 100644 --- a/src/abycore/aby/abyparty.h +++ b/src/abycore/aby/abyparty.h @@ -41,7 +41,7 @@ class CLock; class ABYParty { public: ABYParty(e_role pid, const std::string& addr = "127.0.0.1", uint16_t port = 7766, seclvl seclvl = LT, uint32_t bitlen = 32, - uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t reservegates = 65536); + uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t reservegates = 65536, const std::string& abycircdir = ABY_CIRCUIT_DIR); ~ABYParty(); /** @@ -66,7 +66,7 @@ class ABYParty { BOOL Init(); void Cleanup(); - BOOL InitCircuit(uint32_t bitlen, uint32_t reservegates); + BOOL InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& circdir = ABY_CIRCUIT_DIR); BOOL EstablishConnection(); diff --git a/src/abycore/circuit/booleancircuits.cpp b/src/abycore/circuit/booleancircuits.cpp index 6ac8bb30..2eecfa4c 100644 --- a/src/abycore/circuit/booleancircuits.cpp +++ b/src/abycore/circuit/booleancircuits.cpp @@ -2356,6 +2356,7 @@ std::vector BooleanCircuit::PutGateFromFile(const std::string filename else { std::cerr << "Error: Unable to open circuit file " << filename << std::endl; + std::exit(EXIT_FAILURE); } wires.clear(); @@ -2382,6 +2383,7 @@ std::vector BooleanCircuit::PutUniversalCircuitFromFile(const std::str if(!p1file.is_open()) { std::cerr << "Error: Unable to open programming file " << p1filename << std::endl; + std::exit(EXIT_FAILURE); } #ifdef DEBUG_UC std::cout << "Server Input Control Bits " ; @@ -2423,6 +2425,7 @@ std::vector BooleanCircuit::PutUniversalCircuitFromFile(const std::str if (!myfile.is_open()) { std::cerr << "Error: Unable to open circuit file " << filename << std::endl; + std::exit(EXIT_FAILURE); } while (getline(myfile, line)) { @@ -2524,6 +2527,7 @@ void BooleanCircuit::GetInputLengthFromFile(const std::string filename, uint32_t if (!myfile.is_open()) { std::cerr << "Error: Unable to open circuit file " << filename << std::endl; + std::exit(EXIT_FAILURE); } while (getline(myfile, line)) { @@ -2671,6 +2675,7 @@ std::vector BooleanCircuit::PutLUTGateFromFile(const std::string filen else { std::cerr << "Error: Unable to open circuit file " << filename << std::endl; + std::exit(EXIT_FAILURE); } wires.clear(); @@ -2714,6 +2719,7 @@ uint32_t BooleanCircuit::GetInputLengthFromFile(const std::string filename){ else { std::cerr << "Error: Unable to open circuit file " << filename << std::endl; + std::exit(EXIT_FAILURE); } tokens.clear(); diff --git a/src/abycore/circuit/booleancircuits.h b/src/abycore/circuit/booleancircuits.h index cd858833..95d3b7e4 100755 --- a/src/abycore/circuit/booleancircuits.h +++ b/src/abycore/circuit/booleancircuits.h @@ -33,8 +33,7 @@ /** BooleanCircuit class. */ class BooleanCircuit: public Circuit { public: - //TODO this default circdir works for now, but should be changed, if things move some place else - BooleanCircuit(ABYCircuit* aby, e_role myrole, e_sharing context, const std::string& circdir = "../../bin/circ/") : + BooleanCircuit(ABYCircuit* aby, e_role myrole, e_sharing context, const std::string& circdir = ABY_CIRCUIT_DIR) : Circuit(aby, context, myrole, 1, C_BOOLEAN), m_cCircuitFileDir(circdir) { diff --git a/src/abycore/sharing/boolsharing.cpp b/src/abycore/sharing/boolsharing.cpp index 0531f197..ec74ee85 100644 --- a/src/abycore/sharing/boolsharing.cpp +++ b/src/abycore/sharing/boolsharing.cpp @@ -43,7 +43,7 @@ void BoolSharing::Init() { m_nInputShareRcvSize = 0; m_nOutputShareRcvSize = 0; - m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext); + m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir); #ifdef BENCHBOOLTIME m_nCombTime = 0; diff --git a/src/abycore/sharing/boolsharing.h b/src/abycore/sharing/boolsharing.h index 1d2a93aa..25857a4b 100644 --- a/src/abycore/sharing/boolsharing.h +++ b/src/abycore/sharing/boolsharing.h @@ -50,9 +50,8 @@ class BoolSharing: public Sharing { public: /** Constructor of the class.*/ - BoolSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :\ - - Sharing(context, role, sharebitlen, circuit, crypt) { + BoolSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) : + Sharing(context, role, sharebitlen, circuit, crypt, circdir) { Init(); } ; diff --git a/src/abycore/sharing/sharing.cpp b/src/abycore/sharing/sharing.cpp index ebd2772e..1b973b7d 100644 --- a/src/abycore/sharing/sharing.cpp +++ b/src/abycore/sharing/sharing.cpp @@ -38,7 +38,7 @@ namespace filesystem = std::experimental::filesystem; #include #include -Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) : +Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir) : m_eContext(context), m_nShareBitLen(sharebitlen), m_pCircuit(circuit), @@ -48,7 +48,8 @@ Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircui m_nSecParamBytes(ceil_divide(m_cCrypto->get_seclvl().symbits, 8)), m_nTypeBitLen(sharebitlen), m_nFilePos(-1), - m_ePhaseValue(ePreCompDefault) + m_ePhaseValue(ePreCompDefault), + m_cCircuitFileDir(circdir) {} diff --git a/src/abycore/sharing/sharing.h b/src/abycore/sharing/sharing.h index 20519252..fe545e13 100644 --- a/src/abycore/sharing/sharing.h +++ b/src/abycore/sharing/sharing.h @@ -48,7 +48,7 @@ class Sharing { \brief Initialises the members of the class. */ - Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt); + Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR); /** Destructor of class. @@ -245,6 +245,7 @@ class Sharing { uint32_t m_nTypeBitLen; /** Bit-length of the arithmetic shares in arithsharing */ uint64_t m_nFilePos;/**< Variable which stores the position of the file pointer. */ ePreCompPhase m_ePhaseValue;/**< Variable storing the current Precomputation Mode */ + const std::string m_cCircuitFileDir; /** Storing path to .aby circuit files (e.g. floating point) */ }; diff --git a/src/abycore/sharing/splut.cpp b/src/abycore/sharing/splut.cpp index 12b44524..c6916cdd 100644 --- a/src/abycore/sharing/splut.cpp +++ b/src/abycore/sharing/splut.cpp @@ -26,8 +26,8 @@ #include "../circuit/booleancircuits.h" -SetupLUT::SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) - : Sharing(context, role, sharebitlen, circuit, crypt) { +SetupLUT::SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir) + : Sharing(context, role, sharebitlen, circuit, crypt, circdir) { Init(); } @@ -90,7 +90,7 @@ void SetupLUT::Init() { m_nInputShareRcvSize = 0; m_nOutputShareRcvSize = 0; - m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext); + m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir); //first round: the server is the active part and skips the first send iteration while the client waits until the server is done with depth 1 m_bPlaySender = !((bool) m_eRole); diff --git a/src/abycore/sharing/splut.h b/src/abycore/sharing/splut.h index 1f0a8b35..0e5e3f5f 100644 --- a/src/abycore/sharing/splut.h +++ b/src/abycore/sharing/splut.h @@ -60,7 +60,7 @@ class SetupLUT: public Sharing { public: /** Constructor of the class.*/ - SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt); + SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR); /** Destructor of the class.*/ virtual ~SetupLUT(); diff --git a/src/abycore/sharing/yaoclientsharing.h b/src/abycore/sharing/yaoclientsharing.h index 0845f725..4b775629 100644 --- a/src/abycore/sharing/yaoclientsharing.h +++ b/src/abycore/sharing/yaoclientsharing.h @@ -31,8 +31,8 @@ class YaoClientSharing: public YaoSharing { public: /** Constructor of the class.*/ - YaoClientSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) : - YaoSharing(context, role, sharebitlen, circuit, crypt) { + YaoClientSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) : + YaoSharing(context, role, sharebitlen, circuit, crypt, circdir) { InitClient(); } ; @@ -152,7 +152,7 @@ class YaoClientSharing: public YaoSharing { \param gleft left gate in the queue. \param gright right gate in the queue. */ - BOOL EvaluateUniversalGate(GATE* gate, uint32_t pos, GATE* gleft, GATE* gright); + BOOL EvaluateUniversalGate(GATE* gate, uint32_t pos, GATE* gleft, GATE* gright); /** Method for server output Gate for the inputted Gate. \param gate Gate Object diff --git a/src/abycore/sharing/yaoserversharing.h b/src/abycore/sharing/yaoserversharing.h index 83fccacb..455b86bd 100644 --- a/src/abycore/sharing/yaoserversharing.h +++ b/src/abycore/sharing/yaoserversharing.h @@ -36,8 +36,8 @@ class YaoServerSharing: public YaoSharing { /** Constructor of the class. */ - YaoServerSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) : - YaoSharing(context, role, sharebitlen, circuit, crypt) { + YaoServerSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) : + YaoSharing(context, role, sharebitlen, circuit, crypt, circdir) { InitServer(); } ; diff --git a/src/abycore/sharing/yaosharing.cpp b/src/abycore/sharing/yaosharing.cpp index 7a5516f1..a104cdc0 100644 --- a/src/abycore/sharing/yaosharing.cpp +++ b/src/abycore/sharing/yaosharing.cpp @@ -26,7 +26,7 @@ void YaoSharing::Init() { /* init the class for correctly sized Yao key operations*/ InitYaoKey(&m_pKeyOps, m_cCrypto->get_seclvl().symbits); - m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext); + m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir); m_bZeroBuf = (BYTE*) calloc(m_nSecParamBytes, sizeof(BYTE)); m_bTempKeyBuf = (BYTE*) malloc(sizeof(BYTE) * AES_BYTES); diff --git a/src/abycore/sharing/yaosharing.h b/src/abycore/sharing/yaosharing.h index d866ed11..d703daec 100644 --- a/src/abycore/sharing/yaosharing.h +++ b/src/abycore/sharing/yaosharing.h @@ -59,8 +59,8 @@ class YaoSharing: public Sharing { public: /** Constructor for the class. */ - YaoSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) : - Sharing(context, role, sharebitlen, circuit, crypt) { + YaoSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) : + Sharing(context, role, sharebitlen, circuit, crypt, circdir) { Init(); } ; diff --git a/src/examples/float/abyfloat.cpp b/src/examples/float/abyfloat.cpp index 69bb3ece..021d403c 100644 --- a/src/examples/float/abyfloat.cpp +++ b/src/examples/float/abyfloat.cpp @@ -28,7 +28,7 @@ void read_test_options(int32_t* argcp, char*** argvp, e_role* role, uint32_t* bitlen, uint32_t* nvals, uint32_t* secparam, std::string* address, - uint16_t* port, int32_t* test_op, uint32_t* test_bit, std::string* circuit, double* fpa, double* fpb) { + uint16_t* port, int32_t* test_op, uint32_t* test_bit, double* fpa, double* fpb) { uint32_t int_role = 0, int_port = 0, int_testbit = 0; @@ -39,7 +39,6 @@ void read_test_options(int32_t* argcp, char*** argvp, e_role* role, {(void*) bitlen, T_NUM, "b", "Bit-length, default 32", false,false }, {(void*) secparam, T_NUM, "s", "Symmetric Security Bits, default: 128", false, false }, {(void*) address, T_STR, "a", "IP-address, default: localhost", false, false }, - {(void*) circuit, T_STR, "c", "circuit file name", false, false }, {(void*) &int_port, T_NUM, "p", "Port, default: 7766", false, false }, {(void*) test_op, T_NUM, "t", "Single test (leave out for all operations), default: off", false, false }, {(void*) fpa, T_DOUBLE, "x", "FP a", false, false }, @@ -71,7 +70,9 @@ void test_verilog_add64_SIMD(e_role role, const std::string& address, uint16_t p // for addition we operate on doubles, so set bitlen to 64 bits uint32_t bitlen = 64; - ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg); + std::string circuit_dir = "../../bin/circ/"; + + ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg, 100000, circuit_dir); std::vector& sharings = party->GetSharings(); @@ -159,14 +160,13 @@ int main(int argc, char** argv) { uint16_t port = 7766; std::string address = "127.0.0.1"; - std::string circuit = "none.aby"; int32_t test_op = -1; e_mt_gen_alg mt_alg = MT_OT; uint32_t test_bit = 0; double fpa = 0, fpb = 0; read_test_options(&argc, &argv, &role, &bitlen, &nvals, &secparam, &address, - &port, &test_op, &test_bit, &circuit, &fpa, &fpb); + &port, &test_op, &test_bit, &fpa, &fpb); std::cout << std::fixed << std::setprecision(3); std::cout << "double input values: " << fpa << " ; " << fpb << std::endl;