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

[WIP] GMW share/open and XOR/AND bit operations #200

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
cb13e26
finish bmw share and open function
YuwanXiao Jun 8, 2020
a74011c
Small changes: Linting in files of BMW_demo, return promise to party.…
p-flock Jun 9, 2020
44f6c74
add test for bmw share and open
YuwanXiao Jun 10, 2020
0b0bb3e
add test for bmw share and open
YuwanXiao Jun 10, 2020
3c6c719
comment out console output
YuwanXiao Jun 10, 2020
8879c11
add test for gmw_xor and rename bmw to gmw
YuwanXiao Jun 16, 2020
86cc7b8
rename bmw to gmw
YuwanXiao Jun 16, 2020
062567d
rename bmw to gmw
YuwanXiao Jun 16, 2020
f9677bc
rename bmw to gmw
YuwanXiao Jun 16, 2020
8be7626
change dir name from bmw to gmw
YuwanXiao Jun 16, 2020
dc27178
remove duplicate dir
YuwanXiao Jun 16, 2020
1737173
update skeleton code for OT
YuwanXiao Jun 16, 2020
9327928
fix a require bug
YuwanXiao Jun 17, 2020
3a5c3df
OT implementation with single threaded test using emit and listen
YuwanXiao Jun 17, 2020
d03c1f1
extend to >2 GMW and function with test code
YuwanXiao Jun 19, 2020
e48c83a
update with only partcipating two party for debug test
YuwanXiao Jun 19, 2020
1b436a6
updated and among multiple party, parallel test hanging bug to fix
YuwanXiao Jun 19, 2020
def522c
adjust xor and finish parallel test for gmw_xor
YuwanXiao Jun 25, 2020
9edaeac
count bug with async listen
YuwanXiao Jun 29, 2020
514bf0b
Refactor GMW_XOR function to work similarly to secret addition:
p-flock Jun 29, 2020
8b8c4f2
Update GMW demo:
p-flock Jun 29, 2020
e5aefc1
and with ot function and test
YuwanXiao Jul 1, 2020
14e0cbe
delete unused file
YuwanXiao Jul 1, 2020
cc75748
delete unused file
YuwanXiao Jul 1, 2020
4ad8432
delete unused filr
YuwanXiao Jul 1, 2020
644da3d
delete unused file
YuwanXiao Jul 1, 2020
a5c0b2c
clean up log
YuwanXiao Jul 1, 2020
d5a9837
rename gmw_OT to gmw_and
YuwanXiao Jul 1, 2020
b451d80
clean up log and add document for functions
YuwanXiao Jul 1, 2020
b59c62a
to be update by new one
YuwanXiao Jul 1, 2020
4da71b5
delete gmw_OT
YuwanXiao Jul 1, 2020
1e7c3fd
Delete browser demo, no need
YuwanXiao Jul 2, 2020
d3d5e7d
delete browser demo, no need
YuwanXiao Jul 2, 2020
a0438cf
update readme and jsdoc formatting
YuwanXiao Jul 2, 2020
4decf0b
integrate with i-out-of-n lib,1. tag=0, and 2.overwritten resoving, 3…
YuwanXiao Jul 10, 2020
c6bd9ce
finish merging OT with i-out-of-n lib among multiparty
YuwanXiao Jul 16, 2020
8021f08
Delete example from 1-out-of-n lib
YuwanXiao Jul 16, 2020
6b3870c
delete ascii.js from 1-out-of-n lib
YuwanXiao Jul 16, 2020
b869f6e
delete index from 1-out-of-n lib
YuwanXiao Jul 16, 2020
72ff514
updating submodule
YuwanXiao Jul 16, 2020
f2a9788
Merge branch '197_GMW' of github.com:multiparty/jiff into 197_GMW
YuwanXiao Jul 16, 2020
ecde765
updating submodule
YuwanXiao Jul 16, 2020
632cb74
submodule update IO.js
YuwanXiao Jul 16, 2020
0b8bb9d
clean 1-out-of-n structure
YuwanXiao Jul 20, 2020
3809d09
delete submodule
YuwanXiao Jul 20, 2020
a7d6f6a
Remove a submodule.
YuwanXiao Jul 20, 2020
6228e1b
Remove a submodule.
YuwanXiao Jul 20, 2020
4840a6a
update op_id with ot.js
YuwanXiao Jul 21, 2020
c9687c7
merging share and open to lib
YuwanXiao Jul 21, 2020
53f9a3d
add missing event.js
YuwanXiao Jul 21, 2020
fb0f077
add missing file
YuwanXiao Jul 21, 2020
674c3e0
add dependency
YuwanXiao Jul 22, 2020
ffc23e6
add dependency
YuwanXiao Jul 22, 2020
902ebb0
add dependency
YuwanXiao Jul 22, 2020
2cb878f
code review adjustment
YuwanXiao Jul 22, 2020
c55fd16
merging to lib
YuwanXiao Jul 27, 2020
e6ec73d
update IO with updated generalized ot lib
YuwanXiao Jul 27, 2020
2912739
merge ot listen into lib
YuwanXiao Jul 28, 2020
7016b50
Add GMW suite to travis config
p-flock Jul 29, 2020
42f523d
add unit test for gmw
YuwanXiao Jul 29, 2020
bb3ef99
add missed file
YuwanXiao Jul 29, 2020
c2fcf14
adding browser version demo
YuwanXiao Jul 31, 2020
7d4bc51
update readme
YuwanXiao Jul 31, 2020
bdeb2ce
Merge branch 'master' into 197_GMW
p-flock Aug 7, 2020
9b2ef1e
Merge branch 'master' into 197_GMW
wyatt-howe Aug 10, 2020
2cd7ce0
fix array sharing require path
p-flock Aug 10, 2020
ed23049
Merge branch '197_GMW' of github.com:multiparty/jiff into 197_GMW
p-flock Aug 10, 2020
836a9f4
npm update
YuwanXiao Aug 11, 2020
4aa718b
original jiff-client
YuwanXiao Aug 11, 2020
1d06c01
adding package.json
YuwanXiao Aug 11, 2020
c217ce9
update npm version
YuwanXiao Aug 12, 2020
acfd138
Fix README.md in demos/ (#206) (#210)
p-flock Aug 12, 2020
5aeb436
recover API binding for jiff.open_ND_array()
p-flock Aug 12, 2020
7f6480a
testing and
YuwanXiao Aug 14, 2020
dbd50b9
test update
YuwanXiao Aug 14, 2020
8fc932d
Update jiff-client.js (do `npm run-script build`)
wyatt-howe Aug 23, 2020
0be7937
Rename `GMW_demo` to `GMW-protocol`
wyatt-howe Aug 23, 2020
dd8e1ee
Clean up GMW namespace and use encapsulation like the other protocols do
wyatt-howe Aug 23, 2020
d82eabd
backup
wyatt-howe Sep 8, 2020
b2c866d
Correct misuse of `Math.random` and instead use `jiff.helpers.random`
wyatt-howe Nov 29, 2020
c761cc1
Lint code for readability and typos
wyatt-howe Nov 29, 2020
1adcad9
Disable logs for oblivious transfer—there're too many, and it works fine
wyatt-howe Nov 29, 2020
7c0c4ae
Typo in `jiff_debugging` extension
wyatt-howe Nov 29, 2020
7f7097b
Assert that party IDs be numbers
wyatt-howe Nov 29, 2020
538312b
Add arithmetic and composition GMW protocols
wyatt-howe Nov 29, 2020
42f0a6a
Preliminary demo demonstating arithmetic powered by GMW
wyatt-howe Nov 29, 2020
df50fbc
Finish GMW arithmetic demo (although no test.js yet)
wyatt-howe Nov 30, 2020
abb0302
Update jiff-client.js and remove a debugging line
wyatt-howe Nov 30, 2020
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
67 changes: 67 additions & 0 deletions demos/BMW_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Sum Demo

Description and guide for computing sum of inputs with secure MPC.

## Secure summation protocol

The implementation of the following protocol may be found in jiff/demos/sum/mpc.js lines 23 through 36.

Input: arbitrary number of parties P1,...Pn with inputs x1,...xn

Each party Pi does the following:
- secret shares their input xi to all other parties
- iteratively uses secret addition protocol to add all of the shares they received together to get a total sum
- reconstructs output sum in final opening step

## Note on the code

The compute function in mpc.js executes once for every single party. In line 29 of *mpc.js*, the parties' shares are
created. It is important to note that the variable created in that line, *shares*, is not just the secret shares belonging
to a single parties' inputs but rather includes all shares that that party has received. The *for* loop in line 31 of *mpc.js* loops
through a single party's shares of all of those parties' inputs.

Note also that the parties have to iteratively use secret addition instead of doing a single sum of their shares of x1,...,xn
because in JIFF the secret addition protocol is a binary operation. I.e. if you have shares a, b, and c that you want to
add, then you can't do
```
var output = a.sadd(b,c);
```
but instead have to do
```
var d = a.sadd(b);
var output = d.sadd(c);
```

## Legal inputs

This instantiation of summation only supports positive integer inputs. For an implementation that supports fixed-point
numbers, see the fixedpoint-sum demo.

## Running Demo
1. Running a server:
```shell
node demos/sum/server.js
```

2. Either open browser based parties by going to *http://localhost:8080/demos/sum/client.html* in the browser, or a node.js party by running
```shell
node demos/sum/party.js <input> [<party count> [<computation_id> [<party id>]]]]'
```

3. Running tests: run the following. Note that you *do not* need to have the server running when running the tests; they run the server on their own.
```shell
npm run-script test-demo -- demos/sum/test.js
```
## File structure
The demo consists of the following parts:
1. Server script: *server.js*
2. Web Based Party: Made from the following files:
* *client.html*: UI for the browser.
* *client.js*: Handlers for UI buttons and input validations.
3. Node.js-Based Party:
* *party.js*: Main entry point. Parses input from the command line and initializes the computation.
4. The MPC protocol: Implemented in *mpc.js*. This file is used in both the browser and node.js versions of the demo.
5. test.js: mocha unit tests.
6. Documentation:
* This *README.md* file.

227 changes: 227 additions & 0 deletions demos/BMW_demo/bmw_OT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/**
OT
**/



// csecret=={""}
const BMW=require('./bmw_share.js');
const BMW_OPEN=require('./bmw_open.js');
function send_opts(jiff,csecret, threshold, receivers_list, senders_list, Zp, share_id) {
if (receivers_list == null) {
receivers_list = [];
var i;
for (i = 1; i <= jiff.party_count; i++) {
if (jiff.id!==i) {
receivers_list.push(i);
}
}
}
//console.log('in send_ops');
var four_opts=OTGate(csecret);// object
four_opts['sender_id']=jiff.id;
four_opts = jiff.hooks.execute_array_hooks('beforeOperation', [jiff, 'open', four_opts], 2);
var mymsg=JSON.stringify(four_opts);
//console.log('fmsg'+mymsg);
//console.log('send msg to ');
//console.log(receivers_list);
jiff.emit('custom',receivers_list,mymsg,true);
var ssid=1;
if (jiff.id===1) {
ssid=2;
}
jiff.listen('custom',function (ssid,msg) {

//console.log('hh'+msg);
msg=JSON.parse(msg);

//var sid=msg['sender_id'];
var my_choose=csecret[1]+','+csecret[2];

var result=msg[my_choose];
//console.log('my json get'+my_choose+' '+result+' id'+jiff.id);



var output_shares=BMW.bmw_jiff_share(jiff,result);
//console.log('output_share');
//console.log(output_shares);

var final_deferred = $.Deferred();
var final_promise = final_deferred.promise();
var allPromises = [];
for (var k = 1; k <=Object.keys(output_shares).length; k++) {
allPromises.push(BMW_OPEN.bmw_jiff_open(jiff,output_shares[k]));
// allPromises.push(output_shares[k].value);
}

Promise.all(allPromises).then(function (results) {
//console.log('open up in ot!',results);
//console.log(output_shares);
jiff.disconnect(true, true);

// final_deferred.resolve(results);

});
// return final_promise;
/*
final_promise.then(function (v) {
console.log("reconstruct");
var csec={'1':v[0],'2':v[1]};
console.log(csec);
var re=ooo(jiff,v);
console.log(re);
});
*/
});

//bmw_constant_share(jiff, four_opts, threshold, receivers_list, senders_list, Zp, share_id);
}
/*
function bmw_constant_share(jiff, four_opts, threshold, receivers_list, senders_list, Zp, share_id) {
// 1001,,,
var i, p_id;

// defaults
if (Zp == null) {
Zp = jiff.Zp;
}
if (receivers_list == null) {
receivers_list = [];
for (i = 1; i <= jiff.party_count; i++) {
receivers_list.push(i);
}
} else {
jiff.helpers.sort_ids(receivers_list);
}
if (senders_list == null) {
senders_list = [];
for (i = 1; i <= jiff.party_count; i++) {
senders_list.push(i);
}
} else {
jiff.helpers.sort_ids(senders_list);
}
if (threshold == null) {
threshold = receivers_list.length;
}
if (threshold < 0) {
threshold = 2;
}
if (threshold > receivers_list.length) {
threshold = receivers_list.length;
}

// if party is uninvolved in the share, do nothing
if (receivers_list.indexOf(jiff.id) === -1 && senders_list.indexOf(jiff.id) === -1) {
return {};
}

// compute operation id
if (share_id == null) {
share_id = jiff.counters.gen_op_id2('share', receivers_list, senders_list);
}

// stage sending of shares
if (senders_list.indexOf(jiff.id) > -1) {
// Call hook
// four_opts = jiff.hooks.execute_array_hooks('beforeShare', [jiff, four_opts, threshold, receivers_list, senders_list, Zp], 1);

// compute shares
var shares=four_opts;
// Call hook
// shares = jiff.hooks.execute_array_hooks('afterComputeShare', [jiff, shares, threshold, receivers_list, senders_list, Zp], 1);

// send shares
for (i = 0; i < receivers_list.length; i++) {
p_id = receivers_list[i];
if (p_id === jiff.id) {
continue;
}

// send encrypted and signed shares_id[p_id] to party p_id
var msg = {party_id: p_id, share: shares[p_id], op_id: share_id};
console.log('!!sendingOTmsg '+msg.share+' '+msg.party_id);
msg = jiff.hooks.execute_array_hooks('beforeOperation', [jiff, 'share', msg], 2);
msg['share'] = jiff.hooks.encryptSign(jiff, msg['share'].toString(90), jiff.keymap[msg['party_id']], jiff.secret_key);
jiff.socket.safe_emit('share', JSON.stringify(msg));

}
}

// stage receiving of shares
var result = {};
if (receivers_list.indexOf(jiff.id) > -1) {
// setup a map of deferred for every received share
if (jiff.deferreds[share_id] == null) {
jiff.deferreds[share_id] = {};
}

var _remaining = senders_list.length;
for (i = 0; i < senders_list.length; i++) {
p_id = senders_list[i];
if (p_id === jiff.id) { // Keep party's own share
var my_share = jiff.hooks.execute_array_hooks('receiveShare', [jiff, p_id, shares[p_id]], 2);
result[p_id] = new jiff.SecretShare(my_share, receivers_list, threshold, Zp);
_remaining--;
continue;
}

// check if a deferred is set up (maybe the message was previously received)
if (jiff.deferreds[share_id][p_id] == null) { // not ready, setup a deferred
jiff.deferreds[share_id][p_id] = new jiff.helpers.Deferred();

}

var promise = jiff.deferreds[share_id][p_id].promise;
// destroy deferred when done
(function (promise, p_id) { // p_id is modified in a for loop, must do this to avoid scoping issues.
promise.then(function () {
delete jiff.deferreds[share_id][p_id];
_remaining--;
if (_remaining === 0) {
delete jiff.deferreds[share_id];
}
});
})(promise, p_id);

// receive share_i[id] from party p_id
result[p_id] = new jiff.SecretShare(promise, receivers_list, threshold, Zp);
}
}

return result;



}
*/

function OT_option(cx,cy,i_shares) {
var op=(cx&i_shares[1])^(cy&i_shares[2]);
return op;
}

function OTGate(i_shares) {
var opt1=OT_option(0,0,i_shares);
var opt2=OT_option(0,1,i_shares);
var opt3=OT_option(1,0,i_shares);
var opt4=OT_option(1,1,i_shares);
var msg={'0,0':opt1,'0,1':opt2,'1,0':opt3,'1,1':opt4};
return msg;
}
/*
function ooo(ls) {
var re=ls[1];
for (var i=2;i<=Object.keys(ls).length;i++) {
re=re^ls[i];

}
return re;

}
*/
module.exports = {
send_opts: send_opts,
// bmw_jiff_share:bmw_jiff_share
};
Loading