mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-01-09 13:37:58 -05:00
Maintenance.
This commit is contained in:
@@ -24,11 +24,4 @@ AtlasShare::AtlasShare(const AtlasSecret& other) :
|
||||
{
|
||||
}
|
||||
|
||||
void AtlasShare::random()
|
||||
{
|
||||
AtlasSecret tmp;
|
||||
this->get_party().DataF.get_one(DATA_BIT, tmp);
|
||||
*this = tmp.get_reg(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,8 +63,6 @@ public:
|
||||
{
|
||||
*this = input;
|
||||
}
|
||||
|
||||
void random();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
10
GC/CcdPrep.h
10
GC/CcdPrep.h
@@ -20,17 +20,17 @@ class CcdPrep : public BufferPrep<T>
|
||||
{
|
||||
typename T::part_type::LivePrep part_prep;
|
||||
SubProcessor<typename T::part_type>* part_proc;
|
||||
ShareThread<T>& thread;
|
||||
|
||||
public:
|
||||
CcdPrep(DataPositions& usage, ShareThread<T>& thread) :
|
||||
BufferPrep<T>(usage), part_prep(usage, thread), part_proc(0),
|
||||
thread(thread)
|
||||
static const bool use_part = true;
|
||||
|
||||
CcdPrep(DataPositions& usage) :
|
||||
BufferPrep<T>(usage), part_prep(usage), part_proc(0)
|
||||
{
|
||||
}
|
||||
|
||||
CcdPrep(SubProcessor<T>*, DataPositions& usage) :
|
||||
CcdPrep(usage, ShareThread<T>::s())
|
||||
CcdPrep(usage)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ CcdPrep<T>::~CcdPrep()
|
||||
template<class T>
|
||||
void CcdPrep<T>::set_protocol(typename T::Protocol& protocol)
|
||||
{
|
||||
auto& thread = ShareThread<T>::s();
|
||||
assert(thread.MC);
|
||||
part_proc = new SubProcessor<typename T::part_type>(
|
||||
thread.MC->get_part_MC(), part_prep, protocol.get_part().P);
|
||||
|
||||
@@ -74,13 +74,6 @@ public:
|
||||
*this = input;
|
||||
}
|
||||
|
||||
void random()
|
||||
{
|
||||
CcdSecret<T> tmp;
|
||||
ShareThread<CcdSecret<T>>::s().DataF.get_one(DATA_BIT, tmp);
|
||||
*this = tmp.get_reg(0);
|
||||
}
|
||||
|
||||
This& operator^=(const This& other)
|
||||
{
|
||||
*this += other;
|
||||
|
||||
@@ -136,6 +136,8 @@ public:
|
||||
void andrs(int n, const FakeSecret& x, const FakeSecret& y)
|
||||
{ *this = BitVec(x.a * (y.a & 1)).mask(n); }
|
||||
|
||||
void xor_bit(int i, FakeSecret bit) { *this ^= bit << i; }
|
||||
|
||||
void invert(int n, const FakeSecret& x) { *this = BitVec(~x.a).mask(n); }
|
||||
|
||||
void random_bit() { a = random() % 2; }
|
||||
|
||||
@@ -79,13 +79,6 @@ public:
|
||||
*this = input;
|
||||
}
|
||||
|
||||
void random()
|
||||
{
|
||||
MaliciousCcdSecret<T> tmp;
|
||||
ShareThread<MaliciousCcdSecret<T>>::s().DataF.get_one(DATA_BIT, tmp);
|
||||
*this = tmp.get_reg(0);
|
||||
}
|
||||
|
||||
This& operator^=(const This& other)
|
||||
{
|
||||
*this += other;
|
||||
|
||||
13
GC/NoShare.h
13
GC/NoShare.h
@@ -7,12 +7,12 @@
|
||||
#define GC_NOSHARE_H_
|
||||
|
||||
#include "Processor/DummyProtocol.h"
|
||||
#include "BMR/Register.h"
|
||||
#include "Tools/SwitchableOutput.h"
|
||||
#include "Protocols/ShareInterface.h"
|
||||
|
||||
class InputArgs;
|
||||
class ArithmeticProcessor;
|
||||
class BlackHole;
|
||||
class SwitchableOutput;
|
||||
|
||||
namespace GC
|
||||
{
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
typedef NoShare small_type;
|
||||
|
||||
typedef BlackHole out_type;
|
||||
typedef SwitchableOutput out_type;
|
||||
|
||||
static const bool is_real = false;
|
||||
|
||||
@@ -124,6 +124,11 @@ public:
|
||||
return "no";
|
||||
}
|
||||
|
||||
static void specification(octetStream&)
|
||||
{
|
||||
fail();
|
||||
}
|
||||
|
||||
static int size()
|
||||
{
|
||||
return 0;
|
||||
@@ -172,6 +177,8 @@ public:
|
||||
|
||||
NoShare get_bit(int) const { fail(); return {}; }
|
||||
|
||||
void xor_bit(int, NoShare) const { fail(); }
|
||||
|
||||
void invert(int, NoShare) { fail(); }
|
||||
|
||||
NoShare mask(int) const { fail(); return {}; }
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
static int check_args(const vector<int>& args, int n);
|
||||
|
||||
template<class U>
|
||||
static void check_input(const U& in, int n_bits);
|
||||
static void check_input(const U& in, const int* params);
|
||||
|
||||
Machine<T>* machine;
|
||||
Memories<T>& memories;
|
||||
|
||||
@@ -89,15 +89,15 @@ U GC::Processor<T>::get_long_input(const int* params,
|
||||
else
|
||||
res = input_proc.get_input<FixInput_<U>>(interactive,
|
||||
¶ms[1]).items[0];
|
||||
int n_bits = *params;
|
||||
check_input(res, n_bits);
|
||||
check_input(res, params);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class U>
|
||||
void GC::Processor<T>::check_input(const U& in, int n_bits)
|
||||
void GC::Processor<T>::check_input(const U& in, const int* params)
|
||||
{
|
||||
int n_bits = *params;
|
||||
auto test = in >> (n_bits - 1);
|
||||
if (n_bits == 1)
|
||||
{
|
||||
@@ -106,9 +106,17 @@ void GC::Processor<T>::check_input(const U& in, int n_bits)
|
||||
}
|
||||
else if (not (test == 0 or test == -1))
|
||||
{
|
||||
throw runtime_error(
|
||||
"input too large for a " + std::to_string(n_bits)
|
||||
+ "-bit signed integer: " + to_string(in));
|
||||
if (params[1] == 0)
|
||||
throw runtime_error(
|
||||
"input out of range for a " + std::to_string(n_bits)
|
||||
+ "-bit signed integer: " + to_string(in));
|
||||
else
|
||||
throw runtime_error(
|
||||
"input out of range for a " + to_string(n_bits)
|
||||
+ "-bit fixed-point number with "
|
||||
+ to_string(params[1]) + "-bit precision: "
|
||||
+ to_string(
|
||||
mpf_class(bigint(in)) * exp2(-params[1])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ class RepPrep : public PersonalPrep<T>, ShiftableTripleBuffer<T>
|
||||
ReplicatedBase* protocol;
|
||||
|
||||
public:
|
||||
RepPrep(DataPositions& usage, ShareThread<T>& thread);
|
||||
RepPrep(DataPositions& usage, int input_player = PersonalPrep<T>::SECURE);
|
||||
~RepPrep();
|
||||
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
namespace GC
|
||||
{
|
||||
|
||||
template<class T>
|
||||
RepPrep<T>::RepPrep(DataPositions& usage, ShareThread<T>& thread) :
|
||||
RepPrep<T>(usage)
|
||||
{
|
||||
(void) thread;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
RepPrep<T>::RepPrep(DataPositions& usage, int input_player) :
|
||||
PersonalPrep<T>(usage, input_player), protocol(0)
|
||||
|
||||
@@ -31,6 +31,11 @@ public:
|
||||
{
|
||||
tainted = true;
|
||||
}
|
||||
|
||||
bool is_tainted()
|
||||
{
|
||||
return tainted;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace GC */
|
||||
|
||||
@@ -84,7 +84,6 @@ public:
|
||||
template <class U>
|
||||
static void store_clear_in_dynamic(U& mem, const vector<ClearWriteAccess>& accesses)
|
||||
{ T::store_clear_in_dynamic(mem, accesses); }
|
||||
static void output(T& reg);
|
||||
|
||||
template<class U, class V>
|
||||
static void load(vector< ReadAccess<V> >& accesses, const U& mem);
|
||||
@@ -113,7 +112,7 @@ public:
|
||||
{ T::inputbvec(processor, input_proc, args); }
|
||||
template<class U>
|
||||
static void reveal_inst(Processor<U>& processor, const vector<int>& args)
|
||||
{ processor.reveal(args); }
|
||||
{ T::reveal_inst(processor, args); }
|
||||
|
||||
template<class U>
|
||||
static void trans(Processor<U>& processor, int n_inputs, const vector<int>& args);
|
||||
@@ -148,7 +147,6 @@ public:
|
||||
}
|
||||
void invert(int n, const Secret<T>& x);
|
||||
void and_(int n, const Secret<T>& x, const Secret<T>& y, bool repeat);
|
||||
void andrs(int n, const Secret<T>& x, const Secret<T>& y) { and_(n, x, y, true); }
|
||||
|
||||
template <class U>
|
||||
void reveal(size_t n_bits, U& x);
|
||||
|
||||
@@ -119,12 +119,6 @@ void Secret<T>::store(U& mem,
|
||||
T::store(mem, accesses);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Secret<T>::output(T& reg)
|
||||
{
|
||||
reg.output();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Secret<T>::Secret()
|
||||
{
|
||||
|
||||
@@ -15,10 +15,6 @@ namespace GC
|
||||
class SemiHonestRepPrep : public RepPrep<SemiHonestRepSecret>
|
||||
{
|
||||
public:
|
||||
SemiHonestRepPrep(DataPositions& usage, ShareThread<SemiHonestRepSecret>&) :
|
||||
RepPrep<SemiHonestRepSecret>(usage)
|
||||
{
|
||||
}
|
||||
SemiHonestRepPrep(DataPositions& usage, bool = false) :
|
||||
RepPrep<SemiHonestRepSecret>(usage)
|
||||
{
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
namespace GC
|
||||
{
|
||||
|
||||
SemiPrep::SemiPrep(DataPositions& usage, ShareThread<SemiSecret>&) :
|
||||
SemiPrep(usage)
|
||||
{
|
||||
}
|
||||
|
||||
SemiPrep::SemiPrep(DataPositions& usage, bool) :
|
||||
BufferPrep<SemiSecret>(usage), triple_generator(0)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ class SemiPrep : public BufferPrep<SemiSecret>, ShiftableTripleBuffer<SemiSecret
|
||||
SeededPRNG secure_prng;
|
||||
|
||||
public:
|
||||
SemiPrep(DataPositions& usage, ShareThread<SemiSecret>& thread);
|
||||
SemiPrep(DataPositions& usage, bool = true);
|
||||
~SemiPrep();
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ public:
|
||||
void xor_(int n, const SemiSecret& x, const SemiSecret& y)
|
||||
{ *this = BitVec(x ^ y).mask(n); }
|
||||
|
||||
void xor_bit(int i, const SemiSecret& bit)
|
||||
{ *this ^= bit << i; }
|
||||
|
||||
void reveal(size_t n_bits, Clear& x);
|
||||
|
||||
SemiSecret lsb()
|
||||
|
||||
@@ -161,6 +161,9 @@ public:
|
||||
|
||||
This get_bit(int i)
|
||||
{ return (*this >> i) & 1; }
|
||||
|
||||
void xor_bit(int i, const This& bit)
|
||||
{ *this ^= bit << i; }
|
||||
};
|
||||
|
||||
template<class U>
|
||||
|
||||
@@ -32,9 +32,9 @@ public:
|
||||
|
||||
Preprocessing<T>& DataF;
|
||||
|
||||
ShareThread(const Names& N, OnlineOptions& opts, DataPositions& usage);
|
||||
ShareThread(const Names& N, OnlineOptions& opts, Player& P,
|
||||
typename T::mac_key_type mac_key, DataPositions& usage);
|
||||
ShareThread(Preprocessing<T>& prep);
|
||||
ShareThread(Preprocessing<T>& prep, Player& P,
|
||||
typename T::mac_key_type mac_key);
|
||||
virtual ~ShareThread();
|
||||
|
||||
virtual typename T::MC* new_mc(typename T::mac_key_type mac_key)
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
DataPositions usage;
|
||||
|
||||
StandaloneShareThread(int i, ThreadMaster<T>& master);
|
||||
~StandaloneShareThread();
|
||||
|
||||
void pre_run();
|
||||
void post_run() { ShareThread<T>::post_run(); }
|
||||
|
||||
@@ -18,26 +18,28 @@ namespace GC
|
||||
|
||||
template<class T>
|
||||
StandaloneShareThread<T>::StandaloneShareThread(int i, ThreadMaster<T>& master) :
|
||||
ShareThread<T>(master.N, master.opts, usage), Thread<T>(i, master)
|
||||
ShareThread<T>(*Preprocessing<T>::get_new(master.opts.live_prep,
|
||||
master.N, usage)),
|
||||
Thread<T>(i, master)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ShareThread<T>::ShareThread(const Names& N, OnlineOptions& opts, DataPositions& usage) :
|
||||
P(0), MC(0), protocol(0), DataF(
|
||||
opts.live_prep ?
|
||||
*static_cast<Preprocessing<T>*>(new typename T::LivePrep(
|
||||
usage, *this)) :
|
||||
*static_cast<Preprocessing<T>*>(new BitPrepFiles<T>(N,
|
||||
get_prep_sub_dir<T>(PREP_DIR, N.num_players()),
|
||||
usage, BaseMachine::thread_num)))
|
||||
StandaloneShareThread<T>::~StandaloneShareThread()
|
||||
{
|
||||
delete &this->DataF;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ShareThread<T>::ShareThread(Preprocessing<T>& prep) :
|
||||
P(0), MC(0), protocol(0), DataF(prep)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ShareThread<T>::ShareThread(const Names& N, OnlineOptions& opts, Player& P,
|
||||
typename T::mac_key_type mac_key, DataPositions& usage) :
|
||||
ShareThread(N, opts, usage)
|
||||
ShareThread<T>::ShareThread(Preprocessing<T>& prep, Player& P,
|
||||
typename T::mac_key_type mac_key) :
|
||||
ShareThread(prep)
|
||||
{
|
||||
pre_run(P, mac_key);
|
||||
}
|
||||
@@ -45,7 +47,6 @@ ShareThread<T>::ShareThread(const Names& N, OnlineOptions& opts, Player& P,
|
||||
template<class T>
|
||||
ShareThread<T>::~ShareThread()
|
||||
{
|
||||
delete &DataF;
|
||||
if (MC)
|
||||
delete MC;
|
||||
if (protocol)
|
||||
@@ -76,12 +77,6 @@ void ShareThread<T>::post_run()
|
||||
{
|
||||
protocol->check();
|
||||
MC->Check(*this->P);
|
||||
#ifndef INSECURE
|
||||
#ifdef VERBOSE
|
||||
cerr << "Removing used pre-processed data" << endl;
|
||||
#endif
|
||||
DataF.prune();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
||||
@@ -58,10 +58,8 @@ void Thread<T>::run()
|
||||
P = new PlainPlayer(N, id);
|
||||
processor.open_input_file(N.my_num(), thread_num,
|
||||
master.opts.cmd_private_input_file);
|
||||
processor.out.activate(N.my_num() == 0 or master.opts.interactive);
|
||||
processor.setup_redirection(P->my_num(), thread_num, master.opts);
|
||||
if (processor.stdout_redirect_file.is_open())
|
||||
processor.out.redirect_to_file(processor.stdout_redirect_file);
|
||||
processor.setup_redirection(P->my_num(), thread_num, master.opts,
|
||||
processor.out);
|
||||
|
||||
done.push(0);
|
||||
pre_run();
|
||||
|
||||
@@ -58,6 +58,16 @@ Thread<T>* ThreadMaster<T>::new_thread(int i)
|
||||
template<class T>
|
||||
void ThreadMaster<T>::run()
|
||||
{
|
||||
#ifndef INSECURE
|
||||
if (not opts.live_prep)
|
||||
{
|
||||
cerr
|
||||
<< "Preprocessing from file not supported by binary virtual machines"
|
||||
<< endl;
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
P = new PlainPlayer(N, "main");
|
||||
|
||||
machine.load_schedule(progname);
|
||||
|
||||
@@ -106,11 +106,6 @@ public:
|
||||
party.MC->get_alphai());
|
||||
}
|
||||
|
||||
void random()
|
||||
{
|
||||
*this = get_party().DataF.get_part().get_bit();
|
||||
}
|
||||
|
||||
This lsb() const
|
||||
{
|
||||
return *this;
|
||||
|
||||
@@ -25,7 +25,6 @@ class TinierSharePrep : public PersonalPrep<T>
|
||||
MascotParams params;
|
||||
|
||||
typedef typename T::whole_type secret_type;
|
||||
ShareThread<secret_type>& thread;
|
||||
|
||||
void buffer_triples();
|
||||
void buffer_squares() { throw not_implemented(); }
|
||||
@@ -39,8 +38,6 @@ class TinierSharePrep : public PersonalPrep<T>
|
||||
void init_real(Player& P);
|
||||
|
||||
public:
|
||||
TinierSharePrep(DataPositions& usage, ShareThread<secret_type>& thread,
|
||||
int input_player = PersonalPrep<T>::SECURE);
|
||||
TinierSharePrep(DataPositions& usage, int input_player =
|
||||
PersonalPrep<T>::SECURE);
|
||||
TinierSharePrep(SubProcessor<T>*, DataPositions& usage);
|
||||
|
||||
@@ -15,16 +15,8 @@ namespace GC
|
||||
|
||||
template<class T>
|
||||
TinierSharePrep<T>::TinierSharePrep(DataPositions& usage, int input_player) :
|
||||
TinierSharePrep<T>(usage, ShareThread<secret_type>::s(), input_player)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
TinierSharePrep<T>::TinierSharePrep(DataPositions& usage,
|
||||
ShareThread<secret_type>& thread, int input_player) :
|
||||
PersonalPrep<T>(usage, input_player), triple_generator(0),
|
||||
real_triple_generator(0),
|
||||
thread(thread)
|
||||
real_triple_generator(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -87,6 +79,7 @@ void TinierSharePrep<T>::buffer_inputs(int player)
|
||||
template<class T>
|
||||
void GC::TinierSharePrep<T>::buffer_bits()
|
||||
{
|
||||
auto& thread = ShareThread<secret_type>::s();
|
||||
this->bits.push_back(
|
||||
BufferPrep<T>::get_random_from_inputs(thread.P->num_players()));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ template<class T>
|
||||
void TinierSharePrep<T>::init_real(Player& P)
|
||||
{
|
||||
assert(real_triple_generator == 0);
|
||||
auto& thread = ShareThread<secret_type>::s();
|
||||
real_triple_generator = new typename T::whole_type::TripleGenerator(
|
||||
BaseMachine::s().fresh_ot_setup(), P.N, -1,
|
||||
OnlineOptions::singleton.batch_size, 1, params,
|
||||
@@ -24,6 +25,7 @@ void TinierSharePrep<T>::init_real(Player& P)
|
||||
template<class T>
|
||||
void TinierSharePrep<T>::buffer_secret_triples()
|
||||
{
|
||||
auto& thread = ShareThread<secret_type>::s();
|
||||
auto& triple_generator = real_triple_generator;
|
||||
assert(triple_generator != 0);
|
||||
params.generateBits = false;
|
||||
|
||||
@@ -58,6 +58,11 @@ public:
|
||||
return part_type::size() * default_length;
|
||||
}
|
||||
|
||||
static void specification(octetStream& os)
|
||||
{
|
||||
T::specification(os);
|
||||
}
|
||||
|
||||
static void read_or_generate_mac_key(string directory, const Player& P,
|
||||
mac_key_type& key)
|
||||
{
|
||||
@@ -150,6 +155,17 @@ public:
|
||||
return this->get_reg(i);
|
||||
}
|
||||
|
||||
void xor_bit(size_t i, const T& bit)
|
||||
{
|
||||
if (i < this->get_regs().size())
|
||||
XOR(this->get_reg(i), this->get_reg(i), bit);
|
||||
else
|
||||
{
|
||||
this->resize_regs(i + 1);
|
||||
this->get_reg(i) = bit;
|
||||
}
|
||||
}
|
||||
|
||||
void output(ostream& s, bool human = true) const
|
||||
{
|
||||
assert(this->get_regs().size() == default_length);
|
||||
@@ -179,6 +195,12 @@ public:
|
||||
{
|
||||
inputter.finalize(from, n_bits).mask(*this, n_bits);
|
||||
}
|
||||
|
||||
void random_bit()
|
||||
{
|
||||
auto& thread = GC::ShareThread<typename T::whole_type>::s();
|
||||
*this = thread.DataF.get_part().get_bit();
|
||||
}
|
||||
};
|
||||
|
||||
template<int S>
|
||||
|
||||
@@ -74,13 +74,6 @@ public:
|
||||
*this = super::constant(input, party.P->my_num(),
|
||||
party.MC->get_alphai());
|
||||
}
|
||||
|
||||
void random()
|
||||
{
|
||||
TinySecret<S> tmp;
|
||||
this->get_party().DataF.get_one(DATA_BIT, tmp);
|
||||
*this = tmp.get_reg(0);
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace GC */
|
||||
|
||||
Reference in New Issue
Block a user