aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-10-18 17:07:59 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-10-18 17:07:59 +0800
commitf7c8fc96ae19741d059d04dc0de5908c76c487dd (patch)
tree4d42fd88b24f692a08942294b48f90589cd10307
parent15e970b3fdb7b9e4829738917bb71b821adbf38a (diff)
downloaddexon-mcl-f7c8fc96ae19741d059d04dc0de5908c76c487dd.tar.gz
dexon-mcl-f7c8fc96ae19741d059d04dc0de5908c76c487dd.tar.zst
dexon-mcl-f7c8fc96ae19741d059d04dc0de5908c76c487dd.zip
[js] add PublicKey.convertToCipherTextGT
-rw-r--r--docs/demo/exported-she.js4
-rw-r--r--docs/demo/she-demo.js12
-rw-r--r--docs/demo/she.js29
-rw-r--r--docs/demo/style.css1
-rw-r--r--ffi/js/she-re.txt2
5 files changed, 40 insertions, 8 deletions
diff --git a/docs/demo/exported-she.js b/docs/demo/exported-she.js
index d1c1f18..f4a10e1 100644
--- a/docs/demo/exported-she.js
+++ b/docs/demo/exported-she.js
@@ -41,6 +41,6 @@ sheMul = mod.cwrap('sheMul', 'number', ['number', 'number', 'number', ])
sheReRandG1 = mod.cwrap('sheReRandG1', 'number', ['number', 'number', ])
sheReRandG2 = mod.cwrap('sheReRandG2', 'number', ['number', 'number', ])
sheReRandGT = mod.cwrap('sheReRandGT', 'number', ['number', 'number', ])
-_sheConvertFromG1 = mod.cwrap('sheConvertFromG1', 'number', ['number', 'number', 'number', ])
-_sheConvertFromG2 = mod.cwrap('sheConvertFromG2', 'number', ['number', 'number', 'number', ])
+sheConvertFromG1 = mod.cwrap('sheConvertFromG1', 'number', ['number', 'number', 'number', ])
+sheConvertFromG2 = mod.cwrap('sheConvertFromG2', 'number', ['number', 'number', 'number', ])
}
diff --git a/docs/demo/she-demo.js b/docs/demo/she-demo.js
index e975987..f6edfbb 100644
--- a/docs/demo/she-demo.js
+++ b/docs/demo/she-demo.js
@@ -157,14 +157,18 @@ function onClickTestSHEclass() {
c12 = she.mulInt(c12, -3)
c22 = she.mulInt(c22, -3)
ct2 = she.mulInt(ct2, -3)
- console.log('expect ' + m1 * 3)
- console.log('dec c11=' + sec.dec(c12))
- console.log('dec c21=' + sec.dec(c22))
- console.log('dec ct1=' + sec.dec(ct2))
+ let expect = m1 * 3
+ console.log('dec c11=' + (sec.dec(c12) == expect))
+ console.log('dec c21=' + (sec.dec(c22) == expect))
+ console.log('dec ct1=' + (sec.dec(ct2) == expect))
c12 = pub.encG1(4)
c22 = pub.encG2(5)
ct2 = she.mul(c12, c22)
console.log('dec ct2=' + sec.dec(ct2))
+ ct2 = pub.convertToCipherTextGT(c12)
+ console.log('convertToCipherTextGT(G1)=' + (sec.dec(ct2) == 4))
+ ct2 = pub.convertToCipherTextGT(c22)
+ console.log('convertToCipherTextGT(G2)=' + (sec.dec(ct2) == 5))
reRandTest(sec, pub, c12)
reRandTest(sec, pub, c22)
diff --git a/docs/demo/she.js b/docs/demo/she.js
index 2d9c50a..392ac80 100644
--- a/docs/demo/she.js
+++ b/docs/demo/she.js
@@ -253,6 +253,21 @@
mod.Runtime.stackRestore(stack)
if (r) throw('callReRand err')
}
+ // convertFrom
+ const callConvertFrom = function(func, pub, c) {
+ let ct = new she.CipherTextGT()
+ let stack = mod.Runtime.stackSave()
+ let ctPos = mod.Runtime.stackAlloc(ct.a_.length * 4)
+ let pubPos = mod.Runtime.stackAlloc(pub.length * 4)
+ let cPos = mod.Runtime.stackAlloc(c.length * 4)
+ copyFromUint32Array(pubPos, pub);
+ copyFromUint32Array(cPos, c);
+ let r = func(ctPos, pubPos, cPos)
+ copyToUint32Array(ct.a_, ctPos)
+ mod.Runtime.stackRestore(stack)
+ if (r) throw('callConvertFrom err')
+ return ct
+ }
she_free = function(p) {
mod._free(p)
}
@@ -532,6 +547,20 @@
}
return callReRand(reRand, c.a_, this.a_)
}
+ she.PublicKey.prototype.convertToCipherTextGT = function(c) {
+ let convertFrom = null
+ if (she.CipherTextG1.prototype.isPrototypeOf(c)) {
+ convertFrom = sheConvertFromG1
+ } else if (she.CipherTextG2.prototype.isPrototypeOf(c)) {
+ convertFrom = sheConvertFromG2
+ } else {
+ throw('she.PublicKey.convertToCipherTextGT:not supported')
+ }
+ return callConvertFrom(convertFrom, this.a_, c.a_)
+ }
+ she.PublicKey.prototype.convertFromG2 = function(c) {
+ return she.convertFrom(sheConvertFromG1, this.a_, c.a_)
+ }
}
she.init = function(range = 1024, tryNum = 1024, callback = null) {
diff --git a/docs/demo/style.css b/docs/demo/style.css
index fc097ef..25671e2 100644
--- a/docs/demo/style.css
+++ b/docs/demo/style.css
@@ -56,7 +56,6 @@ div.ret {
#middle {
width:4%;
float:left;
- position: center;
margin: 10px;
background-color: gray;
width:2px;
diff --git a/ffi/js/she-re.txt b/ffi/js/she-re.txt
index 6dc8ba4..a78719d 100644
--- a/ffi/js/she-re.txt
+++ b/ffi/js/she-re.txt
@@ -1 +1 @@
-sheInit|erialize|Str|sheDec|sheConvertFrom
+sheInit|erialize|Str|sheDec