-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('node:assert'); | ||
const { | ||
argon2, | ||
argon2Sync, | ||
} = require('node:crypto'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
sync: [0, 1], | ||
size: [32, 64, 1024], | ||
pass: ['a', 'secret', 'this-is-a-much-longer-password'], | ||
saltlen: [8, 16, 32], | ||
algorithm: ['ARGON2D', 'ARGON2I', 'ARGON2ID'], | ||
secretlen: [0, 8], | ||
adlen: [0, 12], | ||
iter: [2, 3, 4], | ||
memcost: [64 << 10, 256 << 10], | ||
n: [50], | ||
}); | ||
|
||
function measureSync(n, size, pass, salt, options) { | ||
bench.start(); | ||
for (let i = 0; i < n; ++i) | ||
argon2Sync(pass, salt, size, options); | ||
bench.end(n); | ||
} | ||
|
||
function measureAsync(n, size, pass, salt, options) { | ||
let remaining = n; | ||
function done(err) { | ||
assert.ifError(err); | ||
if (--remaining === 0) | ||
bench.end(n); | ||
} | ||
bench.start(); | ||
for (let i = 0; i < n; ++i) | ||
argon2(pass, salt, size, options, done); | ||
} | ||
|
||
function main({ n, sync, size, pass, saltlen, secretlen, adlen, ...options }) { | ||
const salt = Buffer.alloc(saltlen, 0x01); | ||
const secret = Buffer.alloc(secretlen, 0x02); | ||
const ad = Buffer.alloc(adlen, 0x03); | ||
options = { ...options, secret, ad }; | ||
if (sync) | ||
measureSync(n, size, pass, salt, options); | ||
else | ||
measureAsync(n, size, pass, salt, options); | ||
} |