From 70276a34e8d770d894ecc5918db3383422c30171 Mon Sep 17 00:00:00 2001 From: Keith Miller Date: Tue, 11 Feb 2025 10:58:06 -0500 Subject: [PATCH 1/3] Move argon2 to JS-style scoring. --- JetStreamDriver.js | 27 +- wasm/argon2/benchmark.js | 96 ++++ wasm/argon2/build.log | 5 + wasm/argon2/build.sh | 83 ++- wasm/argon2/build/argon2.js | 768 ++++++++++++++++++++++++++++ wasm/argon2/build/argon2.js.symbols | 40 ++ wasm/argon2/build/argon2.wasm | Bin 0 -> 30934 bytes 7 files changed, 981 insertions(+), 38 deletions(-) create mode 100644 wasm/argon2/benchmark.js create mode 100644 wasm/argon2/build.log create mode 100644 wasm/argon2/build/argon2.js create mode 100644 wasm/argon2/build/argon2.js.symbols create mode 100755 wasm/argon2/build/argon2.wasm diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 6ccff01..1c0fcfe 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -454,7 +454,7 @@ class Driver { this.isReady = true; if (isInBrowser) { globalThis.dispatchEvent(new Event("JetStreamReady")); - if (shouldReport) { + if (typeof(globalThis.startDelay) !== "undefined") { setTimeout(() => this.start(), globalThis.startDelay); } } @@ -2054,29 +2054,18 @@ const BENCHMARKS = [ deterministicRandom: true, testGroup: WasmGroup }), - new WasmLegacyBenchmark({ + new WasmEMCCBenchmark({ name: "argon2-wasm", files: [ - "./wasm/argon2-bundle.js", - "./wasm/argon2.js", - "./wasm/argon2-benchmark.js" - ], - preload: { - argon2WasmBlob: "./wasm/argon2.wasm", - }, - testGroup: WasmGroup - }), - new WasmLegacyBenchmark({ - name: "argon2-wasm-simd", - files: [ - "./wasm/argon2-bundle.js", - "./wasm/argon2.js", - "./wasm/argon2-benchmark.js" + "./wasm/argon2/build/argon2.js", + "./wasm/argon2/benchmark.js", ], preload: { - argon2WasmSimdBlob: "./wasm/argon2-simd.wasm", + wasmBinary: "./wasm/argon2/build/argon2.wasm" }, - testGroup: WasmGroup + iterations: 50, + testGroup: WasmGroup, + deterministicRandom: true, }), // WorkerTests new AsyncBenchmark({ diff --git a/wasm/argon2/benchmark.js b/wasm/argon2/benchmark.js new file mode 100644 index 0000000..ce47c64 --- /dev/null +++ b/wasm/argon2/benchmark.js @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2025 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +let passwordStrings = [ + '123456', + 'p@assw0rd', + 'qwerty', + '汉字漢字', + 'كلمة المرور', + 'Z7ihQxGE93', + '0pjTjkrnsM', + '6Kg3AmWnVc', +]; + +// Emscripten doesn't have a way to manage your pointers for you so these will free them when the wrapper dies. +const mallocRegistry = new FinalizationRegistry((ptr) => Module._free(ptr)); + +class CString { + constructor(string) { + this.ptr = Module.stringToNewUTF8(string); + this.length = Module._strlen(this.ptr); + mallocRegistry.register(this, this.ptr); + } +} + +class MallocPtr { + constructor(size) { + this.ptr = Module._malloc(size); + this.size = size; + mallocRegistry.register(this, this.ptr); + } +} + +const tCost = 2; +const mCost = 1024; +const parallelism = 1; +const argon2NumberOfTypes = 2; +const version = 0x13; +const saltLength = 12; + +class Benchmark { + async runIteration() { + // Instantiate the Wasm module before the first run. + if (!Module._argon2_hash) { + await setupModule(Module); + } + + for (let i = 0; i < passwordStrings.length; ++i) + this.hashAndVerify(passwordStrings[i], i % argon2NumberOfTypes); + } + + randomSalt() { + let result = new MallocPtr(saltLength); + const numWords = saltLength / 4; + for (let i = 0; i < numWords; ++i) + Module.HEAPU32[result.ptr + i] = Math.floor(Math.random() * (2 ** 32)); + return result; + } + + hashAndVerify(password, argon2Type) { + password = new CString(password); + let salt = this.randomSalt(); + this.hashBuffer = new MallocPtr(24); + this.encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, saltLength, this.hashBuffer.size, argon2Type) + 1); + + let status = Module._argon2_hash(tCost, mCost, parallelism, password.ptr, password.length, salt.ptr, salt.size, this.hashBuffer.ptr, this.hashBuffer.size, this.encodedBuffer.ptr, this.encodedBuffer.size, argon2Type, version); + if (status !== 0) + throw new Error(`argon2_hash exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`); + + status = Module._argon2_verify(this.encodedBuffer.ptr, password.ptr, password.length, argon2Type); + if (status !== 0) + throw new Error(`argon2_verify exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`); + } +} diff --git a/wasm/argon2/build.log b/wasm/argon2/build.log new file mode 100644 index 0000000..a5ba855 --- /dev/null +++ b/wasm/argon2/build.log @@ -0,0 +1,5 @@ +Built on 2025-02-11T15:51:03Z +Toolchain versions +emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.0-git +Building... +Building done diff --git a/wasm/argon2/build.sh b/wasm/argon2/build.sh index 81f58e0..d332fbb 100755 --- a/wasm/argon2/build.sh +++ b/wasm/argon2/build.sh @@ -1,27 +1,72 @@ #!/usr/bin/env bash -set -e -set -o pipefail -# Log emcc version -EMCC_SDK_PATH="/path/to/emsdk" -EMCC_PATH="$EMCC_SDK_PATH/upstream/emscripten/emcc" -$EMCC_PATH --version > emcc_version.txt +#!/bin/bash -# Build start -rm -rf dist -mkdir dist +set -euo pipefail -./clean-cmake.sh -EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=1 ./build-wasm.sh -mv dist/argon2.wasm ../argon2-simd.wasm +rm -rf build/ -./clean-cmake.sh -EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=0 ./build-wasm.sh -mv dist/argon2.wasm ../argon2.wasm +touch build.log +BUILD_LOG="$(realpath build.log)" +echo "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | tee "$BUILD_LOG" -./clean-cmake.sh -rm -rf dist -# Build end +echo "Toolchain versions" | tee -a "$BUILD_LOG" +emcc --version | head -n1 | tee -a "$BUILD_LOG" -echo Done +# FIXME: Redownload the source if argon2 ever has source updates. At the time of writing it was last changed 5 years ago so this is probably not a high priority. +SOURCES=( + argon2/src/blake2/blake2b.c + + argon2/src/argon2.c + argon2/src/core.c + argon2/src/encoding.c + argon2/src/thread.c + + argon2/src/opt.c +) + +SIMD_FLAGS=( + -msimd128 + -msse2 +) + +echo "Building..." | tee -a "$BUILD_LOG" +mkdir build/ +emcc -o build/argon2.js \ + -s WASM=1 -O2 \ + ${SIMD_FLAGS[@]} \ + -g1 --emit-symbol-map \ + -DARGON2_NO_THREADS \ + -s MODULARIZE=1 -s EXPORT_NAME=setupModule -s EXPORTED_RUNTIME_METHODS=stringToNewUTF8,UTF8ToString -s EXPORTED_FUNCTIONS=_argon2_hash,_argon2_verify,_argon2_encodedlen,_argon2_error_message,_malloc,_free,_strlen \ + -Iargon2/include \ + ${SOURCES[@]} | tee -a "$BUILD_LOG" + +echo "Building done" | tee -a "$BUILD_LOG" +ls -lth build/ + +# set -e +# set -o pipefail + +# # Log emcc version +# EMCC_SDK_PATH="/path/to/emsdk" +# EMCC_PATH="$EMCC_SDK_PATH/upstream/emscripten/emcc" +# $EMCC_PATH --version > emcc_version.txt + +# # Build start +# rm -rf dist +# mkdir dist + +# ./clean-cmake.sh +# EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=1 ./build-wasm.sh +# mv dist/argon2.wasm ../argon2-simd.wasm + +# ./clean-cmake.sh +# EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=0 ./build-wasm.sh +# mv dist/argon2.wasm ../argon2.wasm + +# ./clean-cmake.sh +# rm -rf dist +# # Build end + +# echo Done diff --git a/wasm/argon2/build/argon2.js b/wasm/argon2/build/argon2.js new file mode 100644 index 0000000..a4bb938 --- /dev/null +++ b/wasm/argon2/build/argon2.js @@ -0,0 +1,768 @@ +var setupModule = (() => { + var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined; + if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename; + return ( +async function(moduleArg = {}) { + var moduleRtn; + +// include: shell.js +// The Module object: Our interface to the outside world. We import +// and export values on it. There are various ways Module can be used: +// 1. Not defined. We create it here +// 2. A function parameter, function(moduleArg) => Promise +// 3. pre-run appended it, var Module = {}; ..generated code.. +// 4. External script tag defines var Module. +// We need to check if Module already exists (e.g. case 3 above). +// Substitution will be replaced with actual code on later stage of the build, +// this way Closure Compiler will not mangle it (e.g. case 4. above). +// Note that if you want to run closure, and also to use Module +// after the generated code, you will need to define var Module = {}; +// before the code. Then that object will be used in the code, and you +// can continue to use Module afterwards as well. +var Module = moduleArg; + +// Set up the promise that indicates the Module is initialized +var readyPromiseResolve, readyPromiseReject; + +var readyPromise = new Promise((resolve, reject) => { + readyPromiseResolve = resolve; + readyPromiseReject = reject; +}); + +// Determine the runtime environment we are in. You can customize this by +// setting the ENVIRONMENT setting at compile time (see settings.js). +// Attempt to auto-detect the environment +var ENVIRONMENT_IS_WEB = typeof window == "object"; + +var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined"; + +// N.b. Electron.js environment is simultaneously a NODE-environment, but +// also a web environment. +var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string" && process.type != "renderer"; + +if (ENVIRONMENT_IS_NODE) {} + +// --pre-jses are emitted after the Module integration code, so that they can +// refer to Module (if they choose; they can also define Module) +// Sometimes an existing Module object exists with properties +// meant to overwrite the default module functionality. Here +// we collect those properties and reapply _after_ we configure +// the current environment's defaults to avoid having to be so +// defensive during initialization. +var moduleOverrides = Object.assign({}, Module); + +var arguments_ = []; + +var thisProgram = "./this.program"; + +var quit_ = (status, toThrow) => { + throw toThrow; +}; + +// `/` should be present at the end if `scriptDirectory` is not empty +var scriptDirectory = ""; + +function locateFile(path) { + if (Module["locateFile"]) { + return Module["locateFile"](path, scriptDirectory); + } + return scriptDirectory + path; +} + +// Hooks that are implemented differently in different runtime environments. +var readAsync, readBinary; + +if (ENVIRONMENT_IS_NODE) { + // These modules will usually be used on Node.js. Load them eagerly to avoid + // the complexity of lazy-loading. + var fs = require("fs"); + var nodePath = require("path"); + scriptDirectory = __dirname + "/"; + // include: node_shell_read.js + readBinary = filename => { + // We need to re-wrap `file://` strings to URLs. + filename = isFileURI(filename) ? new URL(filename) : filename; + var ret = fs.readFileSync(filename); + return ret; + }; + readAsync = async (filename, binary = true) => { + // See the comment in the `readBinary` function. + filename = isFileURI(filename) ? new URL(filename) : filename; + var ret = fs.readFileSync(filename, binary ? undefined : "utf8"); + return ret; + }; + // end include: node_shell_read.js + if (!Module["thisProgram"] && process.argv.length > 1) { + thisProgram = process.argv[1].replace(/\\/g, "/"); + } + arguments_ = process.argv.slice(2); + // MODULARIZE will export the module in the proper place outside, we don't need to export here + quit_ = (status, toThrow) => { + process.exitCode = status; + throw toThrow; + }; +} else // Note that this includes Node.js workers when relevant (pthreads is enabled). +// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and +// ENVIRONMENT_IS_NODE. +if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { + if (ENVIRONMENT_IS_WORKER) { + // Check worker, not web, since window could be polyfilled + scriptDirectory = self.location.href; + } else if (typeof document != "undefined" && document.currentScript) { + // web + scriptDirectory = document.currentScript.src; + } + // When MODULARIZE, this JS may be executed later, after document.currentScript + // is gone, so we saved it, and we use it here instead of any other info. + if (_scriptName) { + scriptDirectory = _scriptName; + } + // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them. + // otherwise, slice off the final part of the url to find the script directory. + // if scriptDirectory does not contain a slash, lastIndexOf will return -1, + // and scriptDirectory will correctly be replaced with an empty string. + // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #), + // they are removed because they could contain a slash. + if (scriptDirectory.startsWith("blob:")) { + scriptDirectory = ""; + } else { + scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); + } + { + // include: web_or_worker_shell_read.js + if (ENVIRONMENT_IS_WORKER) { + readBinary = url => { + var xhr = new XMLHttpRequest; + xhr.open("GET", url, false); + xhr.responseType = "arraybuffer"; + xhr.send(null); + return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response)); + }; + } + readAsync = async url => { + // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url. + // See https://github.com/github/fetch/pull/92#issuecomment-140665932 + // Cordova or Electron apps are typically loaded from a file:// url. + // So use XHR on webview if URL is a file URL. + if (isFileURI(url)) { + return new Promise((resolve, reject) => { + var xhr = new XMLHttpRequest; + xhr.open("GET", url, true); + xhr.responseType = "arraybuffer"; + xhr.onload = () => { + if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { + // file URLs can return 0 + resolve(xhr.response); + return; + } + reject(xhr.status); + }; + xhr.onerror = reject; + xhr.send(null); + }); + } + var response = await fetch(url, { + credentials: "same-origin" + }); + if (response.ok) { + return response.arrayBuffer(); + } + throw new Error(response.status + " : " + response.url); + }; + } +} else // end include: web_or_worker_shell_read.js +{} + +var out = Module["print"] || console.log.bind(console); + +var err = Module["printErr"] || console.error.bind(console); + +// Merge back in the overrides +Object.assign(Module, moduleOverrides); + +// Free the object hierarchy contained in the overrides, this lets the GC +// reclaim data used. +moduleOverrides = null; + +// Emit code to handle expected values on the Module object. This applies Module.x +// to the proper local x. This has two benefits: first, we only emit it if it is +// expected to arrive, and second, by using a local everywhere else that can be +// minified. +if (Module["arguments"]) arguments_ = Module["arguments"]; + +if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; + +// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message +// end include: shell.js +// include: preamble.js +// === Preamble library stuff === +// Documentation for the public APIs defined in this file must be updated in: +// site/source/docs/api_reference/preamble.js.rst +// A prebuilt local version of the documentation is available at: +// site/build/text/docs/api_reference/preamble.js.txt +// You can also build docs locally as HTML or other formats in site/ +// An online HTML version (which may be of a different version of Emscripten) +// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html +var wasmBinary = Module["wasmBinary"]; + +// Wasm globals +var wasmMemory; + +//======================================== +// Runtime essentials +//======================================== +// whether we are quitting the application. no code should run after this. +// set in exit() and abort() +var ABORT = false; + +// Memory management +var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /* BigInt64Array type is not correctly defined in closure +/** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure +/** not-t@type {!BigUint64Array} */ HEAPU64, /** @type {!Float64Array} */ HEAPF64; + +var runtimeInitialized = false; + +// include: URIUtils.js +// Prefix of data URIs emitted by SINGLE_FILE and related options. +var dataURIPrefix = "data:application/octet-stream;base64,"; + +/** + * Indicates whether filename is a base64 data URI. + * @noinline + */ var isDataURI = filename => filename.startsWith(dataURIPrefix); + +/** + * Indicates whether filename is delivered via file protocol (as opposed to http/https) + * @noinline + */ var isFileURI = filename => filename.startsWith("file://"); + +// end include: URIUtils.js +// include: runtime_shared.js +// include: runtime_stack_check.js +// end include: runtime_stack_check.js +// include: runtime_exceptions.js +// end include: runtime_exceptions.js +// include: runtime_debug.js +// end include: runtime_debug.js +// include: memoryprofiler.js +// end include: memoryprofiler.js +function updateMemoryViews() { + var b = wasmMemory.buffer; + Module["HEAP8"] = HEAP8 = new Int8Array(b); + Module["HEAP16"] = HEAP16 = new Int16Array(b); + Module["HEAPU8"] = HEAPU8 = new Uint8Array(b); + Module["HEAPU16"] = HEAPU16 = new Uint16Array(b); + Module["HEAP32"] = HEAP32 = new Int32Array(b); + Module["HEAPU32"] = HEAPU32 = new Uint32Array(b); + Module["HEAPF32"] = HEAPF32 = new Float32Array(b); + Module["HEAPF64"] = HEAPF64 = new Float64Array(b); + Module["HEAP64"] = HEAP64 = new BigInt64Array(b); + Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b); +} + +// end include: runtime_shared.js +var __ATPRERUN__ = []; + +// functions called before the runtime is initialized +var __ATINIT__ = []; + +// functions called during shutdown +var __ATPOSTRUN__ = []; + +// functions called after the main() is called +function preRun() { + if (Module["preRun"]) { + if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ]; + while (Module["preRun"].length) { + addOnPreRun(Module["preRun"].shift()); + } + } + callRuntimeCallbacks(__ATPRERUN__); +} + +function initRuntime() { + runtimeInitialized = true; + callRuntimeCallbacks(__ATINIT__); +} + +function postRun() { + if (Module["postRun"]) { + if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ]; + while (Module["postRun"].length) { + addOnPostRun(Module["postRun"].shift()); + } + } + callRuntimeCallbacks(__ATPOSTRUN__); +} + +function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb); +} + +function addOnInit(cb) { + __ATINIT__.unshift(cb); +} + +function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb); +} + +// A counter of dependencies for calling run(). If we need to +// do asynchronous work before running, increment this and +// decrement it. Incrementing must happen in a place like +// Module.preRun (used by emcc to add file preloading). +// Note that you can add dependencies in preRun, even though +// it happens right before run - run will be postponed until +// the dependencies are met. +var runDependencies = 0; + +var dependenciesFulfilled = null; + +function addRunDependency(id) { + runDependencies++; + Module["monitorRunDependencies"]?.(runDependencies); +} + +function removeRunDependency(id) { + runDependencies--; + Module["monitorRunDependencies"]?.(runDependencies); + if (runDependencies == 0) { + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled; + dependenciesFulfilled = null; + callback(); + } + } +} + +/** @param {string|number=} what */ function abort(what) { + Module["onAbort"]?.(what); + what = "Aborted(" + what + ")"; + // TODO(sbc): Should we remove printing and leave it up to whoever + // catches the exception? + err(what); + ABORT = true; + what += ". Build with -sASSERTIONS for more info."; + // Use a wasm runtime error, because a JS error might be seen as a foreign + // exception, which means we'd run destructors on it. We need the error to + // simply make the program stop. + // FIXME This approach does not work in Wasm EH because it currently does not assume + // all RuntimeErrors are from traps; it decides whether a RuntimeError is from + // a trap or not based on a hidden field within the object. So at the moment + // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that + // allows this in the wasm spec. + // Suppress closure compiler warning here. Closure compiler's builtin extern + // definition for WebAssembly.RuntimeError claims it takes no arguments even + // though it can. + // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed. + /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what); + readyPromiseReject(e); + // Throw the error whether or not MODULARIZE is set because abort is used + // in code paths apart from instantiation where an exception is expected + // to be thrown when abort is called. + throw e; +} + +var wasmBinaryFile; + +function findWasmBinary() { + var f = "argon2.wasm"; + if (!isDataURI(f)) { + return locateFile(f); + } + return f; +} + +function getBinarySync(file) { + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary); + } + if (readBinary) { + return readBinary(file); + } + throw "both async and sync fetching of the wasm failed"; +} + +async function getWasmBinary(binaryFile) { + // If we don't have the binary yet, load it asynchronously using readAsync. + if (!wasmBinary) { + // Fetch the binary using readAsync + try { + var response = await readAsync(binaryFile); + return new Uint8Array(response); + } catch {} + } + // Otherwise, getBinarySync should be able to get it synchronously + return getBinarySync(binaryFile); +} + +async function instantiateArrayBuffer(binaryFile, imports) { + try { + var binary = await getWasmBinary(binaryFile); + var instance = await WebAssembly.instantiate(binary, imports); + return instance; + } catch (reason) { + err(`failed to asynchronously prepare wasm: ${reason}`); + abort(reason); + } +} + +async function instantiateAsync(binary, binaryFile, imports) { + if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously. + !isFileURI(binaryFile) && // Avoid instantiateStreaming() on Node.js environment for now, as while + // Node.js v18.1.0 implements it, it does not have a full fetch() + // implementation yet. + // Reference: + // https://github.com/emscripten-core/emscripten/pull/16917 + !ENVIRONMENT_IS_NODE) { + try { + var response = fetch(binaryFile, { + credentials: "same-origin" + }); + var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); + return instantiationResult; + } catch (reason) { + // We expect the most common failure cause to be a bad MIME type for the binary, + // in which case falling back to ArrayBuffer instantiation should work. + err(`wasm streaming compile failed: ${reason}`); + err("falling back to ArrayBuffer instantiation"); + } + } + return instantiateArrayBuffer(binaryFile, imports); +} + +function getWasmImports() { + // prepare imports + return { + "env": wasmImports, + "wasi_snapshot_preview1": wasmImports + }; +} + +// Create the wasm instance. +// Receives the wasm imports, returns the exports. +async function createWasm() { + // Load the wasm module and create an instance of using native support in the JS engine. + // handle a generated wasm instance, receiving its exports and + // performing other necessary setup + /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) { + wasmExports = instance.exports; + wasmMemory = wasmExports["memory"]; + updateMemoryViews(); + addOnInit(wasmExports["__wasm_call_ctors"]); + removeRunDependency("wasm-instantiate"); + return wasmExports; + } + // wait for the pthread pool (if any) + addRunDependency("wasm-instantiate"); + // Prefer streaming instantiation if available. + function receiveInstantiationResult(result) { + // 'result' is a ResultObject object which has both the module and instance. + // receiveInstance() will swap in the exports (to Module.asm) so they can be called + // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line. + // When the regression is fixed, can restore the above PTHREADS-enabled path. + return receiveInstance(result["instance"]); + } + var info = getWasmImports(); + // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback + // to manually instantiate the Wasm module themselves. This allows pages to + // run the instantiation parallel to any other async startup actions they are + // performing. + // Also pthreads and wasm workers initialize the wasm instance through this + // path. + if (Module["instantiateWasm"]) { + try { + return Module["instantiateWasm"](info, receiveInstance); + } catch (e) { + err(`Module.instantiateWasm callback failed with error: ${e}`); + // If instantiation fails, reject the module ready promise. + readyPromiseReject(e); + } + } + wasmBinaryFile ??= findWasmBinary(); + try { + var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info); + var exports = receiveInstantiationResult(result); + return exports; + } catch (e) { + // If instantiation fails, reject the module ready promise. + readyPromiseReject(e); + return Promise.reject(e); + } +} + +// === Body === +// end include: preamble.js +class ExitStatus { + name="ExitStatus"; + constructor(status) { + this.message = `Program terminated with exit(${status})`; + this.status = status; + } +} + +var callRuntimeCallbacks = callbacks => { + while (callbacks.length > 0) { + // Pass the module as the first argument. + callbacks.shift()(Module); + } +}; + +var noExitRuntime = Module["noExitRuntime"] || true; + +var abortOnCannotGrowMemory = requestedSize => { + abort("OOM"); +}; + +var _emscripten_resize_heap = requestedSize => { + var oldSize = HEAPU8.length; + // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned. + requestedSize >>>= 0; + abortOnCannotGrowMemory(requestedSize); +}; + +var lengthBytesUTF8 = str => { + var len = 0; + for (var i = 0; i < str.length; ++i) { + // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code + // unit, not a Unicode code point of the character! So decode + // UTF16->UTF32->UTF8. + // See http://unicode.org/faq/utf_bom.html#utf16-3 + var c = str.charCodeAt(i); + // possibly a lead surrogate + if (c <= 127) { + len++; + } else if (c <= 2047) { + len += 2; + } else if (c >= 55296 && c <= 57343) { + len += 4; + ++i; + } else { + len += 3; + } + } + return len; +}; + +var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => { + // Parameter maxBytesToWrite is not optional. Negative values, 0, null, + // undefined and false each don't write out any bytes. + if (!(maxBytesToWrite > 0)) return 0; + var startIdx = outIdx; + var endIdx = outIdx + maxBytesToWrite - 1; + // -1 for string null terminator. + for (var i = 0; i < str.length; ++i) { + // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code + // unit, not a Unicode code point of the character! So decode + // UTF16->UTF32->UTF8. + // See http://unicode.org/faq/utf_bom.html#utf16-3 + // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description + // and https://www.ietf.org/rfc/rfc2279.txt + // and https://tools.ietf.org/html/rfc3629 + var u = str.charCodeAt(i); + // possibly a lead surrogate + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i); + u = 65536 + ((u & 1023) << 10) | (u1 & 1023); + } + if (u <= 127) { + if (outIdx >= endIdx) break; + heap[outIdx++] = u; + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break; + heap[outIdx++] = 192 | (u >> 6); + heap[outIdx++] = 128 | (u & 63); + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break; + heap[outIdx++] = 224 | (u >> 12); + heap[outIdx++] = 128 | ((u >> 6) & 63); + heap[outIdx++] = 128 | (u & 63); + } else { + if (outIdx + 3 >= endIdx) break; + heap[outIdx++] = 240 | (u >> 18); + heap[outIdx++] = 128 | ((u >> 12) & 63); + heap[outIdx++] = 128 | ((u >> 6) & 63); + heap[outIdx++] = 128 | (u & 63); + } + } + // Null-terminate the pointer to the buffer. + heap[outIdx] = 0; + return outIdx - startIdx; +}; + +var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); + +var stringToNewUTF8 = str => { + var size = lengthBytesUTF8(str) + 1; + var ret = _malloc(size); + if (ret) stringToUTF8(str, ret, size); + return ret; +}; + +var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined; + +/** + * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given + * array that contains uint8 values, returns a copy of that string as a + * Javascript String object. + * heapOrArray is either a regular array, or a JavaScript typed array view. + * @param {number=} idx + * @param {number=} maxBytesToRead + * @return {string} + */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => { + var endIdx = idx + maxBytesToRead; + var endPtr = idx; + // TextDecoder needs to know the byte length in advance, it doesn't stop on + // null terminator by itself. Also, use the length info to avoid running tiny + // strings through TextDecoder, since .subarray() allocates garbage. + // (As a tiny code save trick, compare endPtr against endIdx using a negation, + // so that undefined/NaN means Infinity) + while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; + if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { + return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); + } + var str = ""; + // If building with TextDecoder, we have already computed the string length + // above, so test loop end condition against that + while (idx < endPtr) { + // For UTF8 byte structure, see: + // http://en.wikipedia.org/wiki/UTF-8#Description + // https://www.ietf.org/rfc/rfc2279.txt + // https://tools.ietf.org/html/rfc3629 + var u0 = heapOrArray[idx++]; + if (!(u0 & 128)) { + str += String.fromCharCode(u0); + continue; + } + var u1 = heapOrArray[idx++] & 63; + if ((u0 & 224) == 192) { + str += String.fromCharCode(((u0 & 31) << 6) | u1); + continue; + } + var u2 = heapOrArray[idx++] & 63; + if ((u0 & 240) == 224) { + u0 = ((u0 & 15) << 12) | (u1 << 6) | u2; + } else { + u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63); + } + if (u0 < 65536) { + str += String.fromCharCode(u0); + } else { + var ch = u0 - 65536; + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)); + } + } + return str; +}; + +/** + * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the + * emscripten HEAP, returns a copy of that string as a Javascript String object. + * + * @param {number} ptr + * @param {number=} maxBytesToRead - An optional length that specifies the + * maximum number of bytes to read. You can omit this parameter to scan the + * string until the first 0 byte. If maxBytesToRead is passed, and the string + * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the + * string will cut short at that byte index (i.e. maxBytesToRead will not + * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing + * frequent uses of UTF8ToString() with and without maxBytesToRead may throw + * JS JIT optimizations off, so it is worth to consider consistently using one + * @return {string} + */ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""; + +var wasmImports = { + /** @export */ emscripten_resize_heap: _emscripten_resize_heap +}; + +var wasmExports = await createWasm(); + +var ___wasm_call_ctors = wasmExports["__wasm_call_ctors"]; + +var _argon2_hash = Module["_argon2_hash"] = wasmExports["argon2_hash"]; + +var _malloc = Module["_malloc"] = wasmExports["malloc"]; + +var _free = Module["_free"] = wasmExports["free"]; + +var _argon2_verify = Module["_argon2_verify"] = wasmExports["argon2_verify"]; + +var _strlen = Module["_strlen"] = wasmExports["strlen"]; + +var _argon2_error_message = Module["_argon2_error_message"] = wasmExports["argon2_error_message"]; + +var _argon2_encodedlen = Module["_argon2_encodedlen"] = wasmExports["argon2_encodedlen"]; + +var __emscripten_stack_restore = wasmExports["_emscripten_stack_restore"]; + +var __emscripten_stack_alloc = wasmExports["_emscripten_stack_alloc"]; + +var _emscripten_stack_get_current = wasmExports["emscripten_stack_get_current"]; + +// include: postamble.js +// === Auto-generated postamble setup entry stuff === +Module["UTF8ToString"] = UTF8ToString; + +Module["stringToNewUTF8"] = stringToNewUTF8; + +function run() { + if (runDependencies > 0) { + dependenciesFulfilled = run; + return; + } + preRun(); + // a preRun added a dependency, run will be called later + if (runDependencies > 0) { + dependenciesFulfilled = run; + return; + } + function doRun() { + // run may have just been called through dependencies being fulfilled just in this very frame, + // or while the async setStatus time below was happening + Module["calledRun"] = true; + if (ABORT) return; + initRuntime(); + readyPromiseResolve(Module); + Module["onRuntimeInitialized"]?.(); + postRun(); + } + if (Module["setStatus"]) { + Module["setStatus"]("Running..."); + setTimeout(() => { + setTimeout(() => Module["setStatus"](""), 1); + doRun(); + }, 1); + } else { + doRun(); + } +} + +if (Module["preInit"]) { + if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ]; + while (Module["preInit"].length > 0) { + Module["preInit"].pop()(); + } +} + +run(); + +// end include: postamble.js +// include: postamble_modularize.js +// In MODULARIZE mode we wrap the generated code in a factory function +// and return either the Module itself, or a promise of the module. +// We assign to the `moduleRtn` global here and configure closure to see +// this as and extern so it won't get minified. +moduleRtn = readyPromise; + + + return moduleRtn; +} +); +})(); +if (typeof exports === 'object' && typeof module === 'object') { + module.exports = setupModule; + // This default export looks redundant, but it allows TS to import this + // commonjs style module. + module.exports.default = setupModule; +} else if (typeof define === 'function' && define['amd']) + define([], () => setupModule); diff --git a/wasm/argon2/build/argon2.js.symbols b/wasm/argon2/build/argon2.js.symbols new file mode 100644 index 0000000..895bf3f --- /dev/null +++ b/wasm/argon2/build/argon2.js.symbols @@ -0,0 +1,40 @@ +0:emscripten_resize_heap +1:__wasm_call_ctors +2:blake2b_update +3:blake2b_compress +4:blake2b_final +5:blake2b_long +6:argon2_type2string +7:argon2_ctx +8:argon2_hash +9:argon2_verify +10:argon2_error_message +11:argon2_encodedlen +12:secure_wipe_memory +13:clear_internal_memory +14:validate_inputs +15:decode_decimal +16:from_base64 +17:to_base64 +18:b64len +19:numlen +20:fill_segment +21:fill_block +22:__memset +23:siprintf +24:strlen +25:__towrite +26:__memcpy +27:printf_core +28:out +29:getint +30:pop_arg +31:pad +32:sn_write +33:wctomb +34:emscripten_builtin_malloc +35:emscripten_builtin_free +36:sbrk +37:_emscripten_stack_restore +38:_emscripten_stack_alloc +39:emscripten_stack_get_current diff --git a/wasm/argon2/build/argon2.wasm b/wasm/argon2/build/argon2.wasm new file mode 100755 index 0000000000000000000000000000000000000000..3eec653aec0a4b52896018e37a4765861ccebbc8 GIT binary patch literal 30934 zcmeI5d5~q-UElBaw!ZImzn7H)QoO?A!Z6w7F$RpVZyKiG{$l9=Rk)o2(Fw>Ie z^=M{#(Rh=m+d>0U%2g4>sd54-i(-)i8c<@VB8tVbi&P92L@o$1h9as!xm*Dg0k$K9 zI+M@$ckX@tdKpXJ{-DY|^ZMR=g{#qlFrGhkcJKWC%g2^ZoLQMa zb!2IN`NVtXkK8wZ^h^-M(^oXZD69u@D+z|8D2T%(2%>rz1wk#T1+_Gcg9iWFNi94R z#&NA4h7Uy#MfD~)7cc&7k~aP(?9}g{zyI{oyQ5(A$dPwK*O6mKPo6w-Y~}RQauB9R zm+n1%>bsBJcXau_pjp44s?*1UJh^9Sem=OoQ`VlHUpjHmyMtDJd1dM3{Hb7ktgM({ zS~|USZ0Rx=EWFpc)Q zb~rlp=YJAju{$XK@Ur4hrw&I!@qx>V@8p_39!2qL_}*yNMK^SUVl|6hz>N#_D|l^u z=UniEoq+0KI(i|@V;A*`_lLKrvUnlrWwl~0bn!x-B(pAdwVn%I^72p+q>dKrK|H(O zUJEw=a>+s-`BAN%!F88{ z5_V%3f|YgUs=jOCtsS8x8nQTb5!ePU?ui73iTW6;0VHa8p^~~d{k3Kkt&W|$JOB!? z47S>fh##K&$|qj>>7V?$kG%LN!TGG^8TOZd|Kp$i*nj%+#}A&*x+=MO?!%w?${&B? zCqMhpPp_WOhCK0~KL2n3&)@&I5B|ib=?7x3jjzjUy3Axo*L2p-k; zW;U!#kR@|}^MxUXV6T|8sWfrTKH&7hoJRxPwDI=1^!(h+ zqj~C*vMPKuZ~76R83Y4r2K$49g>KY!t@N=?rFGX~#Ey~DeJ~$&bsMoPc3m5BudlZ5 zA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6inqTI_dh5+NpoVEA>%-!O{5YCp-ni_w#TnoK;uRrM4;;t`!dIqaTe?@kwK7 zysNKt&dvPr%)5fuoO~d-7|w6ZAVXTEtx;IG{2?n&ZEoA z?>xP9d~@GodHM9Q6GvC(kGtbXSB`G3eB0^!=iTXh+`Rv@kM7LTrK9)HugotkyQ53< zhQZ0xr|xy9mjkq_L@A8uR@-VUbsA3gPMck<||dH;CN{5uDpta9bP zrTL@BmxJ3+uQ1^02kyPkRYkYiAG&n*XCja4?@T)T`;#b^4tp_u$X*`JiOU@rozMgBvv2)hP4FgSX6Ye)c`84%PL@_n(FzapWx z|Il0CT5+f1T2(C8m-9LA{2wxP`un9ndi2GJct!H6THpO)y^G!-PSJsx!kc+U&OX{ z+dA7j_C9)i8-~-T9yodOwb+Iq!T7uvBhm z;1g5!CzLJnnd9^Gd_F zao$(3#@0UVs1*Ad1uYe~WV45Z;#1>k*ba*SF`n+(t=9Id48y|+OO6w-3I*T|9yW#%_m2?E1 literal 0 HcmV?d00001 From 2c71f8990221cc11c9b9a2a4c1e9127b9e192614 Mon Sep 17 00:00:00 2001 From: Keith Miller Date: Tue, 11 Feb 2025 11:06:26 -0500 Subject: [PATCH 2/3] Remove old argon2 code and move remaining sources. --- wasm/argon2-benchmark.js | 44 - wasm/argon2-bundle.js | 3768 ----------------- wasm/argon2-simd.wasm | Bin 26935 -> 0 bytes wasm/argon2.js | 118 - wasm/argon2.wasm | Bin 25914 -> 0 bytes wasm/argon2/CMakeLists.txt | 33 - wasm/argon2/README.md | 11 - wasm/argon2/build.log | 2 +- wasm/argon2/build.sh | 43 +- wasm/argon2/clean-cmake.sh | 9 - wasm/argon2/emcc_version.txt | 5 - wasm/argon2/{argon2 => }/include/argon2.h | 0 wasm/argon2/{argon2 => }/src/argon2.c | 0 wasm/argon2/src/argon2_library.c | 171 - wasm/argon2/{argon2 => }/src/bench.c | 0 .../{argon2 => }/src/blake2/blake2-impl.h | 0 wasm/argon2/{argon2 => }/src/blake2/blake2.h | 0 wasm/argon2/{argon2 => }/src/blake2/blake2b.c | 0 .../src/blake2/blamka-round-opt.h | 0 .../src/blake2/blamka-round-ref.h | 0 wasm/argon2/{argon2 => }/src/core.c | 0 wasm/argon2/{argon2 => }/src/core.h | 0 wasm/argon2/{argon2 => }/src/encoding.c | 0 wasm/argon2/{argon2 => }/src/encoding.h | 0 wasm/argon2/{argon2 => }/src/genkat.c | 0 wasm/argon2/{argon2 => }/src/genkat.h | 0 wasm/argon2/{argon2 => }/src/opt.c | 0 wasm/argon2/{argon2 => }/src/ref.c | 0 wasm/argon2/{argon2 => }/src/run.c | 0 wasm/argon2/{argon2 => }/src/test.c | 0 wasm/argon2/{argon2 => }/src/thread.c | 0 wasm/argon2/{argon2 => }/src/thread.h | 0 32 files changed, 8 insertions(+), 4196 deletions(-) delete mode 100644 wasm/argon2-benchmark.js delete mode 100644 wasm/argon2-bundle.js delete mode 100755 wasm/argon2-simd.wasm delete mode 100644 wasm/argon2.js delete mode 100755 wasm/argon2.wasm delete mode 100644 wasm/argon2/CMakeLists.txt delete mode 100644 wasm/argon2/README.md delete mode 100755 wasm/argon2/clean-cmake.sh delete mode 100644 wasm/argon2/emcc_version.txt rename wasm/argon2/{argon2 => }/include/argon2.h (100%) rename wasm/argon2/{argon2 => }/src/argon2.c (100%) delete mode 100644 wasm/argon2/src/argon2_library.c rename wasm/argon2/{argon2 => }/src/bench.c (100%) rename wasm/argon2/{argon2 => }/src/blake2/blake2-impl.h (100%) rename wasm/argon2/{argon2 => }/src/blake2/blake2.h (100%) rename wasm/argon2/{argon2 => }/src/blake2/blake2b.c (100%) rename wasm/argon2/{argon2 => }/src/blake2/blamka-round-opt.h (100%) rename wasm/argon2/{argon2 => }/src/blake2/blamka-round-ref.h (100%) rename wasm/argon2/{argon2 => }/src/core.c (100%) rename wasm/argon2/{argon2 => }/src/core.h (100%) rename wasm/argon2/{argon2 => }/src/encoding.c (100%) rename wasm/argon2/{argon2 => }/src/encoding.h (100%) rename wasm/argon2/{argon2 => }/src/genkat.c (100%) rename wasm/argon2/{argon2 => }/src/genkat.h (100%) rename wasm/argon2/{argon2 => }/src/opt.c (100%) rename wasm/argon2/{argon2 => }/src/ref.c (100%) rename wasm/argon2/{argon2 => }/src/run.c (100%) rename wasm/argon2/{argon2 => }/src/test.c (100%) rename wasm/argon2/{argon2 => }/src/thread.c (100%) rename wasm/argon2/{argon2 => }/src/thread.h (100%) diff --git a/wasm/argon2-benchmark.js b/wasm/argon2-benchmark.js deleted file mode 100644 index 3c82ca6..0000000 --- a/wasm/argon2-benchmark.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2023 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -async function doRun() { - let start = benchmarkTime(); - - if (!isInBrowser) { - globalThis.argon2WasmSimdBlob = Module.argon2WasmSimdBlob; - globalThis.argon2WasmBlob = Module.argon2WasmBlob; - } - - await instantiateArgon2WasmInstance(); - await testArgon2HashAndVerify(); - reportCompileTime(benchmarkTime() - start); - - start = benchmarkTime(); - - for (let i = 0; i < 5; ++i) - await testArgon2HashAndVerify(); - - reportRunTime(benchmarkTime() - start) -} diff --git a/wasm/argon2-bundle.js b/wasm/argon2-bundle.js deleted file mode 100644 index 74b1c3a..0000000 --- a/wasm/argon2-bundle.js +++ /dev/null @@ -1,3768 +0,0 @@ -(function () { - function r(e, n, t) { - function o(i, f) { - if (!n[i]) { - if (!e[i]) { - var c = "function" == typeof require && require; - if (!f && c) return c(i, !0); - if (u) return u(i, !0); - var a = new Error("Cannot find module '" + i + "'"); - throw a.code = "MODULE_NOT_FOUND", a - } - var p = n[i] = { - exports: {} - }; - e[i][0].call(p.exports, function (r) { - var n = e[i][1][r]; - return o(n || r) - }, p, p.exports, r, e, n, t) - } - return n[i].exports - } - for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]); - return o - } - return r -})()({ - 1: [function (require, module, exports) { - // ************************ CHANGE START ************************ - globalThis.argon2 = require('argon2-browser'); - // ************************ CHANGE END ************************ - }, { - "argon2-browser": 3 - }], - 2: [function (require, module, exports) { - (function (process, __dirname) { - (function () { - var Argon2Module = typeof self !== "undefined" && typeof self.Argon2Module !== "undefined" ? self.Argon2Module : {}; - var jsModule = Argon2Module; - var moduleOverrides = {}; - var key; - for (key in Argon2Module) { - if (Argon2Module.hasOwnProperty(key)) { - moduleOverrides[key] = Argon2Module[key] - } - } - var arguments_ = []; - var thisProgram = "./this.program"; - var quit_ = function (status, toThrow) { - throw toThrow - }; - var ENVIRONMENT_IS_WEB = false; - var ENVIRONMENT_IS_WORKER = false; - var ENVIRONMENT_IS_NODE = false; - var ENVIRONMENT_IS_SHELL = false; - ENVIRONMENT_IS_WEB = typeof window === "object"; - ENVIRONMENT_IS_WORKER = typeof importScripts === "function"; - ENVIRONMENT_IS_NODE = typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string"; - ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; - var scriptDirectory = ""; - - function locateFile(path) { - if (Argon2Module["locateFile"]) { - return Argon2Module["locateFile"](path, scriptDirectory) - } - return scriptDirectory + path - } - var read_, readAsync, readBinary, setWindowTitle; - var nodeFS; - var nodePath; - if (ENVIRONMENT_IS_NODE) { - if (ENVIRONMENT_IS_WORKER) { - scriptDirectory = require("path").dirname(scriptDirectory) + "/" - } else { - scriptDirectory = __dirname + "/" - } - read_ = function shell_read(filename, binary) { - if (!nodeFS) nodeFS = require("fs"); - if (!nodePath) nodePath = require("path"); - filename = nodePath["normalize"](filename); - return nodeFS["readFileSync"](filename, binary ? null : "utf8") - }; - readBinary = function readBinary(filename) { - var ret = read_(filename, true); - if (!ret.buffer) { - ret = new Uint8Array(ret) - } - assert(ret.buffer); - return ret - }; - if (process["argv"].length > 1) { - thisProgram = process["argv"][1].replace(/\\/g, "/") - } - arguments_ = process["argv"].slice(2); - if (typeof module !== "undefined") { - module["exports"] = Argon2Module - } - process["on"]("uncaughtException", function (ex) { - if (!(ex instanceof ExitStatus)) { - throw ex - } - }); - process["on"]("unhandledRejection", abort); - quit_ = function (status) { - process["exit"](status) - }; - Argon2Module["inspect"] = function () { - return "[Emscripten Argon2Module object]" - } - } else if (ENVIRONMENT_IS_SHELL) { - if (typeof read != "undefined") { - read_ = function shell_read(f) { - return read(f) - } - } - readBinary = function readBinary(f) { - var data; - if (typeof readbuffer === "function") { - return new Uint8Array(readbuffer(f)) - } - data = read(f, "binary"); - assert(typeof data === "object"); - return data - }; - if (typeof scriptArgs != "undefined") { - arguments_ = scriptArgs - } else if (typeof arguments != "undefined") { - arguments_ = arguments - } - if (typeof quit === "function") { - quit_ = function (status) { - quit(status) - } - } - // ************************ CHANGE START ************************ - // if (typeof print !== "undefined") { - // if (typeof console === "undefined") console = {}; - // console.log = print; - // console.warn = console.error = typeof printErr !== "undefined" ? printErr : print - // } - // ************************ CHANGE END ************************ - } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { - if (ENVIRONMENT_IS_WORKER) { - scriptDirectory = self.location.href - } else if (typeof document !== "undefined" && document.currentScript) { - scriptDirectory = document.currentScript.src - } - if (scriptDirectory.indexOf("blob:") !== 0) { - scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf("/") + 1) - } else { - scriptDirectory = "" - } { - read_ = function (url) { - var xhr = new XMLHttpRequest; - xhr.open("GET", url, false); - xhr.send(null); - return xhr.responseText - }; - if (ENVIRONMENT_IS_WORKER) { - readBinary = function (url) { - var xhr = new XMLHttpRequest; - xhr.open("GET", url, false); - xhr.responseType = "arraybuffer"; - xhr.send(null); - return new Uint8Array(xhr.response) - } - } - readAsync = function (url, onload, onerror) { - var xhr = new XMLHttpRequest; - xhr.open("GET", url, true); - xhr.responseType = "arraybuffer"; - xhr.onload = function () { - if (xhr.status == 200 || xhr.status == 0 && xhr.response) { - onload(xhr.response); - return - } - onerror() - }; - xhr.onerror = onerror; - xhr.send(null) - } - } - setWindowTitle = function (title) { - document.title = title - } - } else { } - var out = Argon2Module["print"] || console.log.bind(console); - var err = Argon2Module["printErr"] || console.warn.bind(console); - for (key in moduleOverrides) { - if (moduleOverrides.hasOwnProperty(key)) { - Argon2Module[key] = moduleOverrides[key] - } - } - moduleOverrides = null; - if (Argon2Module["arguments"]) arguments_ = Argon2Module["arguments"]; - if (Argon2Module["thisProgram"]) thisProgram = Argon2Module["thisProgram"]; - if (Argon2Module["quit"]) quit_ = Argon2Module["quit"]; - var wasmBinary; - if (Argon2Module["wasmBinary"]) wasmBinary = Argon2Module["wasmBinary"]; - var noExitRuntime = Argon2Module["noExitRuntime"] || true; - if (typeof WebAssembly !== "object") { - abort("no native wasm support detected") - } - var wasmMemory; - var ABORT = false; - var EXITSTATUS; - - function assert(condition, text) { - if (!condition) { - abort("Assertion failed: " + text) - } - } - var ALLOC_NORMAL = 0; - var ALLOC_STACK = 1; - - function allocate(slab, allocator) { - var ret; - if (allocator == ALLOC_STACK) { - ret = stackAlloc(slab.length) - } else { - ret = _malloc(slab.length) - } - if (slab.subarray || slab.slice) { - HEAPU8.set(slab, ret) - } else { - HEAPU8.set(new Uint8Array(slab), ret) - } - return ret - } - var UTF8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : undefined; - - function UTF8ArrayToString(heap, idx, maxBytesToRead) { - var endIdx = idx + maxBytesToRead; - var endPtr = idx; - while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr; - if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) { - return UTF8Decoder.decode(heap.subarray(idx, endPtr)) - } else { - var str = ""; - while (idx < endPtr) { - var u0 = heap[idx++]; - if (!(u0 & 128)) { - str += String.fromCharCode(u0); - continue - } - var u1 = heap[idx++] & 63; - if ((u0 & 224) == 192) { - str += String.fromCharCode((u0 & 31) << 6 | u1); - continue - } - var u2 = heap[idx++] & 63; - if ((u0 & 240) == 224) { - u0 = (u0 & 15) << 12 | u1 << 6 | u2 - } else { - u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heap[idx++] & 63 - } - if (u0 < 65536) { - str += String.fromCharCode(u0) - } else { - var ch = u0 - 65536; - str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023) - } - } - } - return str - } - - function UTF8ToString(ptr, maxBytesToRead) { - return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "" - } - - function alignUp(x, multiple) { - if (x % multiple > 0) { - x += multiple - x % multiple - } - return x - } - var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; - - function updateGlobalBufferAndViews(buf) { - buffer = buf; - Argon2Module["HEAP8"] = HEAP8 = new Int8Array(buf); - Argon2Module["HEAP16"] = HEAP16 = new Int16Array(buf); - Argon2Module["HEAP32"] = HEAP32 = new Int32Array(buf); - Argon2Module["HEAPU8"] = HEAPU8 = new Uint8Array(buf); - Argon2Module["HEAPU16"] = HEAPU16 = new Uint16Array(buf); - Argon2Module["HEAPU32"] = HEAPU32 = new Uint32Array(buf); - Argon2Module["HEAPF32"] = HEAPF32 = new Float32Array(buf); - Argon2Module["HEAPF64"] = HEAPF64 = new Float64Array(buf) - } - var INITIAL_MEMORY = Argon2Module["INITIAL_MEMORY"] || 16777216; - var wasmTable; - var __ATPRERUN__ = []; - var __ATINIT__ = []; - var __ATPOSTRUN__ = []; - var runtimeInitialized = false; - - function preRun() { - if (Argon2Module["preRun"]) { - if (typeof Argon2Module["preRun"] == "function") Argon2Module["preRun"] = [Argon2Module["preRun"]]; - while (Argon2Module["preRun"].length) { - addOnPreRun(Argon2Module["preRun"].shift()) - } - } - callRuntimeCallbacks(__ATPRERUN__) - } - - function initRuntime() { - runtimeInitialized = true; - callRuntimeCallbacks(__ATINIT__) - } - - function postRun() { - if (Argon2Module["postRun"]) { - if (typeof Argon2Module["postRun"] == "function") Argon2Module["postRun"] = [Argon2Module["postRun"]]; - while (Argon2Module["postRun"].length) { - addOnPostRun(Argon2Module["postRun"].shift()) - } - } - callRuntimeCallbacks(__ATPOSTRUN__) - } - - function addOnPreRun(cb) { - __ATPRERUN__.unshift(cb) - } - - function addOnInit(cb) { - __ATINIT__.unshift(cb) - } - - function addOnPostRun(cb) { - __ATPOSTRUN__.unshift(cb) - } - var runDependencies = 0; - var runDependencyWatcher = null; - var dependenciesFulfilled = null; - - function addRunDependency(id) { - runDependencies++; - if (Argon2Module["monitorRunDependencies"]) { - Argon2Module["monitorRunDependencies"](runDependencies) - } - } - - function removeRunDependency(id) { - runDependencies--; - if (Argon2Module["monitorRunDependencies"]) { - Argon2Module["monitorRunDependencies"](runDependencies) - } - if (runDependencies == 0) { - if (runDependencyWatcher !== null) { - clearInterval(runDependencyWatcher); - runDependencyWatcher = null - } - if (dependenciesFulfilled) { - var callback = dependenciesFulfilled; - dependenciesFulfilled = null; - callback() - } - } - } - Argon2Module["preloadedImages"] = {}; - Argon2Module["preloadedAudios"] = {}; - - function abort(what) { - if (Argon2Module["onAbort"]) { - Argon2Module["onAbort"](what) - } - what += ""; - err(what); - ABORT = true; - EXITSTATUS = 1; - what = "abort(" + what + "). Build with -s ASSERTIONS=1 for more info."; - var e = new WebAssembly.RuntimeError(what); - throw e - } - var dataURIPrefix = "data:application/octet-stream;base64,"; - - function isDataURI(filename) { - return filename.startsWith(dataURIPrefix) - } - - function isFileURI(filename) { - return filename.startsWith("file://") - } - var wasmBinaryFile = "argon2.wasm"; - if (!isDataURI(wasmBinaryFile)) { - wasmBinaryFile = locateFile(wasmBinaryFile) - } - - function getBinary(file) { - try { - if (file == wasmBinaryFile && wasmBinary) { - return new Uint8Array(wasmBinary) - } - if (readBinary) { - return readBinary(file) - } else { - throw "both async and sync fetching of the wasm failed" - } - } catch (err) { - abort(err) - } - } - - function getBinaryPromise() { - if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { - if (typeof fetch === "function" && !isFileURI(wasmBinaryFile)) { - return fetch(wasmBinaryFile, { - credentials: "same-origin" - }).then(function (response) { - if (!response["ok"]) { - throw "failed to load wasm binary file at '" + wasmBinaryFile + "'" - } - return response["arrayBuffer"]() - }).catch(function () { - return getBinary(wasmBinaryFile) - }) - } else { - if (readAsync) { - return new Promise(function (resolve, reject) { - readAsync(wasmBinaryFile, function (response) { - resolve(new Uint8Array(response)) - }, reject) - }) - } - } - } - return Promise.resolve().then(function () { - return getBinary(wasmBinaryFile) - }) - } - - function createWasm() { - var info = { - "a": asmLibraryArg - }; - - function receiveInstance(instance, module) { - var exports = instance.exports; - Argon2Module["asm"] = exports; - wasmMemory = Argon2Module["asm"]["c"]; - updateGlobalBufferAndViews(wasmMemory.buffer); - wasmTable = Argon2Module["asm"]["k"]; - addOnInit(Argon2Module["asm"]["d"]); - removeRunDependency("wasm-instantiate") - } - addRunDependency("wasm-instantiate"); - - function receiveInstantiationResult(result) { - // ************************ CHANGE START ************************ - if (result) - // ************************ CHANGE END ************************ - receiveInstance(result["instance"]) - } - - function instantiateArrayBuffer(receiver) { - return getBinaryPromise().then(function (_) { - // ************************ CHANGE START ************************ - let binary; - if (globalThis.argon2WasmSimdBlob || Module.argon2WasmSimdBlob) { - binary = globalThis.argon2WasmSimdBlob || Module.argon2WasmSimdBlob; - // console.warn("argon2 instantiating wasm simd binary"); - } - if (globalThis.argon2WasmBlob || Module.argon2WasmBlob) { - binary = globalThis.argon2WasmBlob || Module.argon2WasmBlob; - // console.warn("argon2 instantiating wasm binary"); - } - return WebAssembly.instantiate(binary, info); - // ************************ CHANGE END ************************ - }).then(receiver, function (reason) { - err("failed to asynchronously prepare wasm: " + reason); - abort(reason) - }) - } - - function instantiateAsync() { - if (!wasmBinary && typeof WebAssembly.instantiateStreaming === "function" && !isDataURI(wasmBinaryFile) && !isFileURI(wasmBinaryFile) && typeof fetch === "function") { - return fetch(wasmBinaryFile, { - credentials: "same-origin" - }).then(function (response) { - var result = WebAssembly.instantiateStreaming(response, info); - return result.then(receiveInstantiationResult, function (reason) { - err("wasm streaming compile failed: " + reason); - err("falling back to ArrayBuffer instantiation"); - return instantiateArrayBuffer(receiveInstantiationResult) - }) - }) - } else { - return instantiateArrayBuffer(receiveInstantiationResult) - } - } - if (Argon2Module["instantiateWasm"]) { - try { - var exports = Argon2Module["instantiateWasm"](info, receiveInstance); - return exports - } catch (e) { - err("Argon2Module.instantiateWasm callback failed with error: " + e); - return false - } - } - instantiateAsync(); - return {} - } - - function callRuntimeCallbacks(callbacks) { - while (callbacks.length > 0) { - var callback = callbacks.shift(); - if (typeof callback == "function") { - callback(Argon2Module); - continue - } - var func = callback.func; - if (typeof func === "number") { - if (callback.arg === undefined) { - wasmTable.get(func)() - } else { - wasmTable.get(func)(callback.arg) - } - } else { - func(callback.arg === undefined ? null : callback.arg) - } - } - } - - function _emscripten_memcpy_big(dest, src, num) { - HEAPU8.copyWithin(dest, src, src + num) - } - - function emscripten_realloc_buffer(size) { - try { - wasmMemory.grow(size - buffer.byteLength + 65535 >>> 16); - updateGlobalBufferAndViews(wasmMemory.buffer); - return 1 - } catch (e) { } - } - - function _emscripten_resize_heap(requestedSize) { - var oldSize = HEAPU8.length; - requestedSize = requestedSize >>> 0; - var maxHeapSize = 2147418112; - if (requestedSize > maxHeapSize) { - return false - } - for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { - var overGrownHeapSize = oldSize * (1 + .2 / cutDown); - overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296); - var newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536)); - var replacement = emscripten_realloc_buffer(newSize); - if (replacement) { - return true - } - } - return false - } - var asmLibraryArg = { - "a": _emscripten_memcpy_big, - "b": _emscripten_resize_heap - }; - var asm = createWasm(); - var ___wasm_call_ctors = Argon2Module["___wasm_call_ctors"] = function () { - return (___wasm_call_ctors = Argon2Module["___wasm_call_ctors"] = Argon2Module["asm"]["d"]).apply(null, arguments) - }; - var _argon2_hash = Argon2Module["_argon2_hash"] = function () { - return (_argon2_hash = Argon2Module["_argon2_hash"] = Argon2Module["asm"]["e"]).apply(null, arguments) - }; - var _malloc = Argon2Module["_malloc"] = function () { - return (_malloc = Argon2Module["_malloc"] = Argon2Module["asm"]["f"]).apply(null, arguments) - }; - var _free = Argon2Module["_free"] = function () { - return (_free = Argon2Module["_free"] = Argon2Module["asm"]["g"]).apply(null, arguments) - }; - var _argon2_verify = Argon2Module["_argon2_verify"] = function () { - return (_argon2_verify = Argon2Module["_argon2_verify"] = Argon2Module["asm"]["h"]).apply(null, arguments) - }; - var _argon2_error_message = Argon2Module["_argon2_error_message"] = function () { - return (_argon2_error_message = Argon2Module["_argon2_error_message"] = Argon2Module["asm"]["i"]).apply(null, arguments) - }; - var _argon2_encodedlen = Argon2Module["_argon2_encodedlen"] = function () { - return (_argon2_encodedlen = Argon2Module["_argon2_encodedlen"] = Argon2Module["asm"]["j"]).apply(null, arguments) - }; - var _argon2_hash_ext = Argon2Module["_argon2_hash_ext"] = function () { - return (_argon2_hash_ext = Argon2Module["_argon2_hash_ext"] = Argon2Module["asm"]["l"]).apply(null, arguments) - }; - var _argon2_verify_ext = Argon2Module["_argon2_verify_ext"] = function () { - return (_argon2_verify_ext = Argon2Module["_argon2_verify_ext"] = Argon2Module["asm"]["m"]).apply(null, arguments) - }; - var stackAlloc = Argon2Module["stackAlloc"] = function () { - return (stackAlloc = Argon2Module["stackAlloc"] = Argon2Module["asm"]["n"]).apply(null, arguments) - }; - Argon2Module["allocate"] = allocate; - Argon2Module["UTF8ToString"] = UTF8ToString; - Argon2Module["ALLOC_NORMAL"] = ALLOC_NORMAL; - var calledRun; - - function ExitStatus(status) { - this.name = "ExitStatus"; - this.message = "Program terminated with exit(" + status + ")"; - this.status = status - } - dependenciesFulfilled = function runCaller() { - if (!calledRun) run(); - if (!calledRun) dependenciesFulfilled = runCaller - }; - - function run(args) { - args = args || arguments_; - if (runDependencies > 0) { - return - } - preRun(); - if (runDependencies > 0) { - return - } - - function doRun() { - if (calledRun) return; - calledRun = true; - Argon2Module["calledRun"] = true; - if (ABORT) return; - initRuntime(); - if (Argon2Module["onRuntimeInitialized"]) Argon2Module["onRuntimeInitialized"](); - postRun() - } - if (Argon2Module["setStatus"]) { - Argon2Module["setStatus"]("Running..."); - setTimeout(function () { - setTimeout(function () { - Argon2Module["setStatus"]("") - }, 1); - doRun() - }, 1) - } else { - doRun() - } - } - Argon2Module["run"] = run; - if (Argon2Module["preInit"]) { - if (typeof Argon2Module["preInit"] == "function") Argon2Module["preInit"] = [Argon2Module["preInit"]]; - while (Argon2Module["preInit"].length > 0) { - Argon2Module["preInit"].pop()() - } - } - run(); - if (typeof module !== "undefined") module.exports = Argon2Module; - Argon2Module.unloadRuntime = function () { - if (typeof self !== "undefined") { - delete self.Argon2Module - } - Argon2Module = jsModule = wasmMemory = wasmTable = asm = buffer = HEAP8 = HEAPU8 = HEAP16 = HEAPU16 = HEAP32 = HEAPU32 = HEAPF32 = HEAPF64 = undefined; - if (typeof module !== "undefined") { - delete module.exports - } - }; - - }).call(this) - }).call(this, require('_process'), "/node_modules/argon2-browser/dist") - }, { - "_process": 9, - "fs": 4, - "path": 8 - }], - 3: [function (require, module, exports) { - (function (Buffer) { - (function () { - "use strict"; - - (function (root, factory) { - if (typeof define === 'function' && define.amd) { - define([], factory); - } else if (typeof module === 'object' && module.exports) { - module.exports = factory(); - } else { - root.argon2 = factory(); - } - })(typeof self !== 'undefined' ? self : void 0, function () { - const global = typeof self !== 'undefined' ? self : this; - - /** - * @enum - */ - const ArgonType = { - Argon2d: 0, - Argon2i: 1, - Argon2id: 2 - }; - - function loadModule(mem) { - if (loadModule._promise) { - return loadModule._promise; - } - if (loadModule._module) { - // console.log("loadModule cached"); - return Promise.resolve(loadModule._module); - } - let promise; - if (global.process && global.process.versions && global.process.versions.node) { - promise = loadWasmModule().then(Argon2Module => new Promise(resolve => { - Argon2Module.postRun = () => resolve(Argon2Module); - })); - } else { - promise = loadWasmBinary().then(wasmBinary => { - const wasmMemory = mem ? createWasmMemory(mem) : undefined; - return initWasm(wasmBinary, wasmMemory); - }); - } - loadModule._promise = promise; - return promise.then(Argon2Module => { - loadModule._module = Argon2Module; - delete loadModule._promise; - return Argon2Module; - }); - } - - function initWasm(wasmBinary, wasmMemory) { - return new Promise(resolve => { - global.Argon2Module = { - wasmBinary, - wasmMemory, - postRun() { - resolve(Argon2Module); - } - }; - return loadWasmModule(); - }); - } - - function loadWasmModule() { - if (global.loadArgon2WasmModule) { - return global.loadArgon2WasmModule(); - } - if (typeof require === 'function') { - return Promise.resolve(require('../dist/argon2.js')); - } - return import('../dist/argon2.js'); - } - - function loadWasmBinary() { - if (global.loadArgon2WasmBinary) { - return global.loadArgon2WasmBinary(); - } - - // ************************ CHANGE START ************************ - // if (typeof require === 'function') { - // return Promise.resolve(require('../dist/argon2.wasm')).then( - // (wasmModule) => { - // return decodeWasmBinary(wasmModule); - // } - // ); - // } - // const wasmPath = global.argon2WasmPath || 'node_modules/argon2-browser/dist/argon2.wasm'; - // return fetch(wasmPath).then(response => response.arrayBuffer()).then(ab => new Uint8Array(ab)); - return Promise.resolve(new Uint8Array(0)); - // ************************ CHANGE END ************************ - } - - // ************************ CHANGE START ************************ - // function decodeWasmBinary(base64) { - // const text = atob(base64); - // const binary = new Uint8Array(new ArrayBuffer(text.length)); - // for (let i = 0; i < text.length; i++) { - // binary[i] = text.charCodeAt(i); - // } - // return binary; - // } - // ************************ CHANGE END ************************ - - function createWasmMemory(mem) { - const KB = 1024; - const MB = 1024 * KB; - const GB = 1024 * MB; - const WASM_PAGE_SIZE = 64 * KB; - const totalMemory = (2 * GB - 64 * KB) / WASM_PAGE_SIZE; - const initialMemory = Math.min(Math.max(Math.ceil(mem * KB / WASM_PAGE_SIZE), 256) + 256, totalMemory); - return new WebAssembly.Memory({ - initial: initialMemory, - maximum: totalMemory - }); - } - - function allocateArray(Argon2Module, arr) { - return Argon2Module.allocate(arr, 'i8', Argon2Module.ALLOC_NORMAL); - } - - function allocateArrayStr(Argon2Module, arr) { - const nullTerminatedArray = new Uint8Array([...arr, 0]); - return allocateArray(Argon2Module, nullTerminatedArray); - } - - function encodeUtf8(str) { - if (typeof str !== 'string') { - return str; - } - if (typeof TextEncoder === 'function') { - return new TextEncoder().encode(str); - } else if (typeof Buffer === 'function') { - return Buffer.from(str); - } else { - throw new Error("Don't know how to encode UTF8"); - } - } - - /** - * Argon2 hash - * @param {string|Uint8Array} params.pass - password string - * @param {string|Uint8Array} params.salt - salt string - * @param {number} [params.time=1] - the number of iterations - * @param {number} [params.mem=1024] - used memory, in KiB - * @param {number} [params.hashLen=24] - desired hash length - * @param {number} [params.parallelism=1] - desired parallelism - * @param {number} [params.type=argon2.ArgonType.Argon2d] - hash type: - * argon2.ArgonType.Argon2d - * argon2.ArgonType.Argon2i - * argon2.ArgonType.Argon2id - * - * @return Promise - * - * @example - * argon2.hash({ pass: 'password', salt: 'somesalt' }) - * .then(h => console.log(h.hash, h.hashHex, h.encoded)) - * .catch(e => console.error(e.message, e.code)) - */ - function argon2Hash(params) { - const mCost = params.mem || 1024; - return loadModule(mCost).then(Argon2Module => { - const tCost = params.time || 1; - const parallelism = params.parallelism || 1; - const pwdEncoded = encodeUtf8(params.pass); - const pwd = allocateArrayStr(Argon2Module, pwdEncoded); - const pwdlen = pwdEncoded.length; - const saltEncoded = encodeUtf8(params.salt); - const salt = allocateArrayStr(Argon2Module, saltEncoded); - const saltlen = saltEncoded.length; - const argon2Type = params.type || ArgonType.Argon2d; - const hash = Argon2Module.allocate(new Array(params.hashLen || 24), 'i8', Argon2Module.ALLOC_NORMAL); - const secret = params.secret ? allocateArray(Argon2Module, params.secret) : 0; - const secretlen = params.secret ? params.secret.byteLength : 0; - const ad = params.ad ? allocateArray(Argon2Module, params.ad) : 0; - const adlen = params.ad ? params.ad.byteLength : 0; - const hashlen = params.hashLen || 24; - const encodedlen = Argon2Module._argon2_encodedlen(tCost, mCost, parallelism, saltlen, hashlen, argon2Type); - const encoded = Argon2Module.allocate(new Array(encodedlen + 1), 'i8', Argon2Module.ALLOC_NORMAL); - const version = 0x13; - let err; - let res; - try { - res = Argon2Module._argon2_hash_ext(tCost, mCost, parallelism, pwd, pwdlen, salt, saltlen, hash, hashlen, encoded, encodedlen, argon2Type, secret, secretlen, ad, adlen, version); - } catch (e) { - err = e; - } - let result; - if (res === 0 && !err) { - let hashStr = ''; - const hashArr = new Uint8Array(hashlen); - for (let i = 0; i < hashlen; i++) { - const byte = Argon2Module.HEAP8[hash + i]; - hashArr[i] = byte; - hashStr += ('0' + (0xff & byte).toString(16)).slice(-2); - } - const encodedStr = Argon2Module.UTF8ToString(encoded); - result = { - hash: hashArr, - hashHex: hashStr, - encoded: encodedStr - }; - } else { - try { - if (!err) { - err = Argon2Module.UTF8ToString(Argon2Module._argon2_error_message(res)); - } - } catch (e) { } - result = { - message: err, - code: res - }; - } - try { - Argon2Module._free(pwd); - Argon2Module._free(salt); - Argon2Module._free(hash); - Argon2Module._free(encoded); - if (ad) { - Argon2Module._free(ad); - } - if (secret) { - Argon2Module._free(secret); - } - } catch (e) { } - if (err) { - throw result; - } else { - return result; - } - }); - } - - /** - * Argon2 verify function - * @param {string} params.pass - password string - * @param {string|Uint8Array} params.encoded - encoded hash - * @param {number} [params.type=argon2.ArgonType.Argon2d] - hash type: - * argon2.ArgonType.Argon2d - * argon2.ArgonType.Argon2i - * argon2.ArgonType.Argon2id - * - * @returns Promise - * - * @example - * argon2.verify({ pass: 'password', encoded: 'encoded-hash' }) - * .then(() => console.log('OK')) - * .catch(e => console.error(e.message, e.code)) - */ - function argon2Verify(params) { - return loadModule().then(Argon2Module => { - const pwdEncoded = encodeUtf8(params.pass); - const pwd = allocateArrayStr(Argon2Module, pwdEncoded); - const pwdlen = pwdEncoded.length; - const secret = params.secret ? allocateArray(Argon2Module, params.secret) : 0; - const secretlen = params.secret ? params.secret.byteLength : 0; - const ad = params.ad ? allocateArray(Argon2Module, params.ad) : 0; - const adlen = params.ad ? params.ad.byteLength : 0; - const encEncoded = encodeUtf8(params.encoded); - const enc = allocateArrayStr(Argon2Module, encEncoded); - let argon2Type = params.type; - if (argon2Type === undefined) { - let typeStr = params.encoded.split('$')[1]; - if (typeStr) { - typeStr = typeStr.replace('a', 'A'); - argon2Type = ArgonType[typeStr] || ArgonType.Argon2d; - } - } - let err; - let res; - try { - res = Argon2Module._argon2_verify_ext(enc, pwd, pwdlen, secret, secretlen, ad, adlen, argon2Type); - } catch (e) { - err = e; - } - let result; - if (res || err) { - try { - if (!err) { - err = Argon2Module.UTF8ToString(Argon2Module._argon2_error_message(res)); - } - } catch (e) { } - result = { - message: err, - code: res - }; - } - try { - Argon2Module._free(pwd); - Argon2Module._free(enc); - } catch (e) { } - if (err) { - throw result; - } else { - return result; - } - }); - } - - function unloadRuntime() { - if (loadModule._module) { - loadModule._module.unloadRuntime(); - delete loadModule._promise; - delete loadModule._module; - } - } - return { - ArgonType, - hash: argon2Hash, - verify: argon2Verify, - unloadRuntime, - // ************************ CHANGE START ************************ - loadModule, - // ************************ CHANGE END ************************ - }; - }); - - }).call(this) - }).call(this, require("buffer").Buffer) - }, { - "../dist/argon2.js": 2, - "buffer": 6 - }], - 4: [function (require, module, exports) { - - }, {}], - 5: [function (require, module, exports) { - 'use strict' - - exports.byteLength = byteLength - exports.toByteArray = toByteArray - exports.fromByteArray = fromByteArray - - var lookup = [] - var revLookup = [] - var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array - - var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i] - revLookup[code.charCodeAt(i)] = i - } - - // Support decoding URL-safe base64 strings, as Node.js does. - // See: https://en.wikipedia.org/wiki/Base64#URL_applications - revLookup['-'.charCodeAt(0)] = 62 - revLookup['_'.charCodeAt(0)] = 63 - - function getLens(b64) { - var len = b64.length - - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') - } - - // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - var validLen = b64.indexOf('=') - if (validLen === -1) validLen = len - - var placeHoldersLen = validLen === len ? - 0 : - 4 - (validLen % 4) - - return [validLen, placeHoldersLen] - } - - // base64 is 4/3 + up to two characters of the original data - function byteLength(b64) { - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen - } - - function _byteLength(b64, validLen, placeHoldersLen) { - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen - } - - function toByteArray(b64) { - var tmp - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] - - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) - - var curByte = 0 - - // if there are placeholders, only get up to the last complete 4 chars - var len = placeHoldersLen > 0 ? - validLen - 4 : - validLen - - var i - for (i = 0; i < len; i += 4) { - tmp = - (revLookup[b64.charCodeAt(i)] << 18) | - (revLookup[b64.charCodeAt(i + 1)] << 12) | - (revLookup[b64.charCodeAt(i + 2)] << 6) | - revLookup[b64.charCodeAt(i + 3)] - arr[curByte++] = (tmp >> 16) & 0xFF - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF - } - - if (placeHoldersLen === 2) { - tmp = - (revLookup[b64.charCodeAt(i)] << 2) | - (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[curByte++] = tmp & 0xFF - } - - if (placeHoldersLen === 1) { - tmp = - (revLookup[b64.charCodeAt(i)] << 10) | - (revLookup[b64.charCodeAt(i + 1)] << 4) | - (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF - } - - return arr - } - - function tripletToBase64(num) { - return lookup[num >> 18 & 0x3F] + - lookup[num >> 12 & 0x3F] + - lookup[num >> 6 & 0x3F] + - lookup[num & 0x3F] - } - - function encodeChunk(uint8, start, end) { - var tmp - var output = [] - for (var i = start; i < end; i += 3) { - tmp = - ((uint8[i] << 16) & 0xFF0000) + - ((uint8[i + 1] << 8) & 0xFF00) + - (uint8[i + 2] & 0xFF) - output.push(tripletToBase64(tmp)) - } - return output.join('') - } - - function fromByteArray(uint8) { - var tmp - var len = uint8.length - var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var parts = [] - var maxChunkLength = 16383 // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1] - parts.push( - lookup[tmp >> 2] + - lookup[(tmp << 4) & 0x3F] + - '==' - ) - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1] - parts.push( - lookup[tmp >> 10] + - lookup[(tmp >> 4) & 0x3F] + - lookup[(tmp << 2) & 0x3F] + - '=' - ) - } - - return parts.join('') - } - - }, {}], - 6: [function (require, module, exports) { - (function (Buffer) { - (function () { - /*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - /* eslint-disable no-proto */ - - 'use strict' - - var base64 = require('base64-js') - var ieee754 = require('ieee754') - - exports.Buffer = Buffer - exports.SlowBuffer = SlowBuffer - exports.INSPECT_MAX_BYTES = 50 - - var K_MAX_LENGTH = 0x7fffffff - exports.kMaxLength = K_MAX_LENGTH - - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ - Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() - - if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && - typeof console.error === 'function') { - console.error( - 'This browser lacks typed array (Uint8Array) support which is required by ' + - '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' - ) - } - - function typedArraySupport() { - // Can typed array instances can be augmented? - try { - var arr = new Uint8Array(1) - arr.__proto__ = { - __proto__: Uint8Array.prototype, - foo: function () { - return 42 - } - } - return arr.foo() === 42 - } catch (e) { - return false - } - } - - Object.defineProperty(Buffer.prototype, 'parent', { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined - return this.buffer - } - }) - - Object.defineProperty(Buffer.prototype, 'offset', { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined - return this.byteOffset - } - }) - - function createBuffer(length) { - if (length > K_MAX_LENGTH) { - throw new RangeError('The value "' + length + '" is invalid for option "size"') - } - // Return an augmented `Uint8Array` instance - var buf = new Uint8Array(length) - buf.__proto__ = Buffer.prototype - return buf - } - - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - function Buffer(arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new TypeError( - 'The "string" argument must be of type string. Received type number' - ) - } - return allocUnsafe(arg) - } - return from(arg, encodingOrOffset, length) - } - - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - if (typeof Symbol !== 'undefined' && Symbol.species != null && - Buffer[Symbol.species] === Buffer) { - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true, - enumerable: false, - writable: false - }) - } - - Buffer.poolSize = 8192 // not used by this implementation - - function from(value, encodingOrOffset, length) { - if (typeof value === 'string') { - return fromString(value, encodingOrOffset) - } - - if (ArrayBuffer.isView(value)) { - return fromArrayLike(value) - } - - if (value == null) { - throw TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + (typeof value) - ) - } - - if (isInstance(value, ArrayBuffer) || - (value && isInstance(value.buffer, ArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length) - } - - if (typeof value === 'number') { - throw new TypeError( - 'The "value" argument must not be of type number. Received type number' - ) - } - - var valueOf = value.valueOf && value.valueOf() - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length) - } - - var b = fromObject(value) - if (b) return b - - if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && - typeof value[Symbol.toPrimitive] === 'function') { - return Buffer.from( - value[Symbol.toPrimitive]('string'), encodingOrOffset, length - ) - } - - throw new TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + (typeof value) - ) - } - - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length) - } - - // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: - // https://github.com/feross/buffer/pull/148 - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - - function assertSize(size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be of type number') - } else if (size < 0) { - throw new RangeError('The value "' + size + '" is invalid for option "size"') - } - } - - function alloc(size, fill, encoding) { - assertSize(size) - if (size <= 0) { - return createBuffer(size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' ? - createBuffer(size).fill(fill, encoding) : - createBuffer(size).fill(fill) - } - return createBuffer(size) - } - - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - Buffer.alloc = function (size, fill, encoding) { - return alloc(size, fill, encoding) - } - - function allocUnsafe(size) { - assertSize(size) - return createBuffer(size < 0 ? 0 : checked(size) | 0) - } - - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - Buffer.allocUnsafe = function (size) { - return allocUnsafe(size) - } - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(size) - } - - function fromString(string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8' - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - - var length = byteLength(string, encoding) | 0 - var buf = createBuffer(length) - - var actual = buf.write(string, encoding) - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual) - } - - return buf - } - - function fromArrayLike(array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0 - var buf = createBuffer(length) - for (var i = 0; i < length; i += 1) { - buf[i] = array[i] & 255 - } - return buf - } - - function fromArrayBuffer(array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('"offset" is outside of buffer bounds') - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('"length" is outside of buffer bounds') - } - - var buf - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array) - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset) - } else { - buf = new Uint8Array(array, byteOffset, length) - } - - // Return an augmented `Uint8Array` instance - buf.__proto__ = Buffer.prototype - return buf - } - - function fromObject(obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0 - var buf = createBuffer(len) - - if (buf.length === 0) { - return buf - } - - obj.copy(buf, 0, 0, len) - return buf - } - - if (obj.length !== undefined) { - if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { - return createBuffer(0) - } - return fromArrayLike(obj) - } - - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { - return fromArrayLike(obj.data) - } - } - - function checked(length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') - } - return length | 0 - } - - function SlowBuffer(length) { - if (+length != length) { // eslint-disable-line eqeqeq - length = 0 - } - return Buffer.alloc(+length) - } - - Buffer.isBuffer = function isBuffer(b) { - return b != null && b._isBuffer === true && - b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false - } - - Buffer.compare = function compare(a, b) { - if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) - if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError( - 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' - ) - } - - if (a === b) return 0 - - var x = a.length - var y = b.length - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i] - y = b[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - } - - Buffer.isEncoding = function isEncoding(encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } - } - - Buffer.concat = function concat(list, length) { - if (!Array.isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - - if (list.length === 0) { - return Buffer.alloc(0) - } - - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; ++i) { - length += list[i].length - } - } - - var buffer = Buffer.allocUnsafe(length) - var pos = 0 - for (i = 0; i < list.length; ++i) { - var buf = list[i] - if (isInstance(buf, Uint8Array)) { - buf = Buffer.from(buf) - } - if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') - } - buf.copy(buffer, pos) - pos += buf.length - } - return buffer - } - - function byteLength(string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length - } - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - throw new TypeError( - 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + - 'Received type ' + typeof string - ) - } - - var len = string.length - var mustMatch = (arguments.length > 2 && arguments[2] === true) - if (!mustMatch && len === 0) return 0 - - // Use a for loop to avoid recursion - var loweredCase = false - for (; ;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 - } - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } - } - Buffer.byteLength = byteLength - - function slowToString(encoding, start, end) { - var loweredCase = false - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0 - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' - } - - if (end === undefined || end > this.length) { - end = this.length - } - - if (end <= 0) { - return '' - } - - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0 - start >>>= 0 - - if (end <= start) { - return '' - } - - if (!encoding) encoding = 'utf8' - - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) - - case 'ascii': - return asciiSlice(this, start, end) - - case 'latin1': - case 'binary': - return latin1Slice(this, start, end) - - case 'base64': - return base64Slice(this, start, end) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } - } - } - - // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) - // to detect a Buffer instance. It's not possible to use `instanceof Buffer` - // reliably in a browserify context because there could be multiple different - // copies of the 'buffer' package in use. This method works even for Buffer - // instances that were created from another copy of the `buffer` package. - // See: https://github.com/feross/buffer/issues/154 - Buffer.prototype._isBuffer = true - - function swap(b, n, m) { - var i = b[n] - b[n] = b[m] - b[m] = i - } - - Buffer.prototype.swap16 = function swap16() { - var len = this.length - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1) - } - return this - } - - Buffer.prototype.swap32 = function swap32() { - var len = this.length - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3) - swap(this, i + 1, i + 2) - } - return this - } - - Buffer.prototype.swap64 = function swap64() { - var len = this.length - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits') - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7) - swap(this, i + 1, i + 6) - swap(this, i + 2, i + 5) - swap(this, i + 3, i + 4) - } - return this - } - - Buffer.prototype.toString = function toString() { - var length = this.length - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) - } - - Buffer.prototype.toLocaleString = Buffer.prototype.toString - - Buffer.prototype.equals = function equals(b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 - } - - Buffer.prototype.inspect = function inspect() { - var str = '' - var max = exports.INSPECT_MAX_BYTES - str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() - if (this.length > max) str += ' ... ' - return '' - } - - Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { - if (isInstance(target, Uint8Array)) { - target = Buffer.from(target, target.offset, target.byteLength) - } - if (!Buffer.isBuffer(target)) { - throw new TypeError( - 'The "target" argument must be one of type Buffer or Uint8Array. ' + - 'Received type ' + (typeof target) - ) - } - - if (start === undefined) { - start = 0 - } - if (end === undefined) { - end = target ? target.length : 0 - } - if (thisStart === undefined) { - thisStart = 0 - } - if (thisEnd === undefined) { - thisEnd = this.length - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } - - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } - - start >>>= 0 - end >>>= 0 - thisStart >>>= 0 - thisEnd >>>= 0 - - if (this === target) return 0 - - var x = thisEnd - thisStart - var y = end - start - var len = Math.min(x, y) - - var thisCopy = this.slice(thisStart, thisEnd) - var targetCopy = target.slice(start, end) - - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i] - y = targetCopy[i] - break - } - } - - if (x < y) return -1 - if (y < x) return 1 - return 0 - } - - // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1 - - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset - byteOffset = 0 - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000 - } - byteOffset = +byteOffset // Coerce to Number. - if (numberIsNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : (buffer.length - 1) - } - - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset - if (byteOffset >= buffer.length) { - if (dir) return -1 - else byteOffset = buffer.length - 1 - } else if (byteOffset < 0) { - if (dir) byteOffset = 0 - else return -1 - } - - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding) - } - - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir) - } else if (typeof val === 'number') { - val = val & 0xFF // Search for a byte value [0-255] - if (typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) - } - } - return arrayIndexOf(buffer, [val], byteOffset, encoding, dir) - } - - throw new TypeError('val must be string, number or Buffer') - } - - function arrayIndexOf(arr, val, byteOffset, encoding, dir) { - var indexSize = 1 - var arrLength = arr.length - var valLength = val.length - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase() - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2 - arrLength /= 2 - valLength /= 2 - byteOffset /= 2 - } - } - - function read(buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } - } - - var i - if (dir) { - var foundIndex = -1 - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex - foundIndex = -1 - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength - for (i = byteOffset; i >= 0; i--) { - var found = true - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false - break - } - } - if (found) return i - } - } - - return -1 - } - - Buffer.prototype.includes = function includes(val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 - } - - Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true) - } - - Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false) - } - - function hexWrite(buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - - var strLen = string.length - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (numberIsNaN(parsed)) return i - buf[offset + i] = parsed - } - return i - } - - function utf8Write(buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) - } - - function asciiWrite(buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) - } - - function latin1Write(buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) - } - - function base64Write(buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) - } - - function ucs2Write(buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) - } - - Buffer.prototype.write = function write(string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0 - if (isFinite(length)) { - length = length >>> 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined - } - } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) - } - - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') - } - - if (!encoding) encoding = 'utf8' - - var loweredCase = false - for (; ;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'latin1': - case 'binary': - return latin1Write(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } - } - - Buffer.prototype.toJSON = function toJSON() { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } - } - - function base64Slice(buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) - } - } - - function utf8Slice(buf, start, end) { - end = Math.min(buf.length, end) - var res = [] - - var i = start - while (i < end) { - var firstByte = buf[i] - var codePoint = null - var bytesPerSequence = (firstByte > 0xEF) ? 4 : - (firstByte > 0xDF) ? 3 : - (firstByte > 0xBF) ? 2 : - 1 - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte - } - break - case 2: - secondByte = buf[i + 1] - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint - } - } - break - case 3: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint - } - } - break - case 4: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - fourthByte = buf[i + 3] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD - bytesPerSequence = 1 - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000 - res.push(codePoint >>> 10 & 0x3FF | 0xD800) - codePoint = 0xDC00 | codePoint & 0x3FF - } - - res.push(codePoint) - i += bytesPerSequence - } - - return decodeCodePointsArray(res) - } - - // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - var MAX_ARGUMENTS_LENGTH = 0x1000 - - function decodeCodePointsArray(codePoints) { - var len = codePoints.length - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = '' - var i = 0 - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ) - } - return res - } - - function asciiSlice(buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret - } - - function latin1Slice(buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]) - } - return ret - } - - function hexSlice(buf, start, end) { - var len = buf.length - - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len - - var out = '' - for (var i = start; i < end; ++i) { - out += toHex(buf[i]) - } - return out - } - - function utf16leSlice(buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) - } - return res - } - - Buffer.prototype.slice = function slice(start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end - - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len - } - - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len - } - - if (end < start) end = start - - var newBuf = this.subarray(start, end) - // Return an augmented `Uint8Array` instance - newBuf.__proto__ = Buffer.prototype - return newBuf - } - - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - function checkOffset(offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') - } - - Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - - return val - } - - Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) - } - - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } - - return val - } - - Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] - } - - Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) - } - - Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] - } - - Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) - } - - Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) - } - - Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val - } - - Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) - - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul - } - mul *= 0x80 - - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val - } - - Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) - } - - Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val - } - - Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val - } - - Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) - } - - Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) - } - - Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) - } - - Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) - } - - Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) - } - - Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { - offset = offset >>> 0 - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) - } - - function checkInt(buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') - } - - Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength - } - - Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } - - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } - - return offset + byteLength - } - - Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - this[offset] = (value & 0xff) - return offset + 1 - } - - Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - return offset + 2 - } - - Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - return offset + 2 - } - - Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - return offset + 4 - } - - Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - return offset + 4 - } - - Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - var limit = Math.pow(2, (8 * byteLength) - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = 0 - var mul = 1 - var sub = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength - } - - Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - var limit = Math.pow(2, (8 * byteLength) - 1) - - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } - - var i = byteLength - 1 - var mul = 1 - var sub = 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } - - return offset + byteLength - } - - Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (value < 0) value = 0xff + value + 1 - this[offset] = (value & 0xff) - return offset + 1 - } - - Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - return offset + 2 - } - - Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - return offset + 2 - } - - Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - return offset + 4 - } - - Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - return offset + 4 - } - - function checkIEEE754(buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') - } - - function writeFloat(buf, value, offset, littleEndian, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 - } - - Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) - } - - Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) - } - - function writeDouble(buf, value, offset, littleEndian, noAssert) { - value = +value - offset = offset >>> 0 - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 - } - - Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) - } - - Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) - } - - // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - Buffer.prototype.copy = function copy(target, targetStart, start, end) { - if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start - - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 - - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('Index out of range') - if (end < 0) throw new RangeError('sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start - } - - var len = end - start - - if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { - // Use built-in when available, missing from IE11 - this.copyWithin(targetStart, start, end) - } else if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (var i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, end), - targetStart - ) - } - - return len - } - - // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - Buffer.prototype.fill = function fill(val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start - start = 0 - end = this.length - } else if (typeof end === 'string') { - encoding = end - end = this.length - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - if (val.length === 1) { - var code = val.charCodeAt(0) - if ((encoding === 'utf8' && code < 128) || - encoding === 'latin1') { - // Fast path: If `val` fits into a single byte, use that numeric value. - val = code - } - } - } else if (typeof val === 'number') { - val = val & 255 - } - - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } - - if (end <= start) { - return this - } - - start = start >>> 0 - end = end === undefined ? this.length : end >>> 0 - - if (!val) val = 0 - - var i - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val - } - } else { - var bytes = Buffer.isBuffer(val) ? - val : - Buffer.from(val, encoding) - var len = bytes.length - if (len === 0) { - throw new TypeError('The value "' + val + - '" is invalid for argument "value"') - } - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len] - } - } - - return this - } - - // HELPER FUNCTIONS - // ================ - - var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g - - function base64clean(str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split('=')[0] - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = str.trim().replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str - } - - function toHex(n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) - } - - function utf8ToBytes(string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] - - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i) - - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } - - // valid lead - leadSurrogate = codePoint - - continue - } - - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } - - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - } - - leadSurrogate = null - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') - } - } - - return bytes - } - - function asciiToBytes(str) { - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xFF) - } - return byteArray - } - - function utf16leToBytes(str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break - - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray - } - - function base64ToBytes(str) { - return base64.toByteArray(base64clean(str)) - } - - function blitBuffer(src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] - } - return i - } - - // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass - // the `instanceof` check but they should be treated as of that type. - // See: https://github.com/feross/buffer/issues/166 - function isInstance(obj, type) { - return obj instanceof type || - (obj != null && obj.constructor != null && obj.constructor.name != null && - obj.constructor.name === type.name) - } - - function numberIsNaN(obj) { - // For IE11 support - return obj !== obj // eslint-disable-line no-self-compare - } - - }).call(this) - }).call(this, require("buffer").Buffer) - }, { - "base64-js": 5, - "buffer": 6, - "ieee754": 7 - }], - 7: [function (require, module, exports) { - /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ - exports.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var nBits = -7 - var i = isLE ? (nBytes - 1) : 0 - var d = isLE ? -1 : 1 - var s = buffer[offset + i] - - i += d - - e = s & ((1 << (-nBits)) - 1) - s >>= (-nBits) - nBits += eLen - for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) { } - - m = e & ((1 << (-nBits)) - 1) - e >>= (-nBits) - nBits += mLen - for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) { } - - if (e === 0) { - e = 1 - eBias - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen) - e = e - eBias - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) - } - - exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) - var i = isLE ? 0 : (nBytes - 1) - var d = isLE ? 1 : -1 - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 - - value = Math.abs(value) - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0 - e = eMax - } else { - e = Math.floor(Math.log(value) / Math.LN2) - if (value * (c = Math.pow(2, -e)) < 1) { - e-- - c *= 2 - } - if (e + eBias >= 1) { - value += rt / c - } else { - value += rt * Math.pow(2, 1 - eBias) - } - if (value * c >= 2) { - e++ - c /= 2 - } - - if (e + eBias >= eMax) { - m = 0 - e = eMax - } else if (e + eBias >= 1) { - m = ((value * c) - 1) * Math.pow(2, mLen) - e = e + eBias - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) - e = 0 - } - } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) { } - - e = (e << mLen) | m - eLen += mLen - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) { } - - buffer[offset + i - d] |= s * 128 - } - - }, {}], - 8: [function (require, module, exports) { - (function (process) { - (function () { - // 'path' module extracted from Node.js v8.11.1 (only the posix part) - // transplited with Babel - - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. - - 'use strict'; - - function assertPath(path) { - if (typeof path !== 'string') { - throw new TypeError('Path must be a string. Received ' + JSON.stringify(path)); - } - } - - // Resolves . and .. elements in a path with directory names - function normalizeStringPosix(path, allowAboveRoot) { - var res = ''; - var lastSegmentLength = 0; - var lastSlash = -1; - var dots = 0; - var code; - for (var i = 0; i <= path.length; ++i) { - if (i < path.length) - code = path.charCodeAt(i); - else if (code === 47 /*/*/) - break; - else - code = 47 /*/*/; - if (code === 47 /*/*/) { - if (lastSlash === i - 1 || dots === 1) { - // NOOP - } else if (lastSlash !== i - 1 && dots === 2) { - if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) { - if (res.length > 2) { - var lastSlashIndex = res.lastIndexOf('/'); - if (lastSlashIndex !== res.length - 1) { - if (lastSlashIndex === -1) { - res = ''; - lastSegmentLength = 0; - } else { - res = res.slice(0, lastSlashIndex); - lastSegmentLength = res.length - 1 - res.lastIndexOf('/'); - } - lastSlash = i; - dots = 0; - continue; - } - } else if (res.length === 2 || res.length === 1) { - res = ''; - lastSegmentLength = 0; - lastSlash = i; - dots = 0; - continue; - } - } - if (allowAboveRoot) { - if (res.length > 0) - res += '/..'; - else - res = '..'; - lastSegmentLength = 2; - } - } else { - if (res.length > 0) - res += '/' + path.slice(lastSlash + 1, i); - else - res = path.slice(lastSlash + 1, i); - lastSegmentLength = i - lastSlash - 1; - } - lastSlash = i; - dots = 0; - } else if (code === 46 /*.*/ && dots !== -1) { - ++dots; - } else { - dots = -1; - } - } - return res; - } - - function _format(sep, pathObject) { - var dir = pathObject.dir || pathObject.root; - var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || ''); - if (!dir) { - return base; - } - if (dir === pathObject.root) { - return dir + base; - } - return dir + sep + base; - } - - var posix = { - // path.resolve([from ...], to) - resolve: function resolve() { - var resolvedPath = ''; - var resolvedAbsolute = false; - var cwd; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path; - if (i >= 0) - path = arguments[i]; - else { - if (cwd === undefined) - cwd = process.cwd(); - path = cwd; - } - - assertPath(path); - - // Skip empty entries - if (path.length === 0) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute); - - if (resolvedAbsolute) { - if (resolvedPath.length > 0) - return '/' + resolvedPath; - else - return '/'; - } else if (resolvedPath.length > 0) { - return resolvedPath; - } else { - return '.'; - } - }, - - normalize: function normalize(path) { - assertPath(path); - - if (path.length === 0) return '.'; - - var isAbsolute = path.charCodeAt(0) === 47 /*/*/; - var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/; - - // Normalize the path - path = normalizeStringPosix(path, !isAbsolute); - - if (path.length === 0 && !isAbsolute) path = '.'; - if (path.length > 0 && trailingSeparator) path += '/'; - - if (isAbsolute) return '/' + path; - return path; - }, - - isAbsolute: function isAbsolute(path) { - assertPath(path); - return path.length > 0 && path.charCodeAt(0) === 47 /*/*/; - }, - - join: function join() { - if (arguments.length === 0) - return '.'; - var joined; - for (var i = 0; i < arguments.length; ++i) { - var arg = arguments[i]; - assertPath(arg); - if (arg.length > 0) { - if (joined === undefined) - joined = arg; - else - joined += '/' + arg; - } - } - if (joined === undefined) - return '.'; - return posix.normalize(joined); - }, - - relative: function relative(from, to) { - assertPath(from); - assertPath(to); - - if (from === to) return ''; - - from = posix.resolve(from); - to = posix.resolve(to); - - if (from === to) return ''; - - // Trim any leading backslashes - var fromStart = 1; - for (; fromStart < from.length; ++fromStart) { - if (from.charCodeAt(fromStart) !== 47 /*/*/) - break; - } - var fromEnd = from.length; - var fromLen = fromEnd - fromStart; - - // Trim any leading backslashes - var toStart = 1; - for (; toStart < to.length; ++toStart) { - if (to.charCodeAt(toStart) !== 47 /*/*/) - break; - } - var toEnd = to.length; - var toLen = toEnd - toStart; - - // Compare paths to find the longest common path from root - var length = fromLen < toLen ? fromLen : toLen; - var lastCommonSep = -1; - var i = 0; - for (; i <= length; ++i) { - if (i === length) { - if (toLen > length) { - if (to.charCodeAt(toStart + i) === 47 /*/*/) { - // We get here if `from` is the exact base path for `to`. - // For example: from='/foo/bar'; to='/foo/bar/baz' - return to.slice(toStart + i + 1); - } else if (i === 0) { - // We get here if `from` is the root - // For example: from='/'; to='/foo' - return to.slice(toStart + i); - } - } else if (fromLen > length) { - if (from.charCodeAt(fromStart + i) === 47 /*/*/) { - // We get here if `to` is the exact base path for `from`. - // For example: from='/foo/bar/baz'; to='/foo/bar' - lastCommonSep = i; - } else if (i === 0) { - // We get here if `to` is the root. - // For example: from='/foo'; to='/' - lastCommonSep = 0; - } - } - break; - } - var fromCode = from.charCodeAt(fromStart + i); - var toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) - break; - else if (fromCode === 47 /*/*/) - lastCommonSep = i; - } - - var out = ''; - // Generate the relative path based on the path difference between `to` - // and `from` - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { - if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) { - if (out.length === 0) - out += '..'; - else - out += '/..'; - } - } - - // Lastly, append the rest of the destination (`to`) path that comes after - // the common path parts - if (out.length > 0) - return out + to.slice(toStart + lastCommonSep); - else { - toStart += lastCommonSep; - if (to.charCodeAt(toStart) === 47 /*/*/) - ++toStart; - return to.slice(toStart); - } - }, - - _makeLong: function _makeLong(path) { - return path; - }, - - dirname: function dirname(path) { - assertPath(path); - if (path.length === 0) return '.'; - var code = path.charCodeAt(0); - var hasRoot = code === 47 /*/*/; - var end = -1; - var matchedSlash = true; - for (var i = path.length - 1; i >= 1; --i) { - code = path.charCodeAt(i); - if (code === 47 /*/*/) { - if (!matchedSlash) { - end = i; - break; - } - } else { - // We saw the first non-path separator - matchedSlash = false; - } - } - - if (end === -1) return hasRoot ? '/' : '.'; - if (hasRoot && end === 1) return '//'; - return path.slice(0, end); - }, - - basename: function basename(path, ext) { - if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string'); - assertPath(path); - - var start = 0; - var end = -1; - var matchedSlash = true; - var i; - - if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { - if (ext.length === path.length && ext === path) return ''; - var extIdx = ext.length - 1; - var firstNonSlashEnd = -1; - for (i = path.length - 1; i >= 0; --i) { - var code = path.charCodeAt(i); - if (code === 47 /*/*/) { - // If we reached a path separator that was not part of a set of path - // separators at the end of the string, stop now - if (!matchedSlash) { - start = i + 1; - break; - } - } else { - if (firstNonSlashEnd === -1) { - // We saw the first non-path separator, remember this index in case - // we need it if the extension ends up not matching - matchedSlash = false; - firstNonSlashEnd = i + 1; - } - if (extIdx >= 0) { - // Try to match the explicit extension - if (code === ext.charCodeAt(extIdx)) { - if (--extIdx === -1) { - // We matched the extension, so mark this as the end of our path - // component - end = i; - } - } else { - // Extension does not match, so our result is the entire path - // component - extIdx = -1; - end = firstNonSlashEnd; - } - } - } - } - - if (start === end) end = firstNonSlashEnd; - else if (end === -1) end = path.length; - return path.slice(start, end); - } else { - for (i = path.length - 1; i >= 0; --i) { - if (path.charCodeAt(i) === 47 /*/*/) { - // If we reached a path separator that was not part of a set of path - // separators at the end of the string, stop now - if (!matchedSlash) { - start = i + 1; - break; - } - } else if (end === -1) { - // We saw the first non-path separator, mark this as the end of our - // path component - matchedSlash = false; - end = i + 1; - } - } - - if (end === -1) return ''; - return path.slice(start, end); - } - }, - - extname: function extname(path) { - assertPath(path); - var startDot = -1; - var startPart = 0; - var end = -1; - var matchedSlash = true; - // Track the state of characters (if any) we see before our first dot and - // after any path separator we find - var preDotState = 0; - for (var i = path.length - 1; i >= 0; --i) { - var code = path.charCodeAt(i); - if (code === 47 /*/*/) { - // If we reached a path separator that was not part of a set of path - // separators at the end of the string, stop now - if (!matchedSlash) { - startPart = i + 1; - break; - } - continue; - } - if (end === -1) { - // We saw the first non-path separator, mark this as the end of our - // extension - matchedSlash = false; - end = i + 1; - } - if (code === 46 /*.*/) { - // If this is our first dot, mark it as the start of our extension - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; - } else if (startDot !== -1) { - // We saw a non-dot and non-path separator before our dot, so we should - // have a good chance at having a non-empty extension - preDotState = -1; - } - } - - if (startDot === -1 || end === -1 || - // We saw a non-dot character immediately before the dot - preDotState === 0 || - // The (right-most) trimmed path component is exactly '..' - preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - return ''; - } - return path.slice(startDot, end); - }, - - format: function format(pathObject) { - if (pathObject === null || typeof pathObject !== 'object') { - throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject); - } - return _format('/', pathObject); - }, - - parse: function parse(path) { - assertPath(path); - - var ret = { - root: '', - dir: '', - base: '', - ext: '', - name: '' - }; - if (path.length === 0) return ret; - var code = path.charCodeAt(0); - var isAbsolute = code === 47 /*/*/; - var start; - if (isAbsolute) { - ret.root = '/'; - start = 1; - } else { - start = 0; - } - var startDot = -1; - var startPart = 0; - var end = -1; - var matchedSlash = true; - var i = path.length - 1; - - // Track the state of characters (if any) we see before our first dot and - // after any path separator we find - var preDotState = 0; - - // Get non-dir info - for (; i >= start; --i) { - code = path.charCodeAt(i); - if (code === 47 /*/*/) { - // If we reached a path separator that was not part of a set of path - // separators at the end of the string, stop now - if (!matchedSlash) { - startPart = i + 1; - break; - } - continue; - } - if (end === -1) { - // We saw the first non-path separator, mark this as the end of our - // extension - matchedSlash = false; - end = i + 1; - } - if (code === 46 /*.*/) { - // If this is our first dot, mark it as the start of our extension - if (startDot === -1) startDot = i; - else if (preDotState !== 1) preDotState = 1; - } else if (startDot !== -1) { - // We saw a non-dot and non-path separator before our dot, so we should - // have a good chance at having a non-empty extension - preDotState = -1; - } - } - - if (startDot === -1 || end === -1 || - // We saw a non-dot character immediately before the dot - preDotState === 0 || - // The (right-most) trimmed path component is exactly '..' - preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - if (end !== -1) { - if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end); - else ret.base = ret.name = path.slice(startPart, end); - } - } else { - if (startPart === 0 && isAbsolute) { - ret.name = path.slice(1, startDot); - ret.base = path.slice(1, end); - } else { - ret.name = path.slice(startPart, startDot); - ret.base = path.slice(startPart, end); - } - ret.ext = path.slice(startDot, end); - } - - if (startPart > 0) ret.dir = path.slice(0, startPart - 1); - else if (isAbsolute) ret.dir = '/'; - - return ret; - }, - - sep: '/', - delimiter: ':', - win32: null, - posix: null - }; - - posix.posix = posix; - - module.exports = posix; - - }).call(this) - }).call(this, require('_process')) - }, { - "_process": 9 - }], - 9: [function (require, module, exports) { - // shim for using process in browser - var process = module.exports = {}; - - // cached from whatever global is present so that test runners that stub it - // don't break things. But we need to wrap it in a try catch in case it is - // wrapped in strict mode code which doesn't define any globals. It's inside a - // function because try/catches deoptimize in certain engines. - - var cachedSetTimeout; - var cachedClearTimeout; - - function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); - } - - function defaultClearTimeout() { - throw new Error('clearTimeout has not been defined'); - } - (function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } - }()) - - function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch (e) { - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch (e) { - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - - } - - function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e) { - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e) { - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - - } - var queue = []; - var draining = false; - var currentQueue; - var queueIndex = -1; - - function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } - } - - function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while (len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); - } - - process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } - }; - - // v8 likes predictible objects - function Item(fun, array) { - this.fun = fun; - this.array = array; - } - Item.prototype.run = function () { - this.fun.apply(null, this.array); - }; - process.title = 'browser'; - process.browser = true; - process.env = {}; - process.argv = []; - process.version = ''; // empty string to avoid regexp issues - process.versions = {}; - - function noop() { } - - process.on = noop; - process.addListener = noop; - process.once = noop; - process.off = noop; - process.removeListener = noop; - process.removeAllListeners = noop; - process.emit = noop; - process.prependListener = noop; - process.prependOnceListener = noop; - - process.listeners = function (name) { - return [] - } - - process.binding = function (name) { - throw new Error('process.binding is not supported'); - }; - - process.cwd = function () { - return '/' - }; - process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); - }; - process.umask = function () { - return 0; - }; - - }, {}] -}, {}, [1]); \ No newline at end of file diff --git a/wasm/argon2-simd.wasm b/wasm/argon2-simd.wasm deleted file mode 100755 index 957a03032b3a091057cb3fcab05f2995695e7a22..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26935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uEZXae&rD`7 z+M{gyYVEZeeDi<$r7!#O8(x0o=#8%^W?%E#n{RQ&dk { throw new Error(e.message) }); -} - -globalThis.testArgon2HashAndVerify = async function () { - for (let i = 0; i < randomStrings.length; i += 2) { - await hashAndVerify({ - pass: randomStrings[i], - salt: randomStrings[i + 1], - }); - } - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - type: argon2.ArgonType.Argon2d, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - type: argon2.ArgonType.Argon2i, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - type: argon2.ArgonType.Argon2id, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - time: 10, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - mem: 2048, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - hashLen: 32, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - parallelism: 4, - }); - - await hashAndVerify({ - pass: '汉字漢字', - salt: 'asdfasdfasdfasdf', - type: argon2.ArgonType.Argon2id, - hashLen: 32, - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - ad: new Uint8Array([1, 2, 3]), - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - secret: new Uint8Array([1, 2, 3]), - }); - - await hashAndVerify({ - pass: 'p@ssw0rd', - salt: 'somesalt', - hashLen: 100000, - }); -}; diff --git a/wasm/argon2.wasm b/wasm/argon2.wasm deleted file mode 100755 index ee51ab89292fc4b0619bb9ece8ca3ea33467d48f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25914 zcmdU%dyrgLo!`%W^z(L)dZdvw(g^wVMZgH#FtA24MhkNXKV*!tcVQ_~B*DTOEcJ{f z&BNjmp&5+L$_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{{3xneD=@^VQ;kWDKR3N|f>6>VJ)E4<2bSlt_pKqBqij-6b5V0r#Z^Iv3+^Ow&* z6#vGlg;S^BUQ!SG9G`b3Nsd=EIqq)JVppTgA9pv;Z+;Fvst(olEw4TeRo<}*)Nq9y zultSHzP6%HMYXC}q%YTV-rpbA_g)I#dhFf>F`@NUqqi;3U%kOycR1R>iu5>zI6T0@ zorOKcBJgck=dc=E5V+326){?obHfd6MhML9e|m=@Yly}(C8F5Dw diff --git a/wasm/argon2/CMakeLists.txt b/wasm/argon2/CMakeLists.txt deleted file mode 100644 index 839cfe4..0000000 --- a/wasm/argon2/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project(agron2) - -add_definitions(-DARGON2_NO_THREADS) - -set(ARCHIVE_OUTPUT_DIRECTORY dist) -set(LIBRARY_OUTPUT_DIRECTORY dist) -set(RUNTIME_OUTPUT_DIRECTORY dist) -set(EXECUTABLE_OUTPUT_PATH dist) - -include_directories(argon2/include) - -set(sources - argon2/src/blake2/blake2b.c - - argon2/src/argon2.c - argon2/src/core.c - argon2/src/encoding.c - argon2/src/thread.c - - src/argon2_library.c -) - -if(${CMAKE_C_FLAGS} MATCHES simd) - list(APPEND sources argon2/src/opt.c) -else() - list(APPEND sources argon2/src/ref.c) -endif() - -add_executable(argon2 ${sources}) - -set_target_properties(argon2 PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) diff --git a/wasm/argon2/README.md b/wasm/argon2/README.md deleted file mode 100644 index ee03782..0000000 --- a/wasm/argon2/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -## Building - -Set `EMCC_SDK_PATH` in `build.sh` first and then you can build argon2 wasm binary files with -```bash -./build.sh -``` - -Prerequisites: -- emscripten with WebAssembly support ([howto](http://webassembly.org/getting-started/developers-guide/)) -- CMake diff --git a/wasm/argon2/build.log b/wasm/argon2/build.log index a5ba855..eb36c51 100644 --- a/wasm/argon2/build.log +++ b/wasm/argon2/build.log @@ -1,4 +1,4 @@ -Built on 2025-02-11T15:51:03Z +Built on 2025-02-11T16:03:39Z Toolchain versions emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.0-git Building... diff --git a/wasm/argon2/build.sh b/wasm/argon2/build.sh index d332fbb..16300e7 100755 --- a/wasm/argon2/build.sh +++ b/wasm/argon2/build.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash - -#!/bin/bash - set -euo pipefail rm -rf build/ @@ -16,14 +13,14 @@ emcc --version | head -n1 | tee -a "$BUILD_LOG" # FIXME: Redownload the source if argon2 ever has source updates. At the time of writing it was last changed 5 years ago so this is probably not a high priority. SOURCES=( - argon2/src/blake2/blake2b.c + src/blake2/blake2b.c - argon2/src/argon2.c - argon2/src/core.c - argon2/src/encoding.c - argon2/src/thread.c + src/argon2.c + src/core.c + src/encoding.c + src/thread.c - argon2/src/opt.c + src/opt.c ) SIMD_FLAGS=( @@ -39,34 +36,8 @@ emcc -o build/argon2.js \ -g1 --emit-symbol-map \ -DARGON2_NO_THREADS \ -s MODULARIZE=1 -s EXPORT_NAME=setupModule -s EXPORTED_RUNTIME_METHODS=stringToNewUTF8,UTF8ToString -s EXPORTED_FUNCTIONS=_argon2_hash,_argon2_verify,_argon2_encodedlen,_argon2_error_message,_malloc,_free,_strlen \ - -Iargon2/include \ + -Iinclude \ ${SOURCES[@]} | tee -a "$BUILD_LOG" echo "Building done" | tee -a "$BUILD_LOG" ls -lth build/ - -# set -e -# set -o pipefail - -# # Log emcc version -# EMCC_SDK_PATH="/path/to/emsdk" -# EMCC_PATH="$EMCC_SDK_PATH/upstream/emscripten/emcc" -# $EMCC_PATH --version > emcc_version.txt - -# # Build start -# rm -rf dist -# mkdir dist - -# ./clean-cmake.sh -# EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=1 ./build-wasm.sh -# mv dist/argon2.wasm ../argon2-simd.wasm - -# ./clean-cmake.sh -# EMCC_SDK_PATH=$EMCC_SDK_PATH ARGON_JS_BUILD_BUILD_WITH_SIMD=0 ./build-wasm.sh -# mv dist/argon2.wasm ../argon2.wasm - -# ./clean-cmake.sh -# rm -rf dist -# # Build end - -# echo Done diff --git a/wasm/argon2/clean-cmake.sh b/wasm/argon2/clean-cmake.sh deleted file mode 100755 index 8a2d867..0000000 --- a/wasm/argon2/clean-cmake.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -rm -rf CMakeFiles && -rm -f CMakeCache.txt && -rm -f Makefile && -rm -f cmake_install.cmake diff --git a/wasm/argon2/emcc_version.txt b/wasm/argon2/emcc_version.txt deleted file mode 100644 index 6b08993..0000000 --- a/wasm/argon2/emcc_version.txt +++ /dev/null @@ -1,5 +0,0 @@ -emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64 (a1fe3902bf73a3802eae0357d273d0e37ea79898) -Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt) -This is free and open source software under the MIT license. -There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - diff --git a/wasm/argon2/argon2/include/argon2.h b/wasm/argon2/include/argon2.h similarity index 100% rename from wasm/argon2/argon2/include/argon2.h rename to wasm/argon2/include/argon2.h diff --git a/wasm/argon2/argon2/src/argon2.c b/wasm/argon2/src/argon2.c similarity index 100% rename from wasm/argon2/argon2/src/argon2.c rename to wasm/argon2/src/argon2.c diff --git a/wasm/argon2/src/argon2_library.c b/wasm/argon2/src/argon2_library.c deleted file mode 100644 index 23e94c4..0000000 --- a/wasm/argon2/src/argon2_library.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include - -#include "../argon2/include/argon2.h" -#include "../argon2/src/encoding.h" -#include "../argon2/src/core.h" - -// Copied from argon2/src/argon2.c with additional parameters: "secret"+len and "ad"+len - -int argon2_hash_ext(const uint32_t t_cost, const uint32_t m_cost, - const uint32_t parallelism, const void *pwd, - const size_t pwdlen, const void *salt, const size_t saltlen, - void *hash, const size_t hashlen, char *encoded, - const size_t encodedlen, argon2_type type, - /* argon2-browser: begin added parameters */ - const void* secret, const size_t secretlen, - const void* ad, const size_t adlen, - /* argon2-browser: end added parameters */ - const uint32_t version){ - - argon2_context context; - int result; - uint8_t *out; - - if (pwdlen > ARGON2_MAX_PWD_LENGTH) { - return ARGON2_PWD_TOO_LONG; - } - - if (saltlen > ARGON2_MAX_SALT_LENGTH) { - return ARGON2_SALT_TOO_LONG; - } - - if (hashlen > ARGON2_MAX_OUTLEN) { - return ARGON2_OUTPUT_TOO_LONG; - } - - if (hashlen < ARGON2_MIN_OUTLEN) { - return ARGON2_OUTPUT_TOO_SHORT; - } - - out = malloc(hashlen); - if (!out) { - return ARGON2_MEMORY_ALLOCATION_ERROR; - } - - context.out = (uint8_t *)out; - context.outlen = (uint32_t)hashlen; - context.pwd = CONST_CAST(uint8_t *)pwd; - context.pwdlen = (uint32_t)pwdlen; - context.salt = CONST_CAST(uint8_t *)salt; - context.saltlen = (uint32_t)saltlen; - /* argon2-browser: begin changed parameters */ - context.secret = CONST_CAST(uint8_t *)secret; - context.secretlen = (uint32_t)secretlen; - context.ad = CONST_CAST(uint8_t *)ad; - context.adlen = (uint32_t)adlen; - /* argon2-browser: end changed parameters */ - context.t_cost = t_cost; - context.m_cost = m_cost; - context.lanes = parallelism; - context.threads = parallelism; - context.allocate_cbk = NULL; - context.free_cbk = NULL; - context.flags = ARGON2_DEFAULT_FLAGS; - context.version = version; - - result = argon2_ctx(&context, type); - - if (result != ARGON2_OK) { - clear_internal_memory(out, hashlen); - free(out); - return result; - } - - /* if raw hash requested, write it */ - if (hash) { - memcpy(hash, out, hashlen); - } - - /* if encoding requested, write it */ - if (encoded && encodedlen) { - if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) { - clear_internal_memory(out, hashlen); /* wipe buffers if error */ - clear_internal_memory(encoded, encodedlen); - free(out); - return ARGON2_ENCODING_FAIL; - } - } - clear_internal_memory(out, hashlen); - free(out); - - return ARGON2_OK; -} - -int argon2_verify_ext(const char *encoded, const void *pwd, const size_t pwdlen, - /* argon2-browser: begin added parameters */ - const void* secret, const size_t secretlen, - const void* ad, const size_t adlen, - /* argon2-browser: end added parameters */ - argon2_type type) { - - argon2_context ctx; - uint8_t *desired_result = NULL; - - int ret = ARGON2_OK; - - size_t encoded_len; - uint32_t max_field_len; - - if (pwdlen > ARGON2_MAX_PWD_LENGTH) { - return ARGON2_PWD_TOO_LONG; - } - - if (encoded == NULL) { - return ARGON2_DECODING_FAIL; - } - - encoded_len = strlen(encoded); - if (encoded_len > UINT32_MAX) { - return ARGON2_DECODING_FAIL; - } - - /* No field can be longer than the encoded length */ - max_field_len = (uint32_t)encoded_len; - - ctx.saltlen = max_field_len; - ctx.outlen = max_field_len; - - ctx.salt = malloc(ctx.saltlen); - ctx.out = malloc(ctx.outlen); - if (!ctx.salt || !ctx.out) { - ret = ARGON2_MEMORY_ALLOCATION_ERROR; - goto fail; - } - - ctx.pwd = (uint8_t *)pwd; - ctx.pwdlen = (uint32_t)pwdlen; - - ret = decode_string(&ctx, encoded, type); - if (ret != ARGON2_OK) { - goto fail; - } - - /* Set aside the desired result, and get a new buffer. */ - desired_result = ctx.out; - ctx.out = malloc(ctx.outlen); - if (!ctx.out) { - ret = ARGON2_MEMORY_ALLOCATION_ERROR; - goto fail; - } - - /* argon2-browser: begin changed parameters */ - ctx.secret = CONST_CAST(uint8_t *)secret; - ctx.secretlen = (uint32_t)secretlen; - ctx.ad = CONST_CAST(uint8_t *)ad; - ctx.adlen = (uint32_t)adlen; - /* argon2-browser: end changed parameters */ - - ret = argon2_verify_ctx(&ctx, (char *)desired_result, type); - if (ret != ARGON2_OK) { - goto fail; - } - -fail: - free(ctx.salt); - free(ctx.out); - free(desired_result); - - return ret; -} diff --git a/wasm/argon2/argon2/src/bench.c b/wasm/argon2/src/bench.c similarity index 100% rename from wasm/argon2/argon2/src/bench.c rename to wasm/argon2/src/bench.c diff --git a/wasm/argon2/argon2/src/blake2/blake2-impl.h b/wasm/argon2/src/blake2/blake2-impl.h similarity index 100% rename from wasm/argon2/argon2/src/blake2/blake2-impl.h rename to wasm/argon2/src/blake2/blake2-impl.h diff --git a/wasm/argon2/argon2/src/blake2/blake2.h b/wasm/argon2/src/blake2/blake2.h similarity index 100% rename from wasm/argon2/argon2/src/blake2/blake2.h rename to wasm/argon2/src/blake2/blake2.h diff --git a/wasm/argon2/argon2/src/blake2/blake2b.c b/wasm/argon2/src/blake2/blake2b.c similarity index 100% rename from wasm/argon2/argon2/src/blake2/blake2b.c rename to wasm/argon2/src/blake2/blake2b.c diff --git a/wasm/argon2/argon2/src/blake2/blamka-round-opt.h b/wasm/argon2/src/blake2/blamka-round-opt.h similarity index 100% rename from wasm/argon2/argon2/src/blake2/blamka-round-opt.h rename to wasm/argon2/src/blake2/blamka-round-opt.h diff --git a/wasm/argon2/argon2/src/blake2/blamka-round-ref.h b/wasm/argon2/src/blake2/blamka-round-ref.h similarity index 100% rename from wasm/argon2/argon2/src/blake2/blamka-round-ref.h rename to wasm/argon2/src/blake2/blamka-round-ref.h diff --git a/wasm/argon2/argon2/src/core.c b/wasm/argon2/src/core.c similarity index 100% rename from wasm/argon2/argon2/src/core.c rename to wasm/argon2/src/core.c diff --git a/wasm/argon2/argon2/src/core.h b/wasm/argon2/src/core.h similarity index 100% rename from wasm/argon2/argon2/src/core.h rename to wasm/argon2/src/core.h diff --git a/wasm/argon2/argon2/src/encoding.c b/wasm/argon2/src/encoding.c similarity index 100% rename from wasm/argon2/argon2/src/encoding.c rename to wasm/argon2/src/encoding.c diff --git a/wasm/argon2/argon2/src/encoding.h b/wasm/argon2/src/encoding.h similarity index 100% rename from wasm/argon2/argon2/src/encoding.h rename to wasm/argon2/src/encoding.h diff --git a/wasm/argon2/argon2/src/genkat.c b/wasm/argon2/src/genkat.c similarity index 100% rename from wasm/argon2/argon2/src/genkat.c rename to wasm/argon2/src/genkat.c diff --git a/wasm/argon2/argon2/src/genkat.h b/wasm/argon2/src/genkat.h similarity index 100% rename from wasm/argon2/argon2/src/genkat.h rename to wasm/argon2/src/genkat.h diff --git a/wasm/argon2/argon2/src/opt.c b/wasm/argon2/src/opt.c similarity index 100% rename from wasm/argon2/argon2/src/opt.c rename to wasm/argon2/src/opt.c diff --git a/wasm/argon2/argon2/src/ref.c b/wasm/argon2/src/ref.c similarity index 100% rename from wasm/argon2/argon2/src/ref.c rename to wasm/argon2/src/ref.c diff --git a/wasm/argon2/argon2/src/run.c b/wasm/argon2/src/run.c similarity index 100% rename from wasm/argon2/argon2/src/run.c rename to wasm/argon2/src/run.c diff --git a/wasm/argon2/argon2/src/test.c b/wasm/argon2/src/test.c similarity index 100% rename from wasm/argon2/argon2/src/test.c rename to wasm/argon2/src/test.c diff --git a/wasm/argon2/argon2/src/thread.c b/wasm/argon2/src/thread.c similarity index 100% rename from wasm/argon2/argon2/src/thread.c rename to wasm/argon2/src/thread.c diff --git a/wasm/argon2/argon2/src/thread.h b/wasm/argon2/src/thread.h similarity index 100% rename from wasm/argon2/argon2/src/thread.h rename to wasm/argon2/src/thread.h From 51392afb3179b80f49e454d9c6ab229a852f7f9a Mon Sep 17 00:00:00 2001 From: Keith Miller Date: Wed, 26 Feb 2025 12:16:14 -0500 Subject: [PATCH 3/3] Address DanLeh's Comments 1) Move to an explicit `free` call. 2) Only do `Argon2id` 3) Use `tCost = 3` rather than 2 per best practices. 4) Lower iteration count from 50 -> 30 and worst case from 4 -> 3 --- JetStreamDriver.js | 3 ++- wasm/argon2/benchmark.js | 39 +++++++++++++++++++++++++++++---------- wasm/argon2/build-wasm.sh | 37 ------------------------------------- wasm/argon2/build.sh | 2 +- 4 files changed, 32 insertions(+), 49 deletions(-) delete mode 100755 wasm/argon2/build-wasm.sh diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 1c0fcfe..5d40231 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -2063,7 +2063,8 @@ const BENCHMARKS = [ preload: { wasmBinary: "./wasm/argon2/build/argon2.wasm" }, - iterations: 50, + iterations: 30, + worstCaseCount: 3, testGroup: WasmGroup, deterministicRandom: true, }), diff --git a/wasm/argon2/benchmark.js b/wasm/argon2/benchmark.js index ce47c64..e3fb946 100644 --- a/wasm/argon2/benchmark.js +++ b/wasm/argon2/benchmark.js @@ -27,6 +27,7 @@ let passwordStrings = [ '123456', 'p@assw0rd', 'qwerty', + 'letmein', '汉字漢字', 'كلمة المرور', 'Z7ihQxGE93', @@ -35,13 +36,16 @@ let passwordStrings = [ ]; // Emscripten doesn't have a way to manage your pointers for you so these will free them when the wrapper dies. -const mallocRegistry = new FinalizationRegistry((ptr) => Module._free(ptr)); +// If/when https://github.com/tc39/proposal-explicit-resource-management becomes a thing we should use that syntax/symbol instead of a dispose call. class CString { constructor(string) { this.ptr = Module.stringToNewUTF8(string); this.length = Module._strlen(this.ptr); - mallocRegistry.register(this, this.ptr); + } + + dispose() { + Module._free(this.ptr); } } @@ -49,14 +53,24 @@ class MallocPtr { constructor(size) { this.ptr = Module._malloc(size); this.size = size; - mallocRegistry.register(this, this.ptr); + } + + dispose() { + Module._free(this.ptr); } } -const tCost = 2; +const tCost = 3; const mCost = 1024; const parallelism = 1; -const argon2NumberOfTypes = 2; +// There are three argon2 types (modes), we test all three. See wasm/argon2/include/argon2.h for the enum: +// /* Argon2 primitive type */ +// typedef enum Argon2_type { +// Argon2_d = 0, +// Argon2_i = 1, +// Argon2_id = 2 +// } argon2_type; +const argon2Type = 2; const version = 0x13; const saltLength = 12; @@ -68,7 +82,7 @@ class Benchmark { } for (let i = 0; i < passwordStrings.length; ++i) - this.hashAndVerify(passwordStrings[i], i % argon2NumberOfTypes); + this.hashAndVerify(passwordStrings[i], argon2Type); } randomSalt() { @@ -82,15 +96,20 @@ class Benchmark { hashAndVerify(password, argon2Type) { password = new CString(password); let salt = this.randomSalt(); - this.hashBuffer = new MallocPtr(24); - this.encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, saltLength, this.hashBuffer.size, argon2Type) + 1); + let hashBuffer = new MallocPtr(24); + let encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, salt.size, hashBuffer.size, argon2Type) + 1); - let status = Module._argon2_hash(tCost, mCost, parallelism, password.ptr, password.length, salt.ptr, salt.size, this.hashBuffer.ptr, this.hashBuffer.size, this.encodedBuffer.ptr, this.encodedBuffer.size, argon2Type, version); + let status = Module._argon2_hash(tCost, mCost, parallelism, password.ptr, password.length, salt.ptr, salt.size, hashBuffer.ptr, hashBuffer.size, encodedBuffer.ptr, encodedBuffer.size, argon2Type, version); if (status !== 0) throw new Error(`argon2_hash exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`); - status = Module._argon2_verify(this.encodedBuffer.ptr, password.ptr, password.length, argon2Type); + status = Module._argon2_verify(encodedBuffer.ptr, password.ptr, password.length, argon2Type); if (status !== 0) throw new Error(`argon2_verify exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`); + + password.dispose(); + salt.dispose(); + hashBuffer.dispose(); + encodedBuffer.dispose(); } } diff --git a/wasm/argon2/build-wasm.sh b/wasm/argon2/build-wasm.sh deleted file mode 100755 index 74b7eeb..0000000 --- a/wasm/argon2/build-wasm.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -ARGON_JS_EXTRA_C_FLAGS="" -if [[ "$ARGON_JS_BUILD_BUILD_WITH_SIMD" == "1" ]]; then - ARGON_JS_EXTRA_C_FLAGS="-msimd128 -msse2" -fi - -cmake \ - -DOUTPUT_NAME="argon2" \ - -DCMAKE_TOOLCHAIN_FILE="$EMCC_SDK_PATH/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" \ - -DCMAKE_VERBOSE_MAKEFILE=OFF \ - -DCMAKE_BUILD_TYPE=MinSizeRel \ - -DCMAKE_C_FLAGS="-O $ARGON_JS_EXTRA_C_FLAGS" \ - -DCMAKE_EXE_LINKER_FLAGS="-O3 \ - -s NO_FILESYSTEM=1 \ - -s 'EXPORTED_FUNCTIONS=[\"_argon2_hash\",\"_argon2_hash_ext\",\"_argon2_verify\",\"_argon2_verify_ext\",\"_argon2_error_message\",\"_argon2_encodedlen\",\"_malloc\",\"_free\"]' \ - -s 'EXPORTED_RUNTIME_METHODS=[\"UTF8ToString\",\"allocate\",\"ALLOC_NORMAL\"]' \ - -s DEMANGLE_SUPPORT=0 \ - -s ASSERTIONS=0 \ - -s NO_EXIT_RUNTIME=1 \ - -s TOTAL_MEMORY=16MB \ - -s BINARYEN_MEM_MAX=2147418112 \ - -s ALLOW_MEMORY_GROWTH=1 \ - -s WASM=1" \ - . -cmake --build . - -shasum dist/argon2.js -shasum dist/argon2.wasm - -perl -pi -e 's/"argon2.js.mem"/null/g' dist/argon2.js -perl -pi -e 's/$/if(typeof module!=="undefined")module.exports=Module;Module.unloadRuntime=function(){if(typeof self!=="undefined"){delete self.Module}Module=jsModule=wasmMemory=wasmTable=asm=buffer=HEAP8=HEAPU8=HEAP16=HEAPU16=HEAP32=HEAPU32=HEAPF32=HEAPF64=undefined;if(typeof module!=="undefined"){delete module.exports}};/' dist/argon2.js -perl -pi -e 's/typeof Module!=="undefined"\?Module:\{};/typeof self!=="undefined"&&typeof self.Module!=="undefined"?self.Module:{};var jsModule=Module;/g' dist/argon2.js -perl -pi -e 's/receiveInstantiatedSource\(output\)\{/receiveInstantiatedSource(output){Module=jsModule;if(typeof self!=="undefined")self.Module=Module;/g' dist/argon2.js diff --git a/wasm/argon2/build.sh b/wasm/argon2/build.sh index 16300e7..a797f38 100755 --- a/wasm/argon2/build.sh +++ b/wasm/argon2/build.sh @@ -11,7 +11,7 @@ echo "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | tee "$BUILD_LOG" echo "Toolchain versions" | tee -a "$BUILD_LOG" emcc --version | head -n1 | tee -a "$BUILD_LOG" -# FIXME: Redownload the source if argon2 ever has source updates. At the time of writing it was last changed 5 years ago so this is probably not a high priority. +# FIXME: Redownload the source (from https://github.com/P-H-C/phc-winner-argon2) if argon2 ever has source updates. At the time of writing it was last changed 5 years ago so this is probably not a high priority. SOURCES=( src/blake2/blake2b.c