/* * MalicousRepParty.cpp * */ #ifndef GC_SHARETHREAD_HPP_ #define GC_SHARETHREAD_HPP_ #include #include "Protocols/MaliciousRepMC.h" #include "Math/Setup.h" #include "Processor/Data_Files.hpp" namespace GC { template ShareThread::ShareThread(int i, ThreadMaster& master) : Thread(i, master), usage(master.N.num_players()), DataF( master.opts.live_prep ? *(Preprocessing*) new typename T::LivePrep(usage, *this) : *(Preprocessing*) new Sub_Data_Files(master.N, get_prep_dir(master.N.num_players(), 128, 128), usage)) { } template ShareThread::~ShareThread() { delete &DataF; } template void ShareThread::pre_run() { if (singleton) throw runtime_error("there can only be one"); singleton = this; assert(this->protocol != 0); DataF.set_protocol(*this->protocol); } template void ShareThread::post_run() { #ifndef INSECURE cerr << "Removing used pre-processed data" << endl; DataF.prune(); #endif } template void ShareThread::and_(Processor& processor, const vector& args, bool repeat) { auto& protocol = this->protocol; processor.check_args(args, 4); protocol->init_mul(DataF, *this->MC); for (size_t i = 0; i < args.size(); i += 4) { int n_bits = args[i]; int left = args[i + 2]; int right = args[i + 3]; T y_ext; if (repeat) y_ext = processor.S[right].extend_bit(); else y_ext = processor.S[right]; protocol->prepare_mul(processor.S[left].mask(n_bits), y_ext.mask(n_bits), n_bits); } protocol->exchange(); for (size_t i = 0; i < args.size(); i += 4) { int n_bits = args[i]; int out = args[i + 1]; processor.S[out] = protocol->finalize_mul(n_bits); } } } /* namespace GC */ #endif