From 3eb9a34f08716fb88e4869aae39535ff99bb2a53 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Thu, 27 Feb 2025 18:03:50 +0100 Subject: [PATCH] Cleanups for argon2-wasm Update comment after change, remove unused parameter, remove no longer existing benchmark variant. --- wasm-cli.js | 1 - wasm/argon2/benchmark.js | 17 +++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wasm-cli.js b/wasm-cli.js index 82b6a5e0..2d97abba 100644 --- a/wasm-cli.js +++ b/wasm-cli.js @@ -33,7 +33,6 @@ testList = [ "tfjs-wasm", "tfjs-wasm-simd", "argon2-wasm", - "argon2-wasm-simd", "8bitbench-wasm", "Dart-flute-wasm", "zlib-wasm", diff --git a/wasm/argon2/benchmark.js b/wasm/argon2/benchmark.js index e3fb9465..f7b2e315 100644 --- a/wasm/argon2/benchmark.js +++ b/wasm/argon2/benchmark.js @@ -63,14 +63,15 @@ class MallocPtr { const tCost = 3; const mCost = 1024; const parallelism = 1; -// There are three argon2 types (modes), we test all three. See wasm/argon2/include/argon2.h for the enum: -// /* Argon2 primitive type */ +// There are three argon2 types (modes), but they all exercise the same computational kernel, +// so we chose the recommended one from a security standpoint. +// See wasm/argon2/include/argon2.h for the enum: // typedef enum Argon2_type { // Argon2_d = 0, // Argon2_i = 1, // Argon2_id = 2 // } argon2_type; -const argon2Type = 2; +const argon2idType = 2; const version = 0x13; const saltLength = 12; @@ -82,7 +83,7 @@ class Benchmark { } for (let i = 0; i < passwordStrings.length; ++i) - this.hashAndVerify(passwordStrings[i], argon2Type); + this.hashAndVerify(passwordStrings[i]); } randomSalt() { @@ -93,17 +94,17 @@ class Benchmark { return result; } - hashAndVerify(password, argon2Type) { + hashAndVerify(password) { password = new CString(password); let salt = this.randomSalt(); let hashBuffer = new MallocPtr(24); - let encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, salt.size, hashBuffer.size, argon2Type) + 1); + let encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, salt.size, hashBuffer.size, argon2idType) + 1); - 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); + let status = Module._argon2_hash(tCost, mCost, parallelism, password.ptr, password.length, salt.ptr, salt.size, hashBuffer.ptr, hashBuffer.size, encodedBuffer.ptr, encodedBuffer.size, argon2idType, version); if (status !== 0) throw new Error(`argon2_hash exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`); - status = Module._argon2_verify(encodedBuffer.ptr, password.ptr, password.length, argon2Type); + status = Module._argon2_verify(encodedBuffer.ptr, password.ptr, password.length, argon2idType); if (status !== 0) throw new Error(`argon2_verify exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`);