|
|
@ -26,51 +26,48 @@ |
|
|
|
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 g_callback = null |
|
|
|
|
|
|
|
let g_range = 0 |
|
|
|
|
|
|
|
let g_tryNum = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let capi = {} |
|
|
|
let capi = {} |
|
|
|
exports.capi = capi |
|
|
|
exports.capi = capi |
|
|
|
let mod = exports.mod |
|
|
|
let mod = exports.mod |
|
|
|
|
|
|
|
|
|
|
|
exports.init = function(callback = null, range = 1024, tryNum = 1024) { |
|
|
|
/* |
|
|
|
|
|
|
|
init she |
|
|
|
|
|
|
|
@param range [in] table size of DLP ; require 8 * table size |
|
|
|
|
|
|
|
@param tryNum [in] how many search ; O(tryNum) time |
|
|
|
|
|
|
|
can decrypt (range * tryNum) range value |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
exports.init = (range = 1024, tryNum = 1024) => { |
|
|
|
console.log('init') |
|
|
|
console.log('init') |
|
|
|
g_callback = callback |
|
|
|
if (!isNodeJs) { |
|
|
|
g_range = range |
|
|
|
|
|
|
|
g_tryNum = tryNum |
|
|
|
|
|
|
|
if (isNodeJs) { |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fetch('she_c.wasm') |
|
|
|
fetch('she_c.wasm') |
|
|
|
.then(response => response.arrayBuffer()) |
|
|
|
.then(response => response.arrayBuffer()) |
|
|
|
.then(buffer => new Uint8Array(buffer)) |
|
|
|
.then(buffer => new Uint8Array(buffer)) |
|
|
|
.then(binary => { Module(mod) }) |
|
|
|
.then(binary => { Module(mod) }) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return new Promise((resolve) => { |
|
|
|
|
|
|
|
mod.onRuntimeInitialized = () => { |
|
|
|
mod.onRuntimeInitialized = function () { |
|
|
|
const f = (exportedFuncs) => { |
|
|
|
const f = function(exportedFuncs) { |
|
|
|
exportedFuncs.forEach(func => { |
|
|
|
exportedFuncs.forEach(func => { |
|
|
|
capi[func.exportName] = mod.cwrap(func.name, func.returns, func.args) |
|
|
|
capi[func.exportName] = mod.cwrap(func.name, func.returns, func.args) |
|
|
|
}) |
|
|
|
}) |
|
|
|
define_extra_functions(mod) |
|
|
|
define_extra_functions(mod) |
|
|
|
capi.sheInit() |
|
|
|
capi.sheInit() |
|
|
|
console.log(`initializing sheSetRangeForDLP(range=${range}, tryNum=${tryNum})`) |
|
|
|
console.log('initializing sheSetRangeForDLP') |
|
|
|
const r = capi.sheSetRangeForDLP(range, tryNum) |
|
|
|
const r = capi.sheSetRangeForDLP(g_range, g_tryNum) |
|
|
|
console.log('finished ' + r) |
|
|
|
console.log('finished ' + r) |
|
|
|
resolve() |
|
|
|
if (g_callback) g_callback() |
|
|
|
} |
|
|
|
} |
|
|
|
if (isNodeJs) { |
|
|
|
const EXPORTED_JSON = 'exported-she.json' |
|
|
|
const fs = require('fs') |
|
|
|
if (isNodeJs) { |
|
|
|
const jsonStr = fs.readFileSync('./exported-she.json') |
|
|
|
const fs = require('fs') |
|
|
|
f(JSON.parse(jsonStr)) |
|
|
|
const path = require('path') |
|
|
|
} else { |
|
|
|
const jsonStr = fs.readFileSync(path.resolve(__dirname, EXPORTED_JSON)) |
|
|
|
fetch('exported-she.json') |
|
|
|
f(JSON.parse(jsonStr)) |
|
|
|
.then(response => response.json()) |
|
|
|
} else { |
|
|
|
.then(exportedFuncs => f(exportedFuncs)) |
|
|
|
fetch(EXPORTED_JSON) |
|
|
|
} |
|
|
|
.then(response => response.json()) |
|
|
|
} |
|
|
|
.then(exportedFuncs => f(exportedFuncs)) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ptrToStr = function(pos, n) { |
|
|
|
const ptrToStr = function(pos, n) { |
|
|
|