mirror of
https://github.com/privacy-scaling-explorations/emp-wasm.git
synced 2026-01-10 02:27:55 -05:00
Remove nP template from NetIOMP
This commit is contained in:
@@ -11,9 +11,9 @@ int main(int argc, char** argv) {
|
||||
parse_party_and_port(argv, &party, &port);
|
||||
|
||||
const static int nP = 4;
|
||||
NetIOMP<nP> io(party, port);
|
||||
NetIOMP<nP> io2(party, port+2*(nP+1)*(nP+1)+1);
|
||||
NetIOMP<nP> *ios[2] = {&io, &io2};
|
||||
NetIOMP io(nP, party, port);
|
||||
NetIOMP io2(nP, party, port+2*(nP+1)*(nP+1)+1);
|
||||
NetIOMP *ios[2] = {&io, &io2};
|
||||
BristolFormat cf(circuit_file_location.c_str());
|
||||
|
||||
CMPC<nP>* mpc = new CMPC<nP>(nP, ios, party, &cf);
|
||||
|
||||
@@ -15,14 +15,14 @@ class ABitMP { public:
|
||||
int nP;
|
||||
Vec<std::optional<IKNP>> abit1;
|
||||
Vec<std::optional<IKNP>> abit2;
|
||||
NetIOMP<nP_deprecated> *io;
|
||||
NetIOMP *io;
|
||||
int party;
|
||||
PRG prg;
|
||||
block Delta;
|
||||
Hash hash;
|
||||
int ssp;
|
||||
block * pretable;
|
||||
ABitMP(int nP, NetIOMP<nP_deprecated>* io, int party, bool * _tmp = nullptr, int ssp = 40)
|
||||
ABitMP(int nP, NetIOMP* io, int party, bool * _tmp = nullptr, int ssp = 40)
|
||||
:
|
||||
nP(nP),
|
||||
abit1(nP+1),
|
||||
@@ -99,7 +99,7 @@ class ABitMP { public:
|
||||
}
|
||||
|
||||
void check1(const NVec<block>& MAC, const NVec<block>& KEY, bool* data, int length) {
|
||||
block seed = sampleRandom(io, &prg, party);
|
||||
block seed = sampleRandom(nP, io, &prg, party);
|
||||
PRG prg2(&seed);
|
||||
uint8_t * tmp;
|
||||
block * Ms[nP+1];
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
bool *value;
|
||||
block *key[nP + 1];
|
||||
block *mac[nP + 1];
|
||||
NetIOMP<nP> * io;
|
||||
NetIOMP* io;
|
||||
block Delta;
|
||||
|
||||
vector<int> party_assignment;
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
authenticated_share_assignment.clear();
|
||||
}
|
||||
|
||||
void associate_cmpc(bool *associated_value, NVec<block>& associated_mac, NVec<block>& associated_key, NetIOMP<nP> *associated_io, block associated_Delta) {
|
||||
void associate_cmpc(bool *associated_value, NVec<block>& associated_mac, NVec<block>& associated_key, NetIOMP *associated_io, block associated_Delta) {
|
||||
this->cmpc_associated = true;
|
||||
this->value = associated_value;
|
||||
for(int j = 1; j <= nP; j++) {
|
||||
@@ -510,7 +510,7 @@ public:
|
||||
block *key[nP + 1];
|
||||
block *mac[nP + 1];
|
||||
block *eval_labels[nP + 1];
|
||||
NetIOMP<nP> * io;
|
||||
NetIOMP * io;
|
||||
block Delta;
|
||||
block *labels;
|
||||
|
||||
@@ -539,7 +539,7 @@ public:
|
||||
authenticated_share_results.clear();
|
||||
}
|
||||
|
||||
void associate_cmpc(bool *associated_value, NVec<block>& associated_mac, NVec<block>& associated_key, NVec<block>& associated_eval_labels, Vec<block>& associated_labels, NetIOMP<nP> *associated_io, block associated_Delta) {
|
||||
void associate_cmpc(bool *associated_value, NVec<block>& associated_mac, NVec<block>& associated_key, NVec<block>& associated_eval_labels, Vec<block>& associated_labels, NetIOMP *associated_io, block associated_Delta) {
|
||||
this->cmpc_associated = true;
|
||||
this->value = associated_value;
|
||||
this->labels = &associated_labels.at(0);
|
||||
|
||||
@@ -13,7 +13,7 @@ template<int nP_deprecated>
|
||||
class FpreMP { public:
|
||||
int nP;
|
||||
int party;
|
||||
NetIOMP<nP_deprecated> * io;
|
||||
NetIOMP * io;
|
||||
ABitMP<nP_deprecated>* abit;
|
||||
block Delta;
|
||||
CRH * prps;
|
||||
@@ -21,7 +21,7 @@ class FpreMP { public:
|
||||
PRG * prgs;
|
||||
PRG prg;
|
||||
int ssp;
|
||||
FpreMP(int nP, NetIOMP<nP_deprecated> * io[2], int party, bool * _delta = nullptr, int ssp = 40) {
|
||||
FpreMP(int nP, NetIOMP * io[2], int party, bool * _delta = nullptr, int ssp = 40) {
|
||||
this->nP = nP;
|
||||
this->party = party;
|
||||
this->io = io[0];
|
||||
@@ -199,7 +199,7 @@ class FpreMP { public:
|
||||
check_zero(&tKEYphi.at(party, 0), length*bucket_size);
|
||||
#endif
|
||||
|
||||
block prg_key = sampleRandom(io, &prg, party);
|
||||
block prg_key = sampleRandom(nP, io, &prg, party);
|
||||
PRG prgf(&prg_key);
|
||||
char (*dgst)[Hash::DIGEST_SIZE] = new char[nP+1][Hash::DIGEST_SIZE];
|
||||
bool * tmp = new bool[length*bucket_size];
|
||||
@@ -233,7 +233,7 @@ class FpreMP { public:
|
||||
if(!cmpBlock(&X.at(1, 0), &X.at(2, 0), ssp)) error("AND check");
|
||||
|
||||
//land -> and
|
||||
block S = sampleRandom<nP_deprecated>(io, &prg, party);
|
||||
block S = sampleRandom(nP, io, &prg, party);
|
||||
|
||||
int * ind = new int[length*bucket_size];
|
||||
int *location = new int[length*bucket_size];
|
||||
|
||||
@@ -82,8 +82,7 @@ void recv_partial_block(IOChannel& io, block * data, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
template<int nP>
|
||||
block sampleRandom(NetIOMP<nP> * io, PRG * prg, int party) {
|
||||
block sampleRandom(int nP, NetIOMP * io, PRG * prg, int party) {
|
||||
vector<bool> res2;
|
||||
char (*dgst)[Hash::DIGEST_SIZE] = new char[nP+1][Hash::DIGEST_SIZE];
|
||||
block *S = new block[nP+1];
|
||||
@@ -118,7 +117,7 @@ block sampleRandom(NetIOMP<nP> * io, PRG * prg, int party) {
|
||||
}
|
||||
|
||||
template<int nP>
|
||||
void check_MAC(NetIOMP<nP> * io, const NVec<block>& MAC, const NVec<block>& KEY, bool * r, block Delta, int length, int party) {
|
||||
void check_MAC(NetIOMP * io, const NVec<block>& MAC, const NVec<block>& KEY, bool * r, block Delta, int length, int party) {
|
||||
block * tmp = new block[length];
|
||||
block tD;
|
||||
for(int i = 1; i <= nP; ++i) for(int j = 1; j <= nP; ++j) if (i < j) {
|
||||
@@ -142,7 +141,7 @@ void check_MAC(NetIOMP<nP> * io, const NVec<block>& MAC, const NVec<block>& KEY,
|
||||
}
|
||||
|
||||
template<int nP>
|
||||
void check_correctness(NetIOMP<nP>* io, bool * r, int length, int party) {
|
||||
void check_correctness(NetIOMP* io, bool * r, int length, int party) {
|
||||
if (party == 1) {
|
||||
bool * tmp1 = new bool[length*3];
|
||||
bool * tmp2 = new bool[length*3];
|
||||
|
||||
@@ -35,7 +35,7 @@ class CMPC { public:
|
||||
|
||||
Vec<block> labels; // dim: wires
|
||||
BristolFormat * cf;
|
||||
NetIOMP<nP_deprecated> * io;
|
||||
NetIOMP * io;
|
||||
int num_ands = 0, num_in;
|
||||
int party, total_pre, ssp;
|
||||
block Delta;
|
||||
@@ -49,7 +49,7 @@ class CMPC { public:
|
||||
|
||||
CMPC(
|
||||
int nP,
|
||||
NetIOMP<nP_deprecated> * io[2],
|
||||
NetIOMP * io[2],
|
||||
int party,
|
||||
BristolFormat * cf,
|
||||
bool * _delta = nullptr,
|
||||
|
||||
@@ -1,52 +1,59 @@
|
||||
#ifndef NETIOMP_H
|
||||
#define NETIOMP_H
|
||||
#include <optional>
|
||||
#include <unistd.h>
|
||||
#include <emp-tool/emp-tool.h>
|
||||
#include <emp-tool/io/net_io.h>
|
||||
#include "cmpc_config.h"
|
||||
#include "vec.h"
|
||||
using namespace emp;
|
||||
|
||||
template<int nP>
|
||||
class NetIOMP { public:
|
||||
IOChannel*ios[nP+1];
|
||||
IOChannel*ios2[nP+1];
|
||||
int nP;
|
||||
Vec<std::optional<IOChannel>> ios;
|
||||
Vec<std::optional<IOChannel>> ios2;
|
||||
int party;
|
||||
bool sent[nP+1];
|
||||
NetIOMP(int party, int port) {
|
||||
this->party = party;
|
||||
memset(sent, false, nP+1);
|
||||
Vec<bool> sent;
|
||||
NetIOMP(int nP, int party, int port)
|
||||
:
|
||||
nP(nP),
|
||||
ios(nP+1),
|
||||
ios2(nP+1),
|
||||
party(party),
|
||||
sent(nP+1)
|
||||
{
|
||||
for(int i = 1; i <= nP; ++i)for(int j = 1; j <= nP; ++j)if(i < j){
|
||||
if(i == party) {
|
||||
#ifdef LOCALHOST
|
||||
usleep(1000);
|
||||
ios[j] = new IOChannel(std::make_shared<NetIO>(IP[j], port+2*(i*nP+j)));
|
||||
ios[j].emplace(std::make_shared<NetIO>(IP[j], port+2*(i*nP+j)));
|
||||
#else
|
||||
usleep(1000);
|
||||
ios[j] = new IOChannel(std::make_shared<NetIO>(IP[j], port+2*(i)));
|
||||
ios[j].emplace(std::make_shared<NetIO>(IP[j], port+2*(i)));
|
||||
#endif
|
||||
|
||||
#ifdef LOCALHOST
|
||||
usleep(1000);
|
||||
ios2[j] = new IOChannel(std::make_shared<NetIO>(nullptr, port+2*(i*nP+j)+1));
|
||||
ios2[j].emplace(std::make_shared<NetIO>(nullptr, port+2*(i*nP+j)+1));
|
||||
#else
|
||||
usleep(1000);
|
||||
ios2[j] = new IOChannel(std::make_shared<NetIO>(nullptr, port+2*(j)+1));
|
||||
ios2[j].emplace(std::make_shared<NetIO>(nullptr, port+2*(j)+1));
|
||||
#endif
|
||||
} else if(j == party) {
|
||||
#ifdef LOCALHOST
|
||||
usleep(1000);
|
||||
ios[i] = new IOChannel(std::make_shared<NetIO>(nullptr, port+2*(i*nP+j)));
|
||||
ios[i].emplace(std::make_shared<NetIO>(nullptr, port+2*(i*nP+j)));
|
||||
#else
|
||||
usleep(1000);
|
||||
ios[i] = new IOChannel(std::make_shared<NetIO>(nullptr, port+2*(i)));
|
||||
ios[i].emplace(std::make_shared<NetIO>(nullptr, port+2*(i)));
|
||||
#endif
|
||||
|
||||
#ifdef LOCALHOST
|
||||
usleep(1000);
|
||||
ios2[i] = new IOChannel(std::make_shared<NetIO>(IP[i], port+2*(i*nP+j)+1));
|
||||
ios2[i].emplace(std::make_shared<NetIO>(IP[i], port+2*(i*nP+j)+1));
|
||||
#else
|
||||
usleep(1000);
|
||||
ios2[i] = new IOChannel(std::make_shared<NetIO>(IP[i], port+2*(j)+1));
|
||||
ios2[i].emplace(std::make_shared<NetIO>(IP[i], port+2*(j)+1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -60,13 +67,6 @@ class NetIOMP { public:
|
||||
return res;
|
||||
}
|
||||
|
||||
~NetIOMP() {
|
||||
for(int i = 1; i <= nP; ++i)
|
||||
if(i != party) {
|
||||
delete ios[i];
|
||||
delete ios2[i];
|
||||
}
|
||||
}
|
||||
void send_data(int dst, const void * data, size_t len) {
|
||||
if(dst != 0 and dst!= party) {
|
||||
if(party < dst)
|
||||
@@ -107,16 +107,16 @@ class NetIOMP { public:
|
||||
ios2[idx]->flush();
|
||||
}
|
||||
}
|
||||
void sync() {
|
||||
for(int i = 1; i <= nP; ++i) for(int j = 1; j <= nP; ++j) if(i < j) {
|
||||
if(i == party) {
|
||||
ios[j]->sync();
|
||||
ios2[j]->sync();
|
||||
} else if(j == party) {
|
||||
ios[i]->sync();
|
||||
ios2[i]->sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
// void sync() {
|
||||
// for(int i = 1; i <= nP; ++i) for(int j = 1; j <= nP; ++j) if(i < j) {
|
||||
// if(i == party) {
|
||||
// ios[j]->sync();
|
||||
// ios2[j]->sync();
|
||||
// } else if(j == party) {
|
||||
// ios[i]->sync();
|
||||
// ios2[i]->sync();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
};
|
||||
#endif //NETIOMP_H
|
||||
|
||||
Reference in New Issue
Block a user