Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Issue #4 Signed and Unsigned #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions EzPC/EzPC/ABY_example/common/ezpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_elmt> output_queue;
Expand All @@ -125,15 +126,22 @@ typedef vector<output_queue_elmt> 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);
}

Expand All @@ -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<uint32_t>() << endl;

if(it->type==0){
it->os << it->ptr->get_clear_value<uint32_t>() << endl;}
else{
it->os << it->ptr->get_clear_value<int32_t>() << endl;}


} else {
it->os << it->ptr->get_clear_value<uint64_t>() << endl;

if(it->type==0){
it->os << it->ptr->get_clear_value<uint64_t>() << endl;}
else{
it->os << it->ptr->get_clear_value<int64_t>() << endl;}


}
}
} else {
Expand All @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion EzPC/EzPC/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> "+"
Expand Down
6 changes: 4 additions & 2 deletions EzPC/EzPC/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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<uint32_t>"
Expand Down