Skip to content

Commit

Permalink
preprocess/handlers done
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed Jun 4, 2024
1 parent 8b013ad commit 4c0eafd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
52 changes: 27 additions & 25 deletions lib/client/preprocessing/handlers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// internal functions for use in preprocessing function map
module.exports = {
bits_count: function (threshold, receivers_list, compute_list, Zp, op_id, params) {
class PreprocessHandlers {
bits_count(threshold, receivers_list, compute_list, Zp, op_id, params) {
let bitLength = params.bitLength;
if (bitLength == null) {
bitLength = Zp.toString(2).length;
}
return bitLength;
},
constant_bits_count: function () {
}
constant_bits_count() {
return module.exports.bits_count.apply(null, arguments) - 1;
},
dynamic_bits_cmult: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
}
dynamic_bits_cmult(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
// constant bit length
let constantBits = Zp.toString(2).length;
if (params.constantBits != null) {
Expand All @@ -28,8 +28,8 @@ module.exports = {
ops.push({ op: 'bits.sadd', op_id: ':bits.sadd:' + i, params: { bitLengthLeft: accLength, bitLengthRight: bitLength + i } });
}
return ops;
},
dynamic_bits_smult: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
}
dynamic_bits_smult(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
let bitLength = params.bitLength;
if (bitLength == null) {
bitLength = Zp.toString(2).length;
Expand All @@ -51,8 +51,8 @@ module.exports = {
ops.push({ op: 'bits.sadd', op_id: ':bits.sadd:' + i, params: { bitLengthLeft: accLength, bitLengthRight: max + i } });
}
return ops;
},
choice_bits_count: function (choice, offset) {
}
choice_bits_count(choice, offset) {
if (offset == null) {
offset = 0;
}
Expand All @@ -69,11 +69,11 @@ module.exports = {

return choice(left, right) + offset;
};
},
decomposition_ifelse_count: function (threshold, receivers_list, compute_list, Zp, op_id, params) {
}
decomposition_ifelse_count(threshold, receivers_list, compute_list, Zp, op_id, params) {
return Zp.toString(2).length;
},
dynamic_bits_sdiv: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
}
dynamic_bits_sdiv(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
let bitLength = params.bitLength;
if (bitLength == null) {
bitLength = Zp.toString(2).length;
Expand All @@ -94,8 +94,8 @@ module.exports = {
}
}
return ops;
},
dynamic_bits_cdiv: function (dir) {
}
dynamic_bits_cdiv(dir) {
return function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params) {
let constantBits = Zp.toString(2).length;
if (params.constantBits != null) {
Expand Down Expand Up @@ -131,9 +131,9 @@ module.exports = {
}
return ops;
};
},
}
// rejection sampling
dynamic_rejection_sampling: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
dynamic_rejection_sampling(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
const previousPreprocessing = jiff.preprocessing_table[task.id];
params.reject_count = params.reject_count == null ? -1 : params.reject_count;

Expand Down Expand Up @@ -201,9 +201,9 @@ module.exports = {
}

return [];
},
}
// random quotients for cdiv
dynamic_random_and_quotient: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
dynamic_random_and_quotient(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
const constantNotProvided = params.constant == null;
receivers_list = constantNotProvided ? compute_list : receivers_list;
Zp = Zp ? Zp : jiff.Zp;
Expand Down Expand Up @@ -237,9 +237,9 @@ module.exports = {
);

return dependent_ops;
},
}
// fast exponentiation
dynamic_fast_exponentiation: function (dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
dynamic_fast_exponentiation(dependent_op, count, protocols, threshold, receivers_list, compute_list, Zp, task_id, params, task, jiff) {
Zp = Zp ? Zp : jiff.Zp;
const constantNotProvided = params.constant == null;
let constant = params.constant;
Expand Down Expand Up @@ -275,11 +275,13 @@ module.exports = {
}
ops.push({ op: 'smult', op_id: ':smult0:' + i });
return ops;
},
}
// for various equality tests, preprocess of cpow(Zp - 1) (Fermat's little theorem)
handler_cpow_Zp_minus_1: function (threshold, receivers_list, compute_list, Zp, op_id, params, task, jiff) {
handler_cpow_Zp_minus_1(threshold, receivers_list, compute_list, Zp, op_id, params, task, jiff) {
Zp = Zp ? Zp : jiff.Zp;
params.constant = jiff.share_helpers['-'](Zp, 1);
return params;
}
};
}

module.exports = PreprocessHandlers;
3 changes: 2 additions & 1 deletion lib/client/preprocessing/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const handlers = require('./handlers.js');
const PreprocessHandlers = require('./handlers.js');

Check failure on line 1 in lib/client/preprocessing/map.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/preprocessing/map.js#L1

Require statement not part of import statement.
const handlers = new PreprocessHandlers();

class PreprocessingMap {
constructor(jiffClient) {
Expand Down

0 comments on commit 4c0eafd

Please sign in to comment.