emp-toolkit
np.h
Go to the documentation of this file.
1 #ifndef OT_NP_H__
2 #define OT_NP_H__
3 #include "ot.h"
9 class OTNP: public OT<OTNP> { public:
10  int cnt;
11  eb_t g, C;
12  const eb_t *gTbl;
13  bn_t q;
15  OTNP(NetIO * io): OT(io) {
17  eb_curve_get_gen(g);
18  eb_curve_get_ord(q);
19  gTbl = eb_curve_get_tab();
20  PRG fix_prg(fix_key);
21  fix_prg.random_eb(&C, 1);
22  }
23 
24  void send_impl(const block* data0, const block* data1, int length) {
25  bn_t r0, r1;
26  eb_t pk0, pk1, *gr0 = new eb_t[length], *gr1 = new eb_t[length];
27  eb_newl(pk0, pk1);
28  bn_newl(r0, r1);
29 
30  block *m0 = new block[length];
31  block *m1 = new block[length];
32  for(int i = 0; i < length; ++i) {
33  eb_newl(gr0[i], gr1[i]);
34  }
35 
36  for(int i = 0; i < length; ++i) {
37  prg.random_bn(r0, r1);
38  io->recv_eb(&pk0, 1);
39  eb_sub_norm(pk1, C, pk0);
40  eb_mul_fix_norm(gr0[i], gTbl, r0);
41  eb_mul_fix_norm(gr1[i], gTbl, r1);
42  eb_mul_norm(pk0, pk0, r0);
43  eb_mul_norm(pk1, pk1, r1);
44  m0[i] = KDF(pk0);
45  m1[i] = KDF(pk1);
46  }
47  block m[2];
48  for(int i = 0 ; i < length; ++i) {
49  io->send_eb(&gr0[i], 1);
50  io->send_eb(&gr1[i], 1);
51  m[0] = xorBlocks(data0[i], m0[i]);
52  m[1] = xorBlocks(data1[i], m1[i]);
53  io->send_data(m, 2*sizeof(block));
54  }
55 
56  bn_freel(r0, r1);
57  eb_freel(pk0, pk1);
58  for(int i =0; i < length; ++i)
59  eb_freel(gr0[i], gr1[i]);
60  delete[] gr0;
61  delete[] gr1;
62  delete[] m0;
63  delete[] m1;
64  }
65 
66  void recv_impl(block* data, const bool* b, int length) {
67  bn_t * k = new bn_t[length];
68  eb_t pk[2], E[2];
69  block m[2];
70  eb_newl(E[0], E[1], pk[0], pk[1]);
71  for(int i = 0; i < length; ++i) {
72  bn_newl(k[i]);
73  }
74  prg.random_bn(k, length);
75 
76  for(int i = 0; i< length; ++i) {
77  if(b[i]) {
78  eb_mul_fix_norm(pk[1], gTbl, k[i]);
79  eb_sub_norm(pk[0], C, pk[1]);
80  } else {
81  eb_mul_fix_norm(pk[0], gTbl, k[i]);
82  }
83  io->send_eb(&pk[0], 1);
84  }
85 
86  for(int i = 0; i < length; ++i) {
87  io->recv_eb(E, 2);
88  io->recv_data(m, 2*sizeof(block));
89  int ind = b[i] ? 1 : 0;
90  eb_mul_norm(E[ind], E[ind], k[i]);
91  data[i] = xorBlocks(m[ind], KDF(E[ind]));
92  }
93  for(int i = 0; i < length; ++i) {
94  bn_freel(k[i]);
95  }
96  eb_freel(pk[0], pk[1], E[0], E[1]);
97  delete[] k;
98  }
99 
100 };
102 #endif// OT_NP_H__
void send_data(const void *data, int nbyte)
Definition: io_channel.h:14
void recv_data(void *data, int nbyte)
Definition: io_channel.h:17
__m128i block
Definition: block.h:8
OTNP(NetIO *io)
Definition: np.h:15
block xorBlocks(block x, block y)
Definition: block.h:35
Definition: net_io_channel.h:22
void recv_impl(block *data, const bool *b, int length)
Definition: np.h:66
void recv_eb(eb_t *eb, size_t num)
Definition: io_channel.h:150
void send_eb(const eb_t *eb, size_t num)
Definition: io_channel.h:140
const char fix_key[]
Definition: block.h:130
Definition: np.h:9
bn_t q
Definition: np.h:13
block KDF(eb_t in)
Definition: utils_ec.hpp:20
int cnt
Definition: np.h:10
NetIO * io
Definition: ot.h:9
void initialize_relic()
Definition: utils_ec.hpp:8
Definition: prg.h:16
void send_impl(const block *data0, const block *data1, int length)
Definition: np.h:24
void random_bn(T t, L... l)
Definition: prg.h:87
eb_t C
Definition: np.h:11
const eb_t * gTbl
Definition: np.h:12
void random_eb(T t, L... l)
Definition: prg.h:113
Definition: ot.h:6
PRG prg
Definition: np.h:14
eb_t g
Definition: np.h:11