Skip to content

Commit

Permalink
Circuit directory configurable at runtime, updated float example, exi…
Browse files Browse the repository at this point in the history
…t on file not found
  • Loading branch information
dd23 committed Jul 24, 2019
1 parent f7c9d68 commit ede04f8
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/abycore/ABY_utils/ABYconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/abycore/aby/abyparty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<crypto>(seclvl.symbits)), glock(std::make_unique<CLock>()),
m_eMTGenAlg(mg_algo), m_eRole(pid), m_nNumOTThreads(nthreads),
m_tComm(std::make_unique<comm_ctx>()),
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand All @@ -299,7 +299,7 @@ BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates) {
m_vSharings[S_ARITH] = new ArithSharing<uint32_t>(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());

Expand Down
4 changes: 2 additions & 2 deletions src/abycore/aby/abyparty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand All @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions src/abycore/circuit/booleancircuits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,7 @@ std::vector<uint32_t> BooleanCircuit::PutGateFromFile(const std::string filename

else {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
std::exit(EXIT_FAILURE);
}

wires.clear();
Expand All @@ -2382,6 +2383,7 @@ std::vector<uint32_t> 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 " ;
Expand Down Expand Up @@ -2423,6 +2425,7 @@ std::vector<uint32_t> 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)) {

Expand Down Expand Up @@ -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)) {

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

else {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
std::exit(EXIT_FAILURE);
}

wires.clear();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/abycore/circuit/booleancircuits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/sharing/boolsharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/abycore/sharing/boolsharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
;
Expand Down
5 changes: 3 additions & 2 deletions src/abycore/sharing/sharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace filesystem = std::experimental::filesystem;
#include <iterator>
#include <boost/algorithm/hex.hpp>

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),
Expand All @@ -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)
{}


Expand Down
3 changes: 2 additions & 1 deletion src/abycore/sharing/sharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) */

};

Expand Down
6 changes: 3 additions & 3 deletions src/abycore/sharing/splut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/sharing/splut.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/abycore/sharing/yaoclientsharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/abycore/sharing/yaoserversharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
;
Expand Down
2 changes: 1 addition & 1 deletion src/abycore/sharing/yaosharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/abycore/sharing/yaosharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
;
Expand Down
10 changes: 5 additions & 5 deletions src/examples/float/abyfloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 },
Expand Down Expand Up @@ -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<Sharing*>& sharings = party->GetSharings();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ede04f8

Please sign in to comment.