/* * EvalSecret.h * */ #ifndef GC_SECRET_H_ #define GC_SECRET_H_ #include "GC/config.h" #include "BMR/config.h" #include "BMR/common.h" #include "GC/Clear.h" #include "GC/Memory.h" #include "GC/Access.h" #include "Math/gf2nlong.h" #include "Processor/DummyProtocol.h" #include namespace GC { template class Secret; template inline void XOR(T& res, const T& left, const T& right) { #ifdef FREE_XOR Secret::cast(res).XOR(Secret::cast(left), Secret::cast(right)); #else Secret::cast(res).op(Secret::cast(left), Secret::cast(right), 0x0110); #endif } class AuthValue { public: static string type_string() { return "authenticated value"; } word share; int128 mac; AuthValue() : share(0), mac(0) {} void assign(const word& value, const int128& mac_key, bool first_player); void check(const word& mac_key) const; friend ostream& operator<<(ostream& o, const AuthValue& auth_value); }; class Mask { public: word share; int128 mac; Mask() : share(0) {} }; template class Processor; template class Secret { CheckVector registers; T& get_new_reg(); public: typedef typename T::DynamicMemory DynamicMemory; // dummy typedef DummyMC MC; typedef DummyProtocol Protocol; static string type_string() { return "evaluation secret"; } static string phase_name() { return T::name(); } static int default_length; static typename T::out_type out; static T& cast(T& reg) { return *reinterpret_cast(®); } static const T& cast(const T& reg) { return *reinterpret_cast(®); } static Secret input(party_id_t from, const int128& input, int n_bits = -1); static Secret input(party_id_t from, Processor>& processor, int n_bits = -1); void random(int n_bits, int128 share); void random_bit(); static Secret reconstruct(const int128& x, int length); template static void store_clear_in_dynamic(U& mem, const vector& accesses) { T::store_clear_in_dynamic(mem, accesses); } void store(Memory& mem, size_t address); static Secret carryless_mult(const Secret& x, const Secret& y); static void output(T& reg); template static void load(vector< ReadAccess< Secret > >& accesses, const U& mem); template static void store(U& mem, vector< WriteAccess< Secret > >& accesses); static void andrs(Processor< Secret >& processor, const vector& args) { T::andrs(processor, args); } static void ands(Processor< Secret >& processor, const vector& args) { T::ands(processor, args); } static void inputb(Processor< Secret >& processor, const vector& args) { T::inputb(processor, args); } static void trans(Processor >& processor, int n_inputs, const vector& args); static void convcbit(Integer& dest, const Clear& source) { T::convcbit(dest, source); } Secret(); Secret(const Integer& x) { *this = x; } void load(int n, const Integer& x); void operator=(const Integer& x) { load(default_length, x); } void load(int n, const Memory& mem, size_t address); Secret operator<<(int i); Secret operator>>(int i); void bitcom(Memory< Secret >& S, const vector& regs); void bitdec(Memory< Secret >& S, const vector& regs) const; Secret operator+(const Secret x) const; Secret& operator+=(const Secret x) { *this = *this + x; return *this; } void xor_(int n, const Secret& x, const Secret& y) { resize_regs(n); for (int i = 0; i < n; i++) XOR(registers[i], x.get_reg(i), y.get_reg(i)); } void and_(int n, const Secret& x, const Secret& y, bool repeat); void andrs(int n, const Secret& x, const Secret& y) { and_(n, x, y, true); } template void reveal(size_t n_bits, U& x); int size() const { return registers.size(); } CheckVector& get_regs() { return registers; } const CheckVector& get_regs() const { return registers; } const T& get_reg(int i) const { return *reinterpret_cast(®isters.at(i)); } T& get_reg(int i) { return *reinterpret_cast(®isters.at(i)); } void resize_regs(int n); }; template int Secret::default_length = 128; template typename T::out_type Secret::out = T::out; template inline ostream& operator<<(ostream& o, Secret& secret) { o << "(" << secret.size() << " secret bits)"; return o; } } /* namespace GC */ #endif /* GC_SECRET_H_ */