UNPKG

@cloudcome/utils-core

Version:
1 lines 74 kB
{"version":3,"file":"crypto.cjs","sources":["../src/crypto/md5.mjs","../src/crypto/sha1.mjs","../src/crypto/sha256.mjs","../src/crypto/sha512.mjs","../src/crypto.ts"],"sourcesContent":["/*\n * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message\n * Digest Algorithm, as defined in RFC 1321.\n * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * Distributed under the BSD License\n * See http://pajhome.org.uk/crypt/md5 for more info.\n */\n\n/*\n * Configurable variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n */\nvar hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\nvar b64pad = ''; /* base-64 pad character. \"=\" for strict RFC compliance */\n\n/*\n * These are the functions you'll usually want to call\n * They take string arguments and return either hex or base-64 encoded strings\n */\nexport function hex_md5(s) {\n return rstr2hex(rstr_md5(str2rstr_utf8(s)));\n}\nfunction b64_md5(s) {\n return rstr2b64(rstr_md5(str2rstr_utf8(s)));\n}\nfunction any_md5(s, e) {\n return rstr2any(rstr_md5(str2rstr_utf8(s)), e);\n}\nfunction hex_hmac_md5(k, d) {\n return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));\n}\nfunction b64_hmac_md5(k, d) {\n return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));\n}\nfunction any_hmac_md5(k, d, e) {\n return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);\n}\n\n/*\n * Perform a simple self-test to see if the VM is working\n */\nfunction md5_vm_test() {\n return hex_md5('abc').toLowerCase() == '900150983cd24fb0d6963f7d28e17f72';\n}\n\n/*\n * Calculate the MD5 of a raw string\n */\nfunction rstr_md5(s) {\n return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));\n}\n\n/*\n * Calculate the HMAC-MD5, of a key and some data (raw strings)\n */\nfunction rstr_hmac_md5(key, data) {\n var bkey = rstr2binl(key);\n if (bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);\n\n var ipad = Array(16),\n opad = Array(16);\n for (var i = 0; i < 16; i++) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5c5c5c5c;\n }\n\n var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);\n return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));\n}\n\n/*\n * Convert a raw string to a hex string\n */\nfunction rstr2hex(input) {\n try {\n hexcase;\n } catch (e) {\n hexcase = 0;\n }\n var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef';\n var output = '';\n var x;\n for (var i = 0; i < input.length; i++) {\n x = input.charCodeAt(i);\n output += hex_tab.charAt((x >>> 4) & 0x0f) + hex_tab.charAt(x & 0x0f);\n }\n return output;\n}\n\n/*\n * Convert a raw string to a base-64 string\n */\nfunction rstr2b64(input) {\n try {\n b64pad;\n } catch (e) {\n b64pad = '';\n }\n var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n var output = '';\n var len = input.length;\n for (var i = 0; i < len; i += 3) {\n var triplet =\n (input.charCodeAt(i) << 16) |\n (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) |\n (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (var j = 0; j < 4; j++) {\n if (i * 8 + j * 6 > input.length * 8) output += b64pad;\n else output += tab.charAt((triplet >>> (6 * (3 - j))) & 0x3f);\n }\n }\n return output;\n}\n\n/*\n * Convert a raw string to an arbitrary string encoding\n */\nfunction rstr2any(input, encoding) {\n var divisor = encoding.length;\n var i, j, q, x, quotient;\n\n /* Convert to an array of 16-bit big-endian values, forming the dividend */\n var dividend = Array(Math.ceil(input.length / 2));\n for (i = 0; i < dividend.length; i++) {\n dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n }\n\n /*\n * Repeatedly perform a long division. The binary array forms the dividend,\n * the length of the encoding is the divisor. Once computed, the quotient\n * forms the dividend for the next step. All remainders are stored for later\n * use.\n */\n var full_length = Math.ceil((input.length * 8) / (Math.log(encoding.length) / Math.log(2)));\n var remainders = Array(full_length);\n for (j = 0; j < full_length; j++) {\n quotient = Array();\n x = 0;\n for (i = 0; i < dividend.length; i++) {\n x = (x << 16) + dividend[i];\n q = Math.floor(x / divisor);\n x -= q * divisor;\n if (quotient.length > 0 || q > 0) quotient[quotient.length] = q;\n }\n remainders[j] = x;\n dividend = quotient;\n }\n\n /* Convert the remainders to the output string */\n var output = '';\n for (i = remainders.length - 1; i >= 0; i--) output += encoding.charAt(remainders[i]);\n\n return output;\n}\n\n/*\n * Encode a string as utf-8.\n * For efficiency, this assumes the input is valid utf-16.\n */\nfunction str2rstr_utf8(input) {\n var output = '';\n var i = -1;\n var x, y;\n\n while (++i < input.length) {\n /* Decode utf-16 surrogate pairs */\n x = input.charCodeAt(i);\n y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\n if (0xd800 <= x && x <= 0xdbff && 0xdc00 <= y && y <= 0xdfff) {\n x = 0x10000 + ((x & 0x03ff) << 10) + (y & 0x03ff);\n i++;\n }\n\n /* Encode output as utf-8 */\n if (x <= 0x7f) output += String.fromCharCode(x);\n else if (x <= 0x7ff) output += String.fromCharCode(0xc0 | ((x >>> 6) & 0x1f), 0x80 | (x & 0x3f));\n else if (x <= 0xffff)\n output += String.fromCharCode(0xe0 | ((x >>> 12) & 0x0f), 0x80 | ((x >>> 6) & 0x3f), 0x80 | (x & 0x3f));\n else if (x <= 0x1fffff)\n output += String.fromCharCode(\n 0xf0 | ((x >>> 18) & 0x07),\n 0x80 | ((x >>> 12) & 0x3f),\n 0x80 | ((x >>> 6) & 0x3f),\n 0x80 | (x & 0x3f),\n );\n }\n return output;\n}\n\n/*\n * Encode a string as utf-16\n */\nfunction str2rstr_utf16le(input) {\n var output = '';\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode(input.charCodeAt(i) & 0xff, (input.charCodeAt(i) >>> 8) & 0xff);\n return output;\n}\n\nfunction str2rstr_utf16be(input) {\n var output = '';\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xff, input.charCodeAt(i) & 0xff);\n return output;\n}\n\n/*\n * Convert a raw string to an array of little-endian words\n * Characters >255 have their high-byte silently ignored.\n */\nfunction rstr2binl(input) {\n var output = Array(input.length >> 2);\n for (var i = 0; i < output.length; i++) output[i] = 0;\n for (var i = 0; i < input.length * 8; i += 8) output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32);\n return output;\n}\n\n/*\n * Convert an array of little-endian words to a string\n */\nfunction binl2rstr(input) {\n var output = '';\n for (var i = 0; i < input.length * 32; i += 8) output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff);\n return output;\n}\n\n/*\n * Calculate the MD5 of an array of little-endian words, and a bit length.\n */\nfunction binl_md5(x, len) {\n /* append padding */\n x[len >> 5] |= 0x80 << (len % 32);\n x[(((len + 64) >>> 9) << 4) + 14] = len;\n\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n\n for (var i = 0; i < x.length; i += 16) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n\n a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);\n d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);\n b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);\n\n a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);\n a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);\n\n a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);\n d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);\n c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);\n\n a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);\n d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);\n\n a = safe_add(a, olda);\n b = safe_add(b, oldb);\n c = safe_add(c, oldc);\n d = safe_add(d, oldd);\n }\n return Array(a, b, c, d);\n}\n\n/*\n * These functions implement the four basic operations the algorithm uses.\n */\nfunction md5_cmn(q, a, b, x, s, t) {\n return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);\n}\nfunction md5_ff(a, b, c, d, x, s, t) {\n return md5_cmn((b & c) | (~b & d), a, b, x, s, t);\n}\nfunction md5_gg(a, b, c, d, x, s, t) {\n return md5_cmn((b & d) | (c & ~d), a, b, x, s, t);\n}\nfunction md5_hh(a, b, c, d, x, s, t) {\n return md5_cmn(b ^ c ^ d, a, b, x, s, t);\n}\nfunction md5_ii(a, b, c, d, x, s, t) {\n return md5_cmn(c ^ (b | ~d), a, b, x, s, t);\n}\n\n/*\n * Add integers, wrapping at 2^32. This uses 16-bit operations internally\n * to work around bugs in some JS interpreters.\n */\nfunction safe_add(x, y) {\n var lsw = (x & 0xffff) + (y & 0xffff);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 0xffff);\n}\n\n/*\n * Bitwise rotate a 32-bit number to the left.\n */\nfunction bit_rol(num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n}\n","/*\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined\n * in FIPS 180-1\n * Version 2.2 Copyright Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * Distributed under the BSD License\n * See http://pajhome.org.uk/crypt/md5 for details.\n */\n\n/*\n * Configurable variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n */\nvar hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\nvar b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\n\n/*\n * These are the functions you'll usually want to call\n * They take string arguments and return either hex or base-64 encoded strings\n */\nexport function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }\nfunction b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }\nfunction any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }\nfunction hex_hmac_sha1(k, d) { return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction b64_hmac_sha1(k, d) { return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction any_hmac_sha1(k, d, e) { return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\n\n/*\n * Perform a simple self-test to see if the VM is working\n */\nfunction sha1_vm_test() {\n return hex_sha1(\"abc\").toLowerCase() == \"a9993e364706816aba3e25717850c26c9cd0d89d\";\n}\n\n/*\n * Calculate the SHA1 of a raw string\n */\nfunction rstr_sha1(s) {\n return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));\n}\n\n/*\n * Calculate the HMAC-SHA1 of a key and some data (raw strings)\n */\nfunction rstr_hmac_sha1(key, data) {\n var bkey = rstr2binb(key);\n if (bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);\n\n var ipad = Array(16), opad = Array(16);\n for (var i = 0; i < 16; i++) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n\n var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\n return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));\n}\n\n/*\n * Convert a raw string to a hex string\n */\nfunction rstr2hex(input) {\n try { hexcase } catch (e) { hexcase = 0; }\n var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\n var output = \"\";\n var x;\n for (var i = 0; i < input.length; i++) {\n x = input.charCodeAt(i);\n output += hex_tab.charAt((x >>> 4) & 0x0F)\n + hex_tab.charAt(x & 0x0F);\n }\n return output;\n}\n\n/*\n * Convert a raw string to a base-64 string\n */\nfunction rstr2b64(input) {\n try { b64pad } catch (e) { b64pad = ''; }\n var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n var output = \"\";\n var len = input.length;\n for (var i = 0; i < len; i += 3) {\n var triplet = (input.charCodeAt(i) << 16)\n | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)\n | (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (var j = 0; j < 4; j++) {\n if (i * 8 + j * 6 > input.length * 8) output += b64pad;\n else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);\n }\n }\n return output;\n}\n\n/*\n * Convert a raw string to an arbitrary string encoding\n */\nfunction rstr2any(input, encoding) {\n var divisor = encoding.length;\n var remainders = Array();\n var i, q, x, quotient;\n\n /* Convert to an array of 16-bit big-endian values, forming the dividend */\n var dividend = Array(Math.ceil(input.length / 2));\n for (i = 0; i < dividend.length; i++) {\n dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n }\n\n /*\n * Repeatedly perform a long division. The binary array forms the dividend,\n * the length of the encoding is the divisor. Once computed, the quotient\n * forms the dividend for the next step. We stop when the dividend is zero.\n * All remainders are stored for later use.\n */\n while (dividend.length > 0) {\n quotient = Array();\n x = 0;\n for (i = 0; i < dividend.length; i++) {\n x = (x << 16) + dividend[i];\n q = Math.floor(x / divisor);\n x -= q * divisor;\n if (quotient.length > 0 || q > 0)\n quotient[quotient.length] = q;\n }\n remainders[remainders.length] = x;\n dividend = quotient;\n }\n\n /* Convert the remainders to the output string */\n var output = \"\";\n for (i = remainders.length - 1; i >= 0; i--)\n output += encoding.charAt(remainders[i]);\n\n /* Append leading zero equivalents */\n var full_length = Math.ceil(input.length * 8 /\n (Math.log(encoding.length) / Math.log(2)))\n for (i = output.length; i < full_length; i++)\n output = encoding[0] + output;\n\n return output;\n}\n\n/*\n * Encode a string as utf-8.\n * For efficiency, this assumes the input is valid utf-16.\n */\nfunction str2rstr_utf8(input) {\n var output = \"\";\n var i = -1;\n var x, y;\n\n while (++i < input.length) {\n /* Decode utf-16 surrogate pairs */\n x = input.charCodeAt(i);\n y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\n if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {\n x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\n i++;\n }\n\n /* Encode output as utf-8 */\n if (x <= 0x7F)\n output += String.fromCharCode(x);\n else if (x <= 0x7FF)\n output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),\n 0x80 | (x & 0x3F));\n else if (x <= 0xFFFF)\n output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n else if (x <= 0x1FFFFF)\n output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\n 0x80 | ((x >>> 12) & 0x3F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n }\n return output;\n}\n\n/*\n * Encode a string as utf-16\n */\nfunction str2rstr_utf16le(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode(input.charCodeAt(i) & 0xFF,\n (input.charCodeAt(i) >>> 8) & 0xFF);\n return output;\n}\n\nfunction str2rstr_utf16be(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\n input.charCodeAt(i) & 0xFF);\n return output;\n}\n\n/*\n * Convert a raw string to an array of big-endian words\n * Characters >255 have their high-byte silently ignored.\n */\nfunction rstr2binb(input) {\n var output = Array(input.length >> 2);\n for (var i = 0; i < output.length; i++)\n output[i] = 0;\n for (var i = 0; i < input.length * 8; i += 8)\n output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\n return output;\n}\n\n/*\n * Convert an array of big-endian words to a string\n */\nfunction binb2rstr(input) {\n var output = \"\";\n for (var i = 0; i < input.length * 32; i += 8)\n output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);\n return output;\n}\n\n/*\n * Calculate the SHA-1 of an array of big-endian words, and a bit length\n */\nfunction binb_sha1(x, len) {\n /* append padding */\n x[len >> 5] |= 0x80 << (24 - len % 32);\n x[((len + 64 >> 9) << 4) + 15] = len;\n\n var w = Array(80);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var e = -1009589776;\n\n for (var i = 0; i < x.length; i += 16) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n var olde = e;\n\n for (var j = 0; j < 80; j++) {\n if (j < 16) w[j] = x[i + j];\n else w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);\n var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),\n safe_add(safe_add(e, w[j]), sha1_kt(j)));\n e = d;\n d = c;\n c = bit_rol(b, 30);\n b = a;\n a = t;\n }\n\n a = safe_add(a, olda);\n b = safe_add(b, oldb);\n c = safe_add(c, oldc);\n d = safe_add(d, oldd);\n e = safe_add(e, olde);\n }\n return Array(a, b, c, d, e);\n\n}\n\n/*\n * Perform the appropriate triplet combination function for the current\n * iteration\n */\nfunction sha1_ft(t, b, c, d) {\n if (t < 20) return (b & c) | ((~b) & d);\n if (t < 40) return b ^ c ^ d;\n if (t < 60) return (b & c) | (b & d) | (c & d);\n return b ^ c ^ d;\n}\n\n/*\n * Determine the appropriate additive constant for the current iteration\n */\nfunction sha1_kt(t) {\n return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :\n (t < 60) ? -1894007588 : -899497514;\n}\n\n/*\n * Add integers, wrapping at 2^32. This uses 16-bit operations internally\n * to work around bugs in some JS interpreters.\n */\nfunction safe_add(x, y) {\n var lsw = (x & 0xFFFF) + (y & 0xFFFF);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 0xFFFF);\n}\n\n/*\n * Bitwise rotate a 32-bit number to the left.\n */\nfunction bit_rol(num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n}\n","/*\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined\n * in FIPS 180-2\n * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * Distributed under the BSD License\n * See http://pajhome.org.uk/crypt/md5 for details.\n * Also http://anmar.eu.org/projects/jssha2/\n */\n\n/*\n * Configurable variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n */\nvar hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\nvar b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\n\n/*\n * These are the functions you'll usually want to call\n * They take string arguments and return either hex or base-64 encoded strings\n */\nexport function hex_sha256(s) { return rstr2hex(rstr_sha256(str2rstr_utf8(s))); }\nfunction b64_sha256(s) { return rstr2b64(rstr_sha256(str2rstr_utf8(s))); }\nfunction any_sha256(s, e) { return rstr2any(rstr_sha256(str2rstr_utf8(s)), e); }\nfunction hex_hmac_sha256(k, d) { return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction b64_hmac_sha256(k, d) { return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction any_hmac_sha256(k, d, e) { return rstr2any(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\n\n/*\n * Perform a simple self-test to see if the VM is working\n */\nfunction sha256_vm_test() {\n return hex_sha256(\"abc\").toLowerCase() ==\n \"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\";\n}\n\n/*\n * Calculate the sha256 of a raw string\n */\nfunction rstr_sha256(s) {\n return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));\n}\n\n/*\n * Calculate the HMAC-sha256 of a key and some data (raw strings)\n */\nfunction rstr_hmac_sha256(key, data) {\n var bkey = rstr2binb(key);\n if (bkey.length > 16) bkey = binb_sha256(bkey, key.length * 8);\n\n var ipad = Array(16), opad = Array(16);\n for (var i = 0; i < 16; i++) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n\n var hash = binb_sha256(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\n return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256));\n}\n\n/*\n * Convert a raw string to a hex string\n */\nfunction rstr2hex(input) {\n try { hexcase } catch (e) { hexcase = 0; }\n var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\n var output = \"\";\n var x;\n for (var i = 0; i < input.length; i++) {\n x = input.charCodeAt(i);\n output += hex_tab.charAt((x >>> 4) & 0x0F)\n + hex_tab.charAt(x & 0x0F);\n }\n return output;\n}\n\n/*\n * Convert a raw string to a base-64 string\n */\nfunction rstr2b64(input) {\n try { b64pad } catch (e) { b64pad = ''; }\n var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n var output = \"\";\n var len = input.length;\n for (var i = 0; i < len; i += 3) {\n var triplet = (input.charCodeAt(i) << 16)\n | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)\n | (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (var j = 0; j < 4; j++) {\n if (i * 8 + j * 6 > input.length * 8) output += b64pad;\n else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);\n }\n }\n return output;\n}\n\n/*\n * Convert a raw string to an arbitrary string encoding\n */\nfunction rstr2any(input, encoding) {\n var divisor = encoding.length;\n var remainders = Array();\n var i, q, x, quotient;\n\n /* Convert to an array of 16-bit big-endian values, forming the dividend */\n var dividend = Array(Math.ceil(input.length / 2));\n for (i = 0; i < dividend.length; i++) {\n dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n }\n\n /*\n * Repeatedly perform a long division. The binary array forms the dividend,\n * the length of the encoding is the divisor. Once computed, the quotient\n * forms the dividend for the next step. We stop when the dividend is zero.\n * All remainders are stored for later use.\n */\n while (dividend.length > 0) {\n quotient = Array();\n x = 0;\n for (i = 0; i < dividend.length; i++) {\n x = (x << 16) + dividend[i];\n q = Math.floor(x / divisor);\n x -= q * divisor;\n if (quotient.length > 0 || q > 0)\n quotient[quotient.length] = q;\n }\n remainders[remainders.length] = x;\n dividend = quotient;\n }\n\n /* Convert the remainders to the output string */\n var output = \"\";\n for (i = remainders.length - 1; i >= 0; i--)\n output += encoding.charAt(remainders[i]);\n\n /* Append leading zero equivalents */\n var full_length = Math.ceil(input.length * 8 /\n (Math.log(encoding.length) / Math.log(2)))\n for (i = output.length; i < full_length; i++)\n output = encoding[0] + output;\n\n return output;\n}\n\n/*\n * Encode a string as utf-8.\n * For efficiency, this assumes the input is valid utf-16.\n */\nfunction str2rstr_utf8(input) {\n var output = \"\";\n var i = -1;\n var x, y;\n\n while (++i < input.length) {\n /* Decode utf-16 surrogate pairs */\n x = input.charCodeAt(i);\n y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\n if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {\n x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\n i++;\n }\n\n /* Encode output as utf-8 */\n if (x <= 0x7F)\n output += String.fromCharCode(x);\n else if (x <= 0x7FF)\n output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),\n 0x80 | (x & 0x3F));\n else if (x <= 0xFFFF)\n output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n else if (x <= 0x1FFFFF)\n output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\n 0x80 | ((x >>> 12) & 0x3F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n }\n return output;\n}\n\n/*\n * Encode a string as utf-16\n */\nfunction str2rstr_utf16le(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode(input.charCodeAt(i) & 0xFF,\n (input.charCodeAt(i) >>> 8) & 0xFF);\n return output;\n}\n\nfunction str2rstr_utf16be(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\n input.charCodeAt(i) & 0xFF);\n return output;\n}\n\n/*\n * Convert a raw string to an array of big-endian words\n * Characters >255 have their high-byte silently ignored.\n */\nfunction rstr2binb(input) {\n var output = Array(input.length >> 2);\n for (var i = 0; i < output.length; i++)\n output[i] = 0;\n for (var i = 0; i < input.length * 8; i += 8)\n output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\n return output;\n}\n\n/*\n * Convert an array of big-endian words to a string\n */\nfunction binb2rstr(input) {\n var output = \"\";\n for (var i = 0; i < input.length * 32; i += 8)\n output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);\n return output;\n}\n\n/*\n * Main sha256 function, with its support functions\n */\nfunction sha256_S(X, n) { return (X >>> n) | (X << (32 - n)); }\nfunction sha256_R(X, n) { return (X >>> n); }\nfunction sha256_Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }\nfunction sha256_Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }\nfunction sha256_Sigma0256(x) { return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22)); }\nfunction sha256_Sigma1256(x) { return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25)); }\nfunction sha256_Gamma0256(x) { return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3)); }\nfunction sha256_Gamma1256(x) { return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10)); }\nfunction sha256_Sigma0512(x) { return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39)); }\nfunction sha256_Sigma1512(x) { return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41)); }\nfunction sha256_Gamma0512(x) { return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7)); }\nfunction sha256_Gamma1512(x) { return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6)); }\n\nvar sha256_K = new Array\n (\n 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,\n -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,\n 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,\n 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,\n -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,\n 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,\n 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,\n -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,\n 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,\n 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,\n -1866530822, -1538233109, -1090935817, -965641998\n );\n\nfunction binb_sha256(m, l) {\n var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534,\n 1359893119, -1694144372, 528734635, 1541459225);\n var W = new Array(64);\n var a, b, c, d, e, f, g, h;\n var i, j, T1, T2;\n\n /* append padding */\n m[l >> 5] |= 0x80 << (24 - l % 32);\n m[((l + 64 >> 9) << 4) + 15] = l;\n\n for (i = 0; i < m.length; i += 16) {\n a = HASH[0];\n b = HASH[1];\n c = HASH[2];\n d = HASH[3];\n e = HASH[4];\n f = HASH[5];\n g = HASH[6];\n h = HASH[7];\n\n for (j = 0; j < 64; j++) {\n if (j < 16) W[j] = m[j + i];\n else W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),\n sha256_Gamma0256(W[j - 15])), W[j - 16]);\n\n T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),\n sha256_K[j]), W[j]);\n T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safe_add(d, T1);\n d = c;\n c = b;\n b = a;\n a = safe_add(T1, T2);\n }\n\n HASH[0] = safe_add(a, HASH[0]);\n HASH[1] = safe_add(b, HASH[1]);\n HASH[2] = safe_add(c, HASH[2]);\n HASH[3] = safe_add(d, HASH[3]);\n HASH[4] = safe_add(e, HASH[4]);\n HASH[5] = safe_add(f, HASH[5]);\n HASH[6] = safe_add(g, HASH[6]);\n HASH[7] = safe_add(h, HASH[7]);\n }\n return HASH;\n}\n\nfunction safe_add(x, y) {\n var lsw = (x & 0xFFFF) + (y & 0xFFFF);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 0xFFFF);\n}\n","/*\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined\n * in FIPS 180-2\n * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * Distributed under the BSD License\n * See http://pajhome.org.uk/crypt/md5 for details.\n */\n\n/*\n * Configurable variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n */\nvar hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */\nvar b64pad = \"\"; /* base-64 pad character. \"=\" for strict RFC compliance */\n\n/*\n * These are the functions you'll usually want to call\n * They take string arguments and return either hex or base-64 encoded strings\n */\nexport function hex_sha512(s) { return rstr2hex(rstr_sha512(str2rstr_utf8(s))); }\nfunction b64_sha512(s) { return rstr2b64(rstr_sha512(str2rstr_utf8(s))); }\nfunction any_sha512(s, e) { return rstr2any(rstr_sha512(str2rstr_utf8(s)), e); }\nfunction hex_hmac_sha512(k, d) { return rstr2hex(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction b64_hmac_sha512(k, d) { return rstr2b64(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d))); }\nfunction any_hmac_sha512(k, d, e) { return rstr2any(rstr_hmac_sha512(str2rstr_utf8(k), str2rstr_utf8(d)), e); }\n\n/*\n * Perform a simple self-test to see if the VM is working\n */\nfunction sha512_vm_test() {\n return hex_sha512(\"abc\").toLowerCase() ==\n \"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a\" +\n \"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f\";\n}\n\n/*\n * Calculate the SHA-512 of a raw string\n */\nfunction rstr_sha512(s) {\n return binb2rstr(binb_sha512(rstr2binb(s), s.length * 8));\n}\n\n/*\n * Calculate the HMAC-SHA-512 of a key and some data (raw strings)\n */\nfunction rstr_hmac_sha512(key, data) {\n var bkey = rstr2binb(key);\n if (bkey.length > 32) bkey = binb_sha512(bkey, key.length * 8);\n\n var ipad = Array(32), opad = Array(32);\n for (var i = 0; i < 32; i++) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n\n var hash = binb_sha512(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);\n return binb2rstr(binb_sha512(opad.concat(hash), 1024 + 512));\n}\n\n/*\n * Convert a raw string to a hex string\n */\nfunction rstr2hex(input) {\n try { hexcase } catch (e) { hexcase = 0; }\n var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\n var output = \"\";\n var x;\n for (var i = 0; i < input.length; i++) {\n x = input.charCodeAt(i);\n output += hex_tab.charAt((x >>> 4) & 0x0F)\n + hex_tab.charAt(x & 0x0F);\n }\n return output;\n}\n\n/*\n * Convert a raw string to a base-64 string\n */\nfunction rstr2b64(input) {\n try { b64pad } catch (e) { b64pad = ''; }\n var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n var output = \"\";\n var len = input.length;\n for (var i = 0; i < len; i += 3) {\n var triplet = (input.charCodeAt(i) << 16)\n | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)\n | (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (var j = 0; j < 4; j++) {\n if (i * 8 + j * 6 > input.length * 8) output += b64pad;\n else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);\n }\n }\n return output;\n}\n\n/*\n * Convert a raw string to an arbitrary string encoding\n */\nfunction rstr2any(input, encoding) {\n var divisor = encoding.length;\n var i, j, q, x, quotient;\n\n /* Convert to an array of 16-bit big-endian values, forming the dividend */\n var dividend = Array(Math.ceil(input.length / 2));\n for (i = 0; i < dividend.length; i++) {\n dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n }\n\n /*\n * Repeatedly perform a long division. The binary array forms the dividend,\n * the length of the encoding is the divisor. Once computed, the quotient\n * forms the dividend for the next step. All remainders are stored for later\n * use.\n */\n var full_length = Math.ceil(input.length * 8 /\n (Math.log(encoding.length) / Math.log(2)));\n var remainders = Array(full_length);\n for (j = 0; j < full_length; j++) {\n quotient = Array();\n x = 0;\n for (i = 0; i < dividend.length; i++) {\n x = (x << 16) + dividend[i];\n q = Math.floor(x / divisor);\n x -= q * divisor;\n if (quotient.length > 0 || q > 0)\n quotient[quotient.length] = q;\n }\n remainders[j] = x;\n dividend = quotient;\n }\n\n /* Convert the remainders to the output string */\n var output = \"\";\n for (i = remainders.length - 1; i >= 0; i--)\n output += encoding.charAt(remainders[i]);\n\n return output;\n}\n\n/*\n * Encode a string as utf-8.\n * For efficiency, this assumes the input is valid utf-16.\n */\nfunction str2rstr_utf8(input) {\n var output = \"\";\n var i = -1;\n var x, y;\n\n while (++i < input.length) {\n /* Decode utf-16 surrogate pairs */\n x = input.charCodeAt(i);\n y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;\n if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {\n x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\n i++;\n }\n\n /* Encode output as utf-8 */\n if (x <= 0x7F)\n output += String.fromCharCode(x);\n else if (x <= 0x7FF)\n output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),\n 0x80 | (x & 0x3F));\n else if (x <= 0xFFFF)\n output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n else if (x <= 0x1FFFFF)\n output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\n 0x80 | ((x >>> 12) & 0x3F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n }\n return output;\n}\n\n/*\n * Encode a string as utf-16\n */\nfunction str2rstr_utf16le(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode(input.charCodeAt(i) & 0xFF,\n (input.charCodeAt(i) >>> 8) & 0xFF);\n return output;\n}\n\nfunction str2rstr_utf16be(input) {\n var output = \"\";\n for (var i = 0; i < input.length; i++)\n output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,\n input.charCodeAt(i) & 0xFF);\n return output;\n}\n\n/*\n * Convert a raw string to an array of big-endian words\n * Characters >255 have their high-byte silently ignored.\n */\nfunction rstr2binb(input) {\n var output = Array(input.length >> 2);\n for (var i = 0; i < output.length; i++)\n output[i] = 0;\n for (var i = 0; i < input.length * 8; i += 8)\n output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\n return output;\n}\n\n/*\n * Convert an array of big-endian words to a string\n */\nfunction binb2rstr(input) {\n var output = \"\";\n for (var i = 0; i < input.length * 32; i += 8)\n output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);\n return output;\n}\n\n/*\n * Calculate the SHA-512 of an array of big-endian dwords, and a bit length\n */\nvar sha512_k;\nfunction binb_sha512(x, len) {\n if (sha512_k == undefined) {\n //SHA512 constants\n sha512_k = new Array(\n new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),\n new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),\n new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),\n new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),\n new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),\n new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),\n new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),\n new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),\n new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),\n new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),\n new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),\n new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),\n new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),\n new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),\n new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),\n new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),\n new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),\n new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),\n new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),\n new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),\n new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),\n new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),\n new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),\n new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),\n new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),\n new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),\n new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),\n new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),\n new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),\n new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),\n new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),\n new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),\n new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),\n new int64(-354779690, -840897762), new int64(-176337025, -294727304),\n new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),\n new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),\n new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),\n new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),\n new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),\n new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817));\n }\n\n //Initial hash values\n var H = new Array(\n new int64(0x6a09e667, -205731576),\n new int64(-1150833019, -2067093701),\n new int64(0x3c6ef372, -23791573),\n new int64(-1521486534, 0x5f1d36f1),\n new int64(0x510e527f, -1377402159),\n new int64(-1694144372, 0x2b3e6c1f),\n new int64(0x1f83d9ab, -79577749),\n new int64(0x5be0cd19, 0x137e2179));\n\n var T1 = new int64(0, 0),\n T2 = new int64(0, 0),\n a = new int64(0, 0),\n b = new int64(0, 0),\n c = new int64(0, 0),\n d = new int64(0, 0),\n e = new int64(0, 0),\n f = new int64(0, 0),\n g = new int64(0, 0),\n h = new int64(0, 0),\n //Temporary variables not specified by the document\n s0 = new int64(0, 0),\n s1 = new int64(0, 0),\n Ch = new int64(0, 0),\n Maj = new int64(0, 0),\n r1 = new int64(0, 0),\n r2 = new int64(0, 0),\n r3 = new int64(0, 0);\n var j, i;\n var W = new Array(80);\n for (i = 0; i < 80; i++)\n W[i] = new int64(0, 0);\n\n // append padding to the source string. The format is described in the FIPS.\n x[len >> 5] |= 0x80 << (24 - (len & 0x1f));\n x[((len + 128 >> 10) << 5) + 31] = len;\n\n for (i = 0; i < x.length; i += 32) //32 dwords is the block size\n {\n int64copy(a, H[0]);\n int64copy(b, H[1]);\n int64copy(c, H[2]);\n int64copy(d, H[3]);\n int64copy(e, H[4]);\n int64copy(f, H[5]);\n int64copy(g, H[6]);\n int64copy(h, H[7]);\n\n for (j = 0; j < 16; j++) {\n W[j].h = x[i + 2 * j];\n W[j].l = x[i + 2 * j + 1];\n }\n\n for (j = 16; j < 80; j++) {\n //sigma1\n int64rrot(r1, W[j - 2], 19);\n int64revrrot(r2, W[j - 2], 29);\n int64shr(r3, W[j - 2], 6);\n s1.l = r1.l ^ r2.l ^ r3.l;\n s1.h = r1.h ^ r2.h ^ r3.h;\n //sigma0\n int64rrot(r1, W[j - 15], 1);\n int64rrot(r2, W[j - 15], 8);\n int64shr(r3, W[j - 15], 7);\n s0.l = r1.l ^ r2.l ^ r3.l;\n s0.h = r1.h ^ r2.h ^ r3.h;\n\n int64add4(W[j], s1, W[j - 7], s0, W[j - 16]);\n }\n\n for (j = 0; j < 80; j++) {\n //Ch\n Ch.l = (e.l & f.l) ^ (~e.l & g.l);\n Ch.h = (e.h & f.h) ^ (~e.h & g.h);\n\n //Sigma1\n int64rrot(r1, e, 14);\n int64rrot(r2, e, 18);\n int64revrrot(r3, e, 9);\n s1.l = r1.l ^ r2.l ^ r3.l;\n s1.h = r1.h ^ r2.h ^ r3.h;\n\n //Sigma0\n int64rrot(r1, a, 28);\n int64revrrot(r2, a, 2);\n int64revrrot(r3, a, 7);\n s0.l = r1.l ^ r2.l ^ r3.l;\n s0.h = r1.h ^ r2.h ^ r3.h;\n\n //Maj\n Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);\n Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);\n\n int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);\n int64add(T2, s0, Maj);\n\n int64copy(h, g);\n int64copy(g, f);\n int64copy(f, e);\n int64add(e, d, T1);\n int64copy(d, c);\n int64copy(c, b);\n int64copy(b, a);\n int64add(a, T1, T2);\n }\n int64add(H[0], H[0], a);\n int64add(H[1], H[1], b);\n int64add(H[2], H[2], c);\n int64add(H[3], H[3], d);\n int64add(H[4], H[4], e);\n int64add(H[5], H[5], f);\n int64add(H[6], H[6], g);\n int64add(H[7], H[7], h);\n }\n\n //represent the hash as an array of 32-bit dwords\n var hash = new Array(16);\n for (i = 0; i < 8; i++) {\n hash[2 * i] = H[i].h;\n hash[2 * i + 1] = H[i].l;\n }\n return hash;\n}\n\n//A constructor for 64-bit numbers\nfunction int64(h, l) {\n this.h = h;\n this.l = l;\n //this.toString = int64toString;\n}\n\n//Copies src into dst, assuming both are 64-bit numbers\nfunction int64copy(dst, src) {\n dst.h = src.h;\n dst.l = src.l;\n}\n\n//Right-rotates a 64-bit number by shift\n//Won't handle cases of shift>=32\n//The function revrrot() is for that\nfunction int64rrot(dst, x, shift) {\n dst.l = (x.l >>> shift) | (x.h << (32 - shift));\n dst.h = (x.h >>> shift) | (x.l << (32 - shift));\n}\n\n//Reverses the dwords of the source and then rotates right by shift.\n//This is equivalent to rotation by 32+shift\nfunction int64revrrot(dst, x, shift) {\n dst.l = (x.h >>> shift) | (x.l << (32 - shift));\n dst.h = (x.l >>> shift) | (x.h << (32 - shift));\n}\n\n//Bitwise-shifts right a 64-bit number by shift\n//Won't handle shift>=32, but it's never needed in SHA512\nfunction int64shr(dst, x, shift) {\n dst.l = (x.l >>> shift) | (x.h << (32 - shift));\n dst.h = (x.h >>> shift);\n}\n\n//Adds two 64-bit numbers\n//Like the original implementation, does not rely on 32-bit operations\nfunction int64add(dst, x, y) {\n var w0 = (x.l & 0xffff) + (y.l & 0xffff);\n var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);\n var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);\n var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n}\n\n//Same, except with 4 addends. Works faster than adding them one by one.\nfunction int64add4(dst, a, b, c, d) {\n var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);\n var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);\n var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);\n var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n}\n\n//Same, except with 5 addends\nfunction int64add5(dst, a, b, c, d, e) {\n var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff);\n var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16);\n var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16);\n var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n}\n","import { hex_md5 } from './crypto/md5.mjs';\nimport { hex_sha1 } from './crypto/sha1.mjs';\nimport { hex_sha256 } from './crypto/sha256.mjs';\nimport { hex_sha512 } from './crypto/sha512.mjs';\n\n/**\n * 计算字符串的 MD5 哈希值\n * @param input - 需要计算哈希值的字符串\n * @returns 返回 32 个字符的十六进制 MD5 哈希值\n * @example\n * ```typescript\n * const hash = md5String('hello world');\n * console.log(hash); // '5eb63bbbe01eeed093cb22bb8f5acdc3'\n * ```\n */\nexport function md5String(input: string): string {\n return hex_md5(input);\n}\n\n/**\n * 计算字符串的 SHA1 哈希值\n * @param input - 需要计算哈希值的字符串\n * @returns 返回 40 个字符的十六进制 SHA1 哈希值\n * @example\n * ```typescript\n * const hash = sha1String('hello world');\n * console.log(hash); // '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'\n * ```\n */\nexport function sha1String(input: string): string {\n return hex_sha1(input);\n}\n\n/**\n * 计算字符串的 SHA256 哈希值\n * @param input - 需要计算哈希值的字符串\n * @returns 返回 64 个字符的十六进制 SHA256 哈希值\n * @example\n * ```typescript\n * const hash = sha256String('hello world');\n * console.log(hash); // 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'\n * ```\n */\nexport function sha256String(input: string): string {\n return hex_sha256(input);\n}\n\n/**\n * 计算字符串的 SHA512 哈希值\n * @param input - 需要计算哈希值的字符串\n * @returns 返回 128 个字符的十六进制 SHA512 哈希值\n * @example\n * ```typescript\n * const hash = sha512String('hello world');\n * console.log(hash); // '309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f'\n * ```\n */\nexport function sha512String(input: string): string {\n return hex_sha512(input);\n}\n"],"names":["hexcase","rstr2hex","str2rstr_utf8","safe_add","bit_rol","binb2rstr","rstr2binb"],"mappings":";;AAaA,IAAIA,YAAU;AAOP,SAAS,QAAQ,GAAG;AACzB,SAAOC,WAAS,SAASC,gBAAc,CAAC,CAAC,CAAC;AAC5C;AA2BA,SAAS,SA