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 54 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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

45 changes: 45 additions & 0 deletions demos/GMW_demo/1-out-of-n/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"root": true,
"extends": "eslint:recommended",
"rules": {
"indent": [2, 2, { "SwitchCase": 1 }],
"keyword-spacing": [2, { "before": true, "after": true }],
"object-shorthand": [2, "consistent"],
"no-unused-vars": [1, {"vars": "local", "args": "none"}],
"quote-props": [1, "consistent-as-needed"],
"eqeqeq": [2, "smart"],
"brace-style": 2,
"curly": 2,
"quotes": [2, "single", { "avoidEscape": true }],
"no-trailing-spaces": 2,
"space-before-function-paren": [2, {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
"no-console": 0,
"space-before-blocks": [2, "always"],
"requirejs/no-invalid-define": 2,
"requirejs/no-multiple-define": 2,
"requirejs/no-named-define": 2,
"requirejs/no-commonjs-wrapper": 2,
"requirejs/no-object-define": 1
},
"env": {
"browser": true,
"jquery": true,
"node": true,
"amd": true,
"es6": true
},

"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"plugins": [
"requirejs"
]
}
2 changes: 2 additions & 0 deletions demos/GMW_demo/1-out-of-n/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
3 changes: 3 additions & 0 deletions demos/GMW_demo/1-out-of-n/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
package-lock.json
59 changes: 59 additions & 0 deletions demos/GMW_demo/1-out-of-n/IO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* the IO object to be used for OT
* to pass as the IO parameter for 1-out-of-N.
*
*/
// IO send
const give = function ( op_id, jiff,session_id, tag, msg) {
/* give a message */
const createMSGObj=function (msg,op_id,tag,jiff) {
var four_opts={};
four_opts['opts']=msg;
four_opts['sender_id']=jiff.id;
four_opts['op_id']=op_id;
four_opts['tag']=tag;
return four_opts;
};
var temp=(op_id.split(':')[3]).split('-');
YuwanXiao marked this conversation as resolved.
Show resolved Hide resolved
var to=parseInt(temp[2]); // sending msg to partyid
var from=parseInt(temp[1]);
var four_opts=createMSGObj(msg,op_id,tag,jiff) ;
four_opts = jiff.hooks.execute_array_hooks('beforeOperation', [jiff, 'open', four_opts], 2);
msg=JSON.stringify(four_opts);// jason object
var to_party=to;
if (jiff.id===to) {
to_party=from;
}
var recls=[];
recls.push(to_party);
jiff.emit('OT',recls,msg,true);
return ;
};


// IO receive
const get = function (op_id,jiff,session_id, tag) {
/* get a message */
var temp=(op_id.split(':')[3]).split('-');
YuwanXiao marked this conversation as resolved.
Show resolved Hide resolved
var fromId=parseInt(temp[1]);
var toId=parseInt(temp[2]);
var shareid=op_id+'-'+tag;
var from_party=fromId;
if (jiff.id===fromId) {
from_party=toId;
}

if (jiff.deferreds[shareid] == null) {
jiff.deferreds[shareid] = {};
}
if (jiff.deferreds[shareid][from_party] == null) { // not ready, setup a deferred
jiff.deferreds[shareid][from_party] = new jiff.helpers.Deferred();
}
// resolving in customized listen
return jiff.deferreds[shareid][from_party].promise;
};

module.exports = {
give: give,
get: get
};
21 changes: 21 additions & 0 deletions demos/GMW_demo/1-out-of-n/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Wyatt Howe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions demos/GMW_demo/1-out-of-n/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function (sodium, util) {

// PRF of length m
const PRF = function (k, I) {
var x = Uint8Array.from(util.to_bits(I, 32));
return sodium.crypto_aead_chacha20poly1305_encrypt(x, null, null, new Uint8Array(8), k);
};

// KDF of length t
const KDF = function () {
return sodium.randombytes_buf(32);
};

const encrypt_generic = function (plaintext, key) {
return sodium.crypto_aead_chacha20poly1305_encrypt(plaintext, null, null, new Uint8Array(8), key);
};

const decrypt_generic = function (ciphertext, key) {
return sodium.crypto_aead_chacha20poly1305_decrypt(null, ciphertext, null, new Uint8Array(8), key);
};

return {
PRF: PRF,
KDF: KDF,
encrypt_generic: encrypt_generic,
decrypt_generic: decrypt_generic
};
};
13 changes: 13 additions & 0 deletions demos/GMW_demo/1-out-of-n/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (io, sodium) {
if (sodium == null) {
sodium = require('libsodium-wrappers-sumo');
}

const ot = require('./ot.js')(io, sodium);

return new Promise(function (resolve) {
sodium.ready.then(function () {
resolve(ot);
});
});
};
153 changes: 153 additions & 0 deletions demos/GMW_demo/1-out-of-n/ot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
module.exports = function (io, sodium) {
const util = require('./util.js')(sodium);
const crypto = require('./crypto.js')(sodium, util);

// 1-out-of-2 OT sending
const send_from_2 = function (X1, X2, op_id, jiff,session_id) {
op_id = op_id + ':1in2ot';
var get = io.get.bind(null, op_id,jiff,session_id);
var give = io.give.bind(null, op_id, jiff,session_id);

const a = sodium.crypto_core_ristretto255_scalar_random();
const A = sodium.crypto_scalarmult_ristretto255_base(a);

give('A', util.to_str(A));
get('B').then(function (B_str) {
const B = util.from_str(B_str);

var k0 = sodium.crypto_scalarmult_ristretto255(a, B);
var k1 = sodium.crypto_scalarmult_ristretto255(a, sodium.crypto_core_ristretto255_sub(B, A));

k0 = sodium.crypto_generichash(32, k0);
k1 = sodium.crypto_generichash(32, k1);

const e0 = crypto.encrypt_generic(X1, k0);
const e1 = crypto.encrypt_generic(X2, k1);
give('e', util.to_str([e0, e1]));
});
};

// 1-out-of-2 OT receiving
const receive_from_2 = function (c, op_id, jiff,session_id) {
op_id = op_id + ':1in2ot';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like these are the same as the original 1-out-of-n library, so should be okay when we use it as an npm package (need to deal with jiff_instance parameter as well but I think that will be okay)

var get = io.get.bind(null, op_id, jiff,session_id);
var give = io.give.bind(null, op_id,jiff, session_id);

const b = sodium.crypto_core_ristretto255_scalar_random();
var B = sodium.crypto_scalarmult_ristretto255_base(b);

return new Promise(function (resolve) {
get('A').then(function (A_str) {
const A = util.from_str(A_str);

if (c === 1) {
B = sodium.crypto_core_ristretto255_add(A, B);
}
give('B', util.to_str(B));
get('e').then(function (both_e_str) {
const e12 = util.from_str(both_e_str);
const e = e12[c]; // e_c from [e_1, e_2]

var k = sodium.crypto_scalarmult_ristretto255(b, A);
k = sodium.crypto_generichash(32, k);

var Xc = crypto.decrypt_generic(e, k);
resolve(Xc);
});
});
});
};

// 1-out-of-2 OT sending
const send_from_N = function (X, N, op_id,jiff, session_id) {
var I, j;
op_id = op_id + ':1inNot';
var give = io.give.bind(null, op_id, jiff,session_id);
X = util.sanitize(X); // Check padding and fix if not the right type

if (N == null) {
N = X.length;
}

const l = Math.ceil(Math.log2(N)); // N = 2^l

var K = Array(l);
for (j = 0; j < l; j++) {
K[j] = Array(2);
for (var b = 0; b <= 1; b++) {
K[j][b] = crypto.KDF(); // {K_{j}}^{b}
}
}

var Y = Array(N);
for (I = 0; I < N; I++) {
var i = util.to_bits(I, l); // l bits of I

Y[I] = X[I]; // new Uint8Array(m);
for (j = 0; j < l; j++) {
const i_j = i[j];
const K_j = K[j];
const Kj_ij = K_j[i_j]; // {K_{j}}^{i_j}
Y[I] = util.xor(Y[I], crypto.PRF(Kj_ij, I));
}
}

for (j = 0; j < l; j++) {
const K_j = K[j];

send_from_2(K_j[0], K_j[1], op_id+j,jiff, session_id);
}

for (I = 0; I < N; I++) {
give('I' + String(I), util.to_str(Y[I])); // reveal Y_I
}
};

// 1-out-of-2 OT receiving
const receive_from_N = function (I, N, op_id, jiff,session_id) {
var j;
op_id = op_id + ':1inNot';
var get = io.get.bind(null, op_id, jiff,session_id);

return new Promise(function (resolve) {
const l = Math.ceil(Math.log2(N)); // N = 2^l
const i = util.to_bits(I, l); // l bits of I

var K = Array(l);
for (j = 0; j < l; j++) {
const i_j = i[j]; // bit j=i_j of I
K[j] = receive_from_2(i_j, op_id+j, jiff,session_id); // pick {K_{j}}^{b} which is also {K_{j}}^{i_j}
}

Promise.all(K).then(function (K) {
var Y_I = new Uint8Array(32);
for (var pI = 0; pI < N; pI++) {
const pY_pI = get('I' + String(pI));
if (pI === I) {
Y_I = pY_pI;
}
}

Y_I.then(function (Y_I_str) {
const Y_I = util.from_str(Y_I_str);

var X_I = Y_I; // new Uint8Array(m);
for (j = 0; j < l; j++) {
const Kj_ij = K[j]; // {K_{j}}^{i_j}
X_I = util.xor(X_I, crypto.PRF(Kj_ij, I));
}

// Done
resolve(X_I);
});
});
});
};

return {
send: send_from_N,
receive: receive_from_N,
single_send: send_from_2,
single_receive: receive_from_2
};
};
41 changes: 41 additions & 0 deletions demos/GMW_demo/1-out-of-n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "1-out-of-n",
"version": "0.3.1",
"description": "1-out-of-n oblivious transfer",
"main": "index.js",
"files": [
"index.js",
"lib/crypto.js",
"lib/ot.js",
"lib/util.js"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/wyatt-howe/1-out-of-n.git"
},
"keywords": [
"1-in-n",
"1-out-of-n",
"ot",
"oblivious-transfer",
"oblivious",
"transfer"
],
"author": "Wyatt Howe <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/wyatt-howe/1-out-of-n/issues"
},
"homepage": "https://github.com/wyatt-howe/1-out-of-n/#README",
"dependencies": {
"1-out-of-n": "^0.3.0",
"libsodium-wrappers-sumo": "^0.7.6"
},
"dev-dependencies": {
"eslint": "^7.2.0",
"eslint-plugin-requirejs": "^4.0.0"
}
}
Loading