Skip to content

Commit ab2b4c6

Browse files
committed
Removed FIELD from aggregation calls.
1 parent 362b62d commit ab2b4c6

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

client/script/ssCreate.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ var submitAll = function (sessionstr, emailstr, targetUrl, inputSources, la) {
297297
);
298298

299299
// Secret-share the value in each key-value pair
300-
// Note: FIELD is a global defined and imported from ../shared/mpc.js
301-
var secretShared = secretShareValues(keyValuePairs, FIELD),
300+
var secretShared = secretShareValues(keyValuePairs),
302301
serviceShares = secretShared.service,
303302
analystShares = secretShared.analyst;
304303

@@ -476,8 +475,6 @@ var submissionHandling = function (inputSources, targetUrl) {
476475
function makeBlank(instance, td, row, col, prop, value, cellProperties) {
477476
Handsontable.renderers.NumericRenderer.apply(this, arguments);
478477
td.style.background = '#f3f3f3';
479-
//td.style['background-image'] = 'linear-gradient(to right top, transparent 33%, black 33%, black 66%, transparent 66%)';
480-
//td.style['background-size'] = '3px 3px';
481478
}
482479

483480
function outsideRangeRenderer(instance, td, row, col, prop, value, cellProperties) {

server/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
'use strict';
1515

16-
// TODO: check how to chain
1716
function templateToJoiSchema(template, joiFieldType) {
1817
var schema = {};
1918
for (var key in template) {
@@ -357,7 +356,13 @@ app.post('/get_aggregate', function (req, res) {
357356
// make sure query result is not empty
358357
if (data.length >= 1) {
359358
console.log('Computing share of aggregate.');
360-
var serviceShare = mpc.aggregateShares(data, true);
359+
360+
var invalidShareCount = mpc.countInvalidShares(data, true),
361+
serviceShare = mpc.aggregateShares(data, true);
362+
363+
// TODO: we should set a threshold and abort if there are too
364+
// many invalid shares
365+
console.log('Invalid share count:', invalidShareCount);
361366

362367
console.log('Sending aggregate.');
363368
res.json(serviceShare);

shared/mpc.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*
77
*/
88

9+
'use strict';
10+
911
var MAX_VALUE = 4294967296; // 2^32
1012

1113
/**
@@ -110,7 +112,7 @@ function countInvalidShares (data, db) {
110112
}
111113
else {
112114
isInvalid = function (x) {
113-
var result = parseInt(x, 10);
115+
var result = parseInt(x, 10),
114116
invalid = 0;
115117
if (isNaN(result) || !_inUint32Range(result)) {
116118
invalid = 1;
@@ -122,7 +124,7 @@ function countInvalidShares (data, db) {
122124
// Ensure we are always working with an array.
123125
if (db) {
124126
var arr = [];
125-
for (row in data) {
127+
for (let row in data) {
126128
arr.push(data[row]);
127129
}
128130
data = arr;
@@ -173,7 +175,7 @@ function aggregateShares (data, db) {
173175
// Ensure we are always working with an array.
174176
if (db) {
175177
var arr = [];
176-
for (row in data) {
178+
for (let row in data) {
177179
arr.push(data[row]);
178180
}
179181
data = arr;
@@ -211,7 +213,7 @@ function recombineValues (serviceTuples, analystTuples) {
211213

212214
if (typeof module !== 'undefined') {
213215
module.exports = {
214-
'FIELD': FIELD,
215-
'aggregateShares': aggregateShares
216+
'aggregateShares': aggregateShares,
217+
'countInvalidShares': countInvalidShares
216218
};
217219
}

test/spec/MPCSpec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// TODO: think about safe integers and overflow
22

3+
'use strict';
4+
35
var twoto32 = MAX_VALUE;
46

57
describe("Unsigned integer conversion", function () {
@@ -82,7 +84,7 @@ describe("MPC for single values", function () {
8284
expect(given).toEqual(expected);
8385
});
8486

85-
it("should throw when input >= 2^32", function () {
87+
it("should throw when input to secret sharing >= 2^32", function () {
8688
var f = function () {
8789
_secretShare(twoto32, 2);
8890
};
@@ -93,7 +95,7 @@ describe("MPC for single values", function () {
9395
expect(f).toThrow(new Error('Input value outside valid range'));
9496
});
9597

96-
it("should throw when input is negative", function () {
98+
it("should throw when input to secret sharing is negative", function () {
9799
var f = function () {
98100
_secretShare(-1, 2);
99101
};
@@ -225,6 +227,13 @@ describe("MPC for objects", function () {
225227
expect(result).toEqual(expected);
226228
});
227229

230+
it("should correctly count out-of-bounds in analyst shares", function () {
231+
var shares = [{k: '-1'}, {k: '4294967296'}, {k: '4294967297'}, {k: '7'}],
232+
result = countInvalidShares(shares),
233+
expected = {k: 3};
234+
expect(result).toEqual(expected);
235+
});
236+
228237
it("should correctly count out-of-bounds in service shares", function () {
229238
var shares = [{k: -1}, {k: -10}, {k: 10}, {k: twoto32}, {k: twoto32 + 1}],
230239
wrappedShares = shares.map(function (share) {return {fields: share}}),

unmask/script/unmask.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function unmask(mOut, privateKey, session, callback){
4141

4242
// Aggregate decrypted values by key
4343
var analystResultShare = decrypted.then(function (analystShares) {
44+
var invalidShareCount = countInvalidShares(analystShares);
45+
// TODO: we should set a threshold and abort if there are too
46+
// many invalid shares
47+
console.log('Invalid share count:', invalidShareCount);
4448
return aggregateShares(analystShares);
4549
});
4650

@@ -51,9 +55,7 @@ function unmask(mOut, privateKey, session, callback){
5155
.then(function (resultShares) {
5256
var analystResult = resultShares[0],
5357
serviceResult = resultShares[1],
54-
finalResult = recombineValues(
55-
analystResult, serviceResult, FIELD
56-
);
58+
finalResult = recombineValues(analystResult, serviceResult);
5759
callback(true, finalResult);
5860
}).catch(function (err) {
5961
console.log(err);

0 commit comments

Comments
 (0)