|
|
@ -5,6 +5,8 @@ |
|
|
|
window.she = return_she() |
|
|
|
window.she = return_she() |
|
|
|
} |
|
|
|
} |
|
|
|
})(function() { |
|
|
|
})(function() { |
|
|
|
|
|
|
|
const crypto = window.crypto || window.msCrypto |
|
|
|
|
|
|
|
|
|
|
|
const MCLBN_CURVE_FP254BNB = 0 |
|
|
|
const MCLBN_CURVE_FP254BNB = 0 |
|
|
|
const MCLBN_FP_UNIT_SIZE = 4 |
|
|
|
const MCLBN_FP_UNIT_SIZE = 4 |
|
|
|
const MCLBN_FP_SIZE = MCLBN_FP_UNIT_SIZE * 8 |
|
|
|
const MCLBN_FP_SIZE = MCLBN_FP_UNIT_SIZE * 8 |
|
|
@ -18,8 +20,9 @@ |
|
|
|
const SHE_CIPHERTEXT_G2_SIZE = MCLBN_G2_SIZE * 2 |
|
|
|
const SHE_CIPHERTEXT_G2_SIZE = MCLBN_G2_SIZE * 2 |
|
|
|
const SHE_CIPHERTEXT_GT_SIZE = MCLBN_GT_SIZE * 4 |
|
|
|
const SHE_CIPHERTEXT_GT_SIZE = MCLBN_GT_SIZE * 4 |
|
|
|
|
|
|
|
|
|
|
|
let she = {} |
|
|
|
|
|
|
|
let mod = {} |
|
|
|
let mod = {} |
|
|
|
|
|
|
|
let she = {} |
|
|
|
|
|
|
|
she.mod = mod |
|
|
|
|
|
|
|
|
|
|
|
const setupWasm = function(fileName, nameSpace, setupFct) { |
|
|
|
const setupWasm = function(fileName, nameSpace, setupFct) { |
|
|
|
console.log('setupWasm ' + fileName) |
|
|
|
console.log('setupWasm ' + fileName) |
|
|
@ -36,6 +39,7 @@ |
|
|
|
}) |
|
|
|
}) |
|
|
|
return mod |
|
|
|
return mod |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const define_she_extra_functions = function(mod) { |
|
|
|
const define_she_extra_functions = function(mod) { |
|
|
|
const ptrToStr = function(pos, n) { |
|
|
|
const ptrToStr = function(pos, n) { |
|
|
|
let s = '' |
|
|
|
let s = '' |
|
|
@ -136,14 +140,12 @@ |
|
|
|
return v |
|
|
|
return v |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const crypto = window.crypto || window.msCrypto |
|
|
|
const copyToUint32Array = function(a, pos) { |
|
|
|
|
|
|
|
|
|
|
|
let copyToUint32Array = function(a, pos) { |
|
|
|
|
|
|
|
for (let i = 0; i < a.length; i++) { |
|
|
|
for (let i = 0; i < a.length; i++) { |
|
|
|
a[i] = mod.HEAP32[pos / 4 + i] |
|
|
|
a[i] = mod.HEAP32[pos / 4 + i] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let copyFromUint32Array = function(pos, a) { |
|
|
|
const copyFromUint32Array = function(pos, a) { |
|
|
|
for (let i = 0; i < a.length; i++) { |
|
|
|
for (let i = 0; i < a.length; i++) { |
|
|
|
mod.HEAP32[pos / 4 + i] = a[i] |
|
|
|
mod.HEAP32[pos / 4 + i] = a[i] |
|
|
|
} |
|
|
|
} |
|
|
@ -205,39 +207,33 @@ |
|
|
|
copyToUint32Array(pub, pubPos) |
|
|
|
copyToUint32Array(pub, pubPos) |
|
|
|
mod.Runtime.stackRestore(stack) |
|
|
|
mod.Runtime.stackRestore(stack) |
|
|
|
} |
|
|
|
} |
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
she_free = function(p) { |
|
|
|
she_free = function(p) { |
|
|
|
mod._free(p) |
|
|
|
mod._free(p) |
|
|
|
} |
|
|
|
} |
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
sheSecretKey_malloc = function() { |
|
|
|
sheSecretKey_malloc = function() { |
|
|
|
return mod._malloc(SHE_SECRETKEY_SIZE) |
|
|
|
return mod._malloc(SHE_SECRETKEY_SIZE) |
|
|
|
} |
|
|
|
} |
|
|
|
sheSecretKeySerialize = wrap_outputArray(_sheSecretKeySerialize) |
|
|
|
|
|
|
|
sheSecretKeyDeserialize = wrap_input1(_sheSecretKeyDeserialize) |
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
shePublicKey_malloc = function() { |
|
|
|
shePublicKey_malloc = function() { |
|
|
|
return mod._malloc(SHE_PUBLICKEY_SIZE) |
|
|
|
return mod._malloc(SHE_PUBLICKEY_SIZE) |
|
|
|
} |
|
|
|
} |
|
|
|
shePublicKeySerialize = wrap_outputArray(_shePublicKeySerialize) |
|
|
|
sheCipherTextG2_malloc = function() { |
|
|
|
shePublicKeyDeserialize = wrap_input1(_shePublicKeyDeserialize) |
|
|
|
return mod._malloc(SHE_CIPHERTEXT_G2_SIZE) |
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
} |
|
|
|
|
|
|
|
sheCipherTextGT_malloc = function() { |
|
|
|
|
|
|
|
return mod._malloc(SHE_CIPHERTEXT_GT_SIZE) |
|
|
|
|
|
|
|
} |
|
|
|
sheCipherTextG1_malloc = function() { |
|
|
|
sheCipherTextG1_malloc = function() { |
|
|
|
return mod._malloc(SHE_CIPHERTEXT_G1_SIZE) |
|
|
|
return mod._malloc(SHE_CIPHERTEXT_G1_SIZE) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sheSecretKeySerialize = wrap_outputArray(_sheSecretKeySerialize) |
|
|
|
|
|
|
|
sheSecretKeyDeserialize = wrap_input1(_sheSecretKeyDeserialize) |
|
|
|
|
|
|
|
shePublicKeySerialize = wrap_outputArray(_shePublicKeySerialize) |
|
|
|
|
|
|
|
shePublicKeyDeserialize = wrap_input1(_shePublicKeyDeserialize) |
|
|
|
sheCipherTextG1Serialize = wrap_outputArray(_sheCipherTextG1Serialize) |
|
|
|
sheCipherTextG1Serialize = wrap_outputArray(_sheCipherTextG1Serialize) |
|
|
|
sheCipherTextG1Deserialize = wrap_input1(_sheCipherTextG1Deserialize) |
|
|
|
sheCipherTextG1Deserialize = wrap_input1(_sheCipherTextG1Deserialize) |
|
|
|
sheDecG1 = wrap_dec(_sheDecG1) |
|
|
|
sheDecG1 = wrap_dec(_sheDecG1) |
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
sheCipherTextG2_malloc = function() { |
|
|
|
|
|
|
|
return mod._malloc(SHE_CIPHERTEXT_G2_SIZE) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sheCipherTextG2Serialize = wrap_outputArray(_sheCipherTextG2Serialize) |
|
|
|
sheCipherTextG2Serialize = wrap_outputArray(_sheCipherTextG2Serialize) |
|
|
|
sheCipherTextG2Deserialize = wrap_input1(_sheCipherTextG2Deserialize) |
|
|
|
sheCipherTextG2Deserialize = wrap_input1(_sheCipherTextG2Deserialize) |
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
sheCipherTextGT_malloc = function() { |
|
|
|
|
|
|
|
return mod._malloc(SHE_CIPHERTEXT_GT_SIZE) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sheCipherTextGTSerialize = wrap_outputArray(_sheCipherTextGTSerialize) |
|
|
|
sheCipherTextGTSerialize = wrap_outputArray(_sheCipherTextGTSerialize) |
|
|
|
sheCipherTextGTDeserialize = wrap_input1(_sheCipherTextGTDeserialize) |
|
|
|
sheCipherTextGTDeserialize = wrap_input1(_sheCipherTextGTDeserialize) |
|
|
|
sheDecGT = wrap_dec(_sheDecGT) |
|
|
|
sheDecGT = wrap_dec(_sheDecGT) |
|
|
@ -248,19 +244,6 @@ |
|
|
|
if (r) throw('sheInit') |
|
|
|
if (r) throw('sheInit') |
|
|
|
// r = sheSetRangeForGTDLP(128, 1024)
|
|
|
|
// r = sheSetRangeForGTDLP(128, 1024)
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
she.init = function(callback = null) { |
|
|
|
|
|
|
|
setupWasm('mclshe.wasm', null, function(mod, ns) { |
|
|
|
|
|
|
|
define_exported_she(mod) |
|
|
|
|
|
|
|
define_she_extra_functions(mod) |
|
|
|
|
|
|
|
sheInit() |
|
|
|
|
|
|
|
console.log('initializing sheSetRangeForDLP') |
|
|
|
|
|
|
|
let r = sheSetRangeForDLP(256, 2048) |
|
|
|
|
|
|
|
console.log('finished ' + r) |
|
|
|
|
|
|
|
if (callback) callback() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
she.SecretKey = function() { |
|
|
|
she.SecretKey = function() { |
|
|
|
this.a_ = new Uint32Array(SHE_SECRETKEY_SIZE / 4) |
|
|
|
this.a_ = new Uint32Array(SHE_SECRETKEY_SIZE / 4) |
|
|
|
} |
|
|
|
} |
|
|
@ -292,10 +275,6 @@ |
|
|
|
she.callSetByCSPRNG(this.a_) |
|
|
|
she.callSetByCSPRNG(this.a_) |
|
|
|
} |
|
|
|
} |
|
|
|
she.SecretKey.prototype.getPublicKey = function() { |
|
|
|
she.SecretKey.prototype.getPublicKey = function() { |
|
|
|
let pub = new she.PublicKey() |
|
|
|
|
|
|
|
she.callGetPublicKey(pub.a_, this.a_) |
|
|
|
|
|
|
|
return pub |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
let pub = new she.PublicKey() |
|
|
|
let pub = new she.PublicKey() |
|
|
|
let stack = mod.Runtime.stackSave() |
|
|
|
let stack = mod.Runtime.stackSave() |
|
|
|
let secPos = mod.Runtime.stackAlloc(this.a_.length * 4) |
|
|
|
let secPos = mod.Runtime.stackAlloc(this.a_.length * 4) |
|
|
@ -305,16 +284,29 @@ |
|
|
|
copyToUint32Array(pub.a_, pubPos) |
|
|
|
copyToUint32Array(pub.a_, pubPos) |
|
|
|
mod.Runtime.stackRestore(stack) |
|
|
|
mod.Runtime.stackRestore(stack) |
|
|
|
return pub |
|
|
|
return pub |
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
she.PublicKey.prototype.enc = function(m) { |
|
|
|
she.PublicKey.prototype.enc = function(m) { |
|
|
|
return she.callEnc(sheEnc32G1, she.CipherTextG1, this.a_, m) |
|
|
|
return she.callEnc(sheEnc32G1, she.CipherTextG1, this.a_, m) |
|
|
|
} |
|
|
|
} |
|
|
|
she.SecretKey.prototype.dec = function(c) { |
|
|
|
she.SecretKey.prototype.dec = function(c) { |
|
|
|
if (she.CipherTextG1.prototype.isPrototypeOf(c)) { |
|
|
|
if (she.CipherTextG1.prototype.isPrototypeOf(c)) { |
|
|
|
return she.callDec(sheDecG1, this.a_, c) |
|
|
|
return she.callDec(sheDecG1, this.a_, c.a_) |
|
|
|
} |
|
|
|
} |
|
|
|
throw('she.SecretKey.dec is not supported') |
|
|
|
throw('she.SecretKey.dec is not supported') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
she.init = function(callback = null) { |
|
|
|
|
|
|
|
setupWasm('mclshe.wasm', null, function(_mod, ns) { |
|
|
|
|
|
|
|
mod = _mod |
|
|
|
|
|
|
|
define_exported_she(mod) |
|
|
|
|
|
|
|
define_she_extra_functions(mod) |
|
|
|
|
|
|
|
sheInit() |
|
|
|
|
|
|
|
console.log('initializing sheSetRangeForDLP') |
|
|
|
|
|
|
|
let r = sheSetRangeForDLP(256, 100) |
|
|
|
|
|
|
|
console.log('finished ' + r) |
|
|
|
|
|
|
|
if (callback) callback() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
return she |
|
|
|
return she |
|
|
|
}) |
|
|
|
}) |
|
|
|