From d3e309c1e391e6b32552e5ced134236352614d40 Mon Sep 17 00:00:00 2001 From: jude Date: Thu, 13 Apr 2023 16:33:32 +0100 Subject: [PATCH] .... --- static/js/modules/crypto/paillier.js | 20 ++++++++++++++++- static/js/modules/interface/proofs.js | 31 ++++++++++++++++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/static/js/modules/crypto/paillier.js b/static/js/modules/crypto/paillier.js index 256112a..6e7f401 100644 --- a/static/js/modules/crypto/paillier.js +++ b/static/js/modules/crypto/paillier.js @@ -5,7 +5,16 @@ const PAILLIER = 0; const JURIK = 1; class Ciphertext { - constructor(key, plainText, r) { + constructor(key, plainText, r, set) { + if (set !== undefined) { + this.pubKey = key; + this.plainText = plainText; + + this.readOnly = false; + + return; + } + if (r === undefined) { // Use the optimised form using Jacobi classes r = cryptoRandom(); @@ -107,6 +116,15 @@ class Ciphertext { asReadOnlyCiphertext() { return new ReadOnlyCiphertext(this.pubKey, this.cipherText); } + + clone() { + let c = new Ciphertext(this.pubKey, this.plainText, 0, true); + c.cipherText = this.cipherText; + c.r = this.r; + c.mode = this.mode; + + return c; + } } class ValueProofSessionProver { diff --git a/static/js/modules/interface/proofs.js b/static/js/modules/interface/proofs.js index 93f24b7..bf6df4e 100644 --- a/static/js/modules/interface/proofs.js +++ b/static/js/modules/interface/proofs.js @@ -4,6 +4,7 @@ * Only works on lists up to 255 elements. */ function cryptoShuffle(l) { + let out = []; for (let i = l.length - 1; i > 0; i--) { let value = new Uint8Array([0]); crypto.getRandomValues(value); @@ -11,12 +12,13 @@ function cryptoShuffle(l) { crypto.getRandomValues(value); } - let temp = l[i]; - l[i] = l[value[0]]; - l[value[0]] = temp; + let v = l.splice(value[0], 1); + out.push(v[0]); } - return l; + out.push(l[0]); + + return out; } window.cryptoShuffle = cryptoShuffle; @@ -25,14 +27,27 @@ function proveRegions(regions) { // Construct prover coins let coins = []; - let regionNames = Object.keys(regions.keys()); - for (let x = 0; x < 20; x++) { - let psi = cryptoShuffle(regionNames).join(""); + let regionNames = Object.keys(regions); + for (let x = 0; x < 40; x++) { + let psi = cryptoShuffle(structuredClone(regionNames)).join(""); + let newRegions = structuredClone(regions); + // rearrange keys + for (let index = 0; index < regionNames.length; index++) { + let c = regions[psi[index]].clone(); + // re-blind + c.update(c.pubKey.encrypt(0n)); + newRegions[regionNames[index]] = c.toString(); + } + coins.push(newRegions); } // Construct verifier coins let hasher = new jsSHA("SHA3-256", "TEXT"); - hasher.update(JSON.stringify(regions)); + hasher.update(JSON.stringify(coins)); + + console.log(hasher.getHash("UINT8ARRAY")); // Construct prover proofs } + +window.proveRegions = proveRegions;