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

Class/protocols/preprocess #293

Merged
merged 2 commits into from
Jun 6, 2024
Merged
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
7 changes: 5 additions & 2 deletions lib/client/api/protocols.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const numbers = require('../protocols/preprocessing/numbers.js');
const bits = require('../protocols/preprocessing/bits.js');
const _numbers = require('../protocols/preprocessing/numbers.js');
const _bits = require('../protocols/preprocessing/bits.js');
const triplets = require('../protocols/preprocessing/triplets.js');
const quotients = require('../protocols/preprocessing/quotients.js');
const sampling = require('../protocols/preprocessing/sampling.js');

const numbers = new _numbers();
const bits = new _bits();

/**
* Contains miscellaneous protocols (mostly used in preprocessing)
* @name protocols
Expand Down
16 changes: 9 additions & 7 deletions lib/client/protocols/preprocessing/bits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
class ProprocessBits {
/**
* Generates a random bit under MPC by xoring all bits sent by participating parties using smult / beaver triples
* @function generate_random_bit_bgw
Expand All @@ -14,7 +14,7 @@ module.exports = {
* - compute_threshold: the threshold to use during computation: defaults to compute_list.length
* @return {Object} contains 'share' (this party's share of the generated bit) and 'promise'
*/
generate_random_bit_smult: function (jiff, threshold, receivers_list, compute_list, Zp, params) {
generate_random_bit_smult(jiff, threshold, receivers_list, compute_list, Zp, params) {
if (params.compute_threshold == null) {
params.compute_threshold = threshold;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ module.exports = {
promise = random_bit.value;
}
return { share: random_bit, promise: promise };
},
}
/**
* Generates a random bit under MPC by xoring all bits sent by participating parties using smult_bgw
* @function generate_random_bit_bgw
Expand All @@ -64,7 +64,7 @@ module.exports = {
* - compute_threshold: the threshold to use during computation: defaults to compute_list.length
* @return {Object} contains 'share' (this party's share of the generated bit) and 'promise'
*/
generate_random_bit_bgw: function (jiff, threshold, receivers_list, compute_list, Zp, params) {
generate_random_bit_bgw(jiff, threshold, receivers_list, compute_list, Zp, params) {
if (params.compute_threshold == null) {
params.compute_threshold = Math.floor((compute_list.length + 1) / 2); // honest majority BGW
}
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = {
promise = random_bit.value;
}
return { share: random_bit, promise: promise };
},
}
/**
* Generates a sequence of random bits under MPC
* @function generate_random_bits
Expand All @@ -118,7 +118,7 @@ module.exports = {
* @param {object} protocols - the protocols to use for preprocessing
* @return {Object} contains 'share' (array of secret shares bits) and 'promise'
*/
generate_random_bits: function (jiff, threshold, receivers_list, compute_list, Zp, params, protocols) {
generate_random_bits(jiff, threshold, receivers_list, compute_list, Zp, params, protocols) {
if (params.count == null) {
params.count = 1;
}
Expand Down Expand Up @@ -151,4 +151,6 @@ module.exports = {
}
return { share: bits, promise: Promise.all(promises) };
}
};
}

module.exports = ProprocessBits;
13 changes: 7 additions & 6 deletions lib/client/protocols/preprocessing/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const jiff_share_all_number = function (jiff, n, threshold, receivers_list, comp
return { share: result, promise: promise };
};

module.exports = {
class PreprocessNumber {
/**
* Creates shares of an unknown random number. Every party comes up with its own random number and shares it.
* Then every party combines all the received shares to construct one share of the random unknown number
Expand All @@ -65,14 +65,14 @@ module.exports = {
* - compute_threshold: the threshold to use during computation: defaults to compute_list.length
* @return {Object} contains 'share' (this party's share of the result) and 'promise'
*/
generate_random_number: function (jiff, threshold, receivers_list, compute_list, Zp, params) {
generate_random_number = (jiff, threshold, receivers_list, compute_list, Zp, params) => {
if (params.op_id == null && params.output_op_id == null) {
params.op_id = jiff.counters.gen_op_id2('generate_random_number', receivers_list, compute_list);
} else if (params.op_id == null) {
params.op_id = 'preprocessing:' + params.output_op_id + ':' + compute_list.join(',');
}
return jiff_share_all_number(jiff, jiff.helpers.random(Zp), threshold, receivers_list, compute_list, Zp, params);
},
};
/**
* Creates shares of 0, such that no party knows the other parties' shares.
* Every party secret shares 0, then every party sums all the shares they received, resulting
Expand All @@ -90,12 +90,13 @@ module.exports = {
* - compute_threshold: the threshold to use during computation: defaults to compute_list.length
* @return {Object} contains 'share' (this party's share of the result) and 'promise'
*/
generate_zero: function (jiff, threshold, receivers_list, compute_list, Zp, params) {
generate_zero = (jiff, threshold, receivers_list, compute_list, Zp, params) => {
if (params.op_id == null && params.output_op_id == null) {
params.op_id = jiff.counters.gen_op_id2('generate_zero', receivers_list, compute_list);
} else if (params.op_id == null) {
params.op_id = 'preprocessing:' + params.output_op_id + ':' + compute_list.join(',');
}
return jiff_share_all_number(jiff, 0, threshold, receivers_list, compute_list, Zp, params);
}
};
};
}
module.exports = PreprocessNumber;
Loading