36 for(
int i = 0; i < ssp+1; ++i)
53 IV(
NetIO * io,
int party,
int n1,
int _n2,
int n3) {
55 elgamal =
new Elgamal(io, party, n1);
61 Y0 =
new block[n2*(ssp+1)];
62 Y1 =
new block[n2*(ssp+1)];
66 prgs =
new PRG*[(ssp+1)];
67 seed =
new block[ssp+1];
71 deltas =
new block[ssp+1];
72 input1 =
new bool[
n1];
78 for(
int j = 0; j < ssp+1; ++j) {
79 prgs[j] =
new PRG(&seed[j]);
82 for(
int i = 0; i <
n2; ++i) {
88 for(
int i = 0; i <
n2; ++i) {
89 AES_set_encrypt_key(seed_Y0[i], &aes);
90 memcpy(tmp, &Y0[i*(ssp+1)], (ssp+1)*
sizeof(
block));
91 AES_ecb_encrypt_blks(tmp, ssp+1, &aes);
94 AES_set_encrypt_key(seed_Y1[i], &aes);
95 memcpy(tmp, &Y0[i*(ssp+1)], (ssp+1)*
sizeof(
block));
96 for(
int j = 0; j < ssp+1; ++j)
98 AES_ecb_encrypt_blks(tmp, ssp+1, &aes);
103 input2 =
new bool[
n2];
104 choose =
new bool[
ssp];
106 uint8_t * c =
new uint8_t[
ssp];
108 for(
int i = 0; i <
ssp; ++i) {
109 choose[i] = (c[i]%2 == 1);
114 for(
int i = 0; i <
n2; ++i) {
130 uint8_t * permute =
new uint8_t[
n1];
131 uint8_t * loc =
new uint8_t[
n1];
134 for(
int i = 0; i <
n3; ++i) {
135 bn_newl(omegas[i][0], omegas[i][1]);
136 eb_newl(hs[i][0], hs[i][1]);
138 bn_sub_mod(omegas[i][1], elgamal->
w, omegas[i][1], elgamal->
q);
139 eb_mul_fix_norm(hs[i][0], elgamal->
gTbl, omegas[i][0]);
140 eb_mul_fix_norm(hs[i][1], elgamal->
gTbl, omegas[i][1]);
145 for(
int j = 0; j <
ssp; ++j) {
149 for(
int i = 0; i <
n1; ++i){
150 if(input1[i]) loc[i] = 1-(permute[i]%2);
151 else loc[i] = (permute[i]%2);
154 for(
int i = 0; i <
n1; ++i) {
155 elgamal->
commit(r[0], u[0],
false, prgs[j]);
156 elgamal->
commit(r[1], u[1],
true, prgs[j]);
158 int ind = input1[i] ? 1 : 0;
159 L10[i] =
KDF(u[0][1]);
160 L11[i] =
KDF(u[1][1]);
161 int p = (permute[i] %2);
167 bn_sub_mod(inEqChk, elgamal->
r[i], r[ind], elgamal->
q);
178 for(
int i = 0; i <
n2; ++i) {
179 L2x[i] = Y0[i*(ssp+1)+j];
191 for(
int i = 0; i <
n3; ++i) {
193 eb_mul_fix_norm(outRcvyCom[0], elgamal->
gTbl, K[0]);
194 eb_mul_fix_norm(outRcvyCom[1], elgamal->
gTbl, K[1]);
195 eb_add_norm(outRcvyCom[0], outRcvyCom[0], hs[i][0]);
196 eb_add_norm(outRcvyCom[1], outRcvyCom[1], hs[i][1]);
199 bn_add_mod(outRcvyDecom[0], omegas[i][0], K[0], elgamal->
q);
200 bn_add_mod(outRcvyDecom[1], omegas[i][1], K[1], elgamal->
q);
203 for(
int ind = 0; ind < 2; ++ind) {
206 int bn_size = bn_size_raw(K[ind]);
207 bn_write_raw((uint64_t*)tmp, bn_size, K[ind]);
210 tmp[2] = prp.
H(Lo[i], 2);
238 uint8_t * permute =
new uint8_t[
n1];
239 uint8_t * loc =
new uint8_t[
n1];
241 bool evaluated =
false, recovered =
false;
242 for(
int i = 0; i <
n3; ++i) {
248 for(
int j = 0; j <
ssp; ++j) {
249 if (choose[j] == is_evaluate) {
254 for(
int i = 0; i <
n1; ++i) {
260 if(!elgamal->
check_eq(u, elgamal->
com[i], inEqChk))
264 if(strncmp(com[loc[i]], com_chk,
sizeof(
Com))!=0)
269 for(
int i = 0; i <
n2; ++i) {
271 L2x[i] = Y1[i*(ssp+1)+j];
273 L2x[i] = Y0[i*(ssp+1)+j];
282 eb_tpl outRcvyCom;eb_t tmp;
284 for(
int i = 0; i <
n3; ++i) {
287 eb_mul_fix_norm(tmp, elgamal->
gTbl, outRcvyDecom[0]);
288 if (eb_cmp(tmp, outRcvyCom[0])!=CMP_EQ)
290 eb_mul_fix_norm(tmp, elgamal->
gTbl, outRcvyDecom[1]);
291 if (eb_cmp(tmp, outRcvyCom[1])!=CMP_EQ)
294 for(
int ind = 0; ind < 2; ++ind) {
295 block o = prp.
H(Lo[i], 2);
299 if(recovered)
continue;
302 output[i] = (ind==1);
303 else if (output[i] != (ind == 1)) {
304 tmp_blocks[0] =
xorBlocks(tmp_blocks[0], prp.
H(Lo[i], 0));
305 tmp_blocks[1] =
xorBlocks(tmp_blocks[1], prp.
H(Lo[i], 1));
306 cout <<
"recover input!"<<endl;
324 Com com[2];
Com comchk[2];bn_t inEqChk;
325 for(
int i = 0; i <
n1; ++i) {
326 elgamal->
commit(r[0], u[0],
false, &seed_prg);
327 elgamal->
commit(r[1], u[1],
true, &seed_prg);
328 L10[i] =
KDF(u[0][1]);
329 L11[i] =
KDF(u[1][1]);
331 int p = permute[i]%2;
338 if(strncmp(comchk[p], com[p],
sizeof(
Com))!=0)
341 if(strncmp(comchk[1-p], com[1-p],
sizeof(
Com))!=0)
367 if(strncmp(dgstgc[0], dgstgc[1], 20)!=0)
371 eb_tpl outRcvyCom, outRcvyComChk;
372 block tmp[3], tmp_chk[3];
373 for(
int i = 0; i <
n3; ++i) {
375 eb_mul_fix_norm(outRcvyCom[0], elgamal->
gTbl, K[0]);
376 eb_mul_fix_norm(outRcvyCom[1], elgamal->
gTbl, K[1]);
377 eb_add_norm(outRcvyCom[0], outRcvyCom[0], hs[i][0]);
378 eb_add_norm(outRcvyCom[1], outRcvyCom[1], hs[i][1]);
381 if(eb_cmp(outRcvyComChk[0], outRcvyCom[0])!=CMP_EQ)
385 for(
int ind = 0; ind < 2; ++ind) {
388 bn_write_raw((uint64_t*)tmp, bn_size_raw(K[ind]), K[ind]);
391 tmp[2] = prp.
H(Lo[i], 2);
395 if(!
block_cmp(tmp, tmp_chk, 3))cheat=
true;
419 block prg_seed, Z1, block_tmp;
424 for(
int i = 0; i <
n1; ++i) {
425 eb_newl(X[i][0], X[i][1]);
427 X0lbl[i] =
KDF(X[i][0]);
428 X1lbl[i] =
KDF(X[i][1]);
431 if(f ==
nullptr)
return true;
434 PRG prg_loc(&prg_seed);
436 for(
int i = 0; i <
n1; ++i)
437 *((
char *) &Xlbl[i]) &= 0xfe;
452 bool valid_com = commitment.
open(decomZ, comZ, &Z1,
sizeof(
block));
454 bool f1ok =
block_cmp(&Z1, &block_tmp, 1);
460 return valid_com and f1ok;
465 eb_t * X =
new eb_t[
n1];
469 memcpy(input1, b, n1);
470 block block_tmp, prg_seed, delta, Z1;
472 char hash_eval[20], hash_open[20];
477 if(f ==
nullptr)
return true;
478 for(
int i = 0; i <
n1; ++i)
490 commitment.
commit(decomL, comL, &Z1,
sizeof(
block));
496 PRG prg_loc(&prg_seed);
497 elgamal->
open(Xs, b, X);
499 for(
int i = 0; i <
n1; ++i) {
500 X0lbl[i] =
KDF(Xs[i][0]);
501 X1lbl[i] =
KDF(Xs[i][1]);
504 for(
int i = 0; i <
n1; ++i)
505 *((
char *) &Xlbl[i]) &= 0xfe;
517 bool check_gc = (strncmp(hash_eval, hash_open, 20) == 0);
536 ot->
send(seed_Y0, seed_Y1, n2);
538 if(f ==
nullptr)
return true;
539 for(
int i = 0; i <
n2; ++i) {
540 Ylbl[i] = Y0[i*(ssp+1)+ssp];
541 *((
char *) &Ylbl[i]) &= 0xfe;
554 bool valid_com = commitment.
open 555 (decomZ, comZ, &Z2,
sizeof(
block));
562 return valid_com and f2ok;
566 block Z2, block_tmp, delta, prg_seed;
567 xortree->
gen(input2, b);
570 char hash_eval[20], hash_open[20];
574 ot->
recv(seed_Y, input2, n2);
576 for(
int i = 0; i <
n2; ++i) {
577 AES_set_decrypt_key(seed_Y[i], &aes);
579 AES_ecb_decrypt_blks(&Y1[i*(ssp+1)], ssp+1, &aes);
580 Ylbl[i] = Y1[i*(ssp+1)+ssp];
581 *((
char *) &Ylbl[i]) |= 0x1;
584 AES_ecb_decrypt_blks(&Y0[i*(ssp+1)], ssp+1, &aes);
585 Ylbl[i] = Y0[i*(ssp+1)+ssp];
586 *((
char *) &Ylbl[i]) &= 0xfe;
590 if(f ==
nullptr)
return true;
600 commitment.
commit(decomL, comL, &Z2,
sizeof(
block));
604 PRG seed_prg(&prg_seed);
607 for(
int i = 0; i <
n2; ++i)
608 *((
char *) &Ylbl[i]) &= 0xfe;
617 bool check_gc = (strncmp(hash_open, hash_eval, 20) == 0);
block * Y1
Definition: iv.h:21
IV(NetIO *io, int party, int n1, int _n2, int n3)
Definition: iv.h:53
Definition: privacy_free_eva.h:28
int n2
Definition: iv.h:13
void put_eb(const eb_t *eb, int length)
Definition: hash.h:57
void reset()
Definition: hash.h:45
void recv_eb_enc(eb_t *eb, size_t num)
Definition: io_channel.h:102
static block make_delta(const block &a)
Definition: garble_circuit.h:30
void send_data(const void *data, int nbyte)
Definition: io_channel.h:14
void send_bn_enc(const bn_t *bn, size_t num)
Definition: io_channel.h:54
XorTree * xortree
Definition: iv.h:29
void recv_data(void *data, int nbyte)
Definition: io_channel.h:17
Definition: hash_io_channel.h:9
void run_function(void *function, const Ts &... args)
Definition: utils.h:35
__m128i block
Definition: block.h:8
int input_size()
Definition: xor_tree.h:69
void send(eb_tpl *X)
Definition: elgamal.h:86
bool checkf1Bob(void *f)
Definition: iv.h:414
void send(const block *data0, const block *data1, int length)
Definition: ot.h:10
void recv_bn_enc(bn_t *bn, size_t num)
Definition: io_channel.h:117
bool checkf2Alice(void *f)
Definition: iv.h:530
block xorBlocks(block x, block y)
Definition: block.h:35
Definition: privacy_free_gen.h:28
const bool is_evaluate
Definition: iv.h:9
Definition: net_io_channel.h:22
bn_t w
Definition: elgamal.h:10
void recv_data_enc(void *data, int len)
Definition: io_channel.h:69
void circuit(block *out, block *in)
Definition: xor_tree.h:38
bool * input1
Definition: iv.h:27
block * key
Definition: iv.h:19
#define zero_block()
Definition: block.h:66
int party
Definition: iv.h:12
void gen(bool *out, bool *in)
Definition: xor_tree.h:73
void set_key(const block *b)
Definition: io_channel.h:26
void recv_eb(eb_t *eb, size_t num)
Definition: io_channel.h:150
eb_t eb_tpl[2]
Definition: utils_ec.h:14
bool check_eq(eb_tpl new_com, eb_tpl old_com, bn_t r_diff)
Definition: elgamal.h:73
bn_t * r
Definition: elgamal.h:66
void send_eb(const eb_t *eb, size_t num)
Definition: io_channel.h:140
bn_t q
Definition: elgamal.h:10
bool checkf1Alice(bool *b, void *f)
Definition: iv.h:463
PRG prg
Definition: elgamal.h:12
block * key_seed
Definition: iv.h:19
void generic_to_xor(const block *new_b0, const block *b0, const block *b1, int length)
Definition: halfgate_gen.h:88
bool * input2
Definition: iv.h:28
const eb_t * gTbl
Definition: elgamal.h:9
Definition: xor_tree.h:10
block * seed_Y1
Definition: iv.h:23
void random_block(block *data, int nblocks=1)
Definition: prg.h:75
void send_data_enc(const void *data, int len)
Definition: io_channel.h:37
bool evalgAlice(void *f)
Definition: iv.h:121
bn_t bn_tpl[2]
Definition: utils_ec.h:15
bool evalgBob(void *f, bool *output)
Definition: iv.h:229
block H(block in, uint64_t id)
Definition: prp.h:48
block * seed
Definition: iv.h:19
const int ssp
Definition: iv.h:18
Definition: mextension_kos.h:9
bool * choose
Definition: iv.h:24
block * hcot_seed
Definition: iv.h:19
Elgamal * elgamal
Definition: iv.h:10
int n1
Definition: iv.h:13
char Com[20]
Definition: com.h:10
block KDF(eb_t in)
Definition: utils_ec.hpp:20
void recv(eb_t *X, bool *b)
Definition: elgamal.h:133
void open()
Definition: elgamal.h:124
PRG prg
Definition: iv.h:14
const bool is_check
Definition: iv.h:8
MOTExtension * ot
Definition: iv.h:16
void recv(block *data, const bool *b, int length)
Definition: ot.h:13
block * seed_Y0
Definition: iv.h:22
#define ALICE
Definition: utils.h:15
block delta
Definition: halfgate_gen.h:30
void commit(bn_t r, eb_tpl com, bool b, PRG *prg)
Definition: elgamal.h:67
void get_digest(char *dgst)
Definition: hash_io_channel.h:22
block Decom[1]
Definition: com.h:11
void send_eb_enc(const eb_t *eb, size_t num)
Definition: io_channel.h:87
void random_bn(T t, L... l)
Definition: prg.h:87
bool block_cmp(const block *x, const block *y, int nblocks)
Definition: block.h:56
void random_data(void *data, int nbytes)
Definition: prg.h:49
NetIO * io
Definition: iv.h:11
Definition: halfgate_eva.h:29
void send_block(const block *data, int nblock)
Definition: io_channel.h:132
void privacy_free_to_xor(const block *new_b0, const block *b0, const block *b1, int length)
Definition: privacy_free_gen.h:74
MOTExtension_KOS MOTExtension
Definition: emp-ot.h:14
PRG ** prgs
Definition: iv.h:25
eb_tpl * com
Definition: elgamal.h:64
block * deltas
Definition: iv.h:26
void random_eb(T t, L... l)
Definition: prg.h:113
void recv_block(block *data, int nblock)
Definition: io_channel.h:136
int n3
Definition: iv.h:13
int output_size()
Definition: xor_tree.h:64
PRP prp
Definition: iv.h:15
void digest(char *a)
Definition: hash.h:38
Definition: halfgate_gen.h:29
block * Y0
Definition: iv.h:20
void privacy_free_to_xor(block *new_block, const block *old_block, const bool *b, int length)
Definition: privacy_free_eva.h:60
bool open(Decom decom, Com com, const void *message, int nbytes)
Definition: com.h:24
Commitment commitment
Definition: iv.h:17
GarbleCircuit * local_gc
Definition: backend.cpp:8
void commit(Decom decom, Com com, const void *message, int nbytes)
Definition: com.h:16
void generic_to_xor(block *new_block, const block *old_block, int length)
Definition: halfgate_eva.h:82
bool checkf2Bob(bool *b, void *f)
Definition: iv.h:565
void set_delta(const block &_delta)
Definition: halfgate_gen.h:51
void set_delta(const block &_delta)
Definition: privacy_free_gen.h:51
block delta
Definition: privacy_free_gen.h:29