emp-toolkit
semihonest_gen.h
Go to the documentation of this file.
1 #ifndef SEMIHONEST_GEN_H__
2 #define SEMIHONEST_GEN_H__
3 #include <emp-tool/emp-tool.h>
4 #include <emp-ot/emp-ot.h>
5 #include <iostream>
6 
7 template<typename T>
8 void gen_feed(Backend* be, int party, block * label, const bool*, int length);
9 template<typename T>
10 void gen_reveal(Backend* be, bool* clear, int party, const block * label, int length);
11 
12 template<typename T>
13 class SemiHonestGen: public Backend { public:
19  this->io = io;
20  ot = new SHOTIterated(io, true);
21 
22  this->gc = gc;
23  Feed_internal = gen_feed<T>;
24  Reveal_internal = gen_reveal<T>;
25  }
26 
28  delete ot;
29  }
30 };
31 
32 template<typename T>
33 void gen_feed(Backend* be, int party, block * label, const bool* b, int length) {
34  SemiHonestGen<T> * backend = (SemiHonestGen<T>*)(be);
35  if(party == ALICE) {
36  backend->prg.random_block(label, length);
37  for (int i = 0; i < length; ++i) {
38  block tosend = label[i];
39  if(b[i]) tosend = xorBlocks(tosend, backend->gc->delta);
40  backend->io->send_block(&tosend, 1);
41  }
42  } else {
43  backend->ot->send_cot(label, backend->gc->delta, length);
44  }
45 }
46 
47 template<typename T>
48 void gen_reveal(Backend* be, bool* b, int party, const block * label, int length) {
49  SemiHonestGen<T> * backend = (SemiHonestGen<T>*)(be);
50  for (int i = 0; i < length; ++i) {
51  if(isOne(&label[i]))
52  b[i] = true;
53  else if (isZero(&label[i]))
54  b[i] = false;
55  else {
56  if (party == BOB or party == PUBLIC) {
57  backend->io->send_block(&label[i], 1);
58  b[i] = false;
59  } else if(party == ALICE) {
60  block tmp;
61  backend->io->recv_block(&tmp, 1);
62  b[i] = !(block_cmp(&tmp, &label[i], 1));
63  }
64  }
65  }
66  if(party == PUBLIC)
67  backend->io->recv_data(b, length);
68 }
69 #endif //SEMIHONEST_GEN_H__
NetIO * io
Definition: semihonest_gen.h:14
void gen_feed(Backend *be, int party, block *label, const bool *, int length)
Definition: semihonest_gen.h:33
void recv_data(void *data, int nbyte)
Definition: io_channel.h:17
__m128i block
Definition: block.h:8
bool isZero(const block *b)
Definition: block.h:71
#define BOB
Definition: utils.h:16
void send_cot(block *data0, block delta, int length)
Definition: iterated.h:66
~SemiHonestGen()
Definition: semihonest_gen.h:27
HalfGateGen< T > * gc
Definition: semihonest_gen.h:17
block xorBlocks(block x, block y)
Definition: block.h:35
Definition: net_io_channel.h:22
bool isOne(const block *b)
Definition: block.h:75
#define PUBLIC
Definition: utils.h:14
OTIterated< SHOTExtension > SHOTIterated
Definition: iterated.h:96
Definition: semihonest_gen.h:13
void random_block(block *data, int nblocks=1)
Definition: prg.h:75
void gen_reveal(Backend *be, bool *clear, int party, const block *label, int length)
Definition: semihonest_gen.h:48
PRG prg
Definition: semihonest_gen.h:16
SHOTIterated * ot
Definition: semihonest_gen.h:15
void(* Reveal_internal)(Backend *be, bool *, int, const block *label, int length)
Definition: backend.h:11
Definition: backend.h:8
#define ALICE
Definition: utils.h:15
block delta
Definition: halfgate_gen.h:30
void(* Feed_internal)(Backend *be, int, block *label, const bool *, int length)
Definition: backend.h:10
Definition: prg.h:16
bool block_cmp(const block *x, const block *y, int nblocks)
Definition: block.h:56
SemiHonestGen(NetIO *io, HalfGateGen< T > *gc)
Definition: semihonest_gen.h:18
void send_block(const block *data, int nblock)
Definition: io_channel.h:132
void recv_block(block *data, int nblock)
Definition: io_channel.h:136
int party
Definition: input-check-malicious.cpp:12
Definition: iterated.h:9