Skip to content

Commit c4e2cf1

Browse files
authored
Merge pull request #51 from danleh/main
Minor cleanups for argon2-wasm
2 parents 80e40bb + 3eb9a34 commit c4e2cf1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

wasm-cli.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ testList = [
3333
"tfjs-wasm",
3434
"tfjs-wasm-simd",
3535
"argon2-wasm",
36-
"argon2-wasm-simd",
3736
"8bitbench-wasm",
3837
"Dart-flute-wasm",
3938
"zlib-wasm",

wasm/argon2/benchmark.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ class MallocPtr {
6363
const tCost = 3;
6464
const mCost = 1024;
6565
const parallelism = 1;
66-
// There are three argon2 types (modes), we test all three. See wasm/argon2/include/argon2.h for the enum:
67-
// /* Argon2 primitive type */
66+
// There are three argon2 types (modes), but they all exercise the same computational kernel,
67+
// so we chose the recommended one from a security standpoint.
68+
// See wasm/argon2/include/argon2.h for the enum:
6869
// typedef enum Argon2_type {
6970
// Argon2_d = 0,
7071
// Argon2_i = 1,
7172
// Argon2_id = 2
7273
// } argon2_type;
73-
const argon2Type = 2;
74+
const argon2idType = 2;
7475
const version = 0x13;
7576
const saltLength = 12;
7677

@@ -82,7 +83,7 @@ class Benchmark {
8283
}
8384

8485
for (let i = 0; i < passwordStrings.length; ++i)
85-
this.hashAndVerify(passwordStrings[i], argon2Type);
86+
this.hashAndVerify(passwordStrings[i]);
8687
}
8788

8889
randomSalt() {
@@ -93,17 +94,17 @@ class Benchmark {
9394
return result;
9495
}
9596

96-
hashAndVerify(password, argon2Type) {
97+
hashAndVerify(password) {
9798
password = new CString(password);
9899
let salt = this.randomSalt();
99100
let hashBuffer = new MallocPtr(24);
100-
let encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, salt.size, hashBuffer.size, argon2Type) + 1);
101+
let encodedBuffer = new MallocPtr(Module._argon2_encodedlen(tCost, mCost, parallelism, salt.size, hashBuffer.size, argon2idType) + 1);
101102

102-
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);
103+
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);
103104
if (status !== 0)
104105
throw new Error(`argon2_hash exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`);
105106

106-
status = Module._argon2_verify(encodedBuffer.ptr, password.ptr, password.length, argon2Type);
107+
status = Module._argon2_verify(encodedBuffer.ptr, password.ptr, password.length, argon2idType);
107108
if (status !== 0)
108109
throw new Error(`argon2_verify exited with status: ${status} (${Module.UTF8ToString(Module._argon2_error_message(status))})`);
109110

0 commit comments

Comments
 (0)