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