From 37b353c21dfd338062c37be3505eaf2535d3335e Mon Sep 17 00:00:00 2001 From: g7sim <60353863+g7sim@users.noreply.github.com> Date: Sun, 25 Sep 2022 16:46:09 +0200 Subject: [PATCH] Cryto libs update --- include/js/sha.js | 22 ++ include/js/sha.js.map | 1 + include/js/sha.mjs | 10 + include/js/sha3.js | 21 ++ include/js/sha3.mjs | 9 + include/thirdparty/crypt/Keccak.php | 312 ++++++++++++++++++++++++++++ include/thirdparty/js/sha.js | 22 ++ include/thirdparty/js/sha.js.map | 1 + include/thirdparty/js/sha.mjs | 10 + 9 files changed, 408 insertions(+) create mode 100644 include/js/sha.js create mode 100644 include/js/sha.js.map create mode 100644 include/js/sha.mjs create mode 100644 include/js/sha3.js create mode 100644 include/js/sha3.mjs create mode 100644 include/thirdparty/crypt/Keccak.php create mode 100644 include/thirdparty/js/sha.js create mode 100644 include/thirdparty/js/sha.js.map create mode 100644 include/thirdparty/js/sha.mjs diff --git a/include/js/sha.js b/include/js/sha.js new file mode 100644 index 0000000..3016fc0 --- /dev/null +++ b/include/js/sha.js @@ -0,0 +1,22 @@ +/** + * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, + * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. + * + * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors + * Distributed under the BSD License + * See http://caligatio.github.com/jsSHA/ for more information + * + * Two ECMAScript polyfill functions carry the following license: + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + * MERCHANTABLITY OR NON-INFRINGEMENT. + * + * See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. + */ +!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n="undefined"!=typeof globalThis?globalThis:n||self).jsSHA=r()}(this,(function(){"use strict";var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function r(n,r,t,e){var i,o,u,f=r||[0],w=(t=t||0)>>>3,s=-1===e?3:0;for(i=0;i>>2,f.length<=o&&f.push(0),f[o]|=n[i]<<8*(s+e*(u%4));return{value:f,binLen:8*n.length+t}}function t(t,e,i){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(n,r,t){return function(n,r,t,e){var i,o,u,f;if(0!=n.length%2)throw new Error("String of HEX type must be in byte increments");var w=r||[0],s=(t=t||0)>>>3,a=-1===e?3:0;for(i=0;i>>1)+s)>>>2;w.length<=u;)w.push(0);w[u]|=o<<8*(a+e*(f%4))}return{value:w,binLen:4*n.length+t}}(n,r,t,i)};case"TEXT":return function(n,r,t){return function(n,r,t,e,i){var o,u,f,w,s,a,h,c,v=0,A=t||[0],E=(e=e||0)>>>3;if("UTF8"===r)for(h=-1===i?3:0,f=0;f(o=n.charCodeAt(f))?u.push(o):2048>o?(u.push(192|o>>>6),u.push(128|63&o)):55296>o||57344<=o?u.push(224|o>>>12,128|o>>>6&63,128|63&o):(f+=1,o=65536+((1023&o)<<10|1023&n.charCodeAt(f)),u.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),w=0;w>>2;A.length<=s;)A.push(0);A[s]|=u[w]<<8*(h+i*(a%4)),v+=1}else for(h=-1===i?2:0,c="UTF16LE"===r&&1!==i||"UTF16LE"!==r&&1===i,f=0;f>>8),s=(a=v+E)>>>2;A.length<=s;)A.push(0);A[s]|=o<<8*(h+i*(a%4)),v+=2}return{value:A,binLen:8*v+e}}(n,e,r,t,i)};case"B64":return function(r,t,e){return function(r,t,e,i){var o,u,f,w,s,a,h=0,c=t||[0],v=(e=e||0)>>>3,A=-1===i?3:0,E=r.indexOf("=");if(-1===r.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(r=r.replace(/=/g,""),-1!==E&&E>> 2;\n while (packed.length <= intOffset) {\n packed.push(0);\n }\n packed[intOffset] |=\n ((tmpInt >>> (16 - j * 8)) & 0xff) << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n byteCnt += 1;\n }\n }\n\n return { value: packed, binLen: byteCnt * 8 + existingPackedLen };\n}\n\n/**\n * Convert an Uint8Array to an array of words.\n *\n * @param arr Uint8Array to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Hashmap of the packed values.\n */\nfunction uint8array2packed(\n arr: Uint8Array,\n existingPacked: number[] | undefined,\n existingPackedLen: number | undefined,\n bigEndianMod: -1 | 1\n): packedValue {\n let i, intOffset, byteOffset;\n\n existingPackedLen = existingPackedLen || 0;\n const packed = existingPacked || [0],\n existingByteLen = existingPackedLen >>> 3,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < arr.length; i += 1) {\n byteOffset = i + existingByteLen;\n intOffset = byteOffset >>> 2;\n if (packed.length <= intOffset) {\n packed.push(0);\n }\n packed[intOffset] |= arr[i] << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n }\n\n return { value: packed, binLen: arr.length * 8 + existingPackedLen };\n}\n\n/**\n * Convert an ArrayBuffer to an array of words\n *\n * @param arr ArrayBuffer to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Hashmap of the packed values.\n */\nfunction arraybuffer2packed(\n arr: ArrayBuffer,\n existingPacked: number[] | undefined,\n existingPackedLen: number | undefined,\n bigEndianMod: -1 | 1\n): packedValue {\n return uint8array2packed(new Uint8Array(arr), existingPacked, existingPackedLen, bigEndianMod);\n}\n\n/**\n * Function that takes an input format and UTF encoding and returns the appropriate function used to convert the input.\n *\n * @param format The format of the input to be converted\n * @param utfType The string encoding to use for TEXT inputs.\n * @param bigEndianMod Modifier for whether hash function is big or small endian\n * @returns Function that will convert an input to a packed int array.\n */\nexport function getStrConverter(\n format: FormatType,\n utfType: EncodingType,\n bigEndianMod: -1 | 1\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n): (input: any, existingBin?: number[], existingBinLen?: number) => packedValue {\n /* Validate encoding */\n switch (utfType) {\n case \"UTF8\":\n /* Fallthrough */\n case \"UTF16BE\":\n /* Fallthrough */\n case \"UTF16LE\":\n /* Fallthrough */\n break;\n default:\n throw new Error(\"encoding must be UTF8, UTF16BE, or UTF16LE\");\n }\n\n /* Map inputFormat to the appropriate converter */\n switch (format) {\n case \"HEX\":\n /**\n * @param str String of hexadecimal bytes to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return hex2packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"TEXT\":\n /**\n * @param str Unicode string to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return str2packed(str, utfType, existingBin, existingBinLen, bigEndianMod);\n };\n case \"B64\":\n /**\n * @param str Base64-encoded string to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return b642packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"BYTES\":\n /**\n * @param str String of raw bytes to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return bytes2packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"ARRAYBUFFER\":\n try {\n new ArrayBuffer(0);\n } catch (ignore) {\n throw new Error(arraybuffer_error);\n }\n /**\n * @param arr ArrayBuffer to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (arr: ArrayBuffer, existingBin?: number[], existingBinLen?: number): packedValue {\n return arraybuffer2packed(arr, existingBin, existingBinLen, bigEndianMod);\n };\n case \"UINT8ARRAY\":\n try {\n new Uint8Array(0);\n } catch (ignore) {\n throw new Error(uint8array_error);\n }\n /**\n * @param arr Uint8Array to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (arr: Uint8Array, existingBin?: number[], existingBinLen?: number): packedValue {\n return uint8array2packed(arr, existingBin, existingBinLen, bigEndianMod);\n };\n default:\n throw new Error(\"format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY\");\n }\n}\n\n/**\n * Convert an array of words to a hexadecimal string.\n *\n * toString() won't work here because it removes preceding zeros (e.g. 0x00000001.toString === \"1\" rather than\n * \"00000001\" and 0.toString(16) === \"0\" rather than \"00\").\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param formatOpts Hashmap containing validated output formatting options.\n * @returns Hexadecimal representation of `packed`.\n */\nexport function packed2hex(\n packed: number[],\n outputLength: number,\n bigEndianMod: -1 | 1,\n formatOpts: { outputUpper: boolean; b64Pad: string }\n): string {\n const hex_tab = \"0123456789abcdef\";\n let str = \"\",\n i,\n srcByte;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n /* The below is more than a byte but it gets taken care of later */\n srcByte = packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)));\n str += hex_tab.charAt((srcByte >>> 4) & 0xf) + hex_tab.charAt(srcByte & 0xf);\n }\n\n return formatOpts[\"outputUpper\"] ? str.toUpperCase() : str;\n}\n\n/**\n * Convert an array of words to a base-64 string.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param formatOpts Hashmap containing validated output formatting options.\n * @returns Base64-encoded representation of `packed`.\n */\nexport function packed2b64(\n packed: number[],\n outputLength: number,\n bigEndianMod: -1 | 1,\n formatOpts: { outputUpper: boolean; b64Pad: string }\n): string {\n let str = \"\",\n i,\n j,\n triplet,\n int1,\n int2;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 3) {\n int1 = i + 1 < length ? packed[(i + 1) >>> 2] : 0;\n int2 = i + 2 < length ? packed[(i + 2) >>> 2] : 0;\n triplet =\n (((packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff) << 16) |\n (((int1 >>> (8 * (shiftModifier + bigEndianMod * ((i + 1) % 4)))) & 0xff) << 8) |\n ((int2 >>> (8 * (shiftModifier + bigEndianMod * ((i + 2) % 4)))) & 0xff);\n for (j = 0; j < 4; j += 1) {\n if (i * 8 + j * 6 <= outputLength) {\n str += b64Tab.charAt((triplet >>> (6 * (3 - j))) & 0x3f);\n } else {\n str += formatOpts[\"b64Pad\"];\n }\n }\n }\n return str;\n}\n\n/**\n * Convert an array of words to raw bytes string.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Raw bytes representation of `packed`.\n */\nexport function packed2bytes(packed: number[], outputLength: number, bigEndianMod: -1 | 1): string {\n let str = \"\",\n i,\n srcByte;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n srcByte = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n str += String.fromCharCode(srcByte);\n }\n\n return str;\n}\n\n/**\n * Convert an array of words to an ArrayBuffer.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns An ArrayBuffer containing bytes from `packed.\n */\nexport function packed2arraybuffer(packed: number[], outputLength: number, bigEndianMod: -1 | 1): ArrayBuffer {\n let i;\n const length = outputLength / 8,\n retVal = new ArrayBuffer(length),\n arrView = new Uint8Array(retVal),\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n arrView[i] = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n }\n\n return retVal;\n}\n\n/**\n * Convert an array of words to an Uint8Array.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns An Uint8Array containing bytes from `packed.\n */\nexport function packed2uint8array(packed: number[], outputLength: number, bigEndianMod: -1 | 1): Uint8Array {\n let i;\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0,\n retVal = new Uint8Array(length);\n\n for (i = 0; i < length; i += 1) {\n retVal[i] = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n }\n\n return retVal;\n}\n\n/**\n * Function that takes an output format and associated parameters and returns a function that converts packed integers\n * to that format.\n *\n * @param format The desired output formatting.\n * @param outputBinLen Output length in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param outputOptions Hashmap of output formatting options\n * @returns Function that will convert a packed integer array to desired format.\n */\nexport function getOutputConverter(\n format: \"HEX\" | \"B64\" | \"BYTES\" | \"ARRAYBUFFER\" | \"UINT8ARRAY\",\n outputBinLen: number,\n bigEndianMod: -1 | 1,\n outputOptions: { outputUpper: boolean; b64Pad: string }\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n): (binarray: number[]) => any {\n switch (format) {\n case \"HEX\":\n return function (binarray): string {\n return packed2hex(binarray, outputBinLen, bigEndianMod, outputOptions);\n };\n case \"B64\":\n return function (binarray): string {\n return packed2b64(binarray, outputBinLen, bigEndianMod, outputOptions);\n };\n case \"BYTES\":\n return function (binarray): string {\n return packed2bytes(binarray, outputBinLen, bigEndianMod);\n };\n case \"ARRAYBUFFER\":\n try {\n /* Need to test ArrayBuffer support */\n new ArrayBuffer(0);\n } catch (ignore) {\n throw new Error(arraybuffer_error);\n }\n return function (binarray): ArrayBuffer {\n return packed2arraybuffer(binarray, outputBinLen, bigEndianMod);\n };\n case \"UINT8ARRAY\":\n try {\n /* Need to test Uint8Array support */\n new Uint8Array(0);\n } catch (ignore) {\n throw new Error(uint8array_error);\n }\n return function (binarray): Uint8Array {\n return packed2uint8array(binarray, outputBinLen, bigEndianMod);\n };\n default:\n throw new Error(\"format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY\");\n }\n}\n","import { getStrConverter, getOutputConverter } from \"./converters\";\n\nimport {\n FormatType,\n EncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n packedValue,\n GenericInputType,\n} from \"./custom_types\";\n\nexport const TWO_PWR_32 = 4294967296;\n\n/* Constant used in SHA-2 families */\nexport const K_sha2 = [\n 0x428a2f98,\n 0x71374491,\n 0xb5c0fbcf,\n 0xe9b5dba5,\n 0x3956c25b,\n 0x59f111f1,\n 0x923f82a4,\n 0xab1c5ed5,\n 0xd807aa98,\n 0x12835b01,\n 0x243185be,\n 0x550c7dc3,\n 0x72be5d74,\n 0x80deb1fe,\n 0x9bdc06a7,\n 0xc19bf174,\n 0xe49b69c1,\n 0xefbe4786,\n 0x0fc19dc6,\n 0x240ca1cc,\n 0x2de92c6f,\n 0x4a7484aa,\n 0x5cb0a9dc,\n 0x76f988da,\n 0x983e5152,\n 0xa831c66d,\n 0xb00327c8,\n 0xbf597fc7,\n 0xc6e00bf3,\n 0xd5a79147,\n 0x06ca6351,\n 0x14292967,\n 0x27b70a85,\n 0x2e1b2138,\n 0x4d2c6dfc,\n 0x53380d13,\n 0x650a7354,\n 0x766a0abb,\n 0x81c2c92e,\n 0x92722c85,\n 0xa2bfe8a1,\n 0xa81a664b,\n 0xc24b8b70,\n 0xc76c51a3,\n 0xd192e819,\n 0xd6990624,\n 0xf40e3585,\n 0x106aa070,\n 0x19a4c116,\n 0x1e376c08,\n 0x2748774c,\n 0x34b0bcb5,\n 0x391c0cb3,\n 0x4ed8aa4a,\n 0x5b9cca4f,\n 0x682e6ff3,\n 0x748f82ee,\n 0x78a5636f,\n 0x84c87814,\n 0x8cc70208,\n 0x90befffa,\n 0xa4506ceb,\n 0xbef9a3f7,\n 0xc67178f2,\n];\n\n/* Constant used in SHA-2 families */\nexport const H_trunc = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];\n\n/* Constant used in SHA-2 families */\nexport const H_full = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n\nexport const sha_variant_error = \"Chosen SHA variant is not supported\";\nexport const mac_rounds_error = \"Cannot set numRounds with MAC\";\n\n/**\n * Concatenates 2 packed arrays. Clobbers array `a`.\n *\n * @param a First array to concatenate.\n * @param b Second array to concatenate.\n * @returns The concatentation of `a` + `b`.\n */\nexport function packedLEConcat(a: packedValue, b: packedValue): packedValue {\n let i, arrOffset;\n const aByteLen = a[\"binLen\"] >>> 3,\n bByteLen = b[\"binLen\"] >>> 3,\n leftShiftAmount = aByteLen << 3,\n rightShiftAmount = (4 - aByteLen) << 3;\n\n /* If a only contains \"full\" integers, we can just use concat which is so much easier */\n if (aByteLen % 4 !== 0) {\n for (i = 0; i < bByteLen; i += 4) {\n arrOffset = (aByteLen + i) >>> 2;\n /* Left shift chops off bits over 32-bits */\n a[\"value\"][arrOffset] |= b[\"value\"][i >>> 2] << leftShiftAmount;\n a[\"value\"].push(0);\n a[\"value\"][arrOffset + 1] |= b[\"value\"][i >>> 2] >>> rightShiftAmount;\n }\n\n /* Since an unconditional push was performed above, we may have pushed an extra value if it could have been\n encoded without it. Check if popping an int off (reducing total length by 4 bytes) is still bigger than the\n needed size. */\n if ((a[\"value\"].length << 2) - 4 >= bByteLen + aByteLen) {\n a[\"value\"].pop();\n }\n\n return { value: a[\"value\"], binLen: a[\"binLen\"] + b[\"binLen\"] };\n } else {\n return { value: a[\"value\"].concat(b[\"value\"]), binLen: a[\"binLen\"] + b[\"binLen\"] };\n }\n}\n\n/**\n * Validate hash list containing output formatting options, ensuring presence of every option or adding the default\n * value.\n *\n * @param options Hashmap of output formatting options from user.\n * @returns Validated hashmap containing output formatting options.\n */\nexport function getOutputOpts(options?: {\n outputUpper?: boolean;\n b64Pad?: string;\n shakeLen?: number;\n outputLen?: number;\n}): { outputUpper: boolean; b64Pad: string; outputLen: number } {\n const retVal = { outputUpper: false, b64Pad: \"=\", outputLen: -1 },\n outputOptions: { outputUpper?: boolean; b64Pad?: string; shakeLen?: number; outputLen?: number } = options || {},\n lenErrstr = \"Output length must be a multiple of 8\";\n\n retVal[\"outputUpper\"] = outputOptions[\"outputUpper\"] || false;\n\n if (outputOptions[\"b64Pad\"]) {\n retVal[\"b64Pad\"] = outputOptions[\"b64Pad\"];\n }\n\n if (outputOptions[\"outputLen\"]) {\n if (outputOptions[\"outputLen\"] % 8 !== 0) {\n throw new Error(lenErrstr);\n }\n retVal[\"outputLen\"] = outputOptions[\"outputLen\"];\n } else if (outputOptions[\"shakeLen\"]) {\n if (outputOptions[\"shakeLen\"] % 8 !== 0) {\n throw new Error(lenErrstr);\n }\n retVal[\"outputLen\"] = outputOptions[\"shakeLen\"];\n }\n\n if (\"boolean\" !== typeof retVal[\"outputUpper\"]) {\n throw new Error(\"Invalid outputUpper formatting option\");\n }\n\n if (\"string\" !== typeof retVal[\"b64Pad\"]) {\n throw new Error(\"Invalid b64Pad formatting option\");\n }\n\n return retVal;\n}\n\n/**\n * Parses an external constructor object and returns a packed number, if possible.\n *\n * @param key The human-friendly key name to prefix any errors with\n * @param value The input value object to parse\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param fallback Fallback value if `value` is undefined. If not present and `value` is undefined, an Error is thrown\n */\nexport function parseInputOption(\n key: string,\n value: GenericInputType | undefined,\n bigEndianMod: -1 | 1,\n fallback?: packedValue\n): packedValue {\n const errStr = key + \" must include a value and format\";\n if (!value) {\n if (!fallback) {\n throw new Error(errStr);\n }\n return fallback;\n }\n\n if (typeof value[\"value\"] === \"undefined\" || !value[\"format\"]) {\n throw new Error(errStr);\n }\n\n return getStrConverter(\n value[\"format\"],\n // eslint-disable-next-line @typescript-eslint/ban-ts-ignore\n // @ts-ignore - the value of encoding gets value checked by getStrConverter\n value[\"encoding\"] || \"UTF8\",\n bigEndianMod\n )(value[\"value\"]);\n}\n\nexport abstract class jsSHABase {\n /**\n * @param variant The desired SHA variant.\n * @param inputFormat The input format to be used in future `update` calls.\n * @param options Hashmap of extra input options.\n */\n /* Needed inputs */\n protected readonly shaVariant: VariantT;\n protected readonly inputFormat: FormatType;\n protected readonly utfType: EncodingType;\n protected readonly numRounds: number;\n\n /* State */\n protected abstract intermediateState: StateT;\n protected keyWithIPad: number[];\n protected keyWithOPad: number[];\n protected remainder: number[];\n protected remainderLen: number;\n protected updateCalled: boolean;\n protected processedLen: number;\n protected macKeySet: boolean;\n\n /* Variant specifics */\n protected abstract readonly variantBlockSize: number;\n protected abstract readonly bigEndianMod: -1 | 1;\n protected abstract readonly outputBinLen: number;\n protected abstract readonly isVariableLen: boolean;\n protected abstract readonly HMACSupported: boolean;\n\n /* Functions */\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n protected abstract readonly converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n protected abstract readonly roundFunc: (block: number[], H: StateT) => StateT;\n protected abstract readonly finalizeFunc: (\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: StateT,\n outputLen: number\n ) => number[];\n protected abstract readonly stateCloneFunc: (state: StateT) => StateT;\n protected abstract readonly newStateFunc: (variant: VariantT) => StateT;\n protected abstract readonly getMAC: ((options: { outputLen: number }) => number[]) | null;\n\n protected constructor(variant: VariantT, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n protected constructor(variant: VariantT, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected constructor(variant: any, inputFormat: any, options?: any) {\n const inputOptions = options || {};\n this.inputFormat = inputFormat;\n\n this.utfType = inputOptions[\"encoding\"] || \"UTF8\";\n this.numRounds = inputOptions[\"numRounds\"] || 1;\n\n /* eslint-disable-next-line @typescript-eslint/ban-ts-ignore */\n // @ts-ignore - The spec actually says ToString is called on the first parseInt argument so it's OK to use it here\n // to check if an arugment is an integer. This cheat would break if it's used to get the value of the argument.\n if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) {\n throw new Error(\"numRounds must a integer >= 1\");\n }\n\n this.shaVariant = variant;\n this.remainder = [];\n this.remainderLen = 0;\n this.updateCalled = false;\n this.processedLen = 0;\n this.macKeySet = false;\n this.keyWithIPad = [];\n this.keyWithOPad = [];\n }\n\n /**\n * Hashes as many blocks as possible. Stores the rest for either a future update or getHash call.\n *\n * @param srcString The input to be hashed.\n */\n update(srcString: string | ArrayBuffer | Uint8Array): void {\n let i,\n updateProcessedLen = 0;\n const variantBlockIntInc = this.variantBlockSize >>> 5,\n convertRet = this.converterFunc(srcString, this.remainder, this.remainderLen),\n chunkBinLen = convertRet[\"binLen\"],\n chunk = convertRet[\"value\"],\n chunkIntLen = chunkBinLen >>> 5;\n\n for (i = 0; i < chunkIntLen; i += variantBlockIntInc) {\n if (updateProcessedLen + this.variantBlockSize <= chunkBinLen) {\n this.intermediateState = this.roundFunc(chunk.slice(i, i + variantBlockIntInc), this.intermediateState);\n updateProcessedLen += this.variantBlockSize;\n }\n }\n this.processedLen += updateProcessedLen;\n this.remainder = chunk.slice(updateProcessedLen >>> 5);\n this.remainderLen = chunkBinLen % this.variantBlockSize;\n this.updateCalled = true;\n }\n\n /**\n * Returns the desired SHA hash of the input fed in via `update` calls.\n *\n * @param format The desired output formatting\n * @param options Hashmap of output formatting options. `outputLen` must be specified for variable length hashes.\n * `outputLen` replaces the now deprecated `shakeLen` key.\n * @returns The hash in the format specified.\n */\n getHash(format: \"HEX\", options?: { outputUpper?: boolean; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"B64\", options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"BYTES\", options?: { outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"UINT8ARRAY\", options?: { outputLen?: number; shakeLen?: number }): Uint8Array;\n getHash(format: \"ARRAYBUFFER\", options?: { outputLen?: number; shakeLen?: number }): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHash(format: any, options?: any): any {\n let i,\n finalizedState,\n outputBinLen = this.outputBinLen;\n\n const outputOptions = getOutputOpts(options);\n\n if (this.isVariableLen) {\n if (outputOptions[\"outputLen\"] === -1) {\n throw new Error(\"Output length must be specified in options\");\n }\n outputBinLen = outputOptions[\"outputLen\"];\n }\n\n const formatFunc = getOutputConverter(format, outputBinLen, this.bigEndianMod, outputOptions);\n if (this.macKeySet && this.getMAC) {\n return formatFunc(this.getMAC(outputOptions));\n }\n\n finalizedState = this.finalizeFunc(\n this.remainder.slice(),\n this.remainderLen,\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n outputBinLen\n );\n for (i = 1; i < this.numRounds; i += 1) {\n /* Need to mask out bits that should be zero due to output not being a multiple of 32 */\n if (this.isVariableLen && outputBinLen % 32 !== 0) {\n finalizedState[finalizedState.length - 1] &= 0x00ffffff >>> (24 - (outputBinLen % 32));\n }\n finalizedState = this.finalizeFunc(\n finalizedState,\n outputBinLen,\n 0,\n this.newStateFunc(this.shaVariant),\n outputBinLen\n );\n }\n\n return formatFunc(finalizedState);\n }\n\n /**\n * Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.\n *\n * @param key The key used to calculate the HMAC\n * @param inputFormat The format of key.\n * @param options Hashmap of extra input options.\n */\n setHMACKey(key: string, inputFormat: \"TEXT\", options?: { encoding?: EncodingType }): void;\n setHMACKey(key: string, inputFormat: \"B64\" | \"HEX\" | \"BYTES\"): void;\n setHMACKey(key: ArrayBuffer, inputFormat: \"ARRAYBUFFER\"): void;\n setHMACKey(key: Uint8Array, inputFormat: \"UINT8ARRAY\"): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setHMACKey(key: any, inputFormat: any, options?: any): void {\n if (!this.HMACSupported) {\n throw new Error(\"Variant does not support HMAC\");\n }\n\n if (this.updateCalled) {\n throw new Error(\"Cannot set MAC key after calling update\");\n }\n\n const keyOptions = options || {},\n keyConverterFunc = getStrConverter(inputFormat, keyOptions[\"encoding\"] || \"UTF8\", this.bigEndianMod);\n\n this._setHMACKey(keyConverterFunc(key));\n }\n\n /**\n * Internal function that sets the MAC key.\n *\n * @param key The packed MAC key to use\n */\n protected _setHMACKey(key: packedValue): void {\n const blockByteSize = this.variantBlockSize >>> 3,\n lastArrayIndex = blockByteSize / 4 - 1;\n let i;\n if (this.numRounds !== 1) {\n throw new Error(mac_rounds_error);\n }\n\n if (this.macKeySet) {\n throw new Error(\"MAC key already set\");\n }\n\n /* Figure out what to do with the key based on its size relative to\n * the hash's block size */\n if (blockByteSize < key[\"binLen\"] / 8) {\n key[\"value\"] = this.finalizeFunc(\n key[\"value\"],\n key[\"binLen\"],\n 0,\n this.newStateFunc(this.shaVariant),\n this.outputBinLen\n );\n }\n while (key[\"value\"].length <= lastArrayIndex) {\n key[\"value\"].push(0);\n }\n /* Create ipad and opad */\n for (i = 0; i <= lastArrayIndex; i += 1) {\n this.keyWithIPad[i] = key[\"value\"][i] ^ 0x36363636;\n this.keyWithOPad[i] = key[\"value\"][i] ^ 0x5c5c5c5c;\n }\n\n this.intermediateState = this.roundFunc(this.keyWithIPad, this.intermediateState);\n this.processedLen = this.variantBlockSize;\n\n this.macKeySet = true;\n }\n\n /**\n * Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call.\n *\n * @param format The desired output formatting.\n * @param options Hashmap of extra outputs options.\n * @returns The HMAC in the format specified.\n */\n getHMAC(format: \"HEX\", options?: { outputUpper?: boolean }): string;\n getHMAC(format: \"B64\", options?: { b64Pad?: string }): string;\n getHMAC(format: \"BYTES\"): string;\n getHMAC(format: \"UINT8ARRAY\"): Uint8Array;\n getHMAC(format: \"ARRAYBUFFER\"): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHMAC(format: any, options?: any): any {\n const outputOptions = getOutputOpts(options),\n formatFunc = getOutputConverter(format, this.outputBinLen, this.bigEndianMod, outputOptions);\n\n return formatFunc(this._getHMAC());\n }\n\n /**\n * Internal function that returns the \"raw\" HMAC\n */\n protected _getHMAC(): number[] {\n let finalizedState;\n\n if (!this.macKeySet) {\n throw new Error(\"Cannot call getHMAC without first setting MAC key\");\n }\n\n const firstHash = this.finalizeFunc(\n this.remainder.slice(),\n this.remainderLen,\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n this.outputBinLen\n );\n finalizedState = this.roundFunc(this.keyWithOPad, this.newStateFunc(this.shaVariant));\n finalizedState = this.finalizeFunc(\n firstHash,\n this.outputBinLen,\n this.variantBlockSize,\n finalizedState,\n this.outputBinLen\n );\n\n return finalizedState;\n }\n}\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","/*\n * Note 1: All the functions in this file guarantee only that the bottom 32-bits of the return value are correct.\n * JavaScript is flakey when it comes to bit operations and a '1' in the highest order bit of a 32-bit number causes\n * it to be interpreted as a negative number per two's complement.\n *\n * Note 2: Per the ECMAScript spec, all JavaScript operations mask the shift amount by 0x1F. This results in weird\n * cases like 1 << 32 == 1 and 1 << 33 === 1 << 1 === 2\n */\n\n/**\n * The 32-bit implementation of circular rotate left.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted left circularly by `n` bits\n */\nexport function rotl_32(x: number, n: number): number {\n return (x << n) | (x >>> (32 - n));\n}\n\n/**\n * The 32-bit implementation of circular rotate right.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right circularly by `n` bits\n */\nfunction rotr_32(x: number, n: number): number {\n return (x >>> n) | (x << (32 - n));\n}\n\n/**\n * The 32-bit implementation of shift right.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted by `n` bits.\n */\nfunction shr_32(x: number, n: number): number {\n return x >>> n;\n}\n\n/**\n * The 32-bit implementation of the NIST specified Parity function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function parity_32(x: number, y: number, z: number): number {\n return x ^ y ^ z;\n}\n\n/**\n * The 32-bit implementation of the NIST specified Ch function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function ch_32(x: number, y: number, z: number): number {\n return (x & y) ^ (~x & z);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Maj function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function maj_32(x: number, y: number, z: number): number {\n return (x & y) ^ (x & z) ^ (y & z);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Sigma0 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma0_32(x: number): number {\n return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);\n}\n\n/**\n * Add two 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @returns The sum of `a` + `b`.\n */\nexport function safeAdd_32_2(a: number, b: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * Add four 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @param c The third 32-bit integer argument to be added.\n * @param d The fourth 32-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d`.\n */\nexport function safeAdd_32_4(a: number, b: number, c: number, d: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff) + (c & 0xffff) + (d & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * Add five 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @param c The third 32-bit integer argument to be added.\n * @param d The fourth 32-bit integer argument to be added.\n * @param e The fifth 32-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d` + `e`.\n */\nexport function safeAdd_32_5(a: number, b: number, c: number, d: number, e: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff) + (c & 0xffff) + (d & 0xffff) + (e & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (e >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Gamma1 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma1_32(x: number): number {\n return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Gamma0 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma0_32(x: number): number {\n return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Sigma1 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma1_32(x: number): number {\n return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);\n}\n","import { jsSHABase, TWO_PWR_32, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport { ch_32, parity_32, maj_32, rotl_32, safeAdd_32_2, safeAdd_32_5 } from \"./primitives_32\";\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param _variant: Unused\n * @returns The initial state values.\n */\nfunction getNewState(_variant: \"SHA-1\"): number[] {\n return [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];\n}\n\n/**\n * Performs a round of SHA-1 hashing over a 512-byte block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA1(block: number[], H: number[]): number[] {\n let a, b, c, d, e, T, t;\n const W: number[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n\n for (t = 0; t < 80; t += 1) {\n if (t < 16) {\n W[t] = block[t];\n } else {\n W[t] = rotl_32(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);\n }\n\n if (t < 20) {\n T = safeAdd_32_5(rotl_32(a, 5), ch_32(b, c, d), e, 0x5a827999, W[t]);\n } else if (t < 40) {\n T = safeAdd_32_5(rotl_32(a, 5), parity_32(b, c, d), e, 0x6ed9eba1, W[t]);\n } else if (t < 60) {\n T = safeAdd_32_5(rotl_32(a, 5), maj_32(b, c, d), e, 0x8f1bbcdc, W[t]);\n } else {\n T = safeAdd_32_5(rotl_32(a, 5), parity_32(b, c, d), e, 0xca62c1d6, W[t]);\n }\n\n e = d;\n d = c;\n c = rotl_32(b, 30);\n b = a;\n a = T;\n }\n\n H[0] = safeAdd_32_2(a, H[0]);\n H[1] = safeAdd_32_2(b, H[1]);\n H[2] = safeAdd_32_2(c, H[2]);\n H[3] = safeAdd_32_2(d, H[3]);\n H[4] = safeAdd_32_2(e, H[4]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-1 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @returns The array of integers representing the SHA-1 hash of message.\n */\nfunction finalizeSHA1(remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]): number[] {\n let i;\n\n /* The 65 addition is a hack but it works. The correct number is\n\t\tactually 72 (64 + 8) but the below math fails if\n\t\tremainderBinLen + 72 % 512 = 0. Since remainderBinLen % 8 = 0,\n\t\t\"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 65) >>> 9) << 4) + 15,\n totalLen = remainderBinLen + processedBinLen;\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n\n /* Append length of binary string in the position such that the new\n * length is a multiple of 512. Logic does not work for even multiples\n * of 512 but there can never be even multiples of 512. JavaScript\n * numbers are limited to 2^53 so it's \"safe\" to treat the totalLen as\n * a 64-bit integer. */\n remainder[offset] = totalLen & 0xffffffff;\n\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += 16) {\n H = roundSHA1(remainder.slice(i, i + 16), H);\n }\n\n return H;\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: number[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: number[]) => number[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];\n stateCloneFunc: (state: number[]) => number[];\n newStateFunc: (variant: \"SHA-1\") => number[];\n getMAC: () => number[];\n\n constructor(variant: \"SHA-1\", inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: \"SHA-1\", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (\"SHA-1\" !== variant) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA1;\n this.stateCloneFunc = function (state: number[]): number[] {\n return state.slice();\n };\n this.newStateFunc = getNewState;\n this.finalizeFunc = finalizeSHA1;\n\n this.intermediateState = getNewState(variant);\n this.variantBlockSize = 512;\n this.outputBinLen = 160;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","import { jsSHABase, TWO_PWR_32, H_full, H_trunc, K_sha2, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport {\n ch_32,\n gamma0_32,\n gamma1_32,\n maj_32,\n safeAdd_32_2,\n safeAdd_32_4,\n safeAdd_32_5,\n sigma0_32,\n sigma1_32,\n} from \"./primitives_32\";\n\ntype VariantType = \"SHA-224\" | \"SHA-256\";\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param variant: The SHA-256 family variant.\n * @returns The initial state values.\n */\nfunction getNewState256(variant: VariantType): number[] {\n let retVal;\n\n if (\"SHA-224\" == variant) {\n retVal = H_trunc.slice();\n } else {\n /* \"SHA-256\" */\n retVal = H_full.slice();\n }\n return retVal;\n}\n\n/**\n * Performs a round of SHA-256 hashing over a block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA256(block: number[], H: number[]): number[] {\n let a, b, c, d, e, f, g, h, T1, T2, t;\n\n const W: number[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n f = H[5];\n g = H[6];\n h = H[7];\n\n for (t = 0; t < 64; t += 1) {\n if (t < 16) {\n W[t] = block[t];\n } else {\n W[t] = safeAdd_32_4(gamma1_32(W[t - 2]), W[t - 7], gamma0_32(W[t - 15]), W[t - 16]);\n }\n T1 = safeAdd_32_5(h, sigma1_32(e), ch_32(e, f, g), K_sha2[t], W[t]);\n T2 = safeAdd_32_2(sigma0_32(a), maj_32(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safeAdd_32_2(d, T1);\n d = c;\n c = b;\n b = a;\n a = safeAdd_32_2(T1, T2);\n }\n\n H[0] = safeAdd_32_2(a, H[0]);\n H[1] = safeAdd_32_2(b, H[1]);\n H[2] = safeAdd_32_2(c, H[2]);\n H[3] = safeAdd_32_2(d, H[3]);\n H[4] = safeAdd_32_2(e, H[4]);\n H[5] = safeAdd_32_2(f, H[5]);\n H[6] = safeAdd_32_2(g, H[6]);\n H[7] = safeAdd_32_2(h, H[7]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-256 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @param variant The desired SHA-256 variant.\n * @returns The array of integers representing the SHA-2 hash of message.\n */\nfunction finalizeSHA256(\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: number[],\n variant: VariantType\n): number[] {\n let i, retVal;\n\n /* The 65 addition is a hack but it works. The correct number is\n actually 72 (64 + 8) but the below math fails if\n remainderBinLen + 72 % 512 = 0. Since remainderBinLen % 8 = 0,\n \"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 65) >>> 9) << 4) + 15,\n binaryStringInc = 16,\n totalLen = remainderBinLen + processedBinLen;\n\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n /* Append length of binary string in the position such that the new\n * length is correct. JavaScript numbers are limited to 2^53 so it's\n * \"safe\" to treat the totalLen as a 64-bit integer. */\n\n remainder[offset] = totalLen & 0xffffffff;\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += binaryStringInc) {\n H = roundSHA256(remainder.slice(i, i + binaryStringInc), H);\n }\n\n if (\"SHA-224\" === variant) {\n retVal = [H[0], H[1], H[2], H[3], H[4], H[5], H[6]];\n } else {\n /* \"SHA-256 */\n retVal = H;\n }\n\n return retVal;\n}\nexport default class jsSHA extends jsSHABase {\n intermediateState: number[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: number[]) => number[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];\n stateCloneFunc: (state: number[]) => number[];\n newStateFunc: (variant: VariantType) => number[];\n getMAC: () => number[];\n\n constructor(variant: VariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (!(\"SHA-224\" === variant || \"SHA-256\" === variant)) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.HMACSupported = true;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA256;\n this.stateCloneFunc = function (state): number[] {\n return state.slice();\n };\n\n this.newStateFunc = getNewState256;\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, H): number[] {\n return finalizeSHA256(remainder, remainderBinLen, processedBinLen, H, variant);\n };\n\n this.intermediateState = getNewState256(variant);\n this.variantBlockSize = 512;\n this.outputBinLen = \"SHA-224\" === variant ? 224 : 256;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","/*\n * Note 1: All the functions in this file guarantee only that the bottom 32-bits of the returned Int_64 are correct.\n * JavaScript is flakey when it comes to bit operations and a '1' in the highest order bit of a 32-bit number causes\n * it to be interpreted as a negative number per two's complement.\n *\n * Note 2: Per the ECMAScript spec, all JavaScript operations mask the shift amount by 0x1F. This results in weird\n * cases like 1 << 32 == 1 and 1 << 33 === 1 << 1 === 2\n */\n\n/**\n * Int_64 is a object for 2 32-bit numbers emulating a 64-bit number.\n */\nexport class Int_64 {\n /**\n * @param msint_32 The most significant 32-bits of a 64-bit number.\n * @param lsint_32 The least significant 32-bits of a 64-bit number.\n */\n readonly highOrder: number;\n readonly lowOrder: number;\n constructor(msint_32: number, lsint_32: number) {\n this.highOrder = msint_32;\n this.lowOrder = lsint_32;\n }\n}\n\n/**\n * The 64-bit implementation of circular rotate left.\n *\n * This does not work for n >= 64 or n == 32 but those are never done.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted left circularly by `n` bits.\n */\nexport function rotl_64(x: Int_64, n: number): Int_64 {\n let tmp;\n if (n > 32) {\n tmp = 64 - n;\n return new Int_64((x.lowOrder << n) | (x.highOrder >>> tmp), (x.highOrder << n) | (x.lowOrder >>> tmp));\n } else if (0 !== n) {\n tmp = 32 - n;\n return new Int_64((x.highOrder << n) | (x.lowOrder >>> tmp), (x.lowOrder << n) | (x.highOrder >>> tmp));\n } else {\n return x;\n }\n}\n\n/**\n * The 64-bit implementation of circular rotate right.\n *\n * This does not work for n >= 64, n == 32, or n == 0 but those are never done.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right circularly by `n` bits.\n */\nfunction rotr_64(x: Int_64, n: number): Int_64 {\n let tmp;\n if (n < 32) {\n tmp = 32 - n;\n return new Int_64((x.highOrder >>> n) | (x.lowOrder << tmp), (x.lowOrder >>> n) | (x.highOrder << tmp));\n } else {\n tmp = 64 - n;\n return new Int_64((x.lowOrder >>> n) | (x.highOrder << tmp), (x.highOrder >>> n) | (x.lowOrder << tmp));\n }\n}\n\n/**\n * The 64-bit implementation of shift right.\n *\n * This does not work for n >= 32 but is only called for n < 32.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right by `n` bits\n */\nfunction shr_64(x: Int_64, n: number): Int_64 {\n return new Int_64(x.highOrder >>> n, (x.lowOrder >>> n) | (x.highOrder << (32 - n)));\n}\n\n/**\n * The 64-bit implementation of the NIST specified Ch function.\n *\n * @param x The first 64-bit integer argument.\n * @param y The second 64-bit integer argument.\n * @param z The third 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function ch_64(x: Int_64, y: Int_64, z: Int_64): Int_64 {\n return new Int_64(\n (x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),\n (x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Maj function.\n *\n * @param x The first 64-bit integer argument.\n * @param y The second 64-bit integer argument.\n * @param z The third 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function maj_64(x: Int_64, y: Int_64, z: Int_64): Int_64 {\n return new Int_64(\n (x.highOrder & y.highOrder) ^ (x.highOrder & z.highOrder) ^ (y.highOrder & z.highOrder),\n (x.lowOrder & y.lowOrder) ^ (x.lowOrder & z.lowOrder) ^ (y.lowOrder & z.lowOrder)\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Sigma0 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma0_64(x: Int_64): Int_64 {\n const rotr28 = rotr_64(x, 28),\n rotr34 = rotr_64(x, 34),\n rotr39 = rotr_64(x, 39);\n\n return new Int_64(\n rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,\n rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder\n );\n}\n\n/**\n * Add two 64-bit integers.\n *\n * @param x The first 64-bit integer argument to be added.\n * @param y The second 64-bit integer argument to be added.\n * @returns The sum of `x` + `y`.\n */\nexport function safeAdd_64_2(x: Int_64, y: Int_64): Int_64 {\n let lsw, msw;\n\n lsw = (x.lowOrder & 0xffff) + (y.lowOrder & 0xffff);\n msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw = (x.highOrder & 0xffff) + (y.highOrder & 0xffff) + (msw >>> 16);\n msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * Add four 64-bit integers.\n *\n * @param a The first 64-bit integer argument to be added.\n * @param b The second 64-bit integer argument to be added.\n * @param c The third 64-bit integer argument to be added.\n * @param d The fouth 64-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d`.\n */\nexport function safeAdd_64_4(a: Int_64, b: Int_64, c: Int_64, d: Int_64): Int_64 {\n let lsw, msw;\n\n lsw = (a.lowOrder & 0xffff) + (b.lowOrder & 0xffff) + (c.lowOrder & 0xffff) + (d.lowOrder & 0xffff);\n msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw =\n (a.highOrder & 0xffff) + (b.highOrder & 0xffff) + (c.highOrder & 0xffff) + (d.highOrder & 0xffff) + (msw >>> 16);\n msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * Add five 64-bit integers.\n *\n * @param a The first 64-bit integer argument to be added.\n * @param b The second 64-bit integer argument to be added.\n * @param c The third 64-bit integer argument to be added.\n * @param d The fouth 64-bit integer argument to be added.\n * @param e The fifth 64-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d` + `e`.\n */\nexport function safeAdd_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64 {\n let lsw, msw;\n\n lsw =\n (a.lowOrder & 0xffff) +\n (b.lowOrder & 0xffff) +\n (c.lowOrder & 0xffff) +\n (d.lowOrder & 0xffff) +\n (e.lowOrder & 0xffff);\n msw =\n (a.lowOrder >>> 16) +\n (b.lowOrder >>> 16) +\n (c.lowOrder >>> 16) +\n (d.lowOrder >>> 16) +\n (e.lowOrder >>> 16) +\n (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw =\n (a.highOrder & 0xffff) +\n (b.highOrder & 0xffff) +\n (c.highOrder & 0xffff) +\n (d.highOrder & 0xffff) +\n (e.highOrder & 0xffff) +\n (msw >>> 16);\n msw =\n (a.highOrder >>> 16) +\n (b.highOrder >>> 16) +\n (c.highOrder >>> 16) +\n (d.highOrder >>> 16) +\n (e.highOrder >>> 16) +\n (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * XORs two given arguments.\n *\n * @param a The first argument to be XORed.\n * @param b The second argument to be XORed.\n * @returns The The XOR `a` and `b`\n */\nexport function xor_64_2(a: Int_64, b: Int_64): Int_64 {\n return new Int_64(a.highOrder ^ b.highOrder, a.lowOrder ^ b.lowOrder);\n}\n\n/**\n * XORs five given arguments.\n *\n * @param a The first argument to be XORed.\n * @param b The second argument to be XORed.\n * @param c The third argument to be XORed.\n * @param d The fourth argument to be XORed.\n * @param e The fifth argument to be XORed.\n * @returns The XOR of `a`, `b`, `c`, `d`, and `e`.\n */\nexport function xor_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64 {\n return new Int_64(\n a.highOrder ^ b.highOrder ^ c.highOrder ^ d.highOrder ^ e.highOrder,\n a.lowOrder ^ b.lowOrder ^ c.lowOrder ^ d.lowOrder ^ e.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Gamma1 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma1_64(x: Int_64): Int_64 {\n const rotr19 = rotr_64(x, 19),\n rotr61 = rotr_64(x, 61),\n shr6 = shr_64(x, 6);\n\n return new Int_64(\n rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,\n rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Gamma0 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma0_64(x: Int_64): Int_64 {\n const rotr1 = rotr_64(x, 1),\n rotr8 = rotr_64(x, 8),\n shr7 = shr_64(x, 7);\n\n return new Int_64(\n rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,\n rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Sigma1 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma1_64(x: Int_64): Int_64 {\n const rotr14 = rotr_64(x, 14),\n rotr18 = rotr_64(x, 18),\n rotr41 = rotr_64(x, 41);\n\n return new Int_64(\n rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,\n rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder\n );\n}\n","import { jsSHABase, TWO_PWR_32, H_trunc, H_full, K_sha2, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport {\n ch_64,\n gamma0_64,\n gamma1_64,\n Int_64,\n maj_64,\n safeAdd_64_2,\n safeAdd_64_4,\n safeAdd_64_5,\n sigma0_64,\n sigma1_64,\n} from \"./primitives_64\";\n\ntype VariantType = \"SHA-384\" | \"SHA-512\";\n\nconst K_sha512 = [\n new Int_64(K_sha2[0], 0xd728ae22),\n new Int_64(K_sha2[1], 0x23ef65cd),\n new Int_64(K_sha2[2], 0xec4d3b2f),\n new Int_64(K_sha2[3], 0x8189dbbc),\n new Int_64(K_sha2[4], 0xf348b538),\n new Int_64(K_sha2[5], 0xb605d019),\n new Int_64(K_sha2[6], 0xaf194f9b),\n new Int_64(K_sha2[7], 0xda6d8118),\n new Int_64(K_sha2[8], 0xa3030242),\n new Int_64(K_sha2[9], 0x45706fbe),\n new Int_64(K_sha2[10], 0x4ee4b28c),\n new Int_64(K_sha2[11], 0xd5ffb4e2),\n new Int_64(K_sha2[12], 0xf27b896f),\n new Int_64(K_sha2[13], 0x3b1696b1),\n new Int_64(K_sha2[14], 0x25c71235),\n new Int_64(K_sha2[15], 0xcf692694),\n new Int_64(K_sha2[16], 0x9ef14ad2),\n new Int_64(K_sha2[17], 0x384f25e3),\n new Int_64(K_sha2[18], 0x8b8cd5b5),\n new Int_64(K_sha2[19], 0x77ac9c65),\n new Int_64(K_sha2[20], 0x592b0275),\n new Int_64(K_sha2[21], 0x6ea6e483),\n new Int_64(K_sha2[22], 0xbd41fbd4),\n new Int_64(K_sha2[23], 0x831153b5),\n new Int_64(K_sha2[24], 0xee66dfab),\n new Int_64(K_sha2[25], 0x2db43210),\n new Int_64(K_sha2[26], 0x98fb213f),\n new Int_64(K_sha2[27], 0xbeef0ee4),\n new Int_64(K_sha2[28], 0x3da88fc2),\n new Int_64(K_sha2[29], 0x930aa725),\n new Int_64(K_sha2[30], 0xe003826f),\n new Int_64(K_sha2[31], 0x0a0e6e70),\n new Int_64(K_sha2[32], 0x46d22ffc),\n new Int_64(K_sha2[33], 0x5c26c926),\n new Int_64(K_sha2[34], 0x5ac42aed),\n new Int_64(K_sha2[35], 0x9d95b3df),\n new Int_64(K_sha2[36], 0x8baf63de),\n new Int_64(K_sha2[37], 0x3c77b2a8),\n new Int_64(K_sha2[38], 0x47edaee6),\n new Int_64(K_sha2[39], 0x1482353b),\n new Int_64(K_sha2[40], 0x4cf10364),\n new Int_64(K_sha2[41], 0xbc423001),\n new Int_64(K_sha2[42], 0xd0f89791),\n new Int_64(K_sha2[43], 0x0654be30),\n new Int_64(K_sha2[44], 0xd6ef5218),\n new Int_64(K_sha2[45], 0x5565a910),\n new Int_64(K_sha2[46], 0x5771202a),\n new Int_64(K_sha2[47], 0x32bbd1b8),\n new Int_64(K_sha2[48], 0xb8d2d0c8),\n new Int_64(K_sha2[49], 0x5141ab53),\n new Int_64(K_sha2[50], 0xdf8eeb99),\n new Int_64(K_sha2[51], 0xe19b48a8),\n new Int_64(K_sha2[52], 0xc5c95a63),\n new Int_64(K_sha2[53], 0xe3418acb),\n new Int_64(K_sha2[54], 0x7763e373),\n new Int_64(K_sha2[55], 0xd6b2b8a3),\n new Int_64(K_sha2[56], 0x5defb2fc),\n new Int_64(K_sha2[57], 0x43172f60),\n new Int_64(K_sha2[58], 0xa1f0ab72),\n new Int_64(K_sha2[59], 0x1a6439ec),\n new Int_64(K_sha2[60], 0x23631e28),\n new Int_64(K_sha2[61], 0xde82bde9),\n new Int_64(K_sha2[62], 0xb2c67915),\n new Int_64(K_sha2[63], 0xe372532b),\n new Int_64(0xca273ece, 0xea26619c),\n new Int_64(0xd186b8c7, 0x21c0c207),\n new Int_64(0xeada7dd6, 0xcde0eb1e),\n new Int_64(0xf57d4f7f, 0xee6ed178),\n new Int_64(0x06f067aa, 0x72176fba),\n new Int_64(0x0a637dc5, 0xa2c898a6),\n new Int_64(0x113f9804, 0xbef90dae),\n new Int_64(0x1b710b35, 0x131c471b),\n new Int_64(0x28db77f5, 0x23047d84),\n new Int_64(0x32caab7b, 0x40c72493),\n new Int_64(0x3c9ebe0a, 0x15c9bebc),\n new Int_64(0x431d67c4, 0x9c100d4c),\n new Int_64(0x4cc5d4be, 0xcb3e42b6),\n new Int_64(0x597f299c, 0xfc657e2a),\n new Int_64(0x5fcb6fab, 0x3ad6faec),\n new Int_64(0x6c44198c, 0x4a475817),\n];\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param variant: The SHA-512 family variant.\n * @returns The initial state values.\n */\nfunction getNewState512(variant: VariantType): Int_64[] {\n if (\"SHA-384\" === variant) {\n return [\n new Int_64(0xcbbb9d5d, H_trunc[0]),\n new Int_64(0x0629a292a, H_trunc[1]),\n new Int_64(0x9159015a, H_trunc[2]),\n new Int_64(0x0152fecd8, H_trunc[3]),\n new Int_64(0x67332667, H_trunc[4]),\n new Int_64(0x98eb44a87, H_trunc[5]),\n new Int_64(0xdb0c2e0d, H_trunc[6]),\n new Int_64(0x047b5481d, H_trunc[7]),\n ];\n } else {\n /* SHA-512 */\n return [\n new Int_64(H_full[0], 0xf3bcc908),\n new Int_64(H_full[1], 0x84caa73b),\n new Int_64(H_full[2], 0xfe94f82b),\n new Int_64(H_full[3], 0x5f1d36f1),\n new Int_64(H_full[4], 0xade682d1),\n new Int_64(H_full[5], 0x2b3e6c1f),\n new Int_64(H_full[6], 0xfb41bd6b),\n new Int_64(H_full[7], 0x137e2179),\n ];\n }\n}\n\n/**\n * Performs a round of SHA-512 hashing over a block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA512(block: number[], H: Int_64[]): Int_64[] {\n let a, b, c, d, e, f, g, h, T1, T2, t, offset;\n\n const W: Int_64[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n f = H[5];\n g = H[6];\n h = H[7];\n\n for (t = 0; t < 80; t += 1) {\n if (t < 16) {\n offset = t * 2;\n W[t] = new Int_64(block[offset], block[offset + 1]);\n } else {\n W[t] = safeAdd_64_4(gamma1_64(W[t - 2]), W[t - 7], gamma0_64(W[t - 15]), W[t - 16]);\n }\n T1 = safeAdd_64_5(h, sigma1_64(e), ch_64(e, f, g), K_sha512[t], W[t]);\n T2 = safeAdd_64_2(sigma0_64(a), maj_64(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safeAdd_64_2(d, T1);\n d = c;\n c = b;\n b = a;\n a = safeAdd_64_2(T1, T2);\n }\n\n H[0] = safeAdd_64_2(a, H[0]);\n H[1] = safeAdd_64_2(b, H[1]);\n H[2] = safeAdd_64_2(c, H[2]);\n H[3] = safeAdd_64_2(d, H[3]);\n H[4] = safeAdd_64_2(e, H[4]);\n H[5] = safeAdd_64_2(f, H[5]);\n H[6] = safeAdd_64_2(g, H[6]);\n H[7] = safeAdd_64_2(h, H[7]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-512 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @param variant The desired SHA-512 variant.\n * @returns The array of integers representing the SHA-512 hash of message.\n */\nfunction finalizeSHA512(\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: Int_64[],\n variant: VariantType\n): number[] {\n let i, retVal;\n\n /* The 129 addition is a hack but it works. The correct number is\n actually 136 (128 + 8) but the below math fails if\n remainderBinLen + 136 % 1024 = 0. Since remainderBinLen % 8 = 0,\n \"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 129) >>> 10) << 5) + 31,\n binaryStringInc = 32,\n totalLen = remainderBinLen + processedBinLen;\n\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n /* Append length of binary string in the position such that the new\n * length is correct. JavaScript numbers are limited to 2^53 so it's\n * \"safe\" to treat the totalLen as a 64-bit integer. */\n\n remainder[offset] = totalLen & 0xffffffff;\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += binaryStringInc) {\n H = roundSHA512(remainder.slice(i, i + binaryStringInc), H);\n }\n\n if (\"SHA-384\" === variant) {\n H = (H as unknown) as Int_64[];\n retVal = [\n H[0].highOrder,\n H[0].lowOrder,\n H[1].highOrder,\n H[1].lowOrder,\n H[2].highOrder,\n H[2].lowOrder,\n H[3].highOrder,\n H[3].lowOrder,\n H[4].highOrder,\n H[4].lowOrder,\n H[5].highOrder,\n H[5].lowOrder,\n ];\n } else {\n /* SHA-512 */\n retVal = [\n H[0].highOrder,\n H[0].lowOrder,\n H[1].highOrder,\n H[1].lowOrder,\n H[2].highOrder,\n H[2].lowOrder,\n H[3].highOrder,\n H[3].lowOrder,\n H[4].highOrder,\n H[4].lowOrder,\n H[5].highOrder,\n H[5].lowOrder,\n H[6].highOrder,\n H[6].lowOrder,\n H[7].highOrder,\n H[7].lowOrder,\n ];\n }\n return retVal;\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: Int_64[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: Int_64[]) => Int_64[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: Int_64[]) => number[];\n stateCloneFunc: (state: Int_64[]) => Int_64[];\n newStateFunc: (variant: VariantType) => Int_64[];\n getMAC: () => number[];\n\n constructor(variant: VariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (!(\"SHA-384\" === variant || \"SHA-512\" === variant)) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.HMACSupported = true;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA512;\n this.stateCloneFunc = function (state): Int_64[] {\n return state.slice();\n };\n this.newStateFunc = getNewState512;\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, H): number[] {\n return finalizeSHA512(remainder, remainderBinLen, processedBinLen, H, variant);\n };\n\n this.intermediateState = getNewState512(variant);\n this.variantBlockSize = 1024;\n this.outputBinLen = \"SHA-384\" === variant ? 384 : 512;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","import { jsSHABase, packedLEConcat, sha_variant_error, mac_rounds_error, TWO_PWR_32, parseInputOption } from \"./common\";\nimport {\n packedValue,\n CSHAKEOptionsNoEncodingType,\n CSHAKEOptionsEncodingType,\n SHAKEOptionsNoEncodingType,\n SHAKEOptionsEncodingType,\n KMACOptionsNoEncodingType,\n KMACOptionsEncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n ResolvedCSHAKEOptionsNoEncodingType,\n ResolvedKMACOptionsNoEncodingType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport { Int_64, rotl_64, xor_64_2, xor_64_5 } from \"./primitives_64\";\n\ntype FixedLengthVariantType = \"SHA3-224\" | \"SHA3-256\" | \"SHA3-384\" | \"SHA3-512\" | \"SHAKE128\" | \"SHAKE256\";\n\ntype VariantType = FixedLengthVariantType | \"SHAKE128\" | \"SHAKE256\" | \"CSHAKE128\" | \"CSHAKE256\" | \"KMAC128\" | \"KMAC256\";\n\nconst rc_sha3 = [\n new Int_64(0x00000000, 0x00000001),\n new Int_64(0x00000000, 0x00008082),\n new Int_64(0x80000000, 0x0000808a),\n new Int_64(0x80000000, 0x80008000),\n new Int_64(0x00000000, 0x0000808b),\n new Int_64(0x00000000, 0x80000001),\n new Int_64(0x80000000, 0x80008081),\n new Int_64(0x80000000, 0x00008009),\n new Int_64(0x00000000, 0x0000008a),\n new Int_64(0x00000000, 0x00000088),\n new Int_64(0x00000000, 0x80008009),\n new Int_64(0x00000000, 0x8000000a),\n new Int_64(0x00000000, 0x8000808b),\n new Int_64(0x80000000, 0x0000008b),\n new Int_64(0x80000000, 0x00008089),\n new Int_64(0x80000000, 0x00008003),\n new Int_64(0x80000000, 0x00008002),\n new Int_64(0x80000000, 0x00000080),\n new Int_64(0x00000000, 0x0000800a),\n new Int_64(0x80000000, 0x8000000a),\n new Int_64(0x80000000, 0x80008081),\n new Int_64(0x80000000, 0x00008080),\n new Int_64(0x00000000, 0x80000001),\n new Int_64(0x80000000, 0x80008008),\n];\n\nconst r_sha3 = [\n [0, 36, 3, 41, 18],\n [1, 44, 10, 45, 2],\n [62, 6, 43, 15, 61],\n [28, 55, 25, 21, 56],\n [27, 20, 39, 8, 14],\n];\n\n/**\n * Gets the state values for the specified SHA-3 variant.\n *\n * @param _variant Unused for this family.\n * @returns The initial state values.\n */\nfunction getNewState(_variant: VariantType): Int_64[][] {\n let i;\n const retVal = [];\n\n for (i = 0; i < 5; i += 1) {\n retVal[i] = [new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0)];\n }\n\n return retVal;\n}\n\n/**\n * Returns a clone of the given SHA3 state.\n *\n * @param state The state to be cloned.\n * @returns The cloned state.\n */\nfunction cloneSHA3State(state: Int_64[][]): Int_64[][] {\n let i;\n const clone = [];\n for (i = 0; i < 5; i += 1) {\n clone[i] = state[i].slice();\n }\n\n return clone;\n}\n\n/**\n * Performs a round of SHA-3 hashing over a block. This clobbers `state`.\n *\n * @param block The binary array representation of the block to hash.\n * @param state Hash state from a previous round.\n * @returns The resulting state value.\n */\nfunction roundSHA3(block: number[] | null, state: Int_64[][]): Int_64[][] {\n let round, x, y, B;\n const C = [],\n D = [];\n\n if (null !== block) {\n for (x = 0; x < block.length; x += 2) {\n state[(x >>> 1) % 5][((x >>> 1) / 5) | 0] = xor_64_2(\n state[(x >>> 1) % 5][((x >>> 1) / 5) | 0],\n new Int_64(block[x + 1], block[x])\n );\n }\n }\n\n for (round = 0; round < 24; round += 1) {\n /* Any SHA-3 variant name will do here */\n B = getNewState(\"SHA3-384\");\n\n /* Perform theta step */\n for (x = 0; x < 5; x += 1) {\n C[x] = xor_64_5(state[x][0], state[x][1], state[x][2], state[x][3], state[x][4]);\n }\n for (x = 0; x < 5; x += 1) {\n D[x] = xor_64_2(C[(x + 4) % 5], rotl_64(C[(x + 1) % 5], 1));\n }\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n state[x][y] = xor_64_2(state[x][y], D[x]);\n }\n }\n\n /* Perform combined ro and pi steps */\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n B[y][(2 * x + 3 * y) % 5] = rotl_64(state[x][y], r_sha3[x][y]);\n }\n }\n\n /* Perform chi step */\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n state[x][y] = xor_64_2(\n B[x][y],\n new Int_64(\n ~B[(x + 1) % 5][y].highOrder & B[(x + 2) % 5][y].highOrder,\n ~B[(x + 1) % 5][y].lowOrder & B[(x + 2) % 5][y].lowOrder\n )\n );\n }\n }\n\n /* Perform iota step */\n state[0][0] = xor_64_2(state[0][0], rc_sha3[round]);\n }\n\n return state;\n}\n\n/**\n * Finalizes the SHA-3 hash. This clobbers `remainder` and `state`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param _processedBinLen Unused for this family.\n * @param state The state from a previous round.\n * @param blockSize The block size/rate of the variant in bits\n * @param delimiter The delimiter value for the variant\n * @param outputLen The output length for the variant in bits\n * @returns The array of integers representing the SHA-3 hash of message.\n */\nfunction finalizeSHA3(\n remainder: number[],\n remainderBinLen: number,\n _processedBinLen: number,\n state: Int_64[][],\n blockSize: number,\n delimiter: number,\n outputLen: number\n): number[] {\n let i,\n state_offset = 0,\n temp;\n const retVal = [],\n binaryStringInc = blockSize >>> 5,\n remainderIntLen = remainderBinLen >>> 5;\n\n /* Process as many blocks as possible, some may be here for multiple rounds\n\t\twith SHAKE\n\t*/\n for (i = 0; i < remainderIntLen && remainderBinLen >= blockSize; i += binaryStringInc) {\n state = roundSHA3(remainder.slice(i, i + binaryStringInc), state);\n remainderBinLen -= blockSize;\n }\n\n remainder = remainder.slice(i);\n remainderBinLen = remainderBinLen % blockSize;\n\n /* Pad out the remainder to a full block */\n while (remainder.length < binaryStringInc) {\n remainder.push(0);\n }\n\n /* Find the next \"empty\" byte for the 0x80 and append it via an xor */\n i = remainderBinLen >>> 3;\n remainder[i >> 2] ^= delimiter << (8 * (i % 4));\n\n remainder[binaryStringInc - 1] ^= 0x80000000;\n state = roundSHA3(remainder, state);\n\n while (retVal.length * 32 < outputLen) {\n temp = state[state_offset % 5][(state_offset / 5) | 0];\n retVal.push(temp.lowOrder);\n if (retVal.length * 32 >= outputLen) {\n break;\n }\n retVal.push(temp.highOrder);\n state_offset += 1;\n\n if (0 === (state_offset * 64) % blockSize) {\n roundSHA3(null, state);\n state_offset = 0;\n }\n }\n\n return retVal;\n}\n\n/**\n * Performs NIST left_encode function returned with no extra garbage bits. `x` is limited to <= 9007199254740991.\n *\n * @param x 32-bit number to to encode.\n * @returns The NIST specified output of the function.\n */\nfunction left_encode(x: number): packedValue {\n let byteOffset,\n byte,\n numEncodedBytes = 0;\n /* JavaScript numbers max out at 0x1FFFFFFFFFFFFF (7 bytes) so this will return a maximum of 7 + 1 = 8 bytes */\n const retVal = [0, 0],\n x_64 = [x & 0xffffffff, (x / TWO_PWR_32) & 0x1fffff];\n\n for (byteOffset = 6; byteOffset >= 0; byteOffset--) {\n /* This will surprisingly work for large shifts because JavaScript masks the shift amount by 0x1F */\n byte = (x_64[byteOffset >> 2] >>> (8 * byteOffset)) & 0xff;\n\n /* Starting from the most significant byte of a 64-bit number, start recording the first non-0 byte and then\n every byte thereafter */\n if (byte !== 0 || numEncodedBytes !== 0) {\n retVal[(numEncodedBytes + 1) >> 2] |= byte << ((numEncodedBytes + 1) * 8);\n numEncodedBytes += 1;\n }\n }\n numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;\n retVal[0] |= numEncodedBytes;\n\n return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };\n}\n\n/**\n * Performs NIST right_encode function returned with no extra garbage bits. `x` is limited to <= 9007199254740991.\n *\n * @param x 32-bit number to to encode.\n * @returns The NIST specified output of the function.\n */\nfunction right_encode(x: number): packedValue {\n let byteOffset,\n byte,\n numEncodedBytes = 0;\n /* JavaScript numbers max out at 0x1FFFFFFFFFFFFF (7 bytes) so this will return a maximum of 7 + 1 = 8 bytes */\n const retVal = [0, 0],\n x_64 = [x & 0xffffffff, (x / TWO_PWR_32) & 0x1fffff];\n\n for (byteOffset = 6; byteOffset >= 0; byteOffset--) {\n /* This will surprisingly work for large shifts because JavaScript masks the shift amount by 0x1F */\n byte = (x_64[byteOffset >> 2] >>> (8 * byteOffset)) & 0xff;\n\n /* Starting from the most significant byte of a 64-bit number, start recording the first non-0 byte and then\n every byte thereafter */\n if (byte !== 0 || numEncodedBytes !== 0) {\n retVal[numEncodedBytes >> 2] |= byte << (numEncodedBytes * 8);\n numEncodedBytes += 1;\n }\n }\n numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;\n retVal[numEncodedBytes >> 2] |= numEncodedBytes << (numEncodedBytes * 8);\n\n return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };\n}\n\n/**\n * Performs NIST encode_string function.\n *\n * @param input Packed array of integers.\n * @returns NIST encode_string output.\n */\nfunction encode_string(input: packedValue): packedValue {\n return packedLEConcat(left_encode(input[\"binLen\"]), input);\n}\n\n/**\n * Performs NIST byte_pad function.\n *\n * @param packed Packed array of integers.\n * @param outputByteLen Desired length of the output in bytes, assumed to be a multiple of 4.\n * @returns NIST byte_pad output.\n */\nfunction byte_pad(packed: packedValue, outputByteLen: number): number[] {\n let encodedLen = left_encode(outputByteLen),\n i;\n\n encodedLen = packedLEConcat(encodedLen, packed);\n const outputIntLen = outputByteLen >>> 2,\n intsToAppend = (outputIntLen - (encodedLen[\"value\"].length % outputIntLen)) % outputIntLen;\n\n for (i = 0; i < intsToAppend; i++) {\n encodedLen[\"value\"].push(0);\n }\n\n return encodedLen[\"value\"];\n}\n\n/**\n * Parses/validate constructor options for a CSHAKE variant\n *\n * @param options Option given to constructor\n */\nfunction resolveCSHAKEOptions(options: CSHAKEOptionsNoEncodingType): ResolvedCSHAKEOptionsNoEncodingType {\n const resolvedOptions = options || {};\n\n return {\n funcName: parseInputOption(\"funcName\", resolvedOptions[\"funcName\"], 1, { value: [], binLen: 0 }),\n customization: parseInputOption(\"Customization\", resolvedOptions[\"customization\"], 1, { value: [], binLen: 0 }),\n };\n}\n\n/**\n * Parses/validate constructor options for a KMAC variant\n *\n * @param options Option given to constructor\n */\nfunction resolveKMACOptions(options: KMACOptionsNoEncodingType): ResolvedKMACOptionsNoEncodingType {\n const resolvedOptions = options || {};\n\n return {\n kmacKey: parseInputOption(\"kmacKey\", resolvedOptions[\"kmacKey\"], 1),\n /* This is little-endian packed \"KMAC\" */\n funcName: { value: [0x43414d4b], binLen: 32 },\n customization: parseInputOption(\"Customization\", resolvedOptions[\"customization\"], 1, { value: [], binLen: 0 }),\n };\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: Int_64[][];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: Int_64[][]) => Int_64[][];\n finalizeFunc: (\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: Int_64[][],\n outputLen: number\n ) => number[];\n stateCloneFunc: (state: Int_64[][]) => Int_64[][];\n newStateFunc: (variant: VariantType) => Int_64[][];\n getMAC: ((options: { outputLen: number }) => number[]) | null;\n\n constructor(variant: FixedLengthVariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(\n variant: FixedLengthVariantType,\n inputFormat: FormatNoTextType,\n options?: FixedLengthOptionsNoEncodingType\n );\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: \"TEXT\", options?: SHAKEOptionsEncodingType);\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: \"TEXT\", options?: CSHAKEOptionsEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: \"TEXT\", options: KMACOptionsEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n let delimiter = 0x06,\n variantBlockSize = 0;\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n /* In other variants, this was done after variable initialization but need to do it earlier here becaue we want to\n avoid KMAC initialization */\n if (this.numRounds !== 1) {\n if (resolvedOptions[\"kmacKey\"] || resolvedOptions[\"hmacKey\"]) {\n throw new Error(mac_rounds_error);\n } else if (this.shaVariant === \"CSHAKE128\" || this.shaVariant === \"CSHAKE256\") {\n throw new Error(\"Cannot set numRounds for CSHAKE variants\");\n }\n }\n\n this.bigEndianMod = 1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA3;\n this.stateCloneFunc = cloneSHA3State;\n this.newStateFunc = getNewState;\n this.intermediateState = getNewState(variant);\n\n this.isVariableLen = false;\n switch (variant) {\n case \"SHA3-224\":\n this.variantBlockSize = variantBlockSize = 1152;\n this.outputBinLen = 224;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-256\":\n this.variantBlockSize = variantBlockSize = 1088;\n this.outputBinLen = 256;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-384\":\n this.variantBlockSize = variantBlockSize = 832;\n this.outputBinLen = 384;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-512\":\n this.variantBlockSize = variantBlockSize = 576;\n this.outputBinLen = 512;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHAKE128\":\n delimiter = 0x1f;\n this.variantBlockSize = variantBlockSize = 1344;\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"SHAKE256\":\n delimiter = 0x1f;\n this.variantBlockSize = variantBlockSize = 1088;\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"KMAC128\":\n delimiter = 0x4;\n this.variantBlockSize = variantBlockSize = 1344;\n this._initializeKMAC(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getKMAC;\n break;\n case \"KMAC256\":\n delimiter = 0x4;\n this.variantBlockSize = variantBlockSize = 1088;\n this._initializeKMAC(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getKMAC;\n break;\n case \"CSHAKE128\":\n this.variantBlockSize = variantBlockSize = 1344;\n delimiter = this._initializeCSHAKE(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"CSHAKE256\":\n this.variantBlockSize = variantBlockSize = 1088;\n delimiter = this._initializeCSHAKE(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n default:\n throw new Error(sha_variant_error);\n }\n\n /* This needs to be down here as CSHAKE can change its delimiter */\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, state, outputBinLen): number[] {\n return finalizeSHA3(\n remainder,\n remainderBinLen,\n processedBinLen,\n state,\n variantBlockSize,\n delimiter,\n outputBinLen\n );\n };\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n\n /**\n * Initialize CSHAKE variants.\n *\n * @param options Options containing CSHAKE params.\n * @param funcNameOverride Overrides any \"funcName\" present in `options` (used with KMAC)\n * @returns The delimiter to be used\n */\n protected _initializeCSHAKE(options?: CSHAKEOptionsNoEncodingType, funcNameOverride?: packedValue): number {\n const resolvedOptions = resolveCSHAKEOptions(options || {});\n if (funcNameOverride) {\n resolvedOptions[\"funcName\"] = funcNameOverride;\n }\n const packedParams = packedLEConcat(\n encode_string(resolvedOptions[\"funcName\"]),\n encode_string(resolvedOptions[\"customization\"])\n );\n\n /* CSHAKE is defined to be a call to SHAKE iff both the customization and function-name string are both empty. This\n can be accomplished by processing nothing in this step. */\n if (resolvedOptions[\"customization\"][\"binLen\"] !== 0 || resolvedOptions[\"funcName\"][\"binLen\"] !== 0) {\n const byte_pad_out = byte_pad(packedParams, this.variantBlockSize >>> 3);\n for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {\n this.intermediateState = this.roundFunc(\n byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),\n this.intermediateState\n );\n this.processedLen += this.variantBlockSize;\n }\n return 0x04;\n } else {\n return 0x1f;\n }\n }\n\n /**\n * Initialize KMAC variants.\n *\n * @param options Options containing KMAC params.\n */\n protected _initializeKMAC(options: KMACOptionsNoEncodingType): void {\n const resolvedOptions = resolveKMACOptions(options || {});\n\n this._initializeCSHAKE(options, resolvedOptions[\"funcName\"]);\n const byte_pad_out = byte_pad(encode_string(resolvedOptions[\"kmacKey\"]), this.variantBlockSize >>> 3);\n for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {\n this.intermediateState = this.roundFunc(\n byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),\n this.intermediateState\n );\n this.processedLen += this.variantBlockSize;\n }\n this.macKeySet = true;\n }\n\n /**\n * Returns the the KMAC in the specified format.\n *\n * @param options Hashmap of extra outputs options. `outputLen` must be specified.\n * @returns The KMAC in the format specified.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected _getKMAC(options: { outputLen: number }): number[] {\n const concatedRemainder = packedLEConcat(\n { value: this.remainder.slice(), binLen: this.remainderLen },\n right_encode(options[\"outputLen\"])\n );\n\n return this.finalizeFunc(\n concatedRemainder[\"value\"],\n concatedRemainder[\"binLen\"],\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n options[\"outputLen\"]\n );\n }\n}\n","import { sha_variant_error } from \"./common\";\nimport {\n CSHAKEOptionsEncodingType,\n CSHAKEOptionsNoEncodingType,\n SHAKEOptionsEncodingType,\n SHAKEOptionsNoEncodingType,\n EncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n KMACOptionsNoEncodingType,\n KMACOptionsEncodingType,\n} from \"./custom_types\";\nimport jsSHA1 from \"./sha1\";\nimport jsSHA256 from \"./sha256\";\nimport jsSHA512 from \"./sha512\";\nimport jsSHA3 from \"./sha3\";\n\ntype FixedLengthVariantType =\n | \"SHA-1\"\n | \"SHA-224\"\n | \"SHA-256\"\n | \"SHA-384\"\n | \"SHA-512\"\n | \"SHA3-224\"\n | \"SHA3-256\"\n | \"SHA3-384\"\n | \"SHA3-512\";\n\nexport default class jsSHA {\n private readonly shaObj: jsSHA1 | jsSHA256 | jsSHA512 | jsSHA3;\n /**\n * @param variant The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-256,\n * SHA3-384, SHA3-512, SHAKE128, SHAKE256, CSHAKE128, CSHAKE256, KMAC128, or KMAC256) as a string.\n * @param inputFormat The input format to be used in future `update` calls (TEXT, HEX, B64, BYTES, ARRAYBUFFER,\n * or UINT8ARRAY) as a string.\n * @param options Options in the form of { encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE\"; numRounds?: number }.\n * `encoding` is for only TEXT input (defaults to UTF8) and `numRounds` defaults to 1.\n * `numRounds` is not valid for any of the MAC or CSHAKE variants.\n * * If the variant supports HMAC, `options` may have an additional `hmacKey` key which must be in the form of\n * {value: , format: , encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE\"} where takes the same\n * values as `inputFormat` and can be a `string | ArrayBuffer | Uint8Array` depending on .\n * Supplying this key switches to HMAC calculation and replaces the now deprecated call to `setHMACKey`.\n * * If the variant is CSHAKE128 or CSHAKE256, `options` may have two additional keys, `customization` and `funcName`,\n * which are the NIST customization and function-name strings. Both must be in the same form as `hmacKey`.\n * * If the variant is KMAC128 or KMAC256, `options` can include the `customization` key from CSHAKE variants and\n * *must* have a `kmacKey` key that takes the same form as the `customization` key.\n */\n constructor(variant: FixedLengthVariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(\n variant: FixedLengthVariantType,\n inputFormat: FormatNoTextType,\n options?: FixedLengthOptionsNoEncodingType\n );\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: \"TEXT\", options?: SHAKEOptionsEncodingType);\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: \"TEXT\", options?: CSHAKEOptionsEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: \"TEXT\", options: KMACOptionsEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (\"SHA-1\" == variant) {\n this.shaObj = new jsSHA1(variant, inputFormat, options);\n } else if (\"SHA-224\" == variant || \"SHA-256\" == variant) {\n this.shaObj = new jsSHA256(variant, inputFormat, options);\n } else if (\"SHA-384\" == variant || \"SHA-512\" == variant) {\n this.shaObj = new jsSHA512(variant, inputFormat, options);\n } else if (\n \"SHA3-224\" == variant ||\n \"SHA3-256\" == variant ||\n \"SHA3-384\" == variant ||\n \"SHA3-512\" == variant ||\n \"SHAKE128\" == variant ||\n \"SHAKE256\" == variant ||\n \"CSHAKE128\" == variant ||\n \"CSHAKE256\" == variant ||\n \"KMAC128\" == variant ||\n \"KMAC256\" == variant\n ) {\n this.shaObj = new jsSHA3(variant, inputFormat, options);\n } else {\n throw new Error(sha_variant_error);\n }\n }\n\n /**\n * Takes `input` and hashes as many blocks as possible. Stores the rest for either a future `update` or `getHash` call.\n *\n * @param input The input to be hashed\n */\n update(input: string | ArrayBuffer | Uint8Array): void {\n this.shaObj.update(input);\n }\n\n /**\n * Returns the desired SHA or MAC (if a HMAC/KMAC key was specified) hash of the input fed in via `update` calls.\n *\n * @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { outputUpper?: boolean; b64Pad?: string; outputLen?: number; }.\n * `outputLen` is required for variable length output variants (this option was previously called `shakeLen` which\n * is now deprecated).\n * `outputUpper` is only for HEX output (defaults to false) and b64pad is only for B64 output (defaults to \"=\").\n * @returns The hash in the format specified.\n */\n getHash(format: \"HEX\", options?: { outputUpper?: boolean; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"B64\", options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"BYTES\", options?: { outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"UINT8ARRAY\", options?: { outputLen?: number; shakeLen?: number }): Uint8Array;\n getHash(format: \"ARRAYBUFFER\", options?: { outputLen?: number; shakeLen?: number }): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHash(format: any, options?: any): any {\n return this.shaObj.getHash(format, options);\n }\n\n /**\n * Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.\n * Now deprecated in favor of setting the `hmacKey` at object instantiation.\n *\n * @param key The key used to calculate the HMAC\n * @param inputFormat The format of key (HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE }. `encoding` is only for TEXT\n * and defaults to UTF8.\n */\n setHMACKey(key: string, inputFormat: \"TEXT\", options?: { encoding?: EncodingType }): void;\n setHMACKey(key: string, inputFormat: \"B64\" | \"HEX\" | \"BYTES\"): void;\n setHMACKey(key: ArrayBuffer, inputFormat: \"ARRAYBUFFER\"): void;\n setHMACKey(key: Uint8Array, inputFormat: \"UINT8ARRAY\"): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setHMACKey(key: any, inputFormat: any, options?: any): void {\n this.shaObj.setHMACKey(key, inputFormat, options);\n }\n\n /**\n * Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call. Now deprecated\n * in favor of just calling `getHash`.\n *\n * @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { outputUpper?: boolean; b64Pad?: string }. `outputUpper` is only for HEX\n * output (defaults to false) and `b64pad` is only for B64 output (defaults to \"=\").\n * @returns The HMAC in the format specified.\n */\n getHMAC(format: \"HEX\", options?: { outputUpper?: boolean }): string;\n getHMAC(format: \"B64\", options?: { b64Pad?: string }): string;\n getHMAC(format: \"BYTES\"): string;\n getHMAC(format: \"UINT8ARRAY\"): Uint8Array;\n getHMAC(format: \"ARRAYBUFFER\"): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHMAC(format: any, options?: any): any {\n return this.shaObj.getHMAC(format, options);\n }\n}\n"],"names":["b64Tab","uint8array2packed","arr","existingPacked","existingPackedLen","bigEndianMod","i","intOffset","byteOffset","packed","existingByteLen","shiftModifier","length","push","value","binLen","getStrConverter","format","utfType","Error","str","existingBin","existingBinLen","num","parseInt","substr","isNaN","hex2packed","codePnt","codePntArr","j","transposeBytes","byteCnt","charCodeAt","str2packed","tmpInt","strPart","firstEqual","indexOf","search","replace","charAt","b642packed","bytes2packed","ArrayBuffer","ignore","Uint8Array","arraybuffer2packed","getOutputConverter","outputBinLen","outputOptions","binarray","outputLength","formatOpts","srcByte","toUpperCase","packed2hex","triplet","int1","int2","packed2b64","String","fromCharCode","packed2bytes","retVal","arrView","packed2arraybuffer","packed2uint8array","K_sha2","H_trunc","H_full","sha_variant_error","packedLEConcat","a","b","arrOffset","aByteLen","bByteLen","leftShiftAmount","rightShiftAmount","pop","concat","getOutputOpts","options","outputUpper","b64Pad","outputLen","lenErrstr","parseInputOption","key","fallback","errStr","variant","inputFormat","inputOptions","this","numRounds","shaVariant","remainder","remainderLen","updateCalled","processedLen","macKeySet","keyWithIPad","keyWithOPad","jsSHABase","srcString","updateProcessedLen","variantBlockIntInc","variantBlockSize","convertRet","converterFunc","chunkBinLen","chunk","chunkIntLen","intermediateState","roundFunc","slice","finalizedState","isVariableLen","formatFunc","getMAC","finalizeFunc","stateCloneFunc","newStateFunc","HMACSupported","keyConverterFunc","_setHMACKey","blockByteSize","lastArrayIndex","_getHMAC","firstHash","extendStatics","d","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__extends","__","constructor","create","rotl_32","x","n","rotr_32","shr_32","parity_32","y","z","ch_32","maj_32","sigma0_32","safeAdd_32_2","lsw","safeAdd_32_4","c","safeAdd_32_5","e","gamma0_32","sigma1_32","getNewState","_variant","roundSHA1","block","H","T","t","W","finalizeSHA1","remainderBinLen","processedBinLen","offset","totalLen","resolvedOptions","_this","_super","state","getNewState256","roundSHA256","f","g","h","T1","T2","finalizeSHA256","msint_32","lsint_32","highOrder","lowOrder","rotl_64","tmp","Int_64","rotr_64","shr_64","ch_64","maj_64","sigma0_64","rotr28","rotr34","rotr39","safeAdd_64_2","msw","safeAdd_64_4","safeAdd_64_5","xor_64_2","gamma0_64","rotr1","rotr8","shr7","sigma1_64","rotr14","rotr18","rotr41","K_sha512","getNewState512","roundSHA512","rotr19","rotr61","shr6","finalizeSHA512","rc_sha3","r_sha3","cloneSHA3State","clone","roundSHA3","round","B","C","D","left_encode","byte","numEncodedBytes","x_64","encode_string","input","byte_pad","outputByteLen","encodedLen","outputIntLen","intsToAppend","delimiter","_initializeKMAC","_getKMAC","_initializeCSHAKE","_processedBinLen","blockSize","temp","state_offset","binaryStringInc","remainderIntLen","finalizeSHA3","jsSHA","funcNameOverride","funcName","customization","resolveCSHAKEOptions","packedParams","byte_pad_out","kmacKey","resolveKMACOptions","concatedRemainder","right_encode","shaObj","jsSHA1","jsSHA256","jsSHA512","jsSHA3","update","getHash","setHMACKey","getHMAC"],"mappings":";;;;;;;;;;;;;;;;;;;;sOAIA,IAAMA,EAAS,mEA4Pf,SAASC,EACPC,EACAC,EACAC,EACAC,GAEA,IAAIC,EAAGC,EAAWC,EAGZC,EAASN,GAAkB,CAAC,GAChCO,GAFFN,EAAoBA,GAAqB,KAEC,EACxCO,GAAkC,IAAlBN,EAAsB,EAAI,EAE5C,IAAKC,EAAI,EAAGA,EAAIJ,EAAIU,OAAQN,GAAK,EAE/BC,GADAC,EAAaF,EAAII,KACU,EACvBD,EAAOG,QAAUL,GACnBE,EAAOI,KAAK,GAEdJ,EAAOF,IAAcL,EAAII,IAAO,GAAKK,EAAgBN,GAAgBG,EAAa,IAGpF,MAAO,CAAEM,MAAOL,EAAQM,OAAqB,EAAbb,EAAIU,OAAaR,YA6BnCY,EACdC,EACAC,EACAb,GAIA,OAAQa,GACN,IAAK,OAEL,IAAK,UAEL,IAAK,UAEH,MACF,QACE,MAAM,IAAIC,MAAM,8CAIpB,OAAQF,GACN,IAAK,MAOH,OAAO,SAAUG,EAAaC,EAAwBC,GACpD,OA9NR,SACEF,EACAjB,EACAC,EACAC,GAEA,IAAIC,EAAGiB,EAAKhB,EAAWC,EAEvB,GAAI,GAAMY,EAAIR,OAAS,EACrB,MAAM,IAAIO,MAAM,iDAIlB,IAAMV,EAASN,GAAkB,CAAC,GAChCO,GAFFN,EAAoBA,GAAqB,KAEC,EACxCO,GAAkC,IAAlBN,EAAsB,EAAI,EAE5C,IAAKC,EAAI,EAAGA,EAAIc,EAAIR,OAAQN,GAAK,EAA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EAAaV,QAC1C,GAAI,WAAaS,GAAW,WAAaA,EAC9CG,KAAK4K,EAAS,IAAIE,EAASjL,EAASC,EAAaV,QAC5C,GAAI,WAAaS,GAAW,WAAaA,EAC9CG,KAAK4K,EAAS,IAAIG,EAASlL,EAASC,EAAaV,OAC5C,CAAA,GACL,YAAcS,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,aAAeA,GACf,aAAeA,GACf,WAAaA,GACb,WAAaA,EAIb,MAAM,IAAIzE,MAAMoD,GAFhBwB,KAAK4K,EAAS,IAAII,GAAOnL,EAASC,EAAaV,IAuErD,OA5DE6K,mBAAA,SAAOjB,GACLhJ,KAAK4K,EAAOK,OAAOjC,IAmBrBiB,oBAAA,SAAQ/O,EAAakE,GACnB,OAAOY,KAAK4K,EAAOM,QAAQhQ,EAAQkE,IAiBrC6K,uBAAA,SAAWvK,EAAUI,EAAkBV,GACrCY,KAAK4K,EAAOO,WAAWzL,EAAKI,EAAaV,IAkB3C6K,oBAAA,SAAQ/O,EAAakE,GACnB,OAAOY,KAAK4K,EAAOQ,QAAQlQ,EAAQkE"} \ No newline at end of file diff --git a/include/js/sha.mjs b/include/js/sha.mjs new file mode 100644 index 0000000..cd1264f --- /dev/null +++ b/include/js/sha.mjs @@ -0,0 +1,10 @@ +/** + * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, + * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. + * + * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors + * Distributed under the BSD License + * See http://caligatio.github.com/jsSHA/ for more information + */ +const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function n(t,n,e,r){let i,s,o;const h=n||[0],u=(e=e||0)>>>3,w=-1===r?3:0;for(i=0;i>>2,h.length<=s&&h.push(0),h[s]|=t[i]<<8*(w+r*(o%4));return{value:h,binLen:8*t.length+e}}function e(e,r,i){switch(r){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(t,n,e){return function(t,n,e,r){let i,s,o,h;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const u=n||[0],w=(e=e||0)>>>3,c=-1===r?3:0;for(i=0;i>>1)+w,o=h>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(c+r*(h%4))}return{value:u,binLen:4*t.length+e}}(t,n,e,i)};case"TEXT":return function(t,n,e){return function(t,n,e,r,i){let s,o,h,u,w,c,f,a,l=0;const A=e||[0],E=(r=r||0)>>>3;if("UTF8"===n)for(f=-1===i?3:0,h=0;hs?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(h+=1,s=65536+((1023&s)<<10|1023&t.charCodeAt(h)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u>>2;A.length<=w;)A.push(0);A[w]|=o[u]<<8*(f+i*(c%4)),l+=1}else for(f=-1===i?2:0,a="UTF16LE"===n&&1!==i||"UTF16LE"!==n&&1===i,h=0;h>>8),c=l+E,w=c>>>2;A.length<=w;)A.push(0);A[w]|=s<<8*(f+i*(c%4)),l+=2}return{value:A,binLen:8*l+r}}(t,r,n,e,i)};case"B64":return function(n,e,r){return function(n,e,r,i){let s,o,h,u,w,c,f,a=0;const l=e||[0],A=(r=r||0)>>>3,E=-1===i?3:0,H=n.indexOf("=");if(-1===n.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(n=n.replace(/=/g,""),-1!==H&&H>>2;w.length<=a;)w.push(0);w[a]|=(u>>>16-8*s&255)<<8*(l+i*(h%4)),c+=1}}return{value:w,binLen:8*c+e}}(r,n,e,i)};case"BYTES":return function(r,t,n){return function(r,t,n,e){var i,o,s,u,f=t||[0],a=(n=n||0)>>>3,h=-1===e?3:0;for(o=0;o>>2,f.length<=s&&f.push(0),f[s]|=i<<8*(h+e*(u%4));return{value:f,binLen:8*r.length+n}}(r,t,n,i)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(r){throw new Error("ARRAYBUFFER not supported by this environment")}return function(r,t,e){return function(r,t,e,i){return n(new Uint8Array(r),t,e,i)}(r,t,e,i)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(r){throw new Error("UINT8ARRAY not supported by this environment")}return function(r,t,e){return n(r,t,e,i)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function i(r,n,e,i){switch(r){case"HEX":return function(r){return function(r,t,n,e){var i,o,s="",u=t/8,f=-1===n?3:0;for(i=0;i>>2]>>>8*(f+n*(i%4)),s+="0123456789abcdef".charAt(o>>>4&15)+"0123456789abcdef".charAt(15&o);return e.outputUpper?s.toUpperCase():s}(r,n,e,i)};case"B64":return function(r){return function(r,n,e,i){var o,s,u,f,a,h="",c=n/8,w=-1===e?3:0;for(o=0;o>>2]:0,a=o+2>>2]:0,u=(r[o>>>2]>>>8*(w+e*(o%4))&255)<<16|(f>>>8*(w+e*((o+1)%4))&255)<<8|a>>>8*(w+e*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=n?t.charAt(u>>>6*(3-s)&63):i.b64Pad;return h}(r,n,e,i)};case"BYTES":return function(r){return function(r,t,n){var e,i,o="",s=t/8,u=-1===n?3:0;for(e=0;e>>2]>>>8*(u+n*(e%4))&255,o+=String.fromCharCode(i);return o}(r,n,e)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(r){throw new Error("ARRAYBUFFER not supported by this environment")}return function(r){return function(r,t,n){var e,i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),u=-1===n?3:0;for(e=0;e>>2]>>>8*(u+n*(e%4))&255;return o}(r,n,e)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(r){throw new Error("UINT8ARRAY not supported by this environment")}return function(r){return function(r,t,n){var e,i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(e=0;e>>2]>>>8*(o+n*(e%4))&255;return s}(r,n,e)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(r,t){var n,e,i=r.binLen>>>3,o=t.binLen>>>3,s=i<<3,u=4-i<<3;if(i%4!=0){for(n=0;n>>2,r.value[e]|=t.value[n>>>2]<>>2]>>>u;return(r.value.length<<2)-4>=o+i&&r.value.pop(),{value:r.value,binLen:r.binLen+t.binLen}}return{value:r.value.concat(t.value),binLen:r.binLen+t.binLen}}function s(r){var t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=r||{},e="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(e);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(e);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(r,t,n,i){var o=r+" must include a value and format";if(!t){if(!i)throw new Error(o);return i}if(void 0===t.value||!t.format)throw new Error(o);return e(t.format,t.encoding||"UTF8",n)(t.value)}var f=function(){function r(r,t,n){var e=n||{};if(this.t=t,this.i=e.encoding||"UTF8",this.numRounds=e.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=r,this.s=[],this.u=0,this.h=!1,this.v=0,this.l=!1,this.A=[],this.p=[]}return r.prototype.update=function(r){var t,n=0,e=this.m>>>5,i=this.R(r,this.s,this.u),o=i.binLen,s=i.value,u=o>>>5;for(t=0;t>>5),this.u=o%this.m,this.h=!0},r.prototype.getHash=function(r,t){var n,e,o=this.F,u=s(t);if(this.C){if(-1===u.outputLen)throw new Error("Output length must be specified in options");o=u.outputLen}var f=i(r,o,this.H,u);if(this.l&&this.B)return f(this.B(u));for(e=this.L(this.s.slice(),this.u,this.v,this.S(this.U),o),n=1;n>>24-o%32),e=this.L(e,o,0,this.g(this.o),o);return f(e)},r.prototype.setHMACKey=function(r,t,n){if(!this.k)throw new Error("Variant does not support HMAC");if(this.h)throw new Error("Cannot set MAC key after calling update");var i=e(t,(n||{}).encoding||"UTF8",this.H);this.Y(i(r))},r.prototype.Y=function(r){var t,n=this.m>>>3,e=n/4-1;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.l)throw new Error("MAC key already set");for(n32?(n=64-t,new a(r.K<>>n,r.I<>>n)):0!==t?(n=32-t,new a(r.I<>>n,r.K<>>n)):r}function c(r,t){return new a(r.I^t.I,r.K^t.K)}var w=[new a(0,1),new a(0,32898),new a(2147483648,32906),new a(2147483648,2147516416),new a(0,32907),new a(0,2147483649),new a(2147483648,2147516545),new a(2147483648,32777),new a(0,138),new a(0,136),new a(0,2147516425),new a(0,2147483658),new a(0,2147516555),new a(2147483648,139),new a(2147483648,32905),new a(2147483648,32771),new a(2147483648,32770),new a(2147483648,128),new a(0,32778),new a(2147483648,2147483658),new a(2147483648,2147516545),new a(2147483648,32896),new a(0,2147483649),new a(2147483648,2147516424)],v=[[0,36,3,41,18],[1,44,10,45,2],[62,6,43,15,61],[28,55,25,21,56],[27,20,39,8,14]];function l(r){var t,n=[];for(t=0;t<5;t+=1)n[t]=[new a(0,0),new a(0,0),new a(0,0),new a(0,0),new a(0,0)];return n}function E(r){var t,n=[];for(t=0;t<5;t+=1)n[t]=r[t].slice();return n}function A(r,t){var n,e,i,o,s,u,f,E,A,b=[],d=[];if(null!==r)for(e=0;e>>1)%5][(e>>>1)/5|0]=c(t[(e>>>1)%5][(e>>>1)/5|0],new a(r[e+1],r[e]));for(n=0;n<24;n+=1){for(o=l(),e=0;e<5;e+=1)b[e]=(s=t[e][0],u=t[e][1],f=t[e][2],E=t[e][3],A=t[e][4],new a(s.I^u.I^f.I^E.I^A.I,s.K^u.K^f.K^E.K^A.K));for(e=0;e<5;e+=1)d[e]=c(b[(e+4)%5],h(b[(e+1)%5],1));for(e=0;e<5;e+=1)for(i=0;i<5;i+=1)t[e][i]=c(t[e][i],d[e]);for(e=0;e<5;e+=1)for(i=0;i<5;i+=1)o[i][(2*e+3*i)%5]=h(t[e][i],v[e][i]);for(e=0;e<5;e+=1)for(i=0;i<5;i+=1)t[e][i]=c(o[e][i],new a(~o[(e+1)%5][i].I&o[(e+2)%5][i].I,~o[(e+1)%5][i].K&o[(e+2)%5][i].K));t[0][0]=c(t[0][0],w[n])}return t}function b(r){var t,n,e=0,i=[0,0],o=[4294967295&r,r/4294967296&2097151];for(t=6;t>=0;t--)0===(n=o[t>>2]>>>8*t&255)&&0===e||(i[e+1>>2]|=n<<8*(e+1),e+=1);return e=0!==e?e:1,i[0]|=e,{value:e+1>4?i:[i[0]],binLen:8+8*e}}function d(r){return o(b(r.binLen),r)}function p(r,t){var n,e=b(t),i=t>>>2,s=(i-(e=o(e,r)).value.length%i)%i;for(n=0;n>>5,w=t>>>5;for(u=0;u=i;u+=c)e=A(r.slice(u,u+c),e),t-=i;for(r=r.slice(u),t%=i;r.length>>3)>>2]^=o<=s));)h.push(f.I),0==64*(a+=1)%i&&(A(null,e),a=0);return h}(r,t,0,e,f,s,i)},a.hmacKey&&o.Y(u("hmacKey",a.hmacKey,o.H)),o}return function(t,n){function e(){this.constructor=t}r(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}(n,t),n.prototype.O=function(r,t){var n=function(r){var t=r||{};return{funcName:u("funcName",t.funcName,1,{value:[],binLen:0}),customization:u("Customization",t.customization,1,{value:[],binLen:0})}}(r||{});t&&(n.funcName=t);var e=o(d(n.funcName),d(n.customization));if(0!==n.customization.binLen||0!==n.funcName.binLen){for(var i=p(e,this.m>>>3),s=0;s>>5)this.U=this.T(i.slice(s,s+(this.m>>>5)),this.U),this.v+=this.m;return 4}return 31},n.prototype.M=function(r){var t=function(r){var t=r||{};return{kmacKey:u("kmacKey",t.kmacKey,1),funcName:{value:[1128353099],binLen:32},customization:u("Customization",t.customization,1,{value:[],binLen:0})}}(r||{});this.O(r,t.funcName);for(var n=p(d(t.kmacKey),this.m>>>3),e=0;e>>5)this.U=this.T(n.slice(e,e+(this.m>>>5)),this.U),this.v+=this.m;this.l=!0},n.prototype.X=function(r){var t=o({value:this.s.slice(),binLen:this.u},function(r){var t,n,e=0,i=[0,0],o=[4294967295&r,r/4294967296&2097151];for(t=6;t>=0;t--)0==(n=o[t>>2]>>>8*t&255)&&0===e||(i[e>>2]|=n<<8*e,e+=1);return i[(e=0!==e?e:1)>>2]|=e<<8*e,{value:e+1>4?i:[i[0]],binLen:8+8*e}}(r.outputLen));return this.L(t.value,t.binLen,this.v,this.S(this.U),r.outputLen)},n}(f)})); diff --git a/include/js/sha3.mjs b/include/js/sha3.mjs new file mode 100644 index 0000000..d7b26f7 --- /dev/null +++ b/include/js/sha3.mjs @@ -0,0 +1,9 @@ +/** + * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, + * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. + * + * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors + * Distributed under the BSD License + * See http://caligatio.github.com/jsSHA/ for more information + */ +const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function n(t,n,r,i){let s,e,o;const h=n||[0],u=(r=r||0)>>>3,c=-1===i?3:0;for(s=0;s>>2,h.length<=e&&h.push(0),h[e]|=t[s]<<8*(c+i*(o%4));return{value:h,binLen:8*t.length+r}}function r(r,i,s){switch(i){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(r){case"HEX":return function(t,n,r){return function(t,n,r,i){let s,e,o,h;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const u=n||[0],c=(r=r||0)>>>3,f=-1===i?3:0;for(s=0;s>>1)+c,o=h>>>2;u.length<=o;)u.push(0);u[o]|=e<<8*(f+i*(h%4))}return{value:u,binLen:4*t.length+r}}(t,n,r,s)};case"TEXT":return function(t,n,r){return function(t,n,r,i,s){let e,o,h,u,c,f,a,w,l=0;const A=r||[0],E=(i=i||0)>>>3;if("UTF8"===n)for(a=-1===s?3:0,h=0;he?o.push(e):2048>e?(o.push(192|e>>>6),o.push(128|63&e)):55296>e||57344<=e?o.push(224|e>>>12,128|e>>>6&63,128|63&e):(h+=1,e=65536+((1023&e)<<10|1023&t.charCodeAt(h)),o.push(240|e>>>18,128|e>>>12&63,128|e>>>6&63,128|63&e)),u=0;u>>2;A.length<=c;)A.push(0);A[c]|=o[u]<<8*(a+s*(f%4)),l+=1}else for(a=-1===s?2:0,w="UTF16LE"===n&&1!==s||"UTF16LE"!==n&&1===s,h=0;h>>8),f=l+E,c=f>>>2;A.length<=c;)A.push(0);A[c]|=e<<8*(a+s*(f%4)),l+=2}return{value:A,binLen:8*l+i}}(t,i,n,r,s)};case"B64":return function(n,r,i){return function(n,r,i,s){let e,o,h,u,c,f,a,w=0;const l=r||[0],A=(i=i||0)>>>3,E=-1===s?3:0,b=n.indexOf("=");if(-1===n.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(n=n.replace(/=/g,""),-1!==b&&b> 31)) & (0xFFFFFFFF), + $bc[($i + 4) % 5][1] ^ (($bc[($i + 1) % 5][1] << 1) | ($bc[($i + 1) % 5][0] >> 31)) & (0xFFFFFFFF) + ]; + + for ($j = 0; $j < 25; $j += 5) { + $st[$j + $i] = [ + $st[$j + $i][0] ^ $t[0], + $st[$j + $i][1] ^ $t[1] + ]; + } + } + + // Rho Pi + $t = $st[1]; + for ($i = 0; $i < 24; $i++) { + $j = self::$keccakf_piln[$i]; + + $bc[0] = $st[$j]; + + $n = self::$keccakf_rotc[$i]; + $hi = $t[0]; + $lo = $t[1]; + if ($n >= 32) { + $n -= 32; + $hi = $t[1]; + $lo = $t[0]; + } + + $st[$j] =[ + (($hi << $n) | ($lo >> (32 - $n))) & (0xFFFFFFFF), + (($lo << $n) | ($hi >> (32 - $n))) & (0xFFFFFFFF) + ]; + + $t = $bc[0]; + } + + // Chi + for ($j = 0; $j < 25; $j += 5) { + for ($i = 0; $i < 5; $i++) { + $bc[$i] = $st[$j + $i]; + } + for ($i = 0; $i < 5; $i++) { + $st[$j + $i] = [ + $st[$j + $i][0] ^ ~$bc[($i + 1) % 5][0] & $bc[($i + 2) % 5][0], + $st[$j + $i][1] ^ ~$bc[($i + 1) % 5][1] & $bc[($i + 2) % 5][1] + ]; + } + } + + // Iota + $st[0] = [ + $st[0][0] ^ $keccakf_rndc[$round][0], + $st[0][1] ^ $keccakf_rndc[$round][1] + ]; + } + } + + private static function keccak64($in_raw, int $capacity, int $outputlength, $suffix, bool $raw_output): string { + $capacity /= 8; + + $inlen = mb_strlen($in_raw, self::ENCODING); + + $rsiz = 200 - 2 * $capacity; + $rsizw = $rsiz / 8; + + $st = []; + for ($i = 0; $i < 25; $i++) { + $st[] = [0, 0]; + } + + for ($in_t = 0; $inlen >= $rsiz; $inlen -= $rsiz, $in_t += $rsiz) { + for ($i = 0; $i < $rsizw; $i++) { + $t = unpack('V*', mb_substr($in_raw, intval($i * 8 + $in_t), 8, self::ENCODING)); + + $st[$i] = [ + $st[$i][0] ^ $t[2], + $st[$i][1] ^ $t[1] + ]; + } + + self::keccakf64($st, self::KECCAK_ROUNDS); + } + + $temp = mb_substr($in_raw, (int) $in_t, (int) $inlen, self::ENCODING); + $temp = str_pad($temp, (int) $rsiz, "\x0", STR_PAD_RIGHT); + $temp = substr_replace($temp, chr($suffix), $inlen, 1); + $temp = substr_replace($temp, chr(ord($temp[intval($rsiz - 1)]) | 0x80), $rsiz - 1, 1); + + for ($i = 0; $i < $rsizw; $i++) { + $t = unpack('V*', mb_substr($temp, $i * 8, 8, self::ENCODING)); + + $st[$i] = [ + $st[$i][0] ^ $t[2], + $st[$i][1] ^ $t[1] + ]; + } + + self::keccakf64($st, self::KECCAK_ROUNDS); + + $out = ''; + for ($i = 0; $i < 25; $i++) { + $out .= $t = pack('V*', $st[$i][1], $st[$i][0]); + } + $r = mb_substr($out, 0, intval($outputlength / 8), self::ENCODING); + + return $raw_output ? $r : bin2hex($r); + } + + private static function keccakf32(&$st, $rounds): void { + $keccakf_rndc = [ + [0x0000, 0x0000, 0x0000, 0x0001], [0x0000, 0x0000, 0x0000, 0x8082], [0x8000, 0x0000, 0x0000, 0x0808a], [0x8000, 0x0000, 0x8000, 0x8000], + [0x0000, 0x0000, 0x0000, 0x808b], [0x0000, 0x0000, 0x8000, 0x0001], [0x8000, 0x0000, 0x8000, 0x08081], [0x8000, 0x0000, 0x0000, 0x8009], + [0x0000, 0x0000, 0x0000, 0x008a], [0x0000, 0x0000, 0x0000, 0x0088], [0x0000, 0x0000, 0x8000, 0x08009], [0x0000, 0x0000, 0x8000, 0x000a], + [0x0000, 0x0000, 0x8000, 0x808b], [0x8000, 0x0000, 0x0000, 0x008b], [0x8000, 0x0000, 0x0000, 0x08089], [0x8000, 0x0000, 0x0000, 0x8003], + [0x8000, 0x0000, 0x0000, 0x8002], [0x8000, 0x0000, 0x0000, 0x0080], [0x0000, 0x0000, 0x0000, 0x0800a], [0x8000, 0x0000, 0x8000, 0x000a], + [0x8000, 0x0000, 0x8000, 0x8081], [0x8000, 0x0000, 0x0000, 0x8080], [0x0000, 0x0000, 0x8000, 0x00001], [0x8000, 0x0000, 0x8000, 0x8008] + ]; + + $bc = []; + for ($round = 0; $round < $rounds; $round++) { + + // Theta + for ($i = 0; $i < 5; $i++) { + $bc[$i] = [ + $st[$i][0] ^ $st[$i + 5][0] ^ $st[$i + 10][0] ^ $st[$i + 15][0] ^ $st[$i + 20][0], + $st[$i][1] ^ $st[$i + 5][1] ^ $st[$i + 10][1] ^ $st[$i + 15][1] ^ $st[$i + 20][1], + $st[$i][2] ^ $st[$i + 5][2] ^ $st[$i + 10][2] ^ $st[$i + 15][2] ^ $st[$i + 20][2], + $st[$i][3] ^ $st[$i + 5][3] ^ $st[$i + 10][3] ^ $st[$i + 15][3] ^ $st[$i + 20][3] + ]; + } + + for ($i = 0; $i < 5; $i++) { + $t = [ + $bc[($i + 4) % 5][0] ^ ((($bc[($i + 1) % 5][0] << 1) | ($bc[($i + 1) % 5][1] >> 15)) & (0xFFFF)), + $bc[($i + 4) % 5][1] ^ ((($bc[($i + 1) % 5][1] << 1) | ($bc[($i + 1) % 5][2] >> 15)) & (0xFFFF)), + $bc[($i + 4) % 5][2] ^ ((($bc[($i + 1) % 5][2] << 1) | ($bc[($i + 1) % 5][3] >> 15)) & (0xFFFF)), + $bc[($i + 4) % 5][3] ^ ((($bc[($i + 1) % 5][3] << 1) | ($bc[($i + 1) % 5][0] >> 15)) & (0xFFFF)) + ]; + + for ($j = 0; $j < 25; $j += 5) { + $st[$j + $i] = [ + $st[$j + $i][0] ^ $t[0], + $st[$j + $i][1] ^ $t[1], + $st[$j + $i][2] ^ $t[2], + $st[$j + $i][3] ^ $t[3] + ]; + } + } + + // Rho Pi + $t = $st[1]; + for ($i = 0; $i < 24; $i++) { + $j = self::$keccakf_piln[$i]; + $bc[0] = $st[$j]; + + + $n = self::$keccakf_rotc[$i] >> 4; + $m = self::$keccakf_rotc[$i] % 16; + + $st[$j] = [ + ((($t[(0+$n) %4] << $m) | ($t[(1+$n) %4] >> (16-$m))) & (0xFFFF)), + ((($t[(1+$n) %4] << $m) | ($t[(2+$n) %4] >> (16-$m))) & (0xFFFF)), + ((($t[(2+$n) %4] << $m) | ($t[(3+$n) %4] >> (16-$m))) & (0xFFFF)), + ((($t[(3+$n) %4] << $m) | ($t[(0+$n) %4] >> (16-$m))) & (0xFFFF)) + ]; + + $t = $bc[0]; + } + + // Chi + for ($j = 0; $j < 25; $j += 5) { + for ($i = 0; $i < 5; $i++) { + $bc[$i] = $st[$j + $i]; + } + for ($i = 0; $i < 5; $i++) { + $st[$j + $i] = [ + $st[$j + $i][0] ^ ~$bc[($i + 1) % 5][0] & $bc[($i + 2) % 5][0], + $st[$j + $i][1] ^ ~$bc[($i + 1) % 5][1] & $bc[($i + 2) % 5][1], + $st[$j + $i][2] ^ ~$bc[($i + 1) % 5][2] & $bc[($i + 2) % 5][2], + $st[$j + $i][3] ^ ~$bc[($i + 1) % 5][3] & $bc[($i + 2) % 5][3] + ]; + } + } + + // Iota + $st[0] = [ + $st[0][0] ^ $keccakf_rndc[$round][0], + $st[0][1] ^ $keccakf_rndc[$round][1], + $st[0][2] ^ $keccakf_rndc[$round][2], + $st[0][3] ^ $keccakf_rndc[$round][3] + ]; + } + } + + private static function keccak32($in_raw, int $capacity, int $outputlength, $suffix, bool $raw_output): string { + $capacity /= 8; + + $inlen = mb_strlen($in_raw, self::ENCODING); + + $rsiz = 200 - 2 * $capacity; + $rsizw = $rsiz / 8; + + $st = []; + for ($i = 0; $i < 25; $i++) { + $st[] = [0, 0, 0, 0]; + } + + for ($in_t = 0; $inlen >= $rsiz; $inlen -= $rsiz, $in_t += $rsiz) { + for ($i = 0; $i < $rsizw; $i++) { + $t = unpack('v*', mb_substr($in_raw, intval($i * 8 + $in_t), 8, self::ENCODING)); + + $st[$i] = [ + $st[$i][0] ^ $t[4], + $st[$i][1] ^ $t[3], + $st[$i][2] ^ $t[2], + $st[$i][3] ^ $t[1] + ]; + } + + self::keccakf32($st, self::KECCAK_ROUNDS); + } + + $temp = mb_substr($in_raw, (int) $in_t, (int) $inlen, self::ENCODING); + $temp = str_pad($temp, (int) $rsiz, "\x0", STR_PAD_RIGHT); + $temp = substr_replace($temp, chr($suffix), $inlen, 1); + $temp = substr_replace($temp, chr((int) $temp[intval($rsiz - 1)] | 0x80), $rsiz - 1, 1); + + for ($i = 0; $i < $rsizw; $i++) { + $t = unpack('v*', mb_substr($temp, $i * 8, 8, self::ENCODING)); + + $st[$i] = [ + $st[$i][0] ^ $t[4], + $st[$i][1] ^ $t[3], + $st[$i][2] ^ $t[2], + $st[$i][3] ^ $t[1] + ]; + } + + self::keccakf32($st, self::KECCAK_ROUNDS); + + $out = ''; + for ($i = 0; $i < 25; $i++) { + $out .= $t = pack('v*', $st[$i][3],$st[$i][2], $st[$i][1], $st[$i][0]); + } + $r = mb_substr($out, 0, intval($outputlength / 8), self::ENCODING); + + return $raw_output ? $r: bin2hex($r); + } + + private static function keccak($in_raw, int $capacity, int $outputlength, $suffix, bool $raw_output): string { + return self::$x64 + ? self::keccak64($in_raw, $capacity, $outputlength, $suffix, $raw_output) + : self::keccak32($in_raw, $capacity, $outputlength, $suffix, $raw_output); + } + + public static function hash($in, int $mdlen, bool $raw_output = false): string { + if (!in_array($mdlen, [224, 256, 384, 512], true)) { + throw new Exception('Unsupported Keccak Hash output size.'); + } + + return self::keccak($in, $mdlen, $mdlen, self::LFSR, $raw_output); + } + + public static function shake($in, int $security_level, int $outlen, bool $raw_output = false): string { + if (!in_array($security_level, [128, 256], true)) { + throw new Exception('Unsupported Keccak Shake security level.'); + } + + return self::keccak($in, $security_level, $outlen, 0x1f, $raw_output); + } + +} diff --git a/include/thirdparty/js/sha.js b/include/thirdparty/js/sha.js new file mode 100644 index 0000000..3016fc0 --- /dev/null +++ b/include/thirdparty/js/sha.js @@ -0,0 +1,22 @@ +/** + * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, + * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. + * + * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors + * Distributed under the BSD License + * See http://caligatio.github.com/jsSHA/ for more information + * + * Two ECMAScript polyfill functions carry the following license: + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + * MERCHANTABLITY OR NON-INFRINGEMENT. + * + * See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. + */ +!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n="undefined"!=typeof globalThis?globalThis:n||self).jsSHA=r()}(this,(function(){"use strict";var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function r(n,r,t,e){var i,o,u,f=r||[0],w=(t=t||0)>>>3,s=-1===e?3:0;for(i=0;i>>2,f.length<=o&&f.push(0),f[o]|=n[i]<<8*(s+e*(u%4));return{value:f,binLen:8*n.length+t}}function t(t,e,i){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(n,r,t){return function(n,r,t,e){var i,o,u,f;if(0!=n.length%2)throw new Error("String of HEX type must be in byte increments");var w=r||[0],s=(t=t||0)>>>3,a=-1===e?3:0;for(i=0;i>>1)+s)>>>2;w.length<=u;)w.push(0);w[u]|=o<<8*(a+e*(f%4))}return{value:w,binLen:4*n.length+t}}(n,r,t,i)};case"TEXT":return function(n,r,t){return function(n,r,t,e,i){var o,u,f,w,s,a,h,c,v=0,A=t||[0],E=(e=e||0)>>>3;if("UTF8"===r)for(h=-1===i?3:0,f=0;f(o=n.charCodeAt(f))?u.push(o):2048>o?(u.push(192|o>>>6),u.push(128|63&o)):55296>o||57344<=o?u.push(224|o>>>12,128|o>>>6&63,128|63&o):(f+=1,o=65536+((1023&o)<<10|1023&n.charCodeAt(f)),u.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),w=0;w>>2;A.length<=s;)A.push(0);A[s]|=u[w]<<8*(h+i*(a%4)),v+=1}else for(h=-1===i?2:0,c="UTF16LE"===r&&1!==i||"UTF16LE"!==r&&1===i,f=0;f>>8),s=(a=v+E)>>>2;A.length<=s;)A.push(0);A[s]|=o<<8*(h+i*(a%4)),v+=2}return{value:A,binLen:8*v+e}}(n,e,r,t,i)};case"B64":return function(r,t,e){return function(r,t,e,i){var o,u,f,w,s,a,h=0,c=t||[0],v=(e=e||0)>>>3,A=-1===i?3:0,E=r.indexOf("=");if(-1===r.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(r=r.replace(/=/g,""),-1!==E&&E>> 2;\n while (packed.length <= intOffset) {\n packed.push(0);\n }\n packed[intOffset] |=\n ((tmpInt >>> (16 - j * 8)) & 0xff) << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n byteCnt += 1;\n }\n }\n\n return { value: packed, binLen: byteCnt * 8 + existingPackedLen };\n}\n\n/**\n * Convert an Uint8Array to an array of words.\n *\n * @param arr Uint8Array to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Hashmap of the packed values.\n */\nfunction uint8array2packed(\n arr: Uint8Array,\n existingPacked: number[] | undefined,\n existingPackedLen: number | undefined,\n bigEndianMod: -1 | 1\n): packedValue {\n let i, intOffset, byteOffset;\n\n existingPackedLen = existingPackedLen || 0;\n const packed = existingPacked || [0],\n existingByteLen = existingPackedLen >>> 3,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < arr.length; i += 1) {\n byteOffset = i + existingByteLen;\n intOffset = byteOffset >>> 2;\n if (packed.length <= intOffset) {\n packed.push(0);\n }\n packed[intOffset] |= arr[i] << (8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));\n }\n\n return { value: packed, binLen: arr.length * 8 + existingPackedLen };\n}\n\n/**\n * Convert an ArrayBuffer to an array of words\n *\n * @param arr ArrayBuffer to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Hashmap of the packed values.\n */\nfunction arraybuffer2packed(\n arr: ArrayBuffer,\n existingPacked: number[] | undefined,\n existingPackedLen: number | undefined,\n bigEndianMod: -1 | 1\n): packedValue {\n return uint8array2packed(new Uint8Array(arr), existingPacked, existingPackedLen, bigEndianMod);\n}\n\n/**\n * Function that takes an input format and UTF encoding and returns the appropriate function used to convert the input.\n *\n * @param format The format of the input to be converted\n * @param utfType The string encoding to use for TEXT inputs.\n * @param bigEndianMod Modifier for whether hash function is big or small endian\n * @returns Function that will convert an input to a packed int array.\n */\nexport function getStrConverter(\n format: FormatType,\n utfType: EncodingType,\n bigEndianMod: -1 | 1\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n): (input: any, existingBin?: number[], existingBinLen?: number) => packedValue {\n /* Validate encoding */\n switch (utfType) {\n case \"UTF8\":\n /* Fallthrough */\n case \"UTF16BE\":\n /* Fallthrough */\n case \"UTF16LE\":\n /* Fallthrough */\n break;\n default:\n throw new Error(\"encoding must be UTF8, UTF16BE, or UTF16LE\");\n }\n\n /* Map inputFormat to the appropriate converter */\n switch (format) {\n case \"HEX\":\n /**\n * @param str String of hexadecimal bytes to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return hex2packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"TEXT\":\n /**\n * @param str Unicode string to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return str2packed(str, utfType, existingBin, existingBinLen, bigEndianMod);\n };\n case \"B64\":\n /**\n * @param str Base64-encoded string to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return b642packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"BYTES\":\n /**\n * @param str String of raw bytes to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (str: string, existingBin?: number[], existingBinLen?: number): packedValue {\n return bytes2packed(str, existingBin, existingBinLen, bigEndianMod);\n };\n case \"ARRAYBUFFER\":\n try {\n new ArrayBuffer(0);\n } catch (ignore) {\n throw new Error(arraybuffer_error);\n }\n /**\n * @param arr ArrayBuffer to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (arr: ArrayBuffer, existingBin?: number[], existingBinLen?: number): packedValue {\n return arraybuffer2packed(arr, existingBin, existingBinLen, bigEndianMod);\n };\n case \"UINT8ARRAY\":\n try {\n new Uint8Array(0);\n } catch (ignore) {\n throw new Error(uint8array_error);\n }\n /**\n * @param arr Uint8Array to be converted to binary representation.\n * @param existingPacked A packed int array of bytes to append the results to.\n * @param existingPackedLen The number of bits in `existingPacked` array.\n * @returns Hashmap of the packed values.\n */\n return function (arr: Uint8Array, existingBin?: number[], existingBinLen?: number): packedValue {\n return uint8array2packed(arr, existingBin, existingBinLen, bigEndianMod);\n };\n default:\n throw new Error(\"format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY\");\n }\n}\n\n/**\n * Convert an array of words to a hexadecimal string.\n *\n * toString() won't work here because it removes preceding zeros (e.g. 0x00000001.toString === \"1\" rather than\n * \"00000001\" and 0.toString(16) === \"0\" rather than \"00\").\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param formatOpts Hashmap containing validated output formatting options.\n * @returns Hexadecimal representation of `packed`.\n */\nexport function packed2hex(\n packed: number[],\n outputLength: number,\n bigEndianMod: -1 | 1,\n formatOpts: { outputUpper: boolean; b64Pad: string }\n): string {\n const hex_tab = \"0123456789abcdef\";\n let str = \"\",\n i,\n srcByte;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n /* The below is more than a byte but it gets taken care of later */\n srcByte = packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)));\n str += hex_tab.charAt((srcByte >>> 4) & 0xf) + hex_tab.charAt(srcByte & 0xf);\n }\n\n return formatOpts[\"outputUpper\"] ? str.toUpperCase() : str;\n}\n\n/**\n * Convert an array of words to a base-64 string.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param formatOpts Hashmap containing validated output formatting options.\n * @returns Base64-encoded representation of `packed`.\n */\nexport function packed2b64(\n packed: number[],\n outputLength: number,\n bigEndianMod: -1 | 1,\n formatOpts: { outputUpper: boolean; b64Pad: string }\n): string {\n let str = \"\",\n i,\n j,\n triplet,\n int1,\n int2;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 3) {\n int1 = i + 1 < length ? packed[(i + 1) >>> 2] : 0;\n int2 = i + 2 < length ? packed[(i + 2) >>> 2] : 0;\n triplet =\n (((packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff) << 16) |\n (((int1 >>> (8 * (shiftModifier + bigEndianMod * ((i + 1) % 4)))) & 0xff) << 8) |\n ((int2 >>> (8 * (shiftModifier + bigEndianMod * ((i + 2) % 4)))) & 0xff);\n for (j = 0; j < 4; j += 1) {\n if (i * 8 + j * 6 <= outputLength) {\n str += b64Tab.charAt((triplet >>> (6 * (3 - j))) & 0x3f);\n } else {\n str += formatOpts[\"b64Pad\"];\n }\n }\n }\n return str;\n}\n\n/**\n * Convert an array of words to raw bytes string.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns Raw bytes representation of `packed`.\n */\nexport function packed2bytes(packed: number[], outputLength: number, bigEndianMod: -1 | 1): string {\n let str = \"\",\n i,\n srcByte;\n\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n srcByte = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n str += String.fromCharCode(srcByte);\n }\n\n return str;\n}\n\n/**\n * Convert an array of words to an ArrayBuffer.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns An ArrayBuffer containing bytes from `packed.\n */\nexport function packed2arraybuffer(packed: number[], outputLength: number, bigEndianMod: -1 | 1): ArrayBuffer {\n let i;\n const length = outputLength / 8,\n retVal = new ArrayBuffer(length),\n arrView = new Uint8Array(retVal),\n shiftModifier = bigEndianMod === -1 ? 3 : 0;\n\n for (i = 0; i < length; i += 1) {\n arrView[i] = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n }\n\n return retVal;\n}\n\n/**\n * Convert an array of words to an Uint8Array.\n *\n * @param packed Array of integers to be converted.\n * @param outputLength Length of output in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @returns An Uint8Array containing bytes from `packed.\n */\nexport function packed2uint8array(packed: number[], outputLength: number, bigEndianMod: -1 | 1): Uint8Array {\n let i;\n const length = outputLength / 8,\n shiftModifier = bigEndianMod === -1 ? 3 : 0,\n retVal = new Uint8Array(length);\n\n for (i = 0; i < length; i += 1) {\n retVal[i] = (packed[i >>> 2] >>> (8 * (shiftModifier + bigEndianMod * (i % 4)))) & 0xff;\n }\n\n return retVal;\n}\n\n/**\n * Function that takes an output format and associated parameters and returns a function that converts packed integers\n * to that format.\n *\n * @param format The desired output formatting.\n * @param outputBinLen Output length in bits.\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param outputOptions Hashmap of output formatting options\n * @returns Function that will convert a packed integer array to desired format.\n */\nexport function getOutputConverter(\n format: \"HEX\" | \"B64\" | \"BYTES\" | \"ARRAYBUFFER\" | \"UINT8ARRAY\",\n outputBinLen: number,\n bigEndianMod: -1 | 1,\n outputOptions: { outputUpper: boolean; b64Pad: string }\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n): (binarray: number[]) => any {\n switch (format) {\n case \"HEX\":\n return function (binarray): string {\n return packed2hex(binarray, outputBinLen, bigEndianMod, outputOptions);\n };\n case \"B64\":\n return function (binarray): string {\n return packed2b64(binarray, outputBinLen, bigEndianMod, outputOptions);\n };\n case \"BYTES\":\n return function (binarray): string {\n return packed2bytes(binarray, outputBinLen, bigEndianMod);\n };\n case \"ARRAYBUFFER\":\n try {\n /* Need to test ArrayBuffer support */\n new ArrayBuffer(0);\n } catch (ignore) {\n throw new Error(arraybuffer_error);\n }\n return function (binarray): ArrayBuffer {\n return packed2arraybuffer(binarray, outputBinLen, bigEndianMod);\n };\n case \"UINT8ARRAY\":\n try {\n /* Need to test Uint8Array support */\n new Uint8Array(0);\n } catch (ignore) {\n throw new Error(uint8array_error);\n }\n return function (binarray): Uint8Array {\n return packed2uint8array(binarray, outputBinLen, bigEndianMod);\n };\n default:\n throw new Error(\"format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY\");\n }\n}\n","import { getStrConverter, getOutputConverter } from \"./converters\";\n\nimport {\n FormatType,\n EncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n packedValue,\n GenericInputType,\n} from \"./custom_types\";\n\nexport const TWO_PWR_32 = 4294967296;\n\n/* Constant used in SHA-2 families */\nexport const K_sha2 = [\n 0x428a2f98,\n 0x71374491,\n 0xb5c0fbcf,\n 0xe9b5dba5,\n 0x3956c25b,\n 0x59f111f1,\n 0x923f82a4,\n 0xab1c5ed5,\n 0xd807aa98,\n 0x12835b01,\n 0x243185be,\n 0x550c7dc3,\n 0x72be5d74,\n 0x80deb1fe,\n 0x9bdc06a7,\n 0xc19bf174,\n 0xe49b69c1,\n 0xefbe4786,\n 0x0fc19dc6,\n 0x240ca1cc,\n 0x2de92c6f,\n 0x4a7484aa,\n 0x5cb0a9dc,\n 0x76f988da,\n 0x983e5152,\n 0xa831c66d,\n 0xb00327c8,\n 0xbf597fc7,\n 0xc6e00bf3,\n 0xd5a79147,\n 0x06ca6351,\n 0x14292967,\n 0x27b70a85,\n 0x2e1b2138,\n 0x4d2c6dfc,\n 0x53380d13,\n 0x650a7354,\n 0x766a0abb,\n 0x81c2c92e,\n 0x92722c85,\n 0xa2bfe8a1,\n 0xa81a664b,\n 0xc24b8b70,\n 0xc76c51a3,\n 0xd192e819,\n 0xd6990624,\n 0xf40e3585,\n 0x106aa070,\n 0x19a4c116,\n 0x1e376c08,\n 0x2748774c,\n 0x34b0bcb5,\n 0x391c0cb3,\n 0x4ed8aa4a,\n 0x5b9cca4f,\n 0x682e6ff3,\n 0x748f82ee,\n 0x78a5636f,\n 0x84c87814,\n 0x8cc70208,\n 0x90befffa,\n 0xa4506ceb,\n 0xbef9a3f7,\n 0xc67178f2,\n];\n\n/* Constant used in SHA-2 families */\nexport const H_trunc = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];\n\n/* Constant used in SHA-2 families */\nexport const H_full = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n\nexport const sha_variant_error = \"Chosen SHA variant is not supported\";\nexport const mac_rounds_error = \"Cannot set numRounds with MAC\";\n\n/**\n * Concatenates 2 packed arrays. Clobbers array `a`.\n *\n * @param a First array to concatenate.\n * @param b Second array to concatenate.\n * @returns The concatentation of `a` + `b`.\n */\nexport function packedLEConcat(a: packedValue, b: packedValue): packedValue {\n let i, arrOffset;\n const aByteLen = a[\"binLen\"] >>> 3,\n bByteLen = b[\"binLen\"] >>> 3,\n leftShiftAmount = aByteLen << 3,\n rightShiftAmount = (4 - aByteLen) << 3;\n\n /* If a only contains \"full\" integers, we can just use concat which is so much easier */\n if (aByteLen % 4 !== 0) {\n for (i = 0; i < bByteLen; i += 4) {\n arrOffset = (aByteLen + i) >>> 2;\n /* Left shift chops off bits over 32-bits */\n a[\"value\"][arrOffset] |= b[\"value\"][i >>> 2] << leftShiftAmount;\n a[\"value\"].push(0);\n a[\"value\"][arrOffset + 1] |= b[\"value\"][i >>> 2] >>> rightShiftAmount;\n }\n\n /* Since an unconditional push was performed above, we may have pushed an extra value if it could have been\n encoded without it. Check if popping an int off (reducing total length by 4 bytes) is still bigger than the\n needed size. */\n if ((a[\"value\"].length << 2) - 4 >= bByteLen + aByteLen) {\n a[\"value\"].pop();\n }\n\n return { value: a[\"value\"], binLen: a[\"binLen\"] + b[\"binLen\"] };\n } else {\n return { value: a[\"value\"].concat(b[\"value\"]), binLen: a[\"binLen\"] + b[\"binLen\"] };\n }\n}\n\n/**\n * Validate hash list containing output formatting options, ensuring presence of every option or adding the default\n * value.\n *\n * @param options Hashmap of output formatting options from user.\n * @returns Validated hashmap containing output formatting options.\n */\nexport function getOutputOpts(options?: {\n outputUpper?: boolean;\n b64Pad?: string;\n shakeLen?: number;\n outputLen?: number;\n}): { outputUpper: boolean; b64Pad: string; outputLen: number } {\n const retVal = { outputUpper: false, b64Pad: \"=\", outputLen: -1 },\n outputOptions: { outputUpper?: boolean; b64Pad?: string; shakeLen?: number; outputLen?: number } = options || {},\n lenErrstr = \"Output length must be a multiple of 8\";\n\n retVal[\"outputUpper\"] = outputOptions[\"outputUpper\"] || false;\n\n if (outputOptions[\"b64Pad\"]) {\n retVal[\"b64Pad\"] = outputOptions[\"b64Pad\"];\n }\n\n if (outputOptions[\"outputLen\"]) {\n if (outputOptions[\"outputLen\"] % 8 !== 0) {\n throw new Error(lenErrstr);\n }\n retVal[\"outputLen\"] = outputOptions[\"outputLen\"];\n } else if (outputOptions[\"shakeLen\"]) {\n if (outputOptions[\"shakeLen\"] % 8 !== 0) {\n throw new Error(lenErrstr);\n }\n retVal[\"outputLen\"] = outputOptions[\"shakeLen\"];\n }\n\n if (\"boolean\" !== typeof retVal[\"outputUpper\"]) {\n throw new Error(\"Invalid outputUpper formatting option\");\n }\n\n if (\"string\" !== typeof retVal[\"b64Pad\"]) {\n throw new Error(\"Invalid b64Pad formatting option\");\n }\n\n return retVal;\n}\n\n/**\n * Parses an external constructor object and returns a packed number, if possible.\n *\n * @param key The human-friendly key name to prefix any errors with\n * @param value The input value object to parse\n * @param bigEndianMod Modifier for whether hash function is big or small endian.\n * @param fallback Fallback value if `value` is undefined. If not present and `value` is undefined, an Error is thrown\n */\nexport function parseInputOption(\n key: string,\n value: GenericInputType | undefined,\n bigEndianMod: -1 | 1,\n fallback?: packedValue\n): packedValue {\n const errStr = key + \" must include a value and format\";\n if (!value) {\n if (!fallback) {\n throw new Error(errStr);\n }\n return fallback;\n }\n\n if (typeof value[\"value\"] === \"undefined\" || !value[\"format\"]) {\n throw new Error(errStr);\n }\n\n return getStrConverter(\n value[\"format\"],\n // eslint-disable-next-line @typescript-eslint/ban-ts-ignore\n // @ts-ignore - the value of encoding gets value checked by getStrConverter\n value[\"encoding\"] || \"UTF8\",\n bigEndianMod\n )(value[\"value\"]);\n}\n\nexport abstract class jsSHABase {\n /**\n * @param variant The desired SHA variant.\n * @param inputFormat The input format to be used in future `update` calls.\n * @param options Hashmap of extra input options.\n */\n /* Needed inputs */\n protected readonly shaVariant: VariantT;\n protected readonly inputFormat: FormatType;\n protected readonly utfType: EncodingType;\n protected readonly numRounds: number;\n\n /* State */\n protected abstract intermediateState: StateT;\n protected keyWithIPad: number[];\n protected keyWithOPad: number[];\n protected remainder: number[];\n protected remainderLen: number;\n protected updateCalled: boolean;\n protected processedLen: number;\n protected macKeySet: boolean;\n\n /* Variant specifics */\n protected abstract readonly variantBlockSize: number;\n protected abstract readonly bigEndianMod: -1 | 1;\n protected abstract readonly outputBinLen: number;\n protected abstract readonly isVariableLen: boolean;\n protected abstract readonly HMACSupported: boolean;\n\n /* Functions */\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n protected abstract readonly converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n protected abstract readonly roundFunc: (block: number[], H: StateT) => StateT;\n protected abstract readonly finalizeFunc: (\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: StateT,\n outputLen: number\n ) => number[];\n protected abstract readonly stateCloneFunc: (state: StateT) => StateT;\n protected abstract readonly newStateFunc: (variant: VariantT) => StateT;\n protected abstract readonly getMAC: ((options: { outputLen: number }) => number[]) | null;\n\n protected constructor(variant: VariantT, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n protected constructor(variant: VariantT, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected constructor(variant: any, inputFormat: any, options?: any) {\n const inputOptions = options || {};\n this.inputFormat = inputFormat;\n\n this.utfType = inputOptions[\"encoding\"] || \"UTF8\";\n this.numRounds = inputOptions[\"numRounds\"] || 1;\n\n /* eslint-disable-next-line @typescript-eslint/ban-ts-ignore */\n // @ts-ignore - The spec actually says ToString is called on the first parseInt argument so it's OK to use it here\n // to check if an arugment is an integer. This cheat would break if it's used to get the value of the argument.\n if (isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) {\n throw new Error(\"numRounds must a integer >= 1\");\n }\n\n this.shaVariant = variant;\n this.remainder = [];\n this.remainderLen = 0;\n this.updateCalled = false;\n this.processedLen = 0;\n this.macKeySet = false;\n this.keyWithIPad = [];\n this.keyWithOPad = [];\n }\n\n /**\n * Hashes as many blocks as possible. Stores the rest for either a future update or getHash call.\n *\n * @param srcString The input to be hashed.\n */\n update(srcString: string | ArrayBuffer | Uint8Array): void {\n let i,\n updateProcessedLen = 0;\n const variantBlockIntInc = this.variantBlockSize >>> 5,\n convertRet = this.converterFunc(srcString, this.remainder, this.remainderLen),\n chunkBinLen = convertRet[\"binLen\"],\n chunk = convertRet[\"value\"],\n chunkIntLen = chunkBinLen >>> 5;\n\n for (i = 0; i < chunkIntLen; i += variantBlockIntInc) {\n if (updateProcessedLen + this.variantBlockSize <= chunkBinLen) {\n this.intermediateState = this.roundFunc(chunk.slice(i, i + variantBlockIntInc), this.intermediateState);\n updateProcessedLen += this.variantBlockSize;\n }\n }\n this.processedLen += updateProcessedLen;\n this.remainder = chunk.slice(updateProcessedLen >>> 5);\n this.remainderLen = chunkBinLen % this.variantBlockSize;\n this.updateCalled = true;\n }\n\n /**\n * Returns the desired SHA hash of the input fed in via `update` calls.\n *\n * @param format The desired output formatting\n * @param options Hashmap of output formatting options. `outputLen` must be specified for variable length hashes.\n * `outputLen` replaces the now deprecated `shakeLen` key.\n * @returns The hash in the format specified.\n */\n getHash(format: \"HEX\", options?: { outputUpper?: boolean; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"B64\", options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"BYTES\", options?: { outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"UINT8ARRAY\", options?: { outputLen?: number; shakeLen?: number }): Uint8Array;\n getHash(format: \"ARRAYBUFFER\", options?: { outputLen?: number; shakeLen?: number }): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHash(format: any, options?: any): any {\n let i,\n finalizedState,\n outputBinLen = this.outputBinLen;\n\n const outputOptions = getOutputOpts(options);\n\n if (this.isVariableLen) {\n if (outputOptions[\"outputLen\"] === -1) {\n throw new Error(\"Output length must be specified in options\");\n }\n outputBinLen = outputOptions[\"outputLen\"];\n }\n\n const formatFunc = getOutputConverter(format, outputBinLen, this.bigEndianMod, outputOptions);\n if (this.macKeySet && this.getMAC) {\n return formatFunc(this.getMAC(outputOptions));\n }\n\n finalizedState = this.finalizeFunc(\n this.remainder.slice(),\n this.remainderLen,\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n outputBinLen\n );\n for (i = 1; i < this.numRounds; i += 1) {\n /* Need to mask out bits that should be zero due to output not being a multiple of 32 */\n if (this.isVariableLen && outputBinLen % 32 !== 0) {\n finalizedState[finalizedState.length - 1] &= 0x00ffffff >>> (24 - (outputBinLen % 32));\n }\n finalizedState = this.finalizeFunc(\n finalizedState,\n outputBinLen,\n 0,\n this.newStateFunc(this.shaVariant),\n outputBinLen\n );\n }\n\n return formatFunc(finalizedState);\n }\n\n /**\n * Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.\n *\n * @param key The key used to calculate the HMAC\n * @param inputFormat The format of key.\n * @param options Hashmap of extra input options.\n */\n setHMACKey(key: string, inputFormat: \"TEXT\", options?: { encoding?: EncodingType }): void;\n setHMACKey(key: string, inputFormat: \"B64\" | \"HEX\" | \"BYTES\"): void;\n setHMACKey(key: ArrayBuffer, inputFormat: \"ARRAYBUFFER\"): void;\n setHMACKey(key: Uint8Array, inputFormat: \"UINT8ARRAY\"): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setHMACKey(key: any, inputFormat: any, options?: any): void {\n if (!this.HMACSupported) {\n throw new Error(\"Variant does not support HMAC\");\n }\n\n if (this.updateCalled) {\n throw new Error(\"Cannot set MAC key after calling update\");\n }\n\n const keyOptions = options || {},\n keyConverterFunc = getStrConverter(inputFormat, keyOptions[\"encoding\"] || \"UTF8\", this.bigEndianMod);\n\n this._setHMACKey(keyConverterFunc(key));\n }\n\n /**\n * Internal function that sets the MAC key.\n *\n * @param key The packed MAC key to use\n */\n protected _setHMACKey(key: packedValue): void {\n const blockByteSize = this.variantBlockSize >>> 3,\n lastArrayIndex = blockByteSize / 4 - 1;\n let i;\n if (this.numRounds !== 1) {\n throw new Error(mac_rounds_error);\n }\n\n if (this.macKeySet) {\n throw new Error(\"MAC key already set\");\n }\n\n /* Figure out what to do with the key based on its size relative to\n * the hash's block size */\n if (blockByteSize < key[\"binLen\"] / 8) {\n key[\"value\"] = this.finalizeFunc(\n key[\"value\"],\n key[\"binLen\"],\n 0,\n this.newStateFunc(this.shaVariant),\n this.outputBinLen\n );\n }\n while (key[\"value\"].length <= lastArrayIndex) {\n key[\"value\"].push(0);\n }\n /* Create ipad and opad */\n for (i = 0; i <= lastArrayIndex; i += 1) {\n this.keyWithIPad[i] = key[\"value\"][i] ^ 0x36363636;\n this.keyWithOPad[i] = key[\"value\"][i] ^ 0x5c5c5c5c;\n }\n\n this.intermediateState = this.roundFunc(this.keyWithIPad, this.intermediateState);\n this.processedLen = this.variantBlockSize;\n\n this.macKeySet = true;\n }\n\n /**\n * Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call.\n *\n * @param format The desired output formatting.\n * @param options Hashmap of extra outputs options.\n * @returns The HMAC in the format specified.\n */\n getHMAC(format: \"HEX\", options?: { outputUpper?: boolean }): string;\n getHMAC(format: \"B64\", options?: { b64Pad?: string }): string;\n getHMAC(format: \"BYTES\"): string;\n getHMAC(format: \"UINT8ARRAY\"): Uint8Array;\n getHMAC(format: \"ARRAYBUFFER\"): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHMAC(format: any, options?: any): any {\n const outputOptions = getOutputOpts(options),\n formatFunc = getOutputConverter(format, this.outputBinLen, this.bigEndianMod, outputOptions);\n\n return formatFunc(this._getHMAC());\n }\n\n /**\n * Internal function that returns the \"raw\" HMAC\n */\n protected _getHMAC(): number[] {\n let finalizedState;\n\n if (!this.macKeySet) {\n throw new Error(\"Cannot call getHMAC without first setting MAC key\");\n }\n\n const firstHash = this.finalizeFunc(\n this.remainder.slice(),\n this.remainderLen,\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n this.outputBinLen\n );\n finalizedState = this.roundFunc(this.keyWithOPad, this.newStateFunc(this.shaVariant));\n finalizedState = this.finalizeFunc(\n firstHash,\n this.outputBinLen,\n this.variantBlockSize,\n finalizedState,\n this.outputBinLen\n );\n\n return finalizedState;\n }\n}\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","/*\n * Note 1: All the functions in this file guarantee only that the bottom 32-bits of the return value are correct.\n * JavaScript is flakey when it comes to bit operations and a '1' in the highest order bit of a 32-bit number causes\n * it to be interpreted as a negative number per two's complement.\n *\n * Note 2: Per the ECMAScript spec, all JavaScript operations mask the shift amount by 0x1F. This results in weird\n * cases like 1 << 32 == 1 and 1 << 33 === 1 << 1 === 2\n */\n\n/**\n * The 32-bit implementation of circular rotate left.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted left circularly by `n` bits\n */\nexport function rotl_32(x: number, n: number): number {\n return (x << n) | (x >>> (32 - n));\n}\n\n/**\n * The 32-bit implementation of circular rotate right.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right circularly by `n` bits\n */\nfunction rotr_32(x: number, n: number): number {\n return (x >>> n) | (x << (32 - n));\n}\n\n/**\n * The 32-bit implementation of shift right.\n *\n * @param x The 32-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted by `n` bits.\n */\nfunction shr_32(x: number, n: number): number {\n return x >>> n;\n}\n\n/**\n * The 32-bit implementation of the NIST specified Parity function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function parity_32(x: number, y: number, z: number): number {\n return x ^ y ^ z;\n}\n\n/**\n * The 32-bit implementation of the NIST specified Ch function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function ch_32(x: number, y: number, z: number): number {\n return (x & y) ^ (~x & z);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Maj function.\n *\n * @param x The first 32-bit integer argument.\n * @param y The second 32-bit integer argument.\n * @param z The third 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function maj_32(x: number, y: number, z: number): number {\n return (x & y) ^ (x & z) ^ (y & z);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Sigma0 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma0_32(x: number): number {\n return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);\n}\n\n/**\n * Add two 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @returns The sum of `a` + `b`.\n */\nexport function safeAdd_32_2(a: number, b: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * Add four 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @param c The third 32-bit integer argument to be added.\n * @param d The fourth 32-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d`.\n */\nexport function safeAdd_32_4(a: number, b: number, c: number, d: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff) + (c & 0xffff) + (d & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * Add five 32-bit integers.\n *\n * This uses 16-bit operations internally to work around sign problems due to JavaScript's lack of uint32 support.\n *\n * @param a The first 32-bit integer argument to be added.\n * @param b The second 32-bit integer argument to be added.\n * @param c The third 32-bit integer argument to be added.\n * @param d The fourth 32-bit integer argument to be added.\n * @param e The fifth 32-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d` + `e`.\n */\nexport function safeAdd_32_5(a: number, b: number, c: number, d: number, e: number): number {\n const lsw = (a & 0xffff) + (b & 0xffff) + (c & 0xffff) + (d & 0xffff) + (e & 0xffff),\n msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (e >>> 16) + (lsw >>> 16);\n\n return ((msw & 0xffff) << 16) | (lsw & 0xffff);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Gamma1 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma1_32(x: number): number {\n return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Gamma0 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma0_32(x: number): number {\n return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);\n}\n\n/**\n * The 32-bit implementation of the NIST specified Sigma1 function.\n *\n * @param x The 32-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma1_32(x: number): number {\n return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);\n}\n","import { jsSHABase, TWO_PWR_32, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport { ch_32, parity_32, maj_32, rotl_32, safeAdd_32_2, safeAdd_32_5 } from \"./primitives_32\";\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param _variant: Unused\n * @returns The initial state values.\n */\nfunction getNewState(_variant: \"SHA-1\"): number[] {\n return [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];\n}\n\n/**\n * Performs a round of SHA-1 hashing over a 512-byte block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA1(block: number[], H: number[]): number[] {\n let a, b, c, d, e, T, t;\n const W: number[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n\n for (t = 0; t < 80; t += 1) {\n if (t < 16) {\n W[t] = block[t];\n } else {\n W[t] = rotl_32(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);\n }\n\n if (t < 20) {\n T = safeAdd_32_5(rotl_32(a, 5), ch_32(b, c, d), e, 0x5a827999, W[t]);\n } else if (t < 40) {\n T = safeAdd_32_5(rotl_32(a, 5), parity_32(b, c, d), e, 0x6ed9eba1, W[t]);\n } else if (t < 60) {\n T = safeAdd_32_5(rotl_32(a, 5), maj_32(b, c, d), e, 0x8f1bbcdc, W[t]);\n } else {\n T = safeAdd_32_5(rotl_32(a, 5), parity_32(b, c, d), e, 0xca62c1d6, W[t]);\n }\n\n e = d;\n d = c;\n c = rotl_32(b, 30);\n b = a;\n a = T;\n }\n\n H[0] = safeAdd_32_2(a, H[0]);\n H[1] = safeAdd_32_2(b, H[1]);\n H[2] = safeAdd_32_2(c, H[2]);\n H[3] = safeAdd_32_2(d, H[3]);\n H[4] = safeAdd_32_2(e, H[4]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-1 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @returns The array of integers representing the SHA-1 hash of message.\n */\nfunction finalizeSHA1(remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]): number[] {\n let i;\n\n /* The 65 addition is a hack but it works. The correct number is\n\t\tactually 72 (64 + 8) but the below math fails if\n\t\tremainderBinLen + 72 % 512 = 0. Since remainderBinLen % 8 = 0,\n\t\t\"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 65) >>> 9) << 4) + 15,\n totalLen = remainderBinLen + processedBinLen;\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n\n /* Append length of binary string in the position such that the new\n * length is a multiple of 512. Logic does not work for even multiples\n * of 512 but there can never be even multiples of 512. JavaScript\n * numbers are limited to 2^53 so it's \"safe\" to treat the totalLen as\n * a 64-bit integer. */\n remainder[offset] = totalLen & 0xffffffff;\n\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += 16) {\n H = roundSHA1(remainder.slice(i, i + 16), H);\n }\n\n return H;\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: number[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: number[]) => number[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];\n stateCloneFunc: (state: number[]) => number[];\n newStateFunc: (variant: \"SHA-1\") => number[];\n getMAC: () => number[];\n\n constructor(variant: \"SHA-1\", inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: \"SHA-1\", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (\"SHA-1\" !== variant) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA1;\n this.stateCloneFunc = function (state: number[]): number[] {\n return state.slice();\n };\n this.newStateFunc = getNewState;\n this.finalizeFunc = finalizeSHA1;\n\n this.intermediateState = getNewState(variant);\n this.variantBlockSize = 512;\n this.outputBinLen = 160;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","import { jsSHABase, TWO_PWR_32, H_full, H_trunc, K_sha2, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport {\n ch_32,\n gamma0_32,\n gamma1_32,\n maj_32,\n safeAdd_32_2,\n safeAdd_32_4,\n safeAdd_32_5,\n sigma0_32,\n sigma1_32,\n} from \"./primitives_32\";\n\ntype VariantType = \"SHA-224\" | \"SHA-256\";\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param variant: The SHA-256 family variant.\n * @returns The initial state values.\n */\nfunction getNewState256(variant: VariantType): number[] {\n let retVal;\n\n if (\"SHA-224\" == variant) {\n retVal = H_trunc.slice();\n } else {\n /* \"SHA-256\" */\n retVal = H_full.slice();\n }\n return retVal;\n}\n\n/**\n * Performs a round of SHA-256 hashing over a block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA256(block: number[], H: number[]): number[] {\n let a, b, c, d, e, f, g, h, T1, T2, t;\n\n const W: number[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n f = H[5];\n g = H[6];\n h = H[7];\n\n for (t = 0; t < 64; t += 1) {\n if (t < 16) {\n W[t] = block[t];\n } else {\n W[t] = safeAdd_32_4(gamma1_32(W[t - 2]), W[t - 7], gamma0_32(W[t - 15]), W[t - 16]);\n }\n T1 = safeAdd_32_5(h, sigma1_32(e), ch_32(e, f, g), K_sha2[t], W[t]);\n T2 = safeAdd_32_2(sigma0_32(a), maj_32(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safeAdd_32_2(d, T1);\n d = c;\n c = b;\n b = a;\n a = safeAdd_32_2(T1, T2);\n }\n\n H[0] = safeAdd_32_2(a, H[0]);\n H[1] = safeAdd_32_2(b, H[1]);\n H[2] = safeAdd_32_2(c, H[2]);\n H[3] = safeAdd_32_2(d, H[3]);\n H[4] = safeAdd_32_2(e, H[4]);\n H[5] = safeAdd_32_2(f, H[5]);\n H[6] = safeAdd_32_2(g, H[6]);\n H[7] = safeAdd_32_2(h, H[7]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-256 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @param variant The desired SHA-256 variant.\n * @returns The array of integers representing the SHA-2 hash of message.\n */\nfunction finalizeSHA256(\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: number[],\n variant: VariantType\n): number[] {\n let i, retVal;\n\n /* The 65 addition is a hack but it works. The correct number is\n actually 72 (64 + 8) but the below math fails if\n remainderBinLen + 72 % 512 = 0. Since remainderBinLen % 8 = 0,\n \"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 65) >>> 9) << 4) + 15,\n binaryStringInc = 16,\n totalLen = remainderBinLen + processedBinLen;\n\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n /* Append length of binary string in the position such that the new\n * length is correct. JavaScript numbers are limited to 2^53 so it's\n * \"safe\" to treat the totalLen as a 64-bit integer. */\n\n remainder[offset] = totalLen & 0xffffffff;\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += binaryStringInc) {\n H = roundSHA256(remainder.slice(i, i + binaryStringInc), H);\n }\n\n if (\"SHA-224\" === variant) {\n retVal = [H[0], H[1], H[2], H[3], H[4], H[5], H[6]];\n } else {\n /* \"SHA-256 */\n retVal = H;\n }\n\n return retVal;\n}\nexport default class jsSHA extends jsSHABase {\n intermediateState: number[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: number[]) => number[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: number[]) => number[];\n stateCloneFunc: (state: number[]) => number[];\n newStateFunc: (variant: VariantType) => number[];\n getMAC: () => number[];\n\n constructor(variant: VariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (!(\"SHA-224\" === variant || \"SHA-256\" === variant)) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.HMACSupported = true;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA256;\n this.stateCloneFunc = function (state): number[] {\n return state.slice();\n };\n\n this.newStateFunc = getNewState256;\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, H): number[] {\n return finalizeSHA256(remainder, remainderBinLen, processedBinLen, H, variant);\n };\n\n this.intermediateState = getNewState256(variant);\n this.variantBlockSize = 512;\n this.outputBinLen = \"SHA-224\" === variant ? 224 : 256;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","/*\n * Note 1: All the functions in this file guarantee only that the bottom 32-bits of the returned Int_64 are correct.\n * JavaScript is flakey when it comes to bit operations and a '1' in the highest order bit of a 32-bit number causes\n * it to be interpreted as a negative number per two's complement.\n *\n * Note 2: Per the ECMAScript spec, all JavaScript operations mask the shift amount by 0x1F. This results in weird\n * cases like 1 << 32 == 1 and 1 << 33 === 1 << 1 === 2\n */\n\n/**\n * Int_64 is a object for 2 32-bit numbers emulating a 64-bit number.\n */\nexport class Int_64 {\n /**\n * @param msint_32 The most significant 32-bits of a 64-bit number.\n * @param lsint_32 The least significant 32-bits of a 64-bit number.\n */\n readonly highOrder: number;\n readonly lowOrder: number;\n constructor(msint_32: number, lsint_32: number) {\n this.highOrder = msint_32;\n this.lowOrder = lsint_32;\n }\n}\n\n/**\n * The 64-bit implementation of circular rotate left.\n *\n * This does not work for n >= 64 or n == 32 but those are never done.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted left circularly by `n` bits.\n */\nexport function rotl_64(x: Int_64, n: number): Int_64 {\n let tmp;\n if (n > 32) {\n tmp = 64 - n;\n return new Int_64((x.lowOrder << n) | (x.highOrder >>> tmp), (x.highOrder << n) | (x.lowOrder >>> tmp));\n } else if (0 !== n) {\n tmp = 32 - n;\n return new Int_64((x.highOrder << n) | (x.lowOrder >>> tmp), (x.lowOrder << n) | (x.highOrder >>> tmp));\n } else {\n return x;\n }\n}\n\n/**\n * The 64-bit implementation of circular rotate right.\n *\n * This does not work for n >= 64, n == 32, or n == 0 but those are never done.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right circularly by `n` bits.\n */\nfunction rotr_64(x: Int_64, n: number): Int_64 {\n let tmp;\n if (n < 32) {\n tmp = 32 - n;\n return new Int_64((x.highOrder >>> n) | (x.lowOrder << tmp), (x.lowOrder >>> n) | (x.highOrder << tmp));\n } else {\n tmp = 64 - n;\n return new Int_64((x.lowOrder >>> n) | (x.highOrder << tmp), (x.highOrder >>> n) | (x.lowOrder << tmp));\n }\n}\n\n/**\n * The 64-bit implementation of shift right.\n *\n * This does not work for n >= 32 but is only called for n < 32.\n *\n * @param x The 64-bit integer argument.\n * @param n The number of bits to shift.\n * @returns `x` shifted right by `n` bits\n */\nfunction shr_64(x: Int_64, n: number): Int_64 {\n return new Int_64(x.highOrder >>> n, (x.lowOrder >>> n) | (x.highOrder << (32 - n)));\n}\n\n/**\n * The 64-bit implementation of the NIST specified Ch function.\n *\n * @param x The first 64-bit integer argument.\n * @param y The second 64-bit integer argument.\n * @param z The third 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function ch_64(x: Int_64, y: Int_64, z: Int_64): Int_64 {\n return new Int_64(\n (x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),\n (x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Maj function.\n *\n * @param x The first 64-bit integer argument.\n * @param y The second 64-bit integer argument.\n * @param z The third 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function maj_64(x: Int_64, y: Int_64, z: Int_64): Int_64 {\n return new Int_64(\n (x.highOrder & y.highOrder) ^ (x.highOrder & z.highOrder) ^ (y.highOrder & z.highOrder),\n (x.lowOrder & y.lowOrder) ^ (x.lowOrder & z.lowOrder) ^ (y.lowOrder & z.lowOrder)\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Sigma0 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma0_64(x: Int_64): Int_64 {\n const rotr28 = rotr_64(x, 28),\n rotr34 = rotr_64(x, 34),\n rotr39 = rotr_64(x, 39);\n\n return new Int_64(\n rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,\n rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder\n );\n}\n\n/**\n * Add two 64-bit integers.\n *\n * @param x The first 64-bit integer argument to be added.\n * @param y The second 64-bit integer argument to be added.\n * @returns The sum of `x` + `y`.\n */\nexport function safeAdd_64_2(x: Int_64, y: Int_64): Int_64 {\n let lsw, msw;\n\n lsw = (x.lowOrder & 0xffff) + (y.lowOrder & 0xffff);\n msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw = (x.highOrder & 0xffff) + (y.highOrder & 0xffff) + (msw >>> 16);\n msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * Add four 64-bit integers.\n *\n * @param a The first 64-bit integer argument to be added.\n * @param b The second 64-bit integer argument to be added.\n * @param c The third 64-bit integer argument to be added.\n * @param d The fouth 64-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d`.\n */\nexport function safeAdd_64_4(a: Int_64, b: Int_64, c: Int_64, d: Int_64): Int_64 {\n let lsw, msw;\n\n lsw = (a.lowOrder & 0xffff) + (b.lowOrder & 0xffff) + (c.lowOrder & 0xffff) + (d.lowOrder & 0xffff);\n msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw =\n (a.highOrder & 0xffff) + (b.highOrder & 0xffff) + (c.highOrder & 0xffff) + (d.highOrder & 0xffff) + (msw >>> 16);\n msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * Add five 64-bit integers.\n *\n * @param a The first 64-bit integer argument to be added.\n * @param b The second 64-bit integer argument to be added.\n * @param c The third 64-bit integer argument to be added.\n * @param d The fouth 64-bit integer argument to be added.\n * @param e The fifth 64-bit integer argument to be added.\n * @returns The sum of `a` + `b` + `c` + `d` + `e`.\n */\nexport function safeAdd_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64 {\n let lsw, msw;\n\n lsw =\n (a.lowOrder & 0xffff) +\n (b.lowOrder & 0xffff) +\n (c.lowOrder & 0xffff) +\n (d.lowOrder & 0xffff) +\n (e.lowOrder & 0xffff);\n msw =\n (a.lowOrder >>> 16) +\n (b.lowOrder >>> 16) +\n (c.lowOrder >>> 16) +\n (d.lowOrder >>> 16) +\n (e.lowOrder >>> 16) +\n (lsw >>> 16);\n const lowOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n lsw =\n (a.highOrder & 0xffff) +\n (b.highOrder & 0xffff) +\n (c.highOrder & 0xffff) +\n (d.highOrder & 0xffff) +\n (e.highOrder & 0xffff) +\n (msw >>> 16);\n msw =\n (a.highOrder >>> 16) +\n (b.highOrder >>> 16) +\n (c.highOrder >>> 16) +\n (d.highOrder >>> 16) +\n (e.highOrder >>> 16) +\n (lsw >>> 16);\n const highOrder = ((msw & 0xffff) << 16) | (lsw & 0xffff);\n\n return new Int_64(highOrder, lowOrder);\n}\n\n/**\n * XORs two given arguments.\n *\n * @param a The first argument to be XORed.\n * @param b The second argument to be XORed.\n * @returns The The XOR `a` and `b`\n */\nexport function xor_64_2(a: Int_64, b: Int_64): Int_64 {\n return new Int_64(a.highOrder ^ b.highOrder, a.lowOrder ^ b.lowOrder);\n}\n\n/**\n * XORs five given arguments.\n *\n * @param a The first argument to be XORed.\n * @param b The second argument to be XORed.\n * @param c The third argument to be XORed.\n * @param d The fourth argument to be XORed.\n * @param e The fifth argument to be XORed.\n * @returns The XOR of `a`, `b`, `c`, `d`, and `e`.\n */\nexport function xor_64_5(a: Int_64, b: Int_64, c: Int_64, d: Int_64, e: Int_64): Int_64 {\n return new Int_64(\n a.highOrder ^ b.highOrder ^ c.highOrder ^ d.highOrder ^ e.highOrder,\n a.lowOrder ^ b.lowOrder ^ c.lowOrder ^ d.lowOrder ^ e.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Gamma1 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma1_64(x: Int_64): Int_64 {\n const rotr19 = rotr_64(x, 19),\n rotr61 = rotr_64(x, 61),\n shr6 = shr_64(x, 6);\n\n return new Int_64(\n rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,\n rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Gamma0 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function gamma0_64(x: Int_64): Int_64 {\n const rotr1 = rotr_64(x, 1),\n rotr8 = rotr_64(x, 8),\n shr7 = shr_64(x, 7);\n\n return new Int_64(\n rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,\n rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder\n );\n}\n\n/**\n * The 64-bit implementation of the NIST specified Sigma1 function.\n *\n * @param x The 64-bit integer argument.\n * @returns The NIST specified output of the function.\n */\nexport function sigma1_64(x: Int_64): Int_64 {\n const rotr14 = rotr_64(x, 14),\n rotr18 = rotr_64(x, 18),\n rotr41 = rotr_64(x, 41);\n\n return new Int_64(\n rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,\n rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder\n );\n}\n","import { jsSHABase, TWO_PWR_32, H_trunc, H_full, K_sha2, sha_variant_error, parseInputOption } from \"./common\";\nimport {\n packedValue,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport {\n ch_64,\n gamma0_64,\n gamma1_64,\n Int_64,\n maj_64,\n safeAdd_64_2,\n safeAdd_64_4,\n safeAdd_64_5,\n sigma0_64,\n sigma1_64,\n} from \"./primitives_64\";\n\ntype VariantType = \"SHA-384\" | \"SHA-512\";\n\nconst K_sha512 = [\n new Int_64(K_sha2[0], 0xd728ae22),\n new Int_64(K_sha2[1], 0x23ef65cd),\n new Int_64(K_sha2[2], 0xec4d3b2f),\n new Int_64(K_sha2[3], 0x8189dbbc),\n new Int_64(K_sha2[4], 0xf348b538),\n new Int_64(K_sha2[5], 0xb605d019),\n new Int_64(K_sha2[6], 0xaf194f9b),\n new Int_64(K_sha2[7], 0xda6d8118),\n new Int_64(K_sha2[8], 0xa3030242),\n new Int_64(K_sha2[9], 0x45706fbe),\n new Int_64(K_sha2[10], 0x4ee4b28c),\n new Int_64(K_sha2[11], 0xd5ffb4e2),\n new Int_64(K_sha2[12], 0xf27b896f),\n new Int_64(K_sha2[13], 0x3b1696b1),\n new Int_64(K_sha2[14], 0x25c71235),\n new Int_64(K_sha2[15], 0xcf692694),\n new Int_64(K_sha2[16], 0x9ef14ad2),\n new Int_64(K_sha2[17], 0x384f25e3),\n new Int_64(K_sha2[18], 0x8b8cd5b5),\n new Int_64(K_sha2[19], 0x77ac9c65),\n new Int_64(K_sha2[20], 0x592b0275),\n new Int_64(K_sha2[21], 0x6ea6e483),\n new Int_64(K_sha2[22], 0xbd41fbd4),\n new Int_64(K_sha2[23], 0x831153b5),\n new Int_64(K_sha2[24], 0xee66dfab),\n new Int_64(K_sha2[25], 0x2db43210),\n new Int_64(K_sha2[26], 0x98fb213f),\n new Int_64(K_sha2[27], 0xbeef0ee4),\n new Int_64(K_sha2[28], 0x3da88fc2),\n new Int_64(K_sha2[29], 0x930aa725),\n new Int_64(K_sha2[30], 0xe003826f),\n new Int_64(K_sha2[31], 0x0a0e6e70),\n new Int_64(K_sha2[32], 0x46d22ffc),\n new Int_64(K_sha2[33], 0x5c26c926),\n new Int_64(K_sha2[34], 0x5ac42aed),\n new Int_64(K_sha2[35], 0x9d95b3df),\n new Int_64(K_sha2[36], 0x8baf63de),\n new Int_64(K_sha2[37], 0x3c77b2a8),\n new Int_64(K_sha2[38], 0x47edaee6),\n new Int_64(K_sha2[39], 0x1482353b),\n new Int_64(K_sha2[40], 0x4cf10364),\n new Int_64(K_sha2[41], 0xbc423001),\n new Int_64(K_sha2[42], 0xd0f89791),\n new Int_64(K_sha2[43], 0x0654be30),\n new Int_64(K_sha2[44], 0xd6ef5218),\n new Int_64(K_sha2[45], 0x5565a910),\n new Int_64(K_sha2[46], 0x5771202a),\n new Int_64(K_sha2[47], 0x32bbd1b8),\n new Int_64(K_sha2[48], 0xb8d2d0c8),\n new Int_64(K_sha2[49], 0x5141ab53),\n new Int_64(K_sha2[50], 0xdf8eeb99),\n new Int_64(K_sha2[51], 0xe19b48a8),\n new Int_64(K_sha2[52], 0xc5c95a63),\n new Int_64(K_sha2[53], 0xe3418acb),\n new Int_64(K_sha2[54], 0x7763e373),\n new Int_64(K_sha2[55], 0xd6b2b8a3),\n new Int_64(K_sha2[56], 0x5defb2fc),\n new Int_64(K_sha2[57], 0x43172f60),\n new Int_64(K_sha2[58], 0xa1f0ab72),\n new Int_64(K_sha2[59], 0x1a6439ec),\n new Int_64(K_sha2[60], 0x23631e28),\n new Int_64(K_sha2[61], 0xde82bde9),\n new Int_64(K_sha2[62], 0xb2c67915),\n new Int_64(K_sha2[63], 0xe372532b),\n new Int_64(0xca273ece, 0xea26619c),\n new Int_64(0xd186b8c7, 0x21c0c207),\n new Int_64(0xeada7dd6, 0xcde0eb1e),\n new Int_64(0xf57d4f7f, 0xee6ed178),\n new Int_64(0x06f067aa, 0x72176fba),\n new Int_64(0x0a637dc5, 0xa2c898a6),\n new Int_64(0x113f9804, 0xbef90dae),\n new Int_64(0x1b710b35, 0x131c471b),\n new Int_64(0x28db77f5, 0x23047d84),\n new Int_64(0x32caab7b, 0x40c72493),\n new Int_64(0x3c9ebe0a, 0x15c9bebc),\n new Int_64(0x431d67c4, 0x9c100d4c),\n new Int_64(0x4cc5d4be, 0xcb3e42b6),\n new Int_64(0x597f299c, 0xfc657e2a),\n new Int_64(0x5fcb6fab, 0x3ad6faec),\n new Int_64(0x6c44198c, 0x4a475817),\n];\n\n/**\n * Gets the state values for the specified SHA variant.\n *\n * @param variant: The SHA-512 family variant.\n * @returns The initial state values.\n */\nfunction getNewState512(variant: VariantType): Int_64[] {\n if (\"SHA-384\" === variant) {\n return [\n new Int_64(0xcbbb9d5d, H_trunc[0]),\n new Int_64(0x0629a292a, H_trunc[1]),\n new Int_64(0x9159015a, H_trunc[2]),\n new Int_64(0x0152fecd8, H_trunc[3]),\n new Int_64(0x67332667, H_trunc[4]),\n new Int_64(0x98eb44a87, H_trunc[5]),\n new Int_64(0xdb0c2e0d, H_trunc[6]),\n new Int_64(0x047b5481d, H_trunc[7]),\n ];\n } else {\n /* SHA-512 */\n return [\n new Int_64(H_full[0], 0xf3bcc908),\n new Int_64(H_full[1], 0x84caa73b),\n new Int_64(H_full[2], 0xfe94f82b),\n new Int_64(H_full[3], 0x5f1d36f1),\n new Int_64(H_full[4], 0xade682d1),\n new Int_64(H_full[5], 0x2b3e6c1f),\n new Int_64(H_full[6], 0xfb41bd6b),\n new Int_64(H_full[7], 0x137e2179),\n ];\n }\n}\n\n/**\n * Performs a round of SHA-512 hashing over a block. This clobbers `H`.\n *\n * @param block The binary array representation of the block to hash.\n * @param H The intermediate H values from a previous round.\n * @returns The resulting H values.\n */\nfunction roundSHA512(block: number[], H: Int_64[]): Int_64[] {\n let a, b, c, d, e, f, g, h, T1, T2, t, offset;\n\n const W: Int_64[] = [];\n\n a = H[0];\n b = H[1];\n c = H[2];\n d = H[3];\n e = H[4];\n f = H[5];\n g = H[6];\n h = H[7];\n\n for (t = 0; t < 80; t += 1) {\n if (t < 16) {\n offset = t * 2;\n W[t] = new Int_64(block[offset], block[offset + 1]);\n } else {\n W[t] = safeAdd_64_4(gamma1_64(W[t - 2]), W[t - 7], gamma0_64(W[t - 15]), W[t - 16]);\n }\n T1 = safeAdd_64_5(h, sigma1_64(e), ch_64(e, f, g), K_sha512[t], W[t]);\n T2 = safeAdd_64_2(sigma0_64(a), maj_64(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safeAdd_64_2(d, T1);\n d = c;\n c = b;\n b = a;\n a = safeAdd_64_2(T1, T2);\n }\n\n H[0] = safeAdd_64_2(a, H[0]);\n H[1] = safeAdd_64_2(b, H[1]);\n H[2] = safeAdd_64_2(c, H[2]);\n H[3] = safeAdd_64_2(d, H[3]);\n H[4] = safeAdd_64_2(e, H[4]);\n H[5] = safeAdd_64_2(f, H[5]);\n H[6] = safeAdd_64_2(g, H[6]);\n H[7] = safeAdd_64_2(h, H[7]);\n\n return H;\n}\n\n/**\n * Finalizes the SHA-512 hash. This clobbers `remainder` and `H`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param processedBinLen The number of bits already processed.\n * @param H The intermediate H values from a previous round.\n * @param variant The desired SHA-512 variant.\n * @returns The array of integers representing the SHA-512 hash of message.\n */\nfunction finalizeSHA512(\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: Int_64[],\n variant: VariantType\n): number[] {\n let i, retVal;\n\n /* The 129 addition is a hack but it works. The correct number is\n actually 136 (128 + 8) but the below math fails if\n remainderBinLen + 136 % 1024 = 0. Since remainderBinLen % 8 = 0,\n \"shorting\" the addition is OK. */\n const offset = (((remainderBinLen + 129) >>> 10) << 5) + 31,\n binaryStringInc = 32,\n totalLen = remainderBinLen + processedBinLen;\n\n while (remainder.length <= offset) {\n remainder.push(0);\n }\n /* Append '1' at the end of the binary string */\n remainder[remainderBinLen >>> 5] |= 0x80 << (24 - (remainderBinLen % 32));\n /* Append length of binary string in the position such that the new\n * length is correct. JavaScript numbers are limited to 2^53 so it's\n * \"safe\" to treat the totalLen as a 64-bit integer. */\n\n remainder[offset] = totalLen & 0xffffffff;\n /* Bitwise operators treat the operand as a 32-bit number so need to\n * use hacky division and round to get access to upper 32-ish bits */\n remainder[offset - 1] = (totalLen / TWO_PWR_32) | 0;\n\n /* This will always be at least 1 full chunk */\n for (i = 0; i < remainder.length; i += binaryStringInc) {\n H = roundSHA512(remainder.slice(i, i + binaryStringInc), H);\n }\n\n if (\"SHA-384\" === variant) {\n H = (H as unknown) as Int_64[];\n retVal = [\n H[0].highOrder,\n H[0].lowOrder,\n H[1].highOrder,\n H[1].lowOrder,\n H[2].highOrder,\n H[2].lowOrder,\n H[3].highOrder,\n H[3].lowOrder,\n H[4].highOrder,\n H[4].lowOrder,\n H[5].highOrder,\n H[5].lowOrder,\n ];\n } else {\n /* SHA-512 */\n retVal = [\n H[0].highOrder,\n H[0].lowOrder,\n H[1].highOrder,\n H[1].lowOrder,\n H[2].highOrder,\n H[2].lowOrder,\n H[3].highOrder,\n H[3].lowOrder,\n H[4].highOrder,\n H[4].lowOrder,\n H[5].highOrder,\n H[5].lowOrder,\n H[6].highOrder,\n H[6].lowOrder,\n H[7].highOrder,\n H[7].lowOrder,\n ];\n }\n return retVal;\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: Int_64[];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: Int_64[]) => Int_64[];\n finalizeFunc: (remainder: number[], remainderBinLen: number, processedBinLen: number, H: Int_64[]) => number[];\n stateCloneFunc: (state: Int_64[]) => Int_64[];\n newStateFunc: (variant: VariantType) => Int_64[];\n getMAC: () => number[];\n\n constructor(variant: VariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(variant: VariantType, inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (!(\"SHA-384\" === variant || \"SHA-512\" === variant)) {\n throw new Error(sha_variant_error);\n }\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n this.HMACSupported = true;\n this.bigEndianMod = -1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA512;\n this.stateCloneFunc = function (state): Int_64[] {\n return state.slice();\n };\n this.newStateFunc = getNewState512;\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, H): number[] {\n return finalizeSHA512(remainder, remainderBinLen, processedBinLen, H, variant);\n };\n\n this.intermediateState = getNewState512(variant);\n this.variantBlockSize = 1024;\n this.outputBinLen = \"SHA-384\" === variant ? 384 : 512;\n this.isVariableLen = false;\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n}\n","import { jsSHABase, packedLEConcat, sha_variant_error, mac_rounds_error, TWO_PWR_32, parseInputOption } from \"./common\";\nimport {\n packedValue,\n CSHAKEOptionsNoEncodingType,\n CSHAKEOptionsEncodingType,\n SHAKEOptionsNoEncodingType,\n SHAKEOptionsEncodingType,\n KMACOptionsNoEncodingType,\n KMACOptionsEncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n ResolvedCSHAKEOptionsNoEncodingType,\n ResolvedKMACOptionsNoEncodingType,\n} from \"./custom_types\";\nimport { getStrConverter } from \"./converters\";\nimport { Int_64, rotl_64, xor_64_2, xor_64_5 } from \"./primitives_64\";\n\ntype FixedLengthVariantType = \"SHA3-224\" | \"SHA3-256\" | \"SHA3-384\" | \"SHA3-512\" | \"SHAKE128\" | \"SHAKE256\";\n\ntype VariantType = FixedLengthVariantType | \"SHAKE128\" | \"SHAKE256\" | \"CSHAKE128\" | \"CSHAKE256\" | \"KMAC128\" | \"KMAC256\";\n\nconst rc_sha3 = [\n new Int_64(0x00000000, 0x00000001),\n new Int_64(0x00000000, 0x00008082),\n new Int_64(0x80000000, 0x0000808a),\n new Int_64(0x80000000, 0x80008000),\n new Int_64(0x00000000, 0x0000808b),\n new Int_64(0x00000000, 0x80000001),\n new Int_64(0x80000000, 0x80008081),\n new Int_64(0x80000000, 0x00008009),\n new Int_64(0x00000000, 0x0000008a),\n new Int_64(0x00000000, 0x00000088),\n new Int_64(0x00000000, 0x80008009),\n new Int_64(0x00000000, 0x8000000a),\n new Int_64(0x00000000, 0x8000808b),\n new Int_64(0x80000000, 0x0000008b),\n new Int_64(0x80000000, 0x00008089),\n new Int_64(0x80000000, 0x00008003),\n new Int_64(0x80000000, 0x00008002),\n new Int_64(0x80000000, 0x00000080),\n new Int_64(0x00000000, 0x0000800a),\n new Int_64(0x80000000, 0x8000000a),\n new Int_64(0x80000000, 0x80008081),\n new Int_64(0x80000000, 0x00008080),\n new Int_64(0x00000000, 0x80000001),\n new Int_64(0x80000000, 0x80008008),\n];\n\nconst r_sha3 = [\n [0, 36, 3, 41, 18],\n [1, 44, 10, 45, 2],\n [62, 6, 43, 15, 61],\n [28, 55, 25, 21, 56],\n [27, 20, 39, 8, 14],\n];\n\n/**\n * Gets the state values for the specified SHA-3 variant.\n *\n * @param _variant Unused for this family.\n * @returns The initial state values.\n */\nfunction getNewState(_variant: VariantType): Int_64[][] {\n let i;\n const retVal = [];\n\n for (i = 0; i < 5; i += 1) {\n retVal[i] = [new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0)];\n }\n\n return retVal;\n}\n\n/**\n * Returns a clone of the given SHA3 state.\n *\n * @param state The state to be cloned.\n * @returns The cloned state.\n */\nfunction cloneSHA3State(state: Int_64[][]): Int_64[][] {\n let i;\n const clone = [];\n for (i = 0; i < 5; i += 1) {\n clone[i] = state[i].slice();\n }\n\n return clone;\n}\n\n/**\n * Performs a round of SHA-3 hashing over a block. This clobbers `state`.\n *\n * @param block The binary array representation of the block to hash.\n * @param state Hash state from a previous round.\n * @returns The resulting state value.\n */\nfunction roundSHA3(block: number[] | null, state: Int_64[][]): Int_64[][] {\n let round, x, y, B;\n const C = [],\n D = [];\n\n if (null !== block) {\n for (x = 0; x < block.length; x += 2) {\n state[(x >>> 1) % 5][((x >>> 1) / 5) | 0] = xor_64_2(\n state[(x >>> 1) % 5][((x >>> 1) / 5) | 0],\n new Int_64(block[x + 1], block[x])\n );\n }\n }\n\n for (round = 0; round < 24; round += 1) {\n /* Any SHA-3 variant name will do here */\n B = getNewState(\"SHA3-384\");\n\n /* Perform theta step */\n for (x = 0; x < 5; x += 1) {\n C[x] = xor_64_5(state[x][0], state[x][1], state[x][2], state[x][3], state[x][4]);\n }\n for (x = 0; x < 5; x += 1) {\n D[x] = xor_64_2(C[(x + 4) % 5], rotl_64(C[(x + 1) % 5], 1));\n }\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n state[x][y] = xor_64_2(state[x][y], D[x]);\n }\n }\n\n /* Perform combined ro and pi steps */\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n B[y][(2 * x + 3 * y) % 5] = rotl_64(state[x][y], r_sha3[x][y]);\n }\n }\n\n /* Perform chi step */\n for (x = 0; x < 5; x += 1) {\n for (y = 0; y < 5; y += 1) {\n state[x][y] = xor_64_2(\n B[x][y],\n new Int_64(\n ~B[(x + 1) % 5][y].highOrder & B[(x + 2) % 5][y].highOrder,\n ~B[(x + 1) % 5][y].lowOrder & B[(x + 2) % 5][y].lowOrder\n )\n );\n }\n }\n\n /* Perform iota step */\n state[0][0] = xor_64_2(state[0][0], rc_sha3[round]);\n }\n\n return state;\n}\n\n/**\n * Finalizes the SHA-3 hash. This clobbers `remainder` and `state`.\n *\n * @param remainder Any leftover unprocessed packed ints that still need to be processed.\n * @param remainderBinLen The number of bits in `remainder`.\n * @param _processedBinLen Unused for this family.\n * @param state The state from a previous round.\n * @param blockSize The block size/rate of the variant in bits\n * @param delimiter The delimiter value for the variant\n * @param outputLen The output length for the variant in bits\n * @returns The array of integers representing the SHA-3 hash of message.\n */\nfunction finalizeSHA3(\n remainder: number[],\n remainderBinLen: number,\n _processedBinLen: number,\n state: Int_64[][],\n blockSize: number,\n delimiter: number,\n outputLen: number\n): number[] {\n let i,\n state_offset = 0,\n temp;\n const retVal = [],\n binaryStringInc = blockSize >>> 5,\n remainderIntLen = remainderBinLen >>> 5;\n\n /* Process as many blocks as possible, some may be here for multiple rounds\n\t\twith SHAKE\n\t*/\n for (i = 0; i < remainderIntLen && remainderBinLen >= blockSize; i += binaryStringInc) {\n state = roundSHA3(remainder.slice(i, i + binaryStringInc), state);\n remainderBinLen -= blockSize;\n }\n\n remainder = remainder.slice(i);\n remainderBinLen = remainderBinLen % blockSize;\n\n /* Pad out the remainder to a full block */\n while (remainder.length < binaryStringInc) {\n remainder.push(0);\n }\n\n /* Find the next \"empty\" byte for the 0x80 and append it via an xor */\n i = remainderBinLen >>> 3;\n remainder[i >> 2] ^= delimiter << (8 * (i % 4));\n\n remainder[binaryStringInc - 1] ^= 0x80000000;\n state = roundSHA3(remainder, state);\n\n while (retVal.length * 32 < outputLen) {\n temp = state[state_offset % 5][(state_offset / 5) | 0];\n retVal.push(temp.lowOrder);\n if (retVal.length * 32 >= outputLen) {\n break;\n }\n retVal.push(temp.highOrder);\n state_offset += 1;\n\n if (0 === (state_offset * 64) % blockSize) {\n roundSHA3(null, state);\n state_offset = 0;\n }\n }\n\n return retVal;\n}\n\n/**\n * Performs NIST left_encode function returned with no extra garbage bits. `x` is limited to <= 9007199254740991.\n *\n * @param x 32-bit number to to encode.\n * @returns The NIST specified output of the function.\n */\nfunction left_encode(x: number): packedValue {\n let byteOffset,\n byte,\n numEncodedBytes = 0;\n /* JavaScript numbers max out at 0x1FFFFFFFFFFFFF (7 bytes) so this will return a maximum of 7 + 1 = 8 bytes */\n const retVal = [0, 0],\n x_64 = [x & 0xffffffff, (x / TWO_PWR_32) & 0x1fffff];\n\n for (byteOffset = 6; byteOffset >= 0; byteOffset--) {\n /* This will surprisingly work for large shifts because JavaScript masks the shift amount by 0x1F */\n byte = (x_64[byteOffset >> 2] >>> (8 * byteOffset)) & 0xff;\n\n /* Starting from the most significant byte of a 64-bit number, start recording the first non-0 byte and then\n every byte thereafter */\n if (byte !== 0 || numEncodedBytes !== 0) {\n retVal[(numEncodedBytes + 1) >> 2] |= byte << ((numEncodedBytes + 1) * 8);\n numEncodedBytes += 1;\n }\n }\n numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;\n retVal[0] |= numEncodedBytes;\n\n return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };\n}\n\n/**\n * Performs NIST right_encode function returned with no extra garbage bits. `x` is limited to <= 9007199254740991.\n *\n * @param x 32-bit number to to encode.\n * @returns The NIST specified output of the function.\n */\nfunction right_encode(x: number): packedValue {\n let byteOffset,\n byte,\n numEncodedBytes = 0;\n /* JavaScript numbers max out at 0x1FFFFFFFFFFFFF (7 bytes) so this will return a maximum of 7 + 1 = 8 bytes */\n const retVal = [0, 0],\n x_64 = [x & 0xffffffff, (x / TWO_PWR_32) & 0x1fffff];\n\n for (byteOffset = 6; byteOffset >= 0; byteOffset--) {\n /* This will surprisingly work for large shifts because JavaScript masks the shift amount by 0x1F */\n byte = (x_64[byteOffset >> 2] >>> (8 * byteOffset)) & 0xff;\n\n /* Starting from the most significant byte of a 64-bit number, start recording the first non-0 byte and then\n every byte thereafter */\n if (byte !== 0 || numEncodedBytes !== 0) {\n retVal[numEncodedBytes >> 2] |= byte << (numEncodedBytes * 8);\n numEncodedBytes += 1;\n }\n }\n numEncodedBytes = numEncodedBytes !== 0 ? numEncodedBytes : 1;\n retVal[numEncodedBytes >> 2] |= numEncodedBytes << (numEncodedBytes * 8);\n\n return { value: numEncodedBytes + 1 > 4 ? retVal : [retVal[0]], binLen: 8 + numEncodedBytes * 8 };\n}\n\n/**\n * Performs NIST encode_string function.\n *\n * @param input Packed array of integers.\n * @returns NIST encode_string output.\n */\nfunction encode_string(input: packedValue): packedValue {\n return packedLEConcat(left_encode(input[\"binLen\"]), input);\n}\n\n/**\n * Performs NIST byte_pad function.\n *\n * @param packed Packed array of integers.\n * @param outputByteLen Desired length of the output in bytes, assumed to be a multiple of 4.\n * @returns NIST byte_pad output.\n */\nfunction byte_pad(packed: packedValue, outputByteLen: number): number[] {\n let encodedLen = left_encode(outputByteLen),\n i;\n\n encodedLen = packedLEConcat(encodedLen, packed);\n const outputIntLen = outputByteLen >>> 2,\n intsToAppend = (outputIntLen - (encodedLen[\"value\"].length % outputIntLen)) % outputIntLen;\n\n for (i = 0; i < intsToAppend; i++) {\n encodedLen[\"value\"].push(0);\n }\n\n return encodedLen[\"value\"];\n}\n\n/**\n * Parses/validate constructor options for a CSHAKE variant\n *\n * @param options Option given to constructor\n */\nfunction resolveCSHAKEOptions(options: CSHAKEOptionsNoEncodingType): ResolvedCSHAKEOptionsNoEncodingType {\n const resolvedOptions = options || {};\n\n return {\n funcName: parseInputOption(\"funcName\", resolvedOptions[\"funcName\"], 1, { value: [], binLen: 0 }),\n customization: parseInputOption(\"Customization\", resolvedOptions[\"customization\"], 1, { value: [], binLen: 0 }),\n };\n}\n\n/**\n * Parses/validate constructor options for a KMAC variant\n *\n * @param options Option given to constructor\n */\nfunction resolveKMACOptions(options: KMACOptionsNoEncodingType): ResolvedKMACOptionsNoEncodingType {\n const resolvedOptions = options || {};\n\n return {\n kmacKey: parseInputOption(\"kmacKey\", resolvedOptions[\"kmacKey\"], 1),\n /* This is little-endian packed \"KMAC\" */\n funcName: { value: [0x43414d4b], binLen: 32 },\n customization: parseInputOption(\"Customization\", resolvedOptions[\"customization\"], 1, { value: [], binLen: 0 }),\n };\n}\n\nexport default class jsSHA extends jsSHABase {\n intermediateState: Int_64[][];\n variantBlockSize: number;\n bigEndianMod: -1 | 1;\n outputBinLen: number;\n isVariableLen: boolean;\n HMACSupported: boolean;\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n converterFunc: (input: any, existingBin: number[], existingBinLen: number) => packedValue;\n roundFunc: (block: number[], H: Int_64[][]) => Int_64[][];\n finalizeFunc: (\n remainder: number[],\n remainderBinLen: number,\n processedBinLen: number,\n H: Int_64[][],\n outputLen: number\n ) => number[];\n stateCloneFunc: (state: Int_64[][]) => Int_64[][];\n newStateFunc: (variant: VariantType) => Int_64[][];\n getMAC: ((options: { outputLen: number }) => number[]) | null;\n\n constructor(variant: FixedLengthVariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(\n variant: FixedLengthVariantType,\n inputFormat: FormatNoTextType,\n options?: FixedLengthOptionsNoEncodingType\n );\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: \"TEXT\", options?: SHAKEOptionsEncodingType);\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: \"TEXT\", options?: CSHAKEOptionsEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: \"TEXT\", options: KMACOptionsEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n let delimiter = 0x06,\n variantBlockSize = 0;\n super(variant, inputFormat, options);\n const resolvedOptions = options || {};\n\n /* In other variants, this was done after variable initialization but need to do it earlier here becaue we want to\n avoid KMAC initialization */\n if (this.numRounds !== 1) {\n if (resolvedOptions[\"kmacKey\"] || resolvedOptions[\"hmacKey\"]) {\n throw new Error(mac_rounds_error);\n } else if (this.shaVariant === \"CSHAKE128\" || this.shaVariant === \"CSHAKE256\") {\n throw new Error(\"Cannot set numRounds for CSHAKE variants\");\n }\n }\n\n this.bigEndianMod = 1;\n this.converterFunc = getStrConverter(this.inputFormat, this.utfType, this.bigEndianMod);\n this.roundFunc = roundSHA3;\n this.stateCloneFunc = cloneSHA3State;\n this.newStateFunc = getNewState;\n this.intermediateState = getNewState(variant);\n\n this.isVariableLen = false;\n switch (variant) {\n case \"SHA3-224\":\n this.variantBlockSize = variantBlockSize = 1152;\n this.outputBinLen = 224;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-256\":\n this.variantBlockSize = variantBlockSize = 1088;\n this.outputBinLen = 256;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-384\":\n this.variantBlockSize = variantBlockSize = 832;\n this.outputBinLen = 384;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHA3-512\":\n this.variantBlockSize = variantBlockSize = 576;\n this.outputBinLen = 512;\n this.HMACSupported = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getHMAC;\n break;\n case \"SHAKE128\":\n delimiter = 0x1f;\n this.variantBlockSize = variantBlockSize = 1344;\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"SHAKE256\":\n delimiter = 0x1f;\n this.variantBlockSize = variantBlockSize = 1088;\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"KMAC128\":\n delimiter = 0x4;\n this.variantBlockSize = variantBlockSize = 1344;\n this._initializeKMAC(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getKMAC;\n break;\n case \"KMAC256\":\n delimiter = 0x4;\n this.variantBlockSize = variantBlockSize = 1088;\n this._initializeKMAC(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.getMAC = this._getKMAC;\n break;\n case \"CSHAKE128\":\n this.variantBlockSize = variantBlockSize = 1344;\n delimiter = this._initializeCSHAKE(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n case \"CSHAKE256\":\n this.variantBlockSize = variantBlockSize = 1088;\n delimiter = this._initializeCSHAKE(options);\n /* This will be set in getHash */\n this.outputBinLen = -1;\n this.isVariableLen = true;\n this.HMACSupported = false;\n this.getMAC = null;\n break;\n default:\n throw new Error(sha_variant_error);\n }\n\n /* This needs to be down here as CSHAKE can change its delimiter */\n this.finalizeFunc = function (remainder, remainderBinLen, processedBinLen, state, outputBinLen): number[] {\n return finalizeSHA3(\n remainder,\n remainderBinLen,\n processedBinLen,\n state,\n variantBlockSize,\n delimiter,\n outputBinLen\n );\n };\n\n if (resolvedOptions[\"hmacKey\"]) {\n this._setHMACKey(parseInputOption(\"hmacKey\", resolvedOptions[\"hmacKey\"], this.bigEndianMod));\n }\n }\n\n /**\n * Initialize CSHAKE variants.\n *\n * @param options Options containing CSHAKE params.\n * @param funcNameOverride Overrides any \"funcName\" present in `options` (used with KMAC)\n * @returns The delimiter to be used\n */\n protected _initializeCSHAKE(options?: CSHAKEOptionsNoEncodingType, funcNameOverride?: packedValue): number {\n const resolvedOptions = resolveCSHAKEOptions(options || {});\n if (funcNameOverride) {\n resolvedOptions[\"funcName\"] = funcNameOverride;\n }\n const packedParams = packedLEConcat(\n encode_string(resolvedOptions[\"funcName\"]),\n encode_string(resolvedOptions[\"customization\"])\n );\n\n /* CSHAKE is defined to be a call to SHAKE iff both the customization and function-name string are both empty. This\n can be accomplished by processing nothing in this step. */\n if (resolvedOptions[\"customization\"][\"binLen\"] !== 0 || resolvedOptions[\"funcName\"][\"binLen\"] !== 0) {\n const byte_pad_out = byte_pad(packedParams, this.variantBlockSize >>> 3);\n for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {\n this.intermediateState = this.roundFunc(\n byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),\n this.intermediateState\n );\n this.processedLen += this.variantBlockSize;\n }\n return 0x04;\n } else {\n return 0x1f;\n }\n }\n\n /**\n * Initialize KMAC variants.\n *\n * @param options Options containing KMAC params.\n */\n protected _initializeKMAC(options: KMACOptionsNoEncodingType): void {\n const resolvedOptions = resolveKMACOptions(options || {});\n\n this._initializeCSHAKE(options, resolvedOptions[\"funcName\"]);\n const byte_pad_out = byte_pad(encode_string(resolvedOptions[\"kmacKey\"]), this.variantBlockSize >>> 3);\n for (let i = 0; i < byte_pad_out.length; i += this.variantBlockSize >>> 5) {\n this.intermediateState = this.roundFunc(\n byte_pad_out.slice(i, i + (this.variantBlockSize >>> 5)),\n this.intermediateState\n );\n this.processedLen += this.variantBlockSize;\n }\n this.macKeySet = true;\n }\n\n /**\n * Returns the the KMAC in the specified format.\n *\n * @param options Hashmap of extra outputs options. `outputLen` must be specified.\n * @returns The KMAC in the format specified.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected _getKMAC(options: { outputLen: number }): number[] {\n const concatedRemainder = packedLEConcat(\n { value: this.remainder.slice(), binLen: this.remainderLen },\n right_encode(options[\"outputLen\"])\n );\n\n return this.finalizeFunc(\n concatedRemainder[\"value\"],\n concatedRemainder[\"binLen\"],\n this.processedLen,\n this.stateCloneFunc(this.intermediateState),\n options[\"outputLen\"]\n );\n }\n}\n","import { sha_variant_error } from \"./common\";\nimport {\n CSHAKEOptionsEncodingType,\n CSHAKEOptionsNoEncodingType,\n SHAKEOptionsEncodingType,\n SHAKEOptionsNoEncodingType,\n EncodingType,\n FixedLengthOptionsEncodingType,\n FixedLengthOptionsNoEncodingType,\n FormatNoTextType,\n KMACOptionsNoEncodingType,\n KMACOptionsEncodingType,\n} from \"./custom_types\";\nimport jsSHA1 from \"./sha1\";\nimport jsSHA256 from \"./sha256\";\nimport jsSHA512 from \"./sha512\";\nimport jsSHA3 from \"./sha3\";\n\ntype FixedLengthVariantType =\n | \"SHA-1\"\n | \"SHA-224\"\n | \"SHA-256\"\n | \"SHA-384\"\n | \"SHA-512\"\n | \"SHA3-224\"\n | \"SHA3-256\"\n | \"SHA3-384\"\n | \"SHA3-512\";\n\nexport default class jsSHA {\n private readonly shaObj: jsSHA1 | jsSHA256 | jsSHA512 | jsSHA3;\n /**\n * @param variant The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-224, SHA3-256, SHA3-256,\n * SHA3-384, SHA3-512, SHAKE128, SHAKE256, CSHAKE128, CSHAKE256, KMAC128, or KMAC256) as a string.\n * @param inputFormat The input format to be used in future `update` calls (TEXT, HEX, B64, BYTES, ARRAYBUFFER,\n * or UINT8ARRAY) as a string.\n * @param options Options in the form of { encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE\"; numRounds?: number }.\n * `encoding` is for only TEXT input (defaults to UTF8) and `numRounds` defaults to 1.\n * `numRounds` is not valid for any of the MAC or CSHAKE variants.\n * * If the variant supports HMAC, `options` may have an additional `hmacKey` key which must be in the form of\n * {value: , format: , encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE\"} where takes the same\n * values as `inputFormat` and can be a `string | ArrayBuffer | Uint8Array` depending on .\n * Supplying this key switches to HMAC calculation and replaces the now deprecated call to `setHMACKey`.\n * * If the variant is CSHAKE128 or CSHAKE256, `options` may have two additional keys, `customization` and `funcName`,\n * which are the NIST customization and function-name strings. Both must be in the same form as `hmacKey`.\n * * If the variant is KMAC128 or KMAC256, `options` can include the `customization` key from CSHAKE variants and\n * *must* have a `kmacKey` key that takes the same form as the `customization` key.\n */\n constructor(variant: FixedLengthVariantType, inputFormat: \"TEXT\", options?: FixedLengthOptionsEncodingType);\n constructor(\n variant: FixedLengthVariantType,\n inputFormat: FormatNoTextType,\n options?: FixedLengthOptionsNoEncodingType\n );\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: \"TEXT\", options?: SHAKEOptionsEncodingType);\n constructor(variant: \"SHAKE128\" | \"SHAKE256\", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: \"TEXT\", options?: CSHAKEOptionsEncodingType);\n constructor(variant: \"CSHAKE128\" | \"CSHAKE256\", inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: \"TEXT\", options: KMACOptionsEncodingType);\n constructor(variant: \"KMAC128\" | \"KMAC256\", inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(variant: any, inputFormat: any, options?: any) {\n if (\"SHA-1\" == variant) {\n this.shaObj = new jsSHA1(variant, inputFormat, options);\n } else if (\"SHA-224\" == variant || \"SHA-256\" == variant) {\n this.shaObj = new jsSHA256(variant, inputFormat, options);\n } else if (\"SHA-384\" == variant || \"SHA-512\" == variant) {\n this.shaObj = new jsSHA512(variant, inputFormat, options);\n } else if (\n \"SHA3-224\" == variant ||\n \"SHA3-256\" == variant ||\n \"SHA3-384\" == variant ||\n \"SHA3-512\" == variant ||\n \"SHAKE128\" == variant ||\n \"SHAKE256\" == variant ||\n \"CSHAKE128\" == variant ||\n \"CSHAKE256\" == variant ||\n \"KMAC128\" == variant ||\n \"KMAC256\" == variant\n ) {\n this.shaObj = new jsSHA3(variant, inputFormat, options);\n } else {\n throw new Error(sha_variant_error);\n }\n }\n\n /**\n * Takes `input` and hashes as many blocks as possible. Stores the rest for either a future `update` or `getHash` call.\n *\n * @param input The input to be hashed\n */\n update(input: string | ArrayBuffer | Uint8Array): void {\n this.shaObj.update(input);\n }\n\n /**\n * Returns the desired SHA or MAC (if a HMAC/KMAC key was specified) hash of the input fed in via `update` calls.\n *\n * @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { outputUpper?: boolean; b64Pad?: string; outputLen?: number; }.\n * `outputLen` is required for variable length output variants (this option was previously called `shakeLen` which\n * is now deprecated).\n * `outputUpper` is only for HEX output (defaults to false) and b64pad is only for B64 output (defaults to \"=\").\n * @returns The hash in the format specified.\n */\n getHash(format: \"HEX\", options?: { outputUpper?: boolean; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"B64\", options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"BYTES\", options?: { outputLen?: number; shakeLen?: number }): string;\n getHash(format: \"UINT8ARRAY\", options?: { outputLen?: number; shakeLen?: number }): Uint8Array;\n getHash(format: \"ARRAYBUFFER\", options?: { outputLen?: number; shakeLen?: number }): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHash(format: any, options?: any): any {\n return this.shaObj.getHash(format, options);\n }\n\n /**\n * Sets the HMAC key for an eventual `getHMAC` call. Must be called immediately after jsSHA object instantiation.\n * Now deprecated in favor of setting the `hmacKey` at object instantiation.\n *\n * @param key The key used to calculate the HMAC\n * @param inputFormat The format of key (HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { encoding?: \"UTF8\" | \"UTF16BE\" | \"UTF16LE }. `encoding` is only for TEXT\n * and defaults to UTF8.\n */\n setHMACKey(key: string, inputFormat: \"TEXT\", options?: { encoding?: EncodingType }): void;\n setHMACKey(key: string, inputFormat: \"B64\" | \"HEX\" | \"BYTES\"): void;\n setHMACKey(key: ArrayBuffer, inputFormat: \"ARRAYBUFFER\"): void;\n setHMACKey(key: Uint8Array, inputFormat: \"UINT8ARRAY\"): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setHMACKey(key: any, inputFormat: any, options?: any): void {\n this.shaObj.setHMACKey(key, inputFormat, options);\n }\n\n /**\n * Returns the the HMAC in the specified format using the key given by a previous `setHMACKey` call. Now deprecated\n * in favor of just calling `getHash`.\n *\n * @param format The desired output formatting (B64, HEX, BYTES, ARRAYBUFFER, or UINT8ARRAY) as a string.\n * @param options Options in the form of { outputUpper?: boolean; b64Pad?: string }. `outputUpper` is only for HEX\n * output (defaults to false) and `b64pad` is only for B64 output (defaults to \"=\").\n * @returns The HMAC in the format specified.\n */\n getHMAC(format: \"HEX\", options?: { outputUpper?: boolean }): string;\n getHMAC(format: \"B64\", options?: { b64Pad?: string }): string;\n getHMAC(format: \"BYTES\"): string;\n getHMAC(format: \"UINT8ARRAY\"): Uint8Array;\n getHMAC(format: \"ARRAYBUFFER\"): ArrayBuffer;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getHMAC(format: any, options?: any): any {\n return this.shaObj.getHMAC(format, options);\n }\n}\n"],"names":["b64Tab","uint8array2packed","arr","existingPacked","existingPackedLen","bigEndianMod","i","intOffset","byteOffset","packed","existingByteLen","shiftModifier","length","push","value","binLen","getStrConverter","format","utfType","Error","str","existingBin","existingBinLen","num","parseInt","substr","isNaN","hex2packed","codePnt","codePntArr","j","transposeBytes","byteCnt","charCodeAt","str2packed","tmpInt","strPart","firstEqual","indexOf","search","replace","charAt","b642packed","bytes2packed","ArrayBuffer","ignore","Uint8Array","arraybuffer2packed","getOutputConverter","outputBinLen","outputOptions","binarray","outputLength","formatOpts","srcByte","toUpperCase","packed2hex","triplet","int1","int2","packed2b64","String","fromCharCode","packed2bytes","retVal","arrView","packed2arraybuffer","packed2uint8array","K_sha2","H_trunc","H_full","sha_variant_error","packedLEConcat","a","b","arrOffset","aByteLen","bByteLen","leftShiftAmount","rightShiftAmount","pop","concat","getOutputOpts","options","outputUpper","b64Pad","outputLen","lenErrstr","parseInputOption","key","fallback","errStr","variant","inputFormat","inputOptions","this","numRounds","shaVariant","remainder","remainderLen","updateCalled","processedLen","macKeySet","keyWithIPad","keyWithOPad","jsSHABase","srcString","updateProcessedLen","variantBlockIntInc","variantBlockSize","convertRet","converterFunc","chunkBinLen","chunk","chunkIntLen","intermediateState","roundFunc","slice","finalizedState","isVariableLen","formatFunc","getMAC","finalizeFunc","stateCloneFunc","newStateFunc","HMACSupported","keyConverterFunc","_setHMACKey","blockByteSize","lastArrayIndex","_getHMAC","firstHash","extendStatics","d","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__extends","__","constructor","create","rotl_32","x","n","rotr_32","shr_32","parity_32","y","z","ch_32","maj_32","sigma0_32","safeAdd_32_2","lsw","safeAdd_32_4","c","safeAdd_32_5","e","gamma0_32","sigma1_32","getNewState","_variant","roundSHA1","block","H","T","t","W","finalizeSHA1","remainderBinLen","processedBinLen","offset","totalLen","resolvedOptions","_this","_super","state","getNewState256","roundSHA256","f","g","h","T1","T2","finalizeSHA256","msint_32","lsint_32","highOrder","lowOrder","rotl_64","tmp","Int_64","rotr_64","shr_64","ch_64","maj_64","sigma0_64","rotr28","rotr34","rotr39","safeAdd_64_2","msw","safeAdd_64_4","safeAdd_64_5","xor_64_2","gamma0_64","rotr1","rotr8","shr7","sigma1_64","rotr14","rotr18","rotr41","K_sha512","getNewState512","roundSHA512","rotr19","rotr61","shr6","finalizeSHA512","rc_sha3","r_sha3","cloneSHA3State","clone","roundSHA3","round","B","C","D","left_encode","byte","numEncodedBytes","x_64","encode_string","input","byte_pad","outputByteLen","encodedLen","outputIntLen","intsToAppend","delimiter","_initializeKMAC","_getKMAC","_initializeCSHAKE","_processedBinLen","blockSize","temp","state_offset","binaryStringInc","remainderIntLen","finalizeSHA3","jsSHA","funcNameOverride","funcName","customization","resolveCSHAKEOptions","packedParams","byte_pad_out","kmacKey","resolveKMACOptions","concatedRemainder","right_encode","shaObj","jsSHA1","jsSHA256","jsSHA512","jsSHA3","update","getHash","setHMACKey","getHMAC"],"mappings":";;;;;;;;;;;;;;;;;;;;sOAIA,IAAMA,EAAS,mEA4Pf,SAASC,EACPC,EACAC,EACAC,EACAC,GAEA,IAAIC,EAAGC,EAAWC,EAGZC,EAASN,GAAkB,CAAC,GAChCO,GAFFN,EAAoBA,GAAqB,KAEC,EACxCO,GAAkC,IAAlBN,EAAsB,EAAI,EAE5C,IAAKC,EAAI,EAAGA,EAAIJ,EAAIU,OAAQN,GAAK,EAE/BC,GADAC,EAAaF,EAAII,KACU,EACvBD,EAAOG,QAAUL,GACnBE,EAAOI,KAAK,GAEdJ,EAAOF,IAAcL,EAAII,IAAO,GAAKK,EAAgBN,GAAgBG,EAAa,IAGpF,MAAO,CAAEM,MAAOL,EAAQM,OAAqB,EAAbb,EAAIU,OAAaR,YA6BnCY,EACdC,EACAC,EACAb,GAIA,OAAQa,GACN,IAAK,OAEL,IAAK,UAEL,IAAK,UAEH,MACF,QACE,MAAM,IAAIC,MAAM,8CAIpB,OAAQF,GACN,IAAK,MAOH,OAAO,SAAUG,EAAaC,EAAwBC,GACpD,OA9NR,SACEF,EACAjB,EACAC,EACAC,GAEA,IAAIC,EAAGiB,EAAKhB,EAAWC,EAEvB,GAAI,GAAMY,EAAIR,OAAS,EACrB,MAAM,IAAIO,MAAM,iDAIlB,IAAMV,EAASN,GAAkB,CAAC,GAChCO,GAFFN,EA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C,EAAmB,eAhPUsB,qBC/RjC,WAAYb,EAAcC,EAAkBV,GAC1C,GAAI,SAAWS,EACbG,KAAK4K,EAAS,IAAIC,EAAOhL,EAASC,EAAaV,QAC1C,GAAI,WAAaS,GAAW,WAAaA,EAC9CG,KAAK4K,EAAS,IAAIE,EAASjL,EAASC,EAAaV,QAC5C,GAAI,WAAaS,GAAW,WAAaA,EAC9CG,KAAK4K,EAAS,IAAIG,EAASlL,EAASC,EAAaV,OAC5C,CAAA,GACL,YAAcS,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,YAAcA,GACd,aAAeA,GACf,aAAeA,GACf,WAAaA,GACb,WAAaA,EAIb,MAAM,IAAIzE,MAAMoD,GAFhBwB,KAAK4K,EAAS,IAAII,GAAOnL,EAASC,EAAaV,IAuErD,OA5DE6K,mBAAA,SAAOjB,GACLhJ,KAAK4K,EAAOK,OAAOjC,IAmBrBiB,oBAAA,SAAQ/O,EAAakE,GACnB,OAAOY,KAAK4K,EAAOM,QAAQhQ,EAAQkE,IAiBrC6K,uBAAA,SAAWvK,EAAUI,EAAkBV,GACrCY,KAAK4K,EAAOO,WAAWzL,EAAKI,EAAaV,IAkB3C6K,oBAAA,SAAQ/O,EAAakE,GACnB,OAAOY,KAAK4K,EAAOQ,QAAQlQ,EAAQkE"} \ No newline at end of file diff --git a/include/thirdparty/js/sha.mjs b/include/thirdparty/js/sha.mjs new file mode 100644 index 0000000..cd1264f --- /dev/null +++ b/include/thirdparty/js/sha.mjs @@ -0,0 +1,10 @@ +/** + * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, + * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. + * + * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors + * Distributed under the BSD License + * See http://caligatio.github.com/jsSHA/ for more information + */ +const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function n(t,n,e,r){let i,s,o;const h=n||[0],u=(e=e||0)>>>3,w=-1===r?3:0;for(i=0;i>>2,h.length<=s&&h.push(0),h[s]|=t[i]<<8*(w+r*(o%4));return{value:h,binLen:8*t.length+e}}function e(e,r,i){switch(r){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(t,n,e){return function(t,n,e,r){let i,s,o,h;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const u=n||[0],w=(e=e||0)>>>3,c=-1===r?3:0;for(i=0;i>>1)+w,o=h>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(c+r*(h%4))}return{value:u,binLen:4*t.length+e}}(t,n,e,i)};case"TEXT":return function(t,n,e){return function(t,n,e,r,i){let s,o,h,u,w,c,f,a,l=0;const A=e||[0],E=(r=r||0)>>>3;if("UTF8"===n)for(f=-1===i?3:0,h=0;hs?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(h+=1,s=65536+((1023&s)<<10|1023&t.charCodeAt(h)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u>>2;A.length<=w;)A.push(0);A[w]|=o[u]<<8*(f+i*(c%4)),l+=1}else for(f=-1===i?2:0,a="UTF16LE"===n&&1!==i||"UTF16LE"!==n&&1===i,h=0;h>>8),c=l+E,w=c>>>2;A.length<=w;)A.push(0);A[w]|=s<<8*(f+i*(c%4)),l+=2}return{value:A,binLen:8*l+r}}(t,r,n,e,i)};case"B64":return function(n,e,r){return function(n,e,r,i){let s,o,h,u,w,c,f,a=0;const l=e||[0],A=(r=r||0)>>>3,E=-1===i?3:0,H=n.indexOf("=");if(-1===n.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(n=n.replace(/=/g,""),-1!==H&&H