[js] add getXXXFromHexStr

dev
MITSUNARI Shigeo 7 years ago
parent 2b95f08ab2
commit fc058f0c4d
  1. 25
      docs/demo/she-demo2.js
  2. 25
      docs/demo/she.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 = $('<tr>').attr('id', 'header')
for (var i = 0; i < header.length; i++) {
let t = $('<tr>').attr('id', 'header')
for (let i = 0; i < header.length; i++) {
t.append(
$('<th>').append(header[i])
)
}
obj.append(t)
}
for (var i = 0; i < ct1.length; i++) {
var t = $('<tr>')
for (let i = 0; i < ct1.length; i++) {
let t = $('<tr>')
t.append(
$('<td class="encG1xS">').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)
}

@ -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)

Loading…
Cancel
Save