mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-01-09 13:37:58 -05:00
Protocol in dealer model.
This commit is contained in:
@@ -40,7 +40,7 @@ public:
|
||||
return "CCD";
|
||||
}
|
||||
|
||||
static MAC_Check* new_mc(T)
|
||||
static MAC_Check* new_mc(typename super::mac_key_type)
|
||||
{
|
||||
return new MAC_Check;
|
||||
}
|
||||
|
||||
69
GC/DealerPrep.h
Normal file
69
GC/DealerPrep.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* DealerPrep.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GC_DEALERPREP_H_
|
||||
#define GC_DEALERPREP_H_
|
||||
|
||||
#include "Protocols/DealerPrep.h"
|
||||
#include "Protocols/ProtocolSet.h"
|
||||
#include "ShiftableTripleBuffer.h"
|
||||
#include "SemiSecret.h"
|
||||
|
||||
namespace GC
|
||||
{
|
||||
class DealerPrep : public BufferPrep<DealerSecret>, ShiftableTripleBuffer<DealerSecret>
|
||||
{
|
||||
Player* P;
|
||||
|
||||
public:
|
||||
DealerPrep(DataPositions& usage, int = -1) :
|
||||
BufferPrep<DealerSecret>(usage), P(0)
|
||||
{
|
||||
}
|
||||
|
||||
void set_protocol(DealerSecret::Protocol& protocol)
|
||||
{
|
||||
P = &protocol.P;
|
||||
}
|
||||
|
||||
void buffer_triples()
|
||||
{
|
||||
ProtocolSetup<DealerShare<BitVec>> setup(*P);
|
||||
ProtocolSet<DealerShare<BitVec>> set(*P, setup);
|
||||
for (int i = 0; i < OnlineOptions::singleton.batch_size; i++)
|
||||
{
|
||||
auto triple = set.preprocessing.get_triple(
|
||||
DealerSecret::default_length);
|
||||
this->triples.push_back({{triple[0], triple[1], triple[2]}});
|
||||
}
|
||||
}
|
||||
|
||||
void buffer_bits()
|
||||
{
|
||||
SeededPRNG G;
|
||||
if (P->my_num() != 0)
|
||||
for (int i = 0; i < OnlineOptions::singleton.batch_size; i++)
|
||||
this->bits.push_back(G.get_bit());
|
||||
else
|
||||
this->bits.resize(
|
||||
this->bits.size() + OnlineOptions::singleton.batch_size);
|
||||
}
|
||||
|
||||
void get(Dtype type, DealerSecret* data)
|
||||
{
|
||||
BufferPrep<DealerSecret>::get(type, data);
|
||||
}
|
||||
|
||||
array<DealerSecret, 3> get_triple_no_count(int n_bits)
|
||||
{
|
||||
if (n_bits == -1)
|
||||
n_bits = DealerSecret::default_length;
|
||||
return ShiftableTripleBuffer<DealerSecret>::get_triple_no_count(n_bits);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* GC_DEALERPREP_H_ */
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "GC/Memory.h"
|
||||
#include "GC/Access.h"
|
||||
#include "GC/ArgTuples.h"
|
||||
#include "GC/NoShare.h"
|
||||
|
||||
#include "Math/gf2nlong.h"
|
||||
#include "Tools/SwitchableOutput.h"
|
||||
@@ -40,7 +41,6 @@ public:
|
||||
typedef FakeSecret DynamicType;
|
||||
typedef Memory<FakeSecret> DynamicMemory;
|
||||
|
||||
typedef BitVec mac_key_type;
|
||||
typedef BitVec clear;
|
||||
typedef BitVec open_type;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
return "Malicious CCD";
|
||||
}
|
||||
|
||||
static MAC_Check* new_mc(T)
|
||||
static MAC_Check* new_mc(typename super::mac_key_type)
|
||||
{
|
||||
return new MAC_Check;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
typedef MaliciousRepMC<This> MC;
|
||||
typedef BitVec_<unsigned char> open_type;
|
||||
typedef open_type clear;
|
||||
typedef BitVec mac_key_type;
|
||||
typedef NoValue mac_key_type;
|
||||
|
||||
static MC* new_mc(mac_key_type)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
static const bool expensive_triples = true;
|
||||
|
||||
static MC* new_mc(BitVec)
|
||||
static MC* new_mc(typename super::mac_key_type)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
16
GC/NoShare.h
16
GC/NoShare.h
@@ -60,35 +60,43 @@ public:
|
||||
throw not_implemented();
|
||||
}
|
||||
|
||||
static void init_minimum(int)
|
||||
{
|
||||
}
|
||||
|
||||
static void fail()
|
||||
{
|
||||
throw runtime_error("VM does not support binary circuits");
|
||||
}
|
||||
|
||||
NoValue() {}
|
||||
NoValue(int) { fail(); }
|
||||
NoValue(bool) {}
|
||||
NoValue(ValueInterface) {}
|
||||
NoValue(int128) {}
|
||||
|
||||
void assign(const char*) { fail(); }
|
||||
|
||||
const char* get_ptr() const { return (char*) this; }
|
||||
|
||||
int get() const { fail(); return 0; }
|
||||
|
||||
int operator<<(int) const { fail(); return 0; }
|
||||
void operator+=(int) { fail(); }
|
||||
|
||||
bool operator!=(NoValue) const { fail(); return 0; }
|
||||
bool operator!=(NoValue) const { return false; }
|
||||
|
||||
bool operator==(int) { fail(); return false; }
|
||||
|
||||
bool get_bit(int) { fail(); return 0; }
|
||||
|
||||
void randomize(PRNG&) { fail(); }
|
||||
void randomize(PRNG&) {}
|
||||
|
||||
void invert() { fail(); }
|
||||
|
||||
void mask(int) { fail(); }
|
||||
|
||||
void input(istream&, bool) { fail(); }
|
||||
void output(ostream&, bool) { fail(); }
|
||||
void output(ostream&, bool) {}
|
||||
};
|
||||
|
||||
inline ostream& operator<<(ostream& o, NoValue)
|
||||
|
||||
@@ -340,7 +340,7 @@ void Processor<T>::convcbit2s(const BaseInstruction& instruction)
|
||||
for (int i = 0; i < DIV_CEIL(instruction.get_n(), unit); i++)
|
||||
S[instruction.get_r(0) + i] = T::constant(C[instruction.get_r(1) + i],
|
||||
share_thread.P->my_num(), share_thread.MC->get_alphai(),
|
||||
min(unsigned(unit), instruction.get_n() - i * unit));
|
||||
min(size_t(unit), instruction.get_n() - i * unit));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
106
GC/SemiSecret.h
106
GC/SemiSecret.h
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Protocols/SemiMC.h"
|
||||
#include "Protocols/SemiShare.h"
|
||||
#include "Protocols/DealerShare.h"
|
||||
#include "Processor/DummyProtocol.h"
|
||||
#include "ShareSecret.h"
|
||||
|
||||
@@ -17,71 +18,116 @@ namespace GC
|
||||
{
|
||||
|
||||
class SemiPrep;
|
||||
class DealerPrep;
|
||||
|
||||
class SemiSecret : public SemiShare<BitVec>, public ShareSecret<SemiSecret>
|
||||
template<class T, class V>
|
||||
class SemiSecretBase : public V, public ShareSecret<T>
|
||||
{
|
||||
typedef V super;
|
||||
|
||||
public:
|
||||
typedef Memory<SemiSecret> DynamicMemory;
|
||||
typedef Memory<T> DynamicMemory;
|
||||
|
||||
typedef SemiMC<SemiSecret> MC;
|
||||
typedef DirectSemiMC<SemiSecret> Direct_MC;
|
||||
typedef Beaver<SemiSecret> Protocol;
|
||||
typedef MC MAC_Check;
|
||||
typedef SemiPrep LivePrep;
|
||||
typedef SemiInput<SemiSecret> Input;
|
||||
typedef Beaver<T> Protocol;
|
||||
|
||||
typedef SemiSecret part_type;
|
||||
typedef SemiSecret small_type;
|
||||
typedef T part_type;
|
||||
typedef T small_type;
|
||||
|
||||
static const int default_length = sizeof(BitVec) * 8;
|
||||
|
||||
static string type_string() { return "binary secret"; }
|
||||
static string phase_name() { return "Binary computation"; }
|
||||
|
||||
static MC* new_mc(mac_key_type);
|
||||
|
||||
template<class T>
|
||||
static void generate_mac_key(mac_key_type, T)
|
||||
{
|
||||
}
|
||||
|
||||
static void trans(Processor<SemiSecret>& processor, int n_outputs,
|
||||
static void trans(Processor<T>& processor, int n_outputs,
|
||||
const vector<int>& args);
|
||||
|
||||
SemiSecret()
|
||||
SemiSecretBase()
|
||||
{
|
||||
}
|
||||
SemiSecret(long other) :
|
||||
SemiShare<BitVec>(other)
|
||||
SemiSecretBase(long other) :
|
||||
V(other)
|
||||
{
|
||||
}
|
||||
SemiSecret(const IntBase& other) :
|
||||
SemiShare<BitVec>(other)
|
||||
template<class U>
|
||||
SemiSecretBase(const IntBase<U>& other) :
|
||||
V(other)
|
||||
{
|
||||
}
|
||||
template<int K>
|
||||
SemiSecret(const Z2<K>& other) :
|
||||
SemiShare<BitVec>(other)
|
||||
SemiSecretBase(const Z2<K>& other) :
|
||||
V(other)
|
||||
{
|
||||
}
|
||||
|
||||
void load_clear(int n, const Integer& x);
|
||||
|
||||
void bitcom(Memory<SemiSecret>& S, const vector<int>& regs);
|
||||
void bitdec(Memory<SemiSecret>& S, const vector<int>& regs) const;
|
||||
void bitcom(Memory<T>& S, const vector<int>& regs);
|
||||
void bitdec(Memory<T>& S, const vector<int>& regs) const;
|
||||
|
||||
void xor_(int n, const SemiSecret& x, const SemiSecret& y)
|
||||
void xor_(int n, const T& x, const T& y)
|
||||
{ *this = BitVec(x ^ y).mask(n); }
|
||||
|
||||
void xor_bit(int i, const SemiSecret& bit)
|
||||
void xor_bit(int i, const T& bit)
|
||||
{ *this ^= bit << i; }
|
||||
|
||||
void reveal(size_t n_bits, Clear& x);
|
||||
|
||||
SemiSecret lsb()
|
||||
T lsb()
|
||||
{ return *this & 1; }
|
||||
};
|
||||
|
||||
class SemiSecret: public SemiSecretBase<SemiSecret, SemiShare<BitVec>>
|
||||
{
|
||||
typedef SemiSecret This;
|
||||
|
||||
public:
|
||||
typedef SemiSecretBase<SemiSecret, SemiShare<BitVec>> super;
|
||||
|
||||
typedef SemiMC<This> MC;
|
||||
typedef DirectSemiMC<This> Direct_MC;
|
||||
typedef MC MAC_Check;
|
||||
typedef SemiInput<This> Input;
|
||||
typedef SemiPrep LivePrep;
|
||||
|
||||
static MC* new_mc(typename SemiShare<BitVec>::mac_key_type);
|
||||
|
||||
SemiSecret()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
SemiSecret(const T& other) :
|
||||
super(other)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class DealerSecret : public SemiSecretBase<DealerSecret, DealerShare<BitVec>>
|
||||
{
|
||||
typedef DealerSecret This;
|
||||
|
||||
public:
|
||||
typedef SemiSecretBase<DealerSecret, DealerShare<BitVec>> super;
|
||||
|
||||
typedef DealerMC<This> MC;
|
||||
typedef DirectDealerMC<This> Direct_MC;
|
||||
typedef MC MAC_Check;
|
||||
typedef DealerInput<This> Input;
|
||||
typedef DealerPrep LivePrep;
|
||||
|
||||
static MC* new_mc(typename super::mac_key_type);
|
||||
|
||||
DealerSecret()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
DealerSecret(const T& other) :
|
||||
super(other)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace GC */
|
||||
|
||||
#endif /* GC_SEMISECRET_H_ */
|
||||
|
||||
@@ -4,17 +4,20 @@
|
||||
*/
|
||||
|
||||
#include "GC/ShareParty.h"
|
||||
#include "SemiSecret.h"
|
||||
|
||||
#include "GC/ShareSecret.hpp"
|
||||
#include "Protocols/MAC_Check_Base.hpp"
|
||||
#include "Protocols/DealerMC.h"
|
||||
#include "SemiSecret.h"
|
||||
|
||||
namespace GC
|
||||
{
|
||||
|
||||
const int SemiSecret::default_length;
|
||||
template<class T, class V>
|
||||
const int SemiSecretBase<T, V>::default_length;
|
||||
|
||||
SemiSecret::MC* SemiSecret::new_mc(mac_key_type)
|
||||
inline
|
||||
SemiSecret::MC* SemiSecret::new_mc(
|
||||
typename super::mac_key_type)
|
||||
{
|
||||
if (OnlineOptions::singleton.direct)
|
||||
return new Direct_MC;
|
||||
@@ -22,7 +25,18 @@ SemiSecret::MC* SemiSecret::new_mc(mac_key_type)
|
||||
return new MC;
|
||||
}
|
||||
|
||||
void SemiSecret::trans(Processor<SemiSecret>& processor, int n_outputs,
|
||||
inline
|
||||
DealerSecret::MC* DealerSecret::new_mc(
|
||||
typename super::mac_key_type)
|
||||
{
|
||||
if (OnlineOptions::singleton.direct)
|
||||
return new Direct_MC;
|
||||
else
|
||||
return new MC;
|
||||
}
|
||||
|
||||
template<class T, class V>
|
||||
void SemiSecretBase<T, V>::trans(Processor<T>& processor, int n_outputs,
|
||||
const vector<int>& args)
|
||||
{
|
||||
int N_BITS = default_length;
|
||||
@@ -46,29 +60,33 @@ void SemiSecret::trans(Processor<SemiSecret>& processor, int n_outputs,
|
||||
}
|
||||
}
|
||||
|
||||
void SemiSecret::load_clear(int n, const Integer& x)
|
||||
template<class T, class V>
|
||||
void SemiSecretBase<T, V>::load_clear(int n, const Integer& x)
|
||||
{
|
||||
check_length(n, x);
|
||||
*this = constant(x, ShareThread<SemiSecret>::s().P->my_num());
|
||||
this->check_length(n, x);
|
||||
*this = this->constant(x, ShareThread<T>::s().P->my_num());
|
||||
}
|
||||
|
||||
void SemiSecret::bitcom(Memory<SemiSecret>& S, const vector<int>& regs)
|
||||
template<class T, class V>
|
||||
void SemiSecretBase<T, V>::bitcom(Memory<T>& S, const vector<int>& regs)
|
||||
{
|
||||
*this = 0;
|
||||
for (unsigned int i = 0; i < regs.size(); i++)
|
||||
*this ^= (S[regs[i]] << i);
|
||||
}
|
||||
|
||||
void SemiSecret::bitdec(Memory<SemiSecret>& S,
|
||||
template<class T, class V>
|
||||
void SemiSecretBase<T, V>::bitdec(Memory<T>& S,
|
||||
const vector<int>& regs) const
|
||||
{
|
||||
for (unsigned int i = 0; i < regs.size(); i++)
|
||||
S[regs[i]] = (*this >> i) & 1;
|
||||
}
|
||||
|
||||
void SemiSecret::reveal(size_t n_bits, Clear& x)
|
||||
template<class T, class V>
|
||||
void SemiSecretBase<T, V>::reveal(size_t n_bits, Clear& x)
|
||||
{
|
||||
auto& thread = ShareThread<SemiSecret>::s();
|
||||
auto& thread = ShareThread<T>::s();
|
||||
x = thread.MC->POpen(*this, *thread.P).mask(n_bits);
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ public:
|
||||
|
||||
typedef BitVec clear;
|
||||
typedef BitVec open_type;
|
||||
typedef BitVec mac_type;
|
||||
typedef BitVec mac_key_type;
|
||||
typedef NoShare mac_type;
|
||||
typedef NoValue mac_key_type;
|
||||
|
||||
typedef NoShare bit_type;
|
||||
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
typedef ReplicatedMC<This> MC;
|
||||
typedef BitVec_<unsigned char> open_type;
|
||||
typedef open_type clear;
|
||||
typedef BitVec mac_key_type;
|
||||
typedef NoValue mac_key_type;
|
||||
|
||||
static MC* new_mc(mac_key_type)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include "instructions.h"
|
||||
|
||||
#include "Tools/benchmarking.h"
|
||||
|
||||
#include "Machine.hpp"
|
||||
|
||||
namespace GC
|
||||
@@ -58,15 +60,10 @@ 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);
|
||||
insecure("preprocessing from file in binary virtual machines");
|
||||
}
|
||||
#endif
|
||||
|
||||
P = new PlainPlayer(N, "main");
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ public:
|
||||
part_MC.exchange(P);
|
||||
}
|
||||
|
||||
typename T::open_type finalize_open()
|
||||
typename T::open_type finalize_raw()
|
||||
{
|
||||
int n = sizes.next();
|
||||
typename T::open_type opened = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
opened += typename T::open_type(part_MC.finalize_open().get_bit(0)) << i;
|
||||
opened += typename T::open_type(part_MC.finalize_raw().get_bit(0)) << i;
|
||||
return opened;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user