UNPKG

epir

Version:

EllipticPIR client library (Node.js / TypeScript bindings).

36 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = exports.LOOP = void 0; const types_1 = require("./types"); const util_1 = require("./util"); const addon_1 = require("./addon"); exports.LOOP = 10 * 1000; const run = async () => { const msgs = []; for (let i = 0; i < exports.LOOP; i++) { msgs[i] = Math.floor(Math.random() * types_1.DEFAULT_MMAX); } const epir = await addon_1.createEpir(); const decCtx = await addon_1.createDecryptionContext(types_1.MG_DEFAULT_PATH); const privkey = epir.createPrivkey(); const encrypted = await util_1.printMeasurement(() => { return msgs.map((msg) => epir.encryptFast(privkey, msg)); }, 'Ciphertext encrypted (fast) in'); const decrypted = await util_1.printMeasurement(() => { return encrypted.map((enc) => decCtx.decryptCipher(privkey, enc)); }, 'Ciphertext decrypted in'); for (let i = 0; i < exports.LOOP; i++) { /* istanbul ignore if */ if (msgs[i] !== decrypted[i]) { console.log('Message decrypted to a different data.'); return false; } } return true; }; exports.run = run; /* istanbul ignore if */ if (!module.parent) { exports.run(); } //# sourceMappingURL=bench_ecelgamal.js.map