Skip to content

Minor cleanups for argon2-wasm #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ testList = [
"tfjs-wasm",
"tfjs-wasm-simd",
"argon2-wasm",
"argon2-wasm-simd",
"8bitbench-wasm",
"Dart-flute-wasm",
"zlib-wasm",
Expand Down
17 changes: 9 additions & 8 deletions wasm/argon2/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -82,7 +83,7 @@ class Benchmark {
}

for (let i = 0; i < passwordStrings.length; ++i)
this.hashAndVerify(passwordStrings[i], argon2Type);
this.hashAndVerify(passwordStrings[i]);
}

randomSalt() {
Expand All @@ -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))})`);

Expand Down