Protocol in dealer model.

This commit is contained in:
Marcel Keller
2022-04-19 15:10:18 +02:00
parent eee886570a
commit 9ef15cc2f5
186 changed files with 2008 additions and 618 deletions

View File

@@ -59,6 +59,8 @@ void BaseMachine::load_schedule(const string& progname, bool load_bytecode)
cerr << "Number of program sequences I need to load = " << nprogs << endl;
#endif
bc_filenames.clear();
// Load in the programs
string threadname;
for (int i=0; i<nprogs; i++)

View File

@@ -299,9 +299,7 @@ template<int>
void Sub_Data_Files<T>::buffer_edabits_with_queues(bool strict, int n_bits,
false_type)
{
#ifndef INSECURE
throw runtime_error("no secure implementation of reading edaBits from files");
#endif
insecure("reading edaBits from files");
if (edabit_buffers.find(n_bits) == edabit_buffers.end())
{
string filename = PrepBase::get_edabit_filename(prep_data_dir,

View File

@@ -26,7 +26,7 @@ class InputBase
typedef typename T::clear clear;
protected:
Player* P;
PlayerBase* P;
int my_num;
Buffer<typename T::clear, typename T::clear> buffer;
@@ -63,7 +63,7 @@ public:
/// Initialize input round for ``player``
virtual void reset(int player) = 0;
/// Initialize input round for all players
void reset_all(Player& P);
void reset_all(PlayerBase& P);
/// Schedule input from me
virtual void add_mine(const typename T::open_type& input, int n_bits = -1) = 0;

View File

@@ -81,7 +81,7 @@ void InputBase<T>::reset(int player)
}
template<class T>
void InputBase<T>::reset_all(Player& P)
void InputBase<T>::reset_all(PlayerBase& P)
{
this->P = &P;
my_num = P.my_num();

View File

@@ -328,14 +328,14 @@ protected:
int opcode; // The code
int size; // Vector size
int r[4]; // Fixed parameter registers
unsigned int n; // Possible immediate value
size_t n; // Possible immediate value
vector<int> start; // Values for a start/stop open
public:
virtual ~BaseInstruction() {};
int get_r(int i) const { return r[i]; }
unsigned int get_n() const { return n; }
size_t get_n() const { return n; }
const vector<int>& get_start() const { return start; }
int get_opcode() const { return opcode; }
int get_size() const { return size; }
@@ -350,7 +350,7 @@ public:
bool is_direct_memory_access() const;
// Returns the memory size used if applicable and known
unsigned get_mem(RegType reg_type) const;
size_t get_mem(RegType reg_type) const;
// Returns the maximal register used
unsigned get_max_reg(int reg_type) const;

View File

@@ -218,24 +218,10 @@ void BaseInstruction::parse_operands(istream& s, int pos, int file_pos)
// instructions with 1 register + 1 integer operand
case LDI:
case LDSI:
case LDMC:
case LDMS:
case STMC:
case STMS:
case LDMSB:
case STMSB:
case LDMCB:
case STMCB:
case LDMINT:
case STMINT:
case JMPNZ:
case JMPEQZ:
case GLDI:
case GLDSI:
case GLDMC:
case GLDMS:
case GSTMC:
case GSTMS:
case PRINTREG:
case PRINTREGB:
case GPRINTREG:
@@ -247,6 +233,24 @@ void BaseInstruction::parse_operands(istream& s, int pos, int file_pos)
r[0]=get_int(s);
n = get_int(s);
break;
// instructions with 1 register + 1 long operand
case LDMC:
case LDMS:
case STMC:
case STMS:
case LDMSB:
case STMSB:
case LDMCB:
case STMCB:
case LDMINT:
case STMINT:
case GLDMC:
case GLDMS:
case GSTMC:
case GSTMS:
r[0] = get_int(s);
n = get_long(s);
break;
// instructions with 1 integer operand
case PRINTSTR:
case PRINTCHR:
@@ -783,7 +787,7 @@ unsigned BaseInstruction::get_max_reg(int reg_type) const
}
inline
unsigned BaseInstruction::get_mem(RegType reg_type) const
size_t BaseInstruction::get_mem(RegType reg_type) const
{
if (get_reg_type() == reg_type and is_direct_memory_access())
return n + size;
@@ -843,7 +847,7 @@ inline void Instruction::execute(Processor<sint, sgf2n>& Proc) const
}
int r[3] = {this->r[0], this->r[1], this->r[2]};
int n = this->n;
int64_t n = this->n;
for (int i = 0; i < size; i++)
{ switch (opcode)
{
@@ -1065,7 +1069,7 @@ inline void Instruction::execute(Processor<sint, sgf2n>& Proc) const
case PRINTREG:
{
Proc.out << "Reg[" << r[0] << "] = " << Proc.read_Cp(r[0])
<< " # " << string((char*)&n,sizeof(n)) << endl;
<< " # " << string((char*)&n, 4) << endl;
}
break;
case PRINTREGPLAIN:
@@ -1085,7 +1089,7 @@ inline void Instruction::execute(Processor<sint, sgf2n>& Proc) const
case CONDPRINTSTR:
if (not Proc.read_Cp(r[0]).is_zero())
{
string str = {(char*)&n, sizeof(n)};
string str = {(char*)&n, 4};
size_t n = str.find('\0');
if (n < 4)
str.erase(n);
@@ -1313,7 +1317,7 @@ void Instruction::print(SwitchableOutput& out, T* v, T* p, T* s, T* z, T* nan) c
out << "[";
for (int i = 0; i < size; i++)
{
if (p == 0)
if (p == 0 or (*p == 0 and s == 0))
out << v[i];
else if (s == 0)
out << bigint::get_float(v[i], p[i], {}, {});

View File

@@ -46,6 +46,8 @@ class Machine : public BaseMachine
void load_program(const string& threadname, const string& filename);
void prepare(const string& progname_str);
void suggest_optimizations();
public:
@@ -71,10 +73,10 @@ class Machine : public BaseMachine
ExecutionStats stats;
Machine(int my_number, Names& playerNames, const string& progname,
const string& memtype, int lg2, bool direct, int opening_sum,
bool receive_threads, int max_broadcast, bool use_encryption, bool live_prep,
OnlineOptions opts);
static void init_binary_domains(int security_parameter, int lg2);
Machine(Names& playerNames, bool use_encryption = true,
const OnlineOptions opts = sint(), int lg2 = 0);
~Machine();
const Names& get_N() { return N; }
@@ -92,7 +94,11 @@ class Machine : public BaseMachine
DataPositions run_tape(int thread_number, int tape_number, int arg,
const DataPositions& pos);
DataPositions join_tape(int thread_number);
void run();
void run(const string& progname);
void run_step(const string& progname);
pair<DataPositions, NamedCommStats> stop_threads();
string memory_filename();
@@ -102,6 +108,9 @@ class Machine : public BaseMachine
void reqbl(int n);
typename sint::bit_type::mac_key_type get_bit_mac_key() { return alphabi; }
typename sint::mac_key_type get_sint_mac_key() { return alphapi; }
Player& get_player() { return *P; }
};
#endif /* MACHINE_H_ */

View File

@@ -24,28 +24,52 @@
using namespace std;
template<class sint, class sgf2n>
Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
const string& progname_str, const string& memtype,
int lg2, bool direct,
int opening_sum, bool receive_threads, int max_broadcast,
bool use_encryption, bool live_prep, OnlineOptions opts)
: my_number(my_number), N(playerNames),
direct(direct), opening_sum(opening_sum),
receive_threads(receive_threads), max_broadcast(max_broadcast),
use_encryption(use_encryption), live_prep(live_prep), opts(opts)
void Machine<sint, sgf2n>::init_binary_domains(int security_parameter, int lg2)
{
sgf2n::clear::init_field(lg2);
if (not is_same<typename sgf2n::mac_key_type, GC::NoValue>())
{
if (sgf2n::clear::degree() < security_parameter)
{
cerr << "Security parameter needs to be at most n in GF(2^n)."
<< endl;
cerr << "Increase the latter (-lg2) or decrease the former (-S)."
<< endl;
exit(1);
}
}
if (not is_same<typename sint::bit_type::mac_key_type, GC::NoValue>())
{
sint::bit_type::mac_key_type::init_minimum(security_parameter);
}
else
{
// Initialize field for CCD
sint::bit_type::part_type::open_type::init_field();
}
}
template<class sint, class sgf2n>
Machine<sint, sgf2n>::Machine(Names& playerNames, bool use_encryption,
const OnlineOptions opts, int lg2)
: my_number(playerNames.my_num()), N(playerNames),
direct(opts.direct), opening_sum(opts.opening_sum),
receive_threads(opts.receive_threads), max_broadcast(opts.max_broadcast),
use_encryption(use_encryption), live_prep(opts.live_prep), opts(opts)
{
OnlineOptions::singleton = opts;
if (opening_sum < 2)
this->opening_sum = N.num_players();
if (max_broadcast < 2)
this->max_broadcast = N.num_players();
// Set up the fields
sgf2n::clear::init_field(lg2);
sint::clear::read_or_generate_setup(prep_dir_prefix<sint>(), opts);
sint::bit_type::mac_key_type::init_field();
// Initialize gf2n_short for CCD
sint::bit_type::part_type::open_type::init_field();
init_binary_domains(opts.security_parameter, lg2);
// make directory for outputs if necessary
mkdir_p(PREP_DIR);
@@ -75,6 +99,7 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
sint::clear::next::template init<typename sint::clear>(false);
// Initialize the global memory
auto memtype = opts.memtype;
if (memtype.compare("old")==0)
{
ifstream inpf;
@@ -92,9 +117,18 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
{ cerr << "Invalid memory argument" << endl;
exit(1);
}
}
template<class sint, class sgf2n>
void Machine<sint, sgf2n>::prepare(const string& progname_str)
{
int old_n_threads = nthreads;
progs.clear();
load_schedule(progname_str);
// keep preprocessing
nthreads = max(old_n_threads, nthreads);
// initialize persistence if necessary
for (auto& prog : progs)
{
@@ -122,7 +156,7 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
if (live_prep
and (sint::needs_ot or sgf2n::needs_ot or sint::bit_type::needs_ot))
{
for (int i = 0; i < nthreads; i++)
for (int i = old_n_threads; i < nthreads; i++)
ot_setups.push_back({ *P, true });
}
@@ -132,7 +166,7 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
queues.resize(nthreads);
join_timer.resize(nthreads);
for (int i=0; i<nthreads; i++)
for (int i = old_n_threads; i < nthreads; i++)
{
queues[i] = new ThreadQueue;
// stand-in for initialization
@@ -146,7 +180,7 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
}
// synchronize with clients before starting timer
for (int i=0; i<nthreads; i++)
for (int i=old_n_threads; i<nthreads; i++)
{
queues[i]->result();
}
@@ -155,6 +189,9 @@ Machine<sint, sgf2n>::Machine(int my_number, Names& playerNames,
template<class sint, class sgf2n>
Machine<sint, sgf2n>::~Machine()
{
sint::LivePrep::teardown();
sgf2n::LivePrep::teardown();
delete P;
for (auto& queue : queues)
delete queue;
@@ -308,14 +345,12 @@ DataPositions Machine<sint, sgf2n>::run_tape(int thread_number, int tape_number,
//printf("Running line %d\n",exec);
if (progs[tape_number].usage_unknown())
{
#ifndef INSECURE
if (not opts.live_prep and thread_number != 0)
{
cerr << "Internally called tape " << tape_number <<
" has unknown offline data usage" << endl;
throw invalid_program();
insecure(
"Internally called tape " + to_string(tape_number)
+ " has unknown offline data usage");
}
#endif
return DataPositions(N.num_players());
}
else
@@ -336,23 +371,20 @@ DataPositions Machine<sint, sgf2n>::join_tape(int i)
}
template<class sint, class sgf2n>
void Machine<sint, sgf2n>::run()
void Machine<sint, sgf2n>::run_step(const string& progname)
{
Timer proc_timer(CLOCK_PROCESS_CPUTIME_ID);
proc_timer.start();
timer[0].start({});
// run main tape
prepare(progname);
run_tape(0, 0, 0, N.num_players());
join_tape(0);
}
print_compiler();
finish_timer.start();
template<class sint, class sgf2n>
pair<DataPositions, NamedCommStats> Machine<sint, sgf2n>::stop_threads()
{
// Tell all C-threads to stop
for (int i=0; i<nthreads; i++)
{
//printf("Send kill signal to client\n");
//printf("Send kill signal to client\n");
queues[i]->schedule(-1);
}
@@ -369,6 +401,40 @@ void Machine<sint, sgf2n>::run()
pos.increase(queues[i]->result().pos);
pthread_join(threads[i],NULL);
}
auto comm_stats = total_comm();
for (auto& queue : queues)
delete queue;
queues.clear();
nthreads = 0;
return {pos, comm_stats};
}
template<class sint, class sgf2n>
void Machine<sint, sgf2n>::run(const string& progname)
{
prepare(progname);
Timer proc_timer(CLOCK_PROCESS_CPUTIME_ID);
proc_timer.start();
timer[0].start({});
// run main tape
run_tape(0, 0, 0, N.num_players());
join_tape(0);
print_compiler();
finish_timer.start();
// actual usage
auto res = stop_threads();
DataPositions& pos = res.first;
finish_timer.stop();
#ifdef VERBOSE
@@ -387,7 +453,7 @@ void Machine<sint, sgf2n>::run()
cerr << "Finish timer: " << finish_timer.elapsed() << endl;
#endif
NamedCommStats comm_stats = total_comm();
NamedCommStats& comm_stats = res.second;
if (opts.verbose)
{
@@ -475,17 +541,12 @@ void Machine<sint, sgf2n>::run()
stats.print();
}
#ifndef INSECURE
if (not opts.file_prep_per_thread)
{
Data_Files<sint, sgf2n> df(*this);
df.seekg(pos);
df.prune();
}
#endif
sint::LivePrep::teardown();
sgf2n::LivePrep::teardown();
suggest_optimizations();

View File

@@ -37,13 +37,16 @@ template<class T, class U>
int OfflineMachine<W>::run()
{
T::clear::init_default(this->online_opts.prime_length());
U::clear::init_field(U::clear::default_degree());
T::bit_type::mac_key_type::init_field();
Machine<T, U>::init_binary_domains(this->online_opts.security_parameter,
this->lg2);
auto binary_mac_key = read_generate_write_mac_key<
typename T::bit_type::part_type>(P);
typename T::bit_type::LivePrep bit_prep(usage);
GC::ShareThread<typename T::bit_type> thread(bit_prep, P, binary_mac_key);
// setup before generation to fix prime
T::LivePrep::basic_setup(P);
generate<T>();
generate<typename T::bit_type::part_type>();
generate<U>();

View File

@@ -100,6 +100,9 @@ void thread_info<sint, sgf2n>::Sub_Main_Func()
processor = new Processor<sint, sgf2n>(tinfo->thread_num,P,*MC2,*MCp,machine,progs.at(thread_num > 0));
auto& Proc = *processor;
// don't count communication for initialization
P.reset_stats();
bool flag=true;
int program=-3;
// int exec=0;
@@ -287,10 +290,8 @@ void thread_info<sint, sgf2n>::Sub_Main_Func()
// final check
Proc.check();
#ifndef INSECURE
if (machine.opts.file_prep_per_thread)
Proc.DataF.prune();
#endif
wait_timer.start();
queues->next();

View File

@@ -17,11 +17,11 @@ protected:
const char** argv;
OnlineOptions& online_opts;
int lg2, opening_sum, max_broadcast;
int lg2;
Names playerNames;
bool use_encryption, receive_threads;
bool use_encryption;
ez::ezOptionParser& opt;

View File

@@ -18,7 +18,7 @@ template<class T, class U>
int spdz_main(int argc, const char** argv, ez::ezOptionParser& opt, bool live_prep_default = true)
{
OnlineOptions& online_opts = OnlineOptions::singleton;
online_opts = {opt, argc, argv, 1000, live_prep_default, T::clear::invertible};
online_opts = {opt, argc, argv, T(), live_prep_default};
DishonestMajorityMachine machine(argc, argv, opt, online_opts, typename U::clear());
return machine.run<T, U>();
@@ -28,8 +28,7 @@ template<class V>
OnlineMachine::OnlineMachine(int argc, const char** argv, ez::ezOptionParser& opt,
OnlineOptions& online_opts, int nplayers, V) :
argc(argc), argv(argv), online_opts(online_opts), lg2(0),
opening_sum(0), max_broadcast(0),
use_encryption(false), receive_threads(false),
use_encryption(false),
opt(opt), nplayers(nplayers)
{
opt.add(
@@ -125,33 +124,6 @@ DishonestMajorityMachine::DishonestMajorityMachine(int argc, const char** argv,
opt.example = string() + argv[0] + " -p 0 -N 2 sample-prog\n" + argv[0]
+ " -h localhost -p 1 -N 2 sample-prog\n";
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Sum at most n shares at once when using indirect communication", // Help description.
"-s", // Flag token.
"--opening-sum" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use player-specific threads for communication", // Help description.
"-t", // Flag token.
"--threads" // Flag token.
);
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Maximum number of parties to send to at once", // Help description.
"-mb", // Flag token.
"--max-broadcast" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
@@ -163,11 +135,7 @@ DishonestMajorityMachine::DishonestMajorityMachine(int argc, const char** argv,
);
online_opts.finalize(opt, argc, argv);
opt.get("--opening-sum")->getInt(opening_sum);
opt.get("--max-broadcast")->getInt(max_broadcast);
use_encryption = opt.isSet("--encrypted");
receive_threads = opt.isSet("--threads");
start_networking();
}
@@ -230,12 +198,8 @@ int OnlineMachine::run()
try
#endif
{
Machine<T, U>(online_opts.playerno, playerNames, online_opts.progname,
online_opts.memtype, lg2,
online_opts.direct, opening_sum,
receive_threads, max_broadcast,
use_encryption, online_opts.live_prep,
online_opts).run();
Machine<T, U>(playerNames, use_encryption, online_opts, lg2).run(
online_opts.progname);
if (online_opts.verbose)
{

View File

@@ -8,6 +8,7 @@
#include "Math/gfp.h"
#include "Math/gfpvar.h"
#include "Protocols/HemiOptions.h"
#include "Protocols/config.h"
#include "Math/gfp.hpp"
@@ -26,10 +27,14 @@ OnlineOptions::OnlineOptions() : playerno(-1)
bits_from_squares = false;
direct = false;
bucket_size = 4;
security_parameter = DEFAULT_SECURITY;
cmd_private_input_file = "Player-Data/Input";
cmd_private_output_file = "";
file_prep_per_thread = false;
trunc_error = 40;
trunc_error = DEFAULT_SECURITY;
opening_sum = 0;
max_broadcast = 0;
receive_threads = false;
#ifdef VERBOSE
verbose = true;
#else
@@ -38,7 +43,7 @@ OnlineOptions::OnlineOptions() : playerno(-1)
}
OnlineOptions::OnlineOptions(ez::ezOptionParser& opt, int argc,
const char** argv, false_type) :
const char** argv, bool security) :
OnlineOptions()
{
opt.syntax = std::string(argv[0]) + " [OPTIONS] [<playerno>] <progname>";
@@ -104,6 +109,18 @@ OnlineOptions::OnlineOptions(ez::ezOptionParser& opt, int argc,
"--bucket-size" // Flag token.
);
if (security)
opt.add(
to_string(security_parameter).c_str(), // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
("Security parameter (default: " + to_string(security_parameter)
+ ")").c_str(), // Help description.
"-S", // Flag token.
"--security" // Flag token.
);
opt.parse(argc, argv);
interactive = opt.isSet("-I");
@@ -117,13 +134,24 @@ OnlineOptions::OnlineOptions(ez::ezOptionParser& opt, int argc,
verbose = opt.isSet("--verbose");
#endif
if (security)
{
opt.get("-S")->getInt(security_parameter);
cerr << "Using security parameter " << security_parameter << endl;
if (security_parameter <= 0)
{
cerr << "Invalid security parameter: " << security_parameter << endl;
exit(1);
}
}
opt.resetArgs();
}
OnlineOptions::OnlineOptions(ez::ezOptionParser& opt, int argc,
const char** argv, int default_batch_size, bool default_live_prep,
bool variable_prime_length) :
OnlineOptions(opt, argc, argv, false_type())
bool variable_prime_length, bool security) :
OnlineOptions(opt, argc, argv, security)
{
if (default_batch_size <= 0)
default_batch_size = batch_size;
@@ -263,6 +291,9 @@ void OnlineOptions::finalize(ez::ezOptionParser& opt, int argc,
vector<string> badOptions;
unsigned int i;
opt.footer += "\nSee also https://mp-spdz.readthedocs.io/en/latest/networking.html "
"for documentation on the networking setup.\n";
if (allArgs.size() != 3u - opt.isSet("-p"))
{
cerr << "ERROR: incorrect number of arguments to " << argv[0] << endl;
@@ -329,6 +360,16 @@ void OnlineOptions::finalize(ez::ezOptionParser& opt, int argc,
}
set_trunc_error(opt);
auto o = opt.get("--opening-sum");
if (o)
o->getInt(opening_sum);
o = opt.get("--max-broadcast");
if (o)
o->getInt(max_broadcast);
receive_threads = opt.isSet("--threads");
}
void OnlineOptions::set_trunc_error(ez::ezOptionParser& opt)

View File

@@ -26,21 +26,26 @@ public:
bool bits_from_squares;
bool direct;
int bucket_size;
int security_parameter;
std::string cmd_private_input_file;
std::string cmd_private_output_file;
bool verbose;
bool file_prep_per_thread;
int trunc_error;
int opening_sum, max_broadcast;
bool receive_threads;
OnlineOptions();
OnlineOptions(ez::ezOptionParser& opt, int argc, const char** argv,
false_type);
bool security);
OnlineOptions(ez::ezOptionParser& opt, int argc, const char** argv,
int default_batch_size = 0, bool default_live_prep = true,
bool variable_prime_length = false);
bool variable_prime_length = false, bool security = true);
template<class T>
OnlineOptions(ez::ezOptionParser& opt, int argc, const char** argv, T,
bool default_live_prep = true);
template<class T>
OnlineOptions(T);
~OnlineOptions() {}
void finalize(ez::ezOptionParser& opt, int argc, const char** argv);

View File

@@ -20,11 +20,49 @@ OnlineOptions::OnlineOptions(ez::ezOptionParser& opt, int argc,
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Probabilistic truncation error "
"(2^-x, default: 40)", // Help description.
("Probabilistic truncation error (2^-x, default: "
+ to_string(trunc_error) + ")").c_str(), // Help description.
"-E", // Flag token.
"--trunc-error" // Flag token.
);
if (T::dishonest_majority)
{
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Sum at most n shares at once when using indirect communication", // Help description.
"-s", // Flag token.
"--opening-sum" // Flag token.
);
opt.add(
"", // Default.
0, // Required?
0, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Use player-specific threads for communication", // Help description.
"-t", // Flag token.
"--threads" // Flag token.
);
opt.add(
"0", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Maximum number of parties to send to at once", // Help description.
"-mb", // Flag token.
"--max-broadcast" // Flag token.
);
}
}
template<class T>
OnlineOptions::OnlineOptions(T) : OnlineOptions()
{
if (T::dishonest_majority)
batch_size = 1000;
}
#endif /* PROCESSOR_ONLINEOPTIONS_HPP_ */

View File

@@ -21,7 +21,7 @@ class Program
unsigned max_reg[MAX_REG_TYPE];
// Memory size used directly
unsigned max_mem[MAX_REG_TYPE];
size_t max_mem[MAX_REG_TYPE];
// True if program contains variable-sized loop
bool unknown_usage;
@@ -48,7 +48,7 @@ class Program
unsigned num_reg(RegType reg_type) const
{ return max_reg[reg_type]; }
unsigned direct_mem(RegType reg_type) const
size_t direct_mem(RegType reg_type) const
{ return max_mem[reg_type]; }
friend ostream& operator<<(ostream& s,const Program& P);

View File

@@ -65,7 +65,7 @@ HonestMajorityRingMachineWithSecurity<U, V>::HonestMajorityRingMachineWithSecuri
int argc, const char** argv, ez::ezOptionParser& opt)
{
OnlineOptions online_opts(opt, argc, argv);
RingOptions opts(opt, argc, argv, true);
RingOptions opts(opt, argc, argv);
HonestMajorityMachine machine(argc, argv, opt, online_opts);
int R = opts.ring_size_from_opts_or_schedule(online_opts.progname);
switch (R)
@@ -76,15 +76,19 @@ HonestMajorityRingMachineWithSecurity<U, V>::HonestMajorityRingMachineWithSecuri
break;
#define X(K) \
case K: \
switch (opts.S) \
{ \
int S = online_opts.security_parameter; \
switch (S) \
{ \
Y(K, 40) \
Y(K, DEFAULT_SECURITY) \
default: \
cerr << "not compiled for security parameter " << to_string(opts.S) << endl; \
cerr << "add 'Y(K, " << opts.S << ")' to " __FILE__ ", line 76" << endl; \
cerr << "not compiled for security parameter " << to_string(S) << endl; \
cerr << "add 'Y(K, " << S << ")' to " __FILE__ ", line 76" << endl; \
cerr << "or compile with -DDEFAULT_SECURITY=" << S << endl; \
exit(1); \
} \
break;
break; \
}
X(64)
#ifdef RING_SIZE
X(RING_SIZE)

View File

@@ -9,8 +9,7 @@
#include <iostream>
using namespace std;
RingOptions::RingOptions(ez::ezOptionParser& opt, int argc, const char** argv,
bool security)
RingOptions::RingOptions(ez::ezOptionParser& opt, int argc, const char** argv)
{
opt.add(
"64", // Default.
@@ -21,28 +20,12 @@ RingOptions::RingOptions(ez::ezOptionParser& opt, int argc, const char** argv,
"-R", // Flag token.
"--ring" // Flag token.
);
if (security)
opt.add(
"40", // Default.
0, // Required?
1, // Number of args expected.
0, // Delimiter if expecting multiple args.
"Security parameter (default: 40)", // Help description.
"-S", // Flag token.
"--security" // Flag token.
);
opt.parse(argc, argv);
opt.get("-R")->getInt(R);
if (security)
opt.get("-S")->getInt(S);
else
S = -1;
R_is_set = opt.isSet("-R");
opt.resetArgs();
if (R_is_set)
cerr << "Trying to run " << R << "-bit computation" << endl;
if (security)
cerr << "Using security parameter " << S << endl;
}
int RingOptions::ring_size_from_opts_or_schedule(string progname)

View File

@@ -16,10 +16,8 @@ class RingOptions
public:
int R;
int S;
RingOptions(ez::ezOptionParser& opt, int argc, const char** argv,
bool security = false);
RingOptions(ez::ezOptionParser& opt, int argc, const char** argv);
int ring_size_from_opts_or_schedule(string progname);
};

View File

@@ -203,7 +203,7 @@
*dest++ = *op1++ == *op2++) \
X(PRINTINT, Proc.out << Proc.read_Ci(r[0]) << flush,) \
X(PRINTFLOATPREC, Proc.out << setprecision(n),) \
X(PRINTSTR, Proc.out << string((char*)&n,sizeof(n)) << flush,) \
X(PRINTSTR, Proc.out << string((char*)&n,4) << flush,) \
X(PRINTCHR, Proc.out << string((char*)&n,1) << flush,) \
X(SHUFFLE, shuffle(Proc),) \
X(BITDECINT, bitdecint(Proc),) \
@@ -270,7 +270,7 @@
*dest++ = *op1++ >> n) \
X(GPRINTREG, auto source = &C2[r[0]], \
Proc.out << "Reg[" << r[0] << "] = " << *source++ \
<< " # " << string((char*)&n,sizeof(n)) << endl) \
<< " # " << string((char*)&n, 4) << endl) \
X(GPRINTREGPLAIN, auto source = &C2[r[0]], \
Proc.out << *source++ << flush) \
X(GBITDEC, gbitdec(C2),) \