-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!(argon2): respect the salt provided in hash options (#899)
- Loading branch information
1 parent
fea946f
commit 52c4553
Showing
13 changed files
with
98 additions
and
73 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
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
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
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 |
---|---|---|
@@ -1,42 +1,38 @@ | ||
const { cpus } = require('os') | ||
import { cpus } from 'node:os' | ||
|
||
const nodeArgon2 = require('argon2') | ||
const { Suite } = require('benchmark') | ||
const chalk = require('chalk') | ||
import nodeArgon2 from 'argon2' | ||
import { Bench } from 'tinybench' | ||
|
||
const { hash, verify, Algorithm } = require('../index') | ||
import { hash, verify, Algorithm } from '../index.js' | ||
|
||
const PASSWORD = '$v=19$m=4096,t=3,p=1$fyLYvmzgpBjDTP6QSypj3g$pb1Q3Urv1amxuFft0rGwKfEuZPhURRDV7TJqcBnwlGo' | ||
const CORES = cpus().length | ||
|
||
const suite = new Suite('Hash with all cores') | ||
|
||
suite | ||
.add( | ||
'@node-rs/argon', | ||
async (deferred) => { | ||
await hash(PASSWORD, { | ||
algorithm: Algorithm.Argon2id, | ||
parallelism: CORES, | ||
}) | ||
deferred.resolve() | ||
}, | ||
{ defer: true }, | ||
) | ||
.add( | ||
'node-argon', | ||
async (deferred) => { | ||
await nodeArgon2.hash(PASSWORD, { type: nodeArgon2.argon2id, parallelism: CORES }) | ||
deferred.resolve() | ||
}, | ||
{ | ||
defer: true, | ||
}, | ||
) | ||
.on('cycle', function (event) { | ||
console.info(String(event.target)) | ||
const HASHED = await hash(PASSWORD, { | ||
algorithm: Algorithm.Argon2id, | ||
parallelism: CORES, | ||
}) | ||
|
||
const bench = new Bench('Hash with all cores') | ||
|
||
bench | ||
.add('@node-rs/argon hash', async () => { | ||
await hash(PASSWORD, { | ||
algorithm: Algorithm.Argon2id, | ||
parallelism: CORES, | ||
}) | ||
}) | ||
.add('node-argon hash', async () => { | ||
await nodeArgon2.hash(PASSWORD, { type: nodeArgon2.argon2id, parallelism: CORES }) | ||
}) | ||
.on('complete', function () { | ||
console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) | ||
.add('@node-rs/argon verify', async () => { | ||
console.assert(await verify(HASHED, PASSWORD)) | ||
}) | ||
.run() | ||
.add('node-argon verify', async () => { | ||
console.assert(await nodeArgon2.verify(HASHED, PASSWORD)) | ||
}) | ||
|
||
await bench.warmup() | ||
await bench.run() | ||
|
||
console.table(bench.table()) |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
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
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
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
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
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
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
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
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