Skip to content

Commit ede04f8

Browse files
committed
Circuit directory configurable at runtime, updated float example, exit on file not found
1 parent f7c9d68 commit ede04f8

17 files changed

+50
-40
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.
209209
`bin/` inside the build directory.
210210
* To locally execute an application, run the created executable from **two different terminals** and pass all required parameters accordingly.
211211
* 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.
212-
* **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.
212+
* **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.
213213
* You should get some debug output for you to verify the correctness of the computation.
214-
* 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).
214+
* 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).
215215
216216
#### Creating and Building your own ABY Application
217217
* To get an idea how to create a simple ABY application, you can follow the

src/abycore/ABY_utils/ABYconstants.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464

6565
#define USE_MULTI_MUX_GATES
6666

67+
// default directory containing ABY circuit files.
68+
// can also be passed to ABYParty constructor at runtime
69+
#define ABY_CIRCUIT_DIR "../../bin/circ/"
70+
6771
/**
6872
\enum e_role
6973
\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{
279283
ADD, MUL, SUB, DIV, SIN, SQRT, EXP, EXP2, CMP, LN, LOG2, COS, SQR
280284
}op_t;
281285

282-
// Floating point operation cinfiguration.
286+
// Floating point operation cinfiguration.
283287
typedef enum fp_op_setting{
284288
ieee, no_status
285289
}fp_op_setting;

src/abycore/aby/abyparty.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ABYParty::CPartyWorkerThread: public CThread {
6565

6666
ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl seclvl,
6767
uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mg_algo,
68-
uint32_t reservegates)
68+
uint32_t reservegates, const std::string& abycircdir)
6969
: m_cCrypt(std::make_unique<crypto>(seclvl.symbits)), glock(std::make_unique<CLock>()),
7070
m_eMTGenAlg(mg_algo), m_eRole(pid), m_nNumOTThreads(nthreads),
7171
m_tComm(std::make_unique<comm_ctx>()),
@@ -97,7 +97,7 @@ ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl se
9797
std::cout << "Generating circuit" << std::endl;
9898
#endif
9999
StartWatch("Generating circuit", P_CIRCUIT);
100-
if (!InitCircuit(bitlen, reservegates)) {
100+
if (!InitCircuit(bitlen, reservegates, abycircdir)) {
101101
std::cout << "There was an while initializing the circuit, ending! " << std::endl;
102102
std::exit(EXIT_FAILURE);
103103
}
@@ -268,19 +268,19 @@ void ABYParty::ExecCircuit() {
268268
}
269269

270270

271-
BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates) {
271+
BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& abycircdir) {
272272
// Default reserved gates in abyparty.h constructur
273273
m_pCircuit = new ABYCircuit(reservegates);
274274

275275
m_vSharings.resize(S_LAST);
276-
m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get());
276+
m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir);
277277
if (m_eRole == SERVER) {
278-
m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
279-
m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
278+
m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
279+
m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
280280
}
281281
else {
282-
m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
283-
m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
282+
m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
283+
m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
284284
}
285285
switch (bitlen) {
286286
case 8:
@@ -299,7 +299,7 @@ BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates) {
299299
m_vSharings[S_ARITH] = new ArithSharing<uint32_t>(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
300300
break;
301301
}
302-
m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get());
302+
m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir);
303303

304304
m_vGates = &(m_pCircuit->GatesVec());
305305

src/abycore/aby/abyparty.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CLock;
4141
class ABYParty {
4242
public:
4343
ABYParty(e_role pid, const std::string& addr = "127.0.0.1", uint16_t port = 7766, seclvl seclvl = LT, uint32_t bitlen = 32,
44-
uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t reservegates = 65536);
44+
uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t reservegates = 65536, const std::string& abycircdir = ABY_CIRCUIT_DIR);
4545
~ABYParty();
4646

4747
/**
@@ -66,7 +66,7 @@ class ABYParty {
6666
BOOL Init();
6767
void Cleanup();
6868

69-
BOOL InitCircuit(uint32_t bitlen, uint32_t reservegates);
69+
BOOL InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& circdir = ABY_CIRCUIT_DIR);
7070

7171
BOOL EstablishConnection();
7272

src/abycore/circuit/booleancircuits.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,7 @@ std::vector<uint32_t> BooleanCircuit::PutGateFromFile(const std::string filename
23562356

23572357
else {
23582358
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
2359+
std::exit(EXIT_FAILURE);
23592360
}
23602361

23612362
wires.clear();
@@ -2382,6 +2383,7 @@ std::vector<uint32_t> BooleanCircuit::PutUniversalCircuitFromFile(const std::str
23822383

23832384
if(!p1file.is_open()) {
23842385
std::cerr << "Error: Unable to open programming file " << p1filename << std::endl;
2386+
std::exit(EXIT_FAILURE);
23852387
}
23862388
#ifdef DEBUG_UC
23872389
std::cout << "Server Input Control Bits " ;
@@ -2423,6 +2425,7 @@ std::vector<uint32_t> BooleanCircuit::PutUniversalCircuitFromFile(const std::str
24232425

24242426
if (!myfile.is_open()) {
24252427
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
2428+
std::exit(EXIT_FAILURE);
24262429
}
24272430
while (getline(myfile, line)) {
24282431

@@ -2524,6 +2527,7 @@ void BooleanCircuit::GetInputLengthFromFile(const std::string filename, uint32_t
25242527

25252528
if (!myfile.is_open()) {
25262529
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
2530+
std::exit(EXIT_FAILURE);
25272531
}
25282532
while (getline(myfile, line)) {
25292533

@@ -2671,6 +2675,7 @@ std::vector<uint32_t> BooleanCircuit::PutLUTGateFromFile(const std::string filen
26712675

26722676
else {
26732677
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
2678+
std::exit(EXIT_FAILURE);
26742679
}
26752680

26762681
wires.clear();
@@ -2714,6 +2719,7 @@ uint32_t BooleanCircuit::GetInputLengthFromFile(const std::string filename){
27142719

27152720
else {
27162721
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
2722+
std::exit(EXIT_FAILURE);
27172723
}
27182724

27192725
tokens.clear();

src/abycore/circuit/booleancircuits.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
/** BooleanCircuit class. */
3434
class BooleanCircuit: public Circuit {
3535
public:
36-
//TODO this default circdir works for now, but should be changed, if things move some place else
37-
BooleanCircuit(ABYCircuit* aby, e_role myrole, e_sharing context, const std::string& circdir = "../../bin/circ/") :
36+
BooleanCircuit(ABYCircuit* aby, e_role myrole, e_sharing context, const std::string& circdir = ABY_CIRCUIT_DIR) :
3837
Circuit(aby, context, myrole, 1, C_BOOLEAN),
3938
m_cCircuitFileDir(circdir)
4039
{

src/abycore/sharing/boolsharing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void BoolSharing::Init() {
4343
m_nInputShareRcvSize = 0;
4444
m_nOutputShareRcvSize = 0;
4545

46-
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext);
46+
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir);
4747

4848
#ifdef BENCHBOOLTIME
4949
m_nCombTime = 0;

src/abycore/sharing/boolsharing.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ class BoolSharing: public Sharing {
5050

5151
public:
5252
/** Constructor of the class.*/
53-
BoolSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :\
54-
55-
Sharing(context, role, sharebitlen, circuit, crypt) {
53+
BoolSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) :
54+
Sharing(context, role, sharebitlen, circuit, crypt, circdir) {
5655
Init();
5756
}
5857
;

src/abycore/sharing/sharing.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace filesystem = std::experimental::filesystem;
3838
#include <iterator>
3939
#include <boost/algorithm/hex.hpp>
4040

41-
Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :
41+
Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir) :
4242
m_eContext(context),
4343
m_nShareBitLen(sharebitlen),
4444
m_pCircuit(circuit),
@@ -48,7 +48,8 @@ Sharing::Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircui
4848
m_nSecParamBytes(ceil_divide(m_cCrypto->get_seclvl().symbits, 8)),
4949
m_nTypeBitLen(sharebitlen),
5050
m_nFilePos(-1),
51-
m_ePhaseValue(ePreCompDefault)
51+
m_ePhaseValue(ePreCompDefault),
52+
m_cCircuitFileDir(circdir)
5253
{}
5354

5455

src/abycore/sharing/sharing.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Sharing {
4848
4949
\brief Initialises the members of the class.
5050
*/
51-
Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt);
51+
Sharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR);
5252

5353
/**
5454
Destructor of class.
@@ -245,6 +245,7 @@ class Sharing {
245245
uint32_t m_nTypeBitLen; /** Bit-length of the arithmetic shares in arithsharing */
246246
uint64_t m_nFilePos;/**< Variable which stores the position of the file pointer. */
247247
ePreCompPhase m_ePhaseValue;/**< Variable storing the current Precomputation Mode */
248+
const std::string m_cCircuitFileDir; /** Storing path to .aby circuit files (e.g. floating point) */
248249

249250
};
250251

src/abycore/sharing/splut.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "../circuit/booleancircuits.h"
2727

2828

29-
SetupLUT::SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt)
30-
: Sharing(context, role, sharebitlen, circuit, crypt) {
29+
SetupLUT::SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir)
30+
: Sharing(context, role, sharebitlen, circuit, crypt, circdir) {
3131
Init();
3232
}
3333

@@ -90,7 +90,7 @@ void SetupLUT::Init() {
9090
m_nInputShareRcvSize = 0;
9191
m_nOutputShareRcvSize = 0;
9292

93-
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext);
93+
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir);
9494

9595
//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
9696
m_bPlaySender = !((bool) m_eRole);

src/abycore/sharing/splut.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SetupLUT: public Sharing {
6060

6161
public:
6262
/** Constructor of the class.*/
63-
SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt);
63+
SetupLUT(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR);
6464

6565
/** Destructor of the class.*/
6666
virtual ~SetupLUT();

src/abycore/sharing/yaoclientsharing.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class YaoClientSharing: public YaoSharing {
3131

3232
public:
3333
/** Constructor of the class.*/
34-
YaoClientSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :
35-
YaoSharing(context, role, sharebitlen, circuit, crypt) {
34+
YaoClientSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) :
35+
YaoSharing(context, role, sharebitlen, circuit, crypt, circdir) {
3636
InitClient();
3737
}
3838
;
@@ -152,7 +152,7 @@ class YaoClientSharing: public YaoSharing {
152152
\param gleft left gate in the queue.
153153
\param gright right gate in the queue.
154154
*/
155-
BOOL EvaluateUniversalGate(GATE* gate, uint32_t pos, GATE* gleft, GATE* gright);
155+
BOOL EvaluateUniversalGate(GATE* gate, uint32_t pos, GATE* gleft, GATE* gright);
156156
/**
157157
Method for server output Gate for the inputted Gate.
158158
\param gate Gate Object

src/abycore/sharing/yaoserversharing.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class YaoServerSharing: public YaoSharing {
3636
/**
3737
Constructor of the class.
3838
*/
39-
YaoServerSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :
40-
YaoSharing(context, role, sharebitlen, circuit, crypt) {
39+
YaoServerSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) :
40+
YaoSharing(context, role, sharebitlen, circuit, crypt, circdir) {
4141
InitServer();
4242
}
4343
;

src/abycore/sharing/yaosharing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void YaoSharing::Init() {
2626
/* init the class for correctly sized Yao key operations*/
2727
InitYaoKey(&m_pKeyOps, m_cCrypto->get_seclvl().symbits);
2828

29-
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext);
29+
m_cBoolCircuit = new BooleanCircuit(m_pCircuit, m_eRole, m_eContext, m_cCircuitFileDir);
3030

3131
m_bZeroBuf = (BYTE*) calloc(m_nSecParamBytes, sizeof(BYTE));
3232
m_bTempKeyBuf = (BYTE*) malloc(sizeof(BYTE) * AES_BYTES);

src/abycore/sharing/yaosharing.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class YaoSharing: public Sharing {
5959
public:
6060

6161
/** Constructor for the class. */
62-
YaoSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt) :
63-
Sharing(context, role, sharebitlen, circuit, crypt) {
62+
YaoSharing(e_sharing context, e_role role, uint32_t sharebitlen, ABYCircuit* circuit, crypto* crypt, const std::string& circdir = ABY_CIRCUIT_DIR) :
63+
Sharing(context, role, sharebitlen, circuit, crypt, circdir) {
6464
Init();
6565
}
6666
;

src/examples/float/abyfloat.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
void read_test_options(int32_t* argcp, char*** argvp, e_role* role,
3030
uint32_t* bitlen, uint32_t* nvals, uint32_t* secparam, std::string* address,
31-
uint16_t* port, int32_t* test_op, uint32_t* test_bit, std::string* circuit, double* fpa, double* fpb) {
31+
uint16_t* port, int32_t* test_op, uint32_t* test_bit, double* fpa, double* fpb) {
3232

3333
uint32_t int_role = 0, int_port = 0, int_testbit = 0;
3434

@@ -39,7 +39,6 @@ void read_test_options(int32_t* argcp, char*** argvp, e_role* role,
3939
{(void*) bitlen, T_NUM, "b", "Bit-length, default 32", false,false },
4040
{(void*) secparam, T_NUM, "s", "Symmetric Security Bits, default: 128", false, false },
4141
{(void*) address, T_STR, "a", "IP-address, default: localhost", false, false },
42-
{(void*) circuit, T_STR, "c", "circuit file name", false, false },
4342
{(void*) &int_port, T_NUM, "p", "Port, default: 7766", false, false },
4443
{(void*) test_op, T_NUM, "t", "Single test (leave out for all operations), default: off", false, false },
4544
{(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
7170
// for addition we operate on doubles, so set bitlen to 64 bits
7271
uint32_t bitlen = 64;
7372

74-
ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg);
73+
std::string circuit_dir = "../../bin/circ/";
74+
75+
ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg, 100000, circuit_dir);
7576

7677
std::vector<Sharing*>& sharings = party->GetSharings();
7778

@@ -159,14 +160,13 @@ int main(int argc, char** argv) {
159160

160161
uint16_t port = 7766;
161162
std::string address = "127.0.0.1";
162-
std::string circuit = "none.aby";
163163
int32_t test_op = -1;
164164
e_mt_gen_alg mt_alg = MT_OT;
165165
uint32_t test_bit = 0;
166166
double fpa = 0, fpb = 0;
167167

168168
read_test_options(&argc, &argv, &role, &bitlen, &nvals, &secparam, &address,
169-
&port, &test_op, &test_bit, &circuit, &fpa, &fpb);
169+
&port, &test_op, &test_bit, &fpa, &fpb);
170170

171171
std::cout << std::fixed << std::setprecision(3);
172172
std::cout << "double input values: " << fpa << " ; " << fpb << std::endl;

0 commit comments

Comments
 (0)