From fc058f0c4d6126ecd8dd29c36003a38c0dd6602f Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 18 Oct 2017 15:27:35 +0900 Subject: [PATCH] [js] add getXXXFromHexStr --- docs/demo/she-demo2.js | 25 +++++++++++-------------- docs/demo/she.js | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/docs/demo/she-demo2.js b/docs/demo/she-demo2.js index f9d7f80..bd57008 100644 --- a/docs/demo/she-demo2.js +++ b/docs/demo/she-demo2.js @@ -88,22 +88,22 @@ function send() { $('.encG2y').each(function() { ct2.push($(this).text()) }) - var obj = $('#server_table') + let obj = $('#server_table') obj.html('') { - var header = [ + let header = [ 'EncG1(x)', 'EncG2(y)', 'EncGT(x * y)' ] - var t = $('').attr('id', 'header') - for (var i = 0; i < header.length; i++) { + let t = $('').attr('id', 'header') + for (let i = 0; i < header.length; i++) { t.append( $('').append(header[i]) ) } obj.append(t) } - for (var i = 0; i < ct1.length; i++) { - var t = $('') + for (let i = 0; i < ct1.length; i++) { + let t = $('') t.append( $('').append(ct1[i]) ).append( @@ -116,22 +116,20 @@ function send() { } function mul() { - let c1 = new she.CipherTextG1() - let c2 = new she.CipherTextG2() $('.encG1xS').each(function() { let o = $(this) - c1.fromHexStr(o.text()) - c2.fromHexStr(o.next().text()) + let c1 = she.getCipherTextG1FromHexStr(o.text()) + let c2 = she.getCipherTextG2FromHexStr(o.next().text()) let ct = she.mul(c1, c2) o.next().next().text(ct.toHexStr()) }) } function sum() { - let ct = new she.CipherTextGT() let csum = pub.encGT(0) $('.encGTxyS').each(function() { - ct.fromHexStr($(this).text()) + let s = $(this).text() + let ct = she.getCipherTextGTFromHexStr(s) csum = she.add(csum, ct) }) setText('encSumS', csum.toHexStr()) @@ -143,8 +141,7 @@ function recv() { function dec() { let s = getText('encSumC') - let ct = new she.CipherTextGT() - ct.fromHexStr(s) + let ct = she.getCipherTextGTFromHexStr(s) let v = sec.dec(ct) setText('ret', v) } diff --git a/docs/demo/she.js b/docs/demo/she.js index 6f1e2a4..2d9c50a 100644 --- a/docs/demo/she.js +++ b/docs/demo/she.js @@ -308,6 +308,11 @@ she.SecretKey.prototype.dump = function(msg = 'sec ') { console.log(msg + this.toHexStr()) } + she.getSecretKeyFromHexStr = function(s) { + r = new she.SecretKey() + r.fromHexStr(s) + return r + } she.PublicKey = function() { this.a_ = new Uint32Array(SHE_PUBLICKEY_SIZE / 4) } @@ -326,6 +331,11 @@ she.PublicKey.prototype.dump = function(msg = 'pub ') { console.log(msg + this.toHexStr()) } + she.getPublicKeyFromHexStr = function(s) { + r = new she.PublicKey() + r.fromHexStr(s) + return r + } she.CipherTextG1 = function() { this.a_ = new Uint32Array(SHE_CIPHERTEXT_G1_SIZE / 4) } @@ -344,6 +354,11 @@ she.CipherTextG1.prototype.dump = function(msg = 'ct1 ') { console.log(msg + this.toHexStr()) } + she.getCipherTextG1FromHexStr = function(s) { + r = new she.CipherTextG1() + r.fromHexStr(s) + return r + } she.CipherTextG2 = function() { this.a_ = new Uint32Array(SHE_CIPHERTEXT_G2_SIZE / 4) } @@ -362,6 +377,11 @@ she.CipherTextG2.prototype.dump = function(msg = 'ct2 ') { console.log(msg + this.toHexStr()) } + she.getCipherTextG2FromHexStr = function(s) { + r = new she.CipherTextG2() + r.fromHexStr(s) + return r + } she.CipherTextGT = function() { this.a_ = new Uint32Array(SHE_CIPHERTEXT_GT_SIZE / 4) } @@ -380,6 +400,11 @@ she.CipherTextGT.prototype.dump = function(msg = 'ctt ') { console.log(msg + this.toHexStr()) } + she.getCipherTextGTFromHexStr = function(s) { + r = new she.CipherTextGT() + r.fromHexStr(s) + return r + } she.SecretKey.prototype.setByCSPRNG = function() { let stack = mod.Runtime.stackSave() let secPos = mod.Runtime.stackAlloc(this.a_.length * 4)