Skip to content

Commit 3f9f3be

Browse files
committed
Half-gate garbling, native 2D convolution, TensorFlow inference.
1 parent 31e43a6 commit 3f9f3be

File tree

138 files changed

+2672
-1199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2672
-1199
lines changed

BMR/AuthValue.cpp

Lines changed: 0 additions & 31 deletions
This file was deleted.

BMR/CommonParty.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class CommonParty
5858
LocalBuffer wires;
5959
ReceivedMsgStore wire_storage;
6060

61-
template<class T, class U>
62-
GC::BreakType first_phase(GC::Program<U>& program, GC::Processor<T>& processor,
61+
template<class T>
62+
GC::BreakType first_phase(GC::Program& program, GC::Processor<T>& processor,
6363
GC::Machine<T>& machine);
6464
template<class T, class U>
65-
GC::BreakType second_phase(GC::Program<T>& program, GC::Processor<T>& processor,
65+
GC::BreakType second_phase(GC::Program& program, GC::Processor<T>& processor,
6666
GC::Machine<T>& machine, U& dynamic_memory);
6767

6868
public:

BMR/CommonParty.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "CommonParty.h"
1010

11-
template <class T, class U>
12-
GC::BreakType CommonParty::first_phase(GC::Program<U>& program,
11+
template <class T>
12+
GC::BreakType CommonParty::first_phase(GC::Program& program,
1313
GC::Processor<T>& processor, GC::Machine<T>& machine)
1414
{
1515
(void)machine;
@@ -20,7 +20,7 @@ GC::BreakType CommonParty::first_phase(GC::Program<U>& program,
2020
GC::BreakType next;
2121
try
2222
{
23-
next = (reinterpret_cast<GC::Program<T>*>(&program))->execute(processor, dynamic_memory);
23+
next = program.execute(processor, dynamic_memory);
2424
}
2525
catch (needs_cleaning& e)
2626
{
@@ -44,7 +44,7 @@ GC::BreakType CommonParty::first_phase(GC::Program<U>& program,
4444
}
4545

4646
template<class T, class U>
47-
GC::BreakType CommonParty::second_phase(GC::Program<T>& program,
47+
GC::BreakType CommonParty::second_phase(GC::Program& program,
4848
GC::Processor<T>& processor, GC::Machine<T>& machine,
4949
U& dynamic_memory)
5050
{

BMR/Key.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Key {
3737
void serialize(SendBuffer& output) const { output.serialize(r); }
3838
void serialize_no_allocate(SendBuffer& output) const { output.serialize_no_allocate(r); }
3939

40-
bool get_signal() const { return _mm_cvtsi128_si64(r) & 1; }
40+
bool get_signal() const { return _mm_cvtsi128_si32(r) & 1; }
4141
void set_signal(bool signal);
4242

4343
Key doubling(int i) const;

BMR/Machine.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.

BMR/Party.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ void FakeProgramParty::receive_spdz_wires(ReceivedMsg& msg)
382382
void ProgramParty::store_wire(const Register& reg)
383383
{
384384
wires.serialize(reg.key(get_id(), 0));
385-
#ifndef FREE_XOR
386-
wires.serialize(reg.key(get_id(), 1));
387-
#endif
388385
#ifdef DEBUG
389386
cout << "storing wire" << endl;
390387
reg.print();
@@ -394,11 +391,7 @@ void ProgramParty::store_wire(const Register& reg)
394391
void ProgramParty::load_wire(Register& reg)
395392
{
396393
wires.unserialize(reg.key(get_id(), 0));
397-
#ifdef FREE_XOR
398394
reg.key(get_id(), 1) = reg.key(get_id(), 0) ^ get_delta();
399-
#else
400-
wires.unserialize(reg.key(get_id(), 1));
401-
#endif
402395
#ifdef DEBUG
403396
cout << "loading wire" << endl;
404397
reg.print();

BMR/Party.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ProgramParty : virtual public CommonParty, virtual public PartyProperties,
9999

100100
GC::Machine< GC::Secret<EvalRegister> > machine;
101101
GC::Processor<GC::Secret<EvalRegister> > processor;
102-
GC::Program<GC::Secret<EvalRegister> > program;
102+
GC::Program program;
103103

104104
GC::Machine< GC::Secret<PRFRegister> > prf_machine;
105105
GC::Processor<GC::Secret<PRFRegister> > prf_processor;
@@ -170,11 +170,7 @@ class ProgramPartySpec : public ProgramParty
170170
void get_spdz_wire(SpdzOp op, DualWire<T>& spdz_wire);
171171
};
172172

173-
#ifdef SPDZ_AUTH
174173
typedef ProgramPartySpec<Share<gf2n_long>> FakeProgramPartySuper;
175-
#else
176-
typedef ProgramPartySpec<GC::Memory<AuthValue>> FakeProgramPartySuper;
177-
#endif
178174

179175
class FakeProgramParty : virtual public BaseParty, virtual public FakeProgramPartySuper
180176
{

BMR/ProgramParty.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ void ProgramPartySpec<T>::load(string progname)
3131
program.parse(progname + "-0");
3232
machine.reset(program, dynamic_memory);
3333
processor.reset(program);
34-
prf_machine.reset(*reinterpret_cast<GC::Program<GC::Secret<PRFRegister> >* >(&program));
35-
prf_processor.reset(*reinterpret_cast<GC::Program<GC::Secret<PRFRegister> >* >(&program));
34+
prf_machine.reset(program);
35+
prf_processor.reset(program);
3636
}
3737

3838
template<class T>

BMR/RealProgramParty.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ RealProgramParty<T>::RealProgramParty(int argc, const char** argv) :
7878
P = new CryptoPlayer(N, 0);
7979

8080
delta = prng.get_doubleword();
81-
#ifdef KEY_SIGNAL
8281
delta.set_signal(1);
83-
#endif
8482
#ifdef VERBOSE
8583
cerr << "delta: " << delta << endl;
8684
#endif
@@ -201,16 +199,11 @@ RealProgramParty<T>::~RealProgramParty()
201199
template<class T>
202200
void RealProgramParty<T>::receive_keys(Register& reg)
203201
{
204-
#ifndef FREE_XOR
205-
#error not implemented
206-
#endif
207202
auto& _id = this->_id;
208203
auto& _N = this->_N;
209204
reg.init(_N);
210205
reg.keys[0][_id - 1] = this->prng.get_doubleword();
211-
#ifdef KEY_SIGNAL
212206
reg.keys[0][_id - 1].set_signal(0);
213-
#endif
214207
reg.keys[1][_id - 1] = reg.keys[0][_id - 1] ^ this->get_delta();
215208
}
216209

BMR/Register.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ void Register::init(int rfd, int n_parties) {
4848
mask = mask>0 ? 1 : 0;
4949
keys.init(n_parties);
5050
keys.randomize();
51-
#ifdef KEY_SIGNAL
5251
for (int i = 0; i < 2; i++)
5352
for (size_t j = 0; j < keys[i].size(); j++)
5453
if (keys[i][j].get_signal() != i)
5554
keys[i][j] ^= Key(1);
56-
#endif
5755
}
5856

5957
void Register::set_eval_keys()
@@ -284,21 +282,7 @@ void Register::eval(const Register& left, const Register& right, GarbledGate& ga
284282
// }
285283
// std::cout << std::endl;
286284

287-
#ifdef KEY_SIGNAL
288285
external = garbled_entry[my_id - 1].get_signal();
289-
#else
290-
if(garbled_entry[my_id-1] == key(my_id, 0)) {
291-
external = 0;
292-
} else if (garbled_entry[my_id-1] == key(my_id, 1)) {
293-
external = 1;
294-
} else {
295-
printf("\nERROR!!!\n");
296-
cout << "got key: " << garbled_entry[my_id - 1] << endl;
297-
cout << "possibilities: " << key(my_id, 0) << " " << key(my_id, 1) << endl;
298-
throw std::invalid_argument("result key doesn't fit any of my keys");
299-
// return NO_SIGNAL;
300-
}
301-
#endif
302286

303287
#ifdef DEBUG_MASK
304288
cout << "output signal: " << (int)external << endl;
@@ -680,9 +664,7 @@ void RandomRegister::randomize()
680664
party.random_timer.start();
681665
init(party.randomfd, party._N);
682666
party.random_timer.stop();
683-
#ifdef FREE_XOR
684667
keys[1] = keys[0] ^ party.get_deltas();
685-
#endif
686668
party.add_keys(*this);
687669
}
688670

@@ -764,16 +746,13 @@ void EvalRegister::output()
764746
ProgramParty& party = ProgramParty::s();
765747
party.load_wire(*this);
766748
set_mask(party.output_masks.pop_front());
767-
#ifdef KEY_SIGNAL
768749
#ifdef DEBUG_REGS
769750
cout << "check " << get_id() << endl;
770751
#endif
771752
check_signal_key(party.get_id(), garbled_entry);
772-
#endif
773753
party.taint();
774754
}
775755

776-
#ifdef FREE_XOR
777756
void RandomRegister::XOR(const Register& left, const Register& right)
778757
{
779758
mask = left.get_mask() ^ right.get_mask();
@@ -824,46 +803,6 @@ void EvalRegister::XOR(const Register& left, const Register& right)
824803
<< " ^ " << right.get_garbled_entry()[i] << endl;
825804
#endif
826805
}
827-
#endif
828-
829-
void EvalRegister::check(const int128& value, word share, int128 mac)
830-
{
831-
#ifdef DEBUG_DYNAMIC
832-
cout << "check result " << value << endl;
833-
#endif
834-
if (value != 0)
835-
{
836-
cout << "MAC check: " << value << " " << share<< " " << mac << endl;
837-
throw runtime_error("MAC check failed");
838-
}
839-
}
840-
841-
void EvalRegister::get_dyn_mask(GC::Mask& mask, int length, int mac_length)
842-
{
843-
mask.share = CommonParty::s().prng.get_word() & ((1ULL << length) - 1);
844-
mask.mac = int128(CommonParty::s().prng.get_doubleword())
845-
& int128::ones(mac_length);
846-
#ifdef DEBUG_DYNAMIC
847-
cout << "mask " << hex << mask.share << " " << mask.mac << " ";
848-
cout << ((1ULL << length) - 1) << " " << int128::ones(mac_length) << endl;
849-
#endif
850-
}
851-
852-
void EvalRegister::unmask(GC::AuthValue& dest, word mask_share, int128 mac_mask_share,
853-
word masked, int128 masked_mac)
854-
{
855-
dest.share = mask_share;
856-
dest.mac = mac_mask_share;
857-
if (ProgramParty::s()._id == 1)
858-
{
859-
dest.share ^= masked;
860-
dest.mac ^= masked_mac;
861-
}
862-
#ifdef DEBUG_DYNAMIC
863-
cout << dest.share << " ?= " << mask_share << " ^ " << masked << endl;
864-
cout << dest.mac << " ?= " << mac_mask_share << " ^ " << masked_mac << endl;
865-
#endif
866-
}
867806

868807
template <>
869808
void RandomRegister::store(NoMemory& mem,

0 commit comments

Comments
 (0)