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/shamir #295

Merged
merged 4 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/sharing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const shareProtocol = require('../protocols/shamir/share.js');
const openProtocol = require('../protocols/shamir/open.js');
const _shareProtocol = require('../protocols/shamir/share.js');
const _openProtocol = require('../protocols/shamir/open.js');
const reshareProtocol = require('../protocols/shamir/reshare.js');
const arraysSharing = require('../protocols/arrays/api.js');

const openProtocol = new _openProtocol();
const shareProtocol = new _shareProtocol();

module.exports = function (jiffClient) {
/**
* Share a secret input
Expand Down
4 changes: 2 additions & 2 deletions lib/client/arch/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function Hooks(jiffClient) {
* @param threshold {number} - threshold of sharing
* @param Zp {number} - the field prime
*/
Hooks.prototype.computeShares = shamir_share.jiff_compute_shares;
Hooks.prototype.reconstructShare = shamir_open.jiff_lagrange;
Hooks.prototype.computeShares = shamir_share.prototype.jiff_compute_shares;
Hooks.prototype.reconstructShare = shamir_open.prototype.jiff_lagrange;

// Crypto hooks
Hooks.prototype.encryptSign = function (jiffClient, message) {
Expand Down
12 changes: 7 additions & 5 deletions lib/client/protocols/shamir/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const jiff_broadcast = function (jiff, share, parties, op_id) {
}
};

module.exports = {
class ShamirOpen {
/**
* Open up the given share to the participating parties.
* @function jiff_open
Expand All @@ -37,7 +37,7 @@ module.exports = {
* @returns {?promise} a (JQuery) promise to the open value of the secret, or null if the calling party is not a receiving party
*
*/
jiff_open: function (jiff, share, parties, op_id) {
jiff_open = (jiff, share, parties, op_id) => {
if (!(share.jiff === jiff)) {
throw 'share does not belong to given instance';
}
Expand Down Expand Up @@ -111,7 +111,7 @@ module.exports = {
}

return null;
},
};
/**
* Uses Lagrange polynomials to interpolate the polynomial
* described by the given shares (points)
Expand All @@ -122,7 +122,7 @@ module.exports = {
* @returns {number} the value of the polynomial at x=0 (the secret value)
*
*/
jiff_lagrange: function (jiff, shares) {
jiff_lagrange(jiff, shares) {
const lagrange_coeff = []; // will contain shares.length many elements.

// Compute the Langrange coefficients at 0.
Expand Down Expand Up @@ -150,4 +150,6 @@ module.exports = {

return recons_secret;
}
};
}

module.exports = ShamirOpen;
18 changes: 10 additions & 8 deletions lib/client/protocols/shamir/share.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
class ShamirShare {
/**
* Default way of computing shares (can be overridden using hooks).
* Compute the shares of the secret (as many shares as parties) using Shamir secret sharing
Expand All @@ -13,7 +13,7 @@ module.exports = {
* point from the polynomial.
*
*/
jiff_compute_shares: function (jiff, secret, parties_list, threshold, Zp) {
jiff_compute_shares(jiff, secret, parties_list, threshold, Zp) {
const shares = {}; // Keeps the shares

// Each player's random polynomial f must have
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = {
}

return shares;
},
}
/**
* Share given secret to the participating parties.
* @ignore
Expand All @@ -68,7 +68,7 @@ module.exports = {
* if the party that calls this function is not a receiver then the map
* will be empty.
*/
jiff_share: function (jiff, secret, threshold, receivers_list, senders_list, Zp, share_id) {
jiff_share = (jiff, secret, threshold, receivers_list, senders_list, Zp, share_id) => {
let p_id;

// defaults
Expand Down Expand Up @@ -147,8 +147,8 @@ module.exports = {
}

let _remaining = senders_list.length;
for (i = 0; i < senders_list.length; i++) {
p_id = senders_list[i];
for (let i = 0; i < senders_list.length; i++) {
p_id = senders_list[parseInt(i, 10)];
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);
Expand Down Expand Up @@ -182,5 +182,7 @@ module.exports = {
}

return result;
}
};
};
}

module.exports = ShamirShare;
2 changes: 1 addition & 1 deletion lib/server/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ServerHooks.prototype.onInitializeUsedId = function (jiff, computation_id, party
};

// Computing hooks
ServerHooks.prototype.computeShares = shamir_share.jiff_compute_shares;
ServerHooks.prototype.computeShares = shamir_share.prototype.jiff_compute_shares;

// Crypto hooks
ServerHooks.prototype.generateKeyPair = function (jiff) {
Expand Down
Loading