UNPKG

@polkadot/util-crypto

Version:
23 lines (22 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scryptFromU8a = void 0; const util_1 = require("@polkadot/util"); const bn_js_1 = require("../bn.js"); const defaults_js_1 = require("./defaults.js"); function scryptFromU8a(data) { const salt = data.subarray(0, 32); const N = (0, util_1.u8aToBn)(data.subarray(32 + 0, 32 + 4), bn_js_1.BN_LE_OPTS).toNumber(); const p = (0, util_1.u8aToBn)(data.subarray(32 + 4, 32 + 8), bn_js_1.BN_LE_OPTS).toNumber(); const r = (0, util_1.u8aToBn)(data.subarray(32 + 8, 32 + 12), bn_js_1.BN_LE_OPTS).toNumber(); // FIXME At this moment we assume these to be fixed params, this is not a great idea // since we lose flexibility and updates for greater security. However we need some // protection against carefully-crafted params that can eat up CPU since these are user // inputs. So we need to get very clever here, but atm we only allow the defaults // and if no match, bail out if (N !== defaults_js_1.DEFAULT_PARAMS.N || p !== defaults_js_1.DEFAULT_PARAMS.p || r !== defaults_js_1.DEFAULT_PARAMS.r) { throw new Error('Invalid injected scrypt params found'); } return { params: { N, p, r }, salt }; } exports.scryptFromU8a = scryptFromU8a;