From 4e3f00cdb585f2e9a7bce72fee0cfe919691bc5b Mon Sep 17 00:00:00 2001 From: rasswanth <43314053+rasswanth-s@users.noreply.github.com> Date: Sun, 10 Jan 2021 14:43:29 +0530 Subject: [PATCH 1/3] Update ast.ml Adding Function to convert base-type to string. --- EzPC/EzPC/ast.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/EzPC/EzPC/ast.ml b/EzPC/EzPC/ast.ml index 77d4ab52..3d94ed1d 100644 --- a/EzPC/EzPC/ast.ml +++ b/EzPC/EzPC/ast.ml @@ -155,7 +155,16 @@ let unop_to_string (u:unop) :string = | U_minus -> "-" | Bitwise_neg -> "~" | Not -> "!" - + +let bt_to_string (bt:base_type) :string = + match bt with + | UInt32 -> "uint32_t" + | UInt64 -> "uint64_t" + | Int32 -> "int32_t" + | Int64 -> "int64_t" + | Bool -> "uint32_t" + + let binop_to_string (b:binop) :string = match b with | Sum -> "+" From 39e8dc41dda659228da403f82a0db7b03a3e0c1f Mon Sep 17 00:00:00 2001 From: rasswanth <43314053+rasswanth-s@users.noreply.github.com> Date: Sun, 10 Jan 2021 14:49:02 +0530 Subject: [PATCH 2/3] Update codegen.ml Outputting the data type as a parameter for output queue. --- EzPC/EzPC/codegen.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/EzPC/EzPC/codegen.ml b/EzPC/EzPC/codegen.ml index 2b005cc1..2eef9857 100644 --- a/EzPC/EzPC/codegen.ml +++ b/EzPC/EzPC/codegen.ml @@ -497,7 +497,8 @@ let rec o_stmt (g:gamma) (s:stmt) :comp * gamma = aux (App_codegen ("add_to_output_queue", [Base_e (Var { name = "out_q"; index = 0 } |> mk_dsyntax ""); Output_g (r, sl, elmt_of_e); Base_e e_role; - Base_e (Var { name = "cout"; index = 0 } |> mk_dsyntax "")])) + Base_e (Var { name = "cout"; index = 0 } |> mk_dsyntax ""); + Base_e (Var { name = "\""^ (bt_to_string bt)^ "\""; index = 0 } |> mk_dsyntax "") ])) in o_codegen_stmt g (Seq_codegen (print_output_msg, output_gate_loops)) @@ -569,7 +570,8 @@ and read_or_write_interim (g:gamma) (write:bool) (e_var:expr) (t:typ) (f:string) Base_e (Var {name = "role"; index = 0 } |> mk_dsyntax ""); Base_e (Var {name = fstream_add_name; index = 0 } |> mk_dsyntax ""); Base_e (Var {name = fstream_rand_name; index = 0 } |> mk_dsyntax ""); - Base_e (Var { name = "out_q"; index = 0 } |> mk_dsyntax "")]) + Base_e (Var { name = "out_q"; index = 0 } |> mk_dsyntax ""); + Base_e (Var { name = "\""^ (bt_to_string bt)^ "\""; index = 0 } |> mk_dsyntax "")]) else let fname = if Config.get_bitlen () = 32 then "read_share" From 206176aa3061ca0f1ecfeb1f6bb0abca2aa32c0a Mon Sep 17 00:00:00 2001 From: rasswanth <43314053+rasswanth-s@users.noreply.github.com> Date: Sun, 10 Jan 2021 15:01:49 +0530 Subject: [PATCH 3/3] Update ezpc.h Adding type value to output queue for outputting signed and unsigned data. --- EzPC/EzPC/ABY_example/common/ezpc.h | 39 ++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/EzPC/EzPC/ABY_example/common/ezpc.h b/EzPC/EzPC/ABY_example/common/ezpc.h index a283d1f1..0f0183ec 100644 --- a/EzPC/EzPC/ABY_example/common/ezpc.h +++ b/EzPC/EzPC/ABY_example/common/ezpc.h @@ -116,6 +116,7 @@ struct output_queue_elmt { enum {PrintMsg, PrintValue } kind; string msg; share *ptr; + bool type; // To know the Signedness of the data(0:unsigned 1 :signed) }; typedef vector output_queue; @@ -125,15 +126,22 @@ typedef vector output_queue; void add_to_output_queue(output_queue &q, share *ptr, e_role role, - ostream &os) + ostream &os, + string type) { - struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintValue, "", ptr }; - q.push_back(elmt); + if(type=="uint32_t"){ + struct output_queue_elmt elmt{ os, role, output_queue_elmt::PrintValue, "", ptr ,0}; + q.push_back(elmt); + } + else{ + struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintValue, "", ptr ,1}; + q.push_back(elmt); + } } void add_print_msg_to_output_queue (output_queue &q, string msg, e_role role, ostream &os) { - struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintMsg, msg, NULL }; + struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintMsg, msg, NULL ,0}; q.push_back(elmt); } @@ -148,9 +156,21 @@ void flush_output_queue(output_queue &q, e_role role, uint32_t bitlen) if (it->kind == output_queue_elmt::PrintValue) { if(it->role == ALL || it->role == role) { //if the queue element role is same as mine if(bitlen == 32) { //output to the stream - it->os << it->ptr->get_clear_value() << endl; + + if(it->type==0){ + it->os << it->ptr->get_clear_value() << endl;} + else{ + it->os << it->ptr->get_clear_value() << endl;} + + } else { - it->os << it->ptr->get_clear_value() << endl; + + if(it->type==0){ + it->os << it->ptr->get_clear_value() << endl;} + else{ + it->os << it->ptr->get_clear_value() << endl;} + + } } } else { @@ -170,15 +190,16 @@ void flush_output_queue(output_queue &q, e_role role, uint32_t bitlen) void write_share(share *ptr, Circuit *circ, uint32_t bitlen, e_role role, ofstream &of_add, ofstream &of_rand, - output_queue &q) + output_queue &q, + string type ) { /* input shares of a random value, SERVER handles rand, CLIENT handles added shares */ share *rand_sh = role == SERVER ? circ->PutINGate((uint32_t)rand(), bitlen, SERVER) : circ->PutDummyINGate(bitlen); /* add the input share with the random share */ share *add_sh = circ->PutADDGate(ptr, rand_sh); /* add to the output q, so that it gets written out */ - add_to_output_queue(q, circ->PutOUTGate(rand_sh, SERVER), SERVER, of_rand); - add_to_output_queue(q, circ->PutOUTGate(add_sh, CLIENT), CLIENT, of_add); + add_to_output_queue(q, circ->PutOUTGate(rand_sh, SERVER), SERVER, of_rand,type); + add_to_output_queue(q, circ->PutOUTGate(add_sh, CLIENT), CLIENT, of_add,type); /* TODO: can we optimize OUTPUT gates for the random value, since we already have its clear value in hand? */ return; }