/** @fileOverview Password-based key-derivation function, version 2.0. * * @author Emily Stark * @author Mike Hamburg * @author Dan Boneh */ /** Password-Based Key-Derivation Function, version 2.0. * * Generate keys from passwords using PBKDF2-HMAC-SHA256. * * This is the method specified by RSA's PKCS #5 standard. * * @param {bitArray|String} password The password. * @param {bitArray|String} salt The salt. Should have lots of entropy. * @param {Number} [count=1000] The number of iterations. Higher numbers make the function slower but more secure. * @param {Number} [length] The length of the derived key. Defaults to the output size of the hash function. * @param {Object} [Prff=sjcl.misc.hmac] The pseudorandom function family. * @return {bitArray} the derived key. */ "use strict"; function q(a) { throw a; } var t = void 0, u = !1; var sjcl = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function (a) { this.toString = function () { return "CORRUPT: " + this.message }; this.message = a }, invalid: function (a) { this.toString = function () { return "INVALID: " + this.message }; this.message = a }, bug: function (a) { this.toString = function () { return "BUG: " + this.message }; this.message = a }, notReady: function (a) { this.toString = function () { return "NOT READY: " + this.message }; this.message = a } } }; sjcl.codec.utf8String = { fromBits: function (a) { var b = "", c = sjcl.bitArray.bitLength(a), d, e; for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 24), e <<= 8; return decodeURIComponent(escape(b)) }, toBits: function (a) { a = unescape(encodeURIComponent(a)); var b = [], c, d = 0; for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); c & 3 && b.push(sjcl.bitArray.partial(8 * (c & 3), d)); return b } }; sjcl.misc.pbkdf2 = function (password, salt, count, length, Prff) { 'use strict'; count = count || 1000; if (length < 0 || count < 0) { throw sjcl.exception.invalid("invalid params to pbkdf2"); } if (typeof password === "string") { password = sjcl.codec.utf8String.toBits(password); } if (typeof salt === "string") { salt = sjcl.codec.utf8String.toBits(salt); } Prff = Prff || sjcl.misc.hmac; var prf = new Prff(password), u, ui, i, j, k, out = [], b = sjcl.bitArray; for (k = 1; 32 * out.length < (length || 1) ; k++) { u = ui = prf.encrypt(b.concat(salt, [k])); for (i = 1; i < count; i++) { ui = prf.encrypt(ui); for (j = 0; j < ui.length; j++) { u[j] ^= ui[j]; } } out = out.concat(u); } if (length) { out = b.clamp(out, length); } return out; };