Skip to content
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

fix(argond2id):reordering parameters order during serialization to ma… #13

Merged
merged 2 commits into from
Sep 17, 2024
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
2 changes: 1 addition & 1 deletion src/drivers/argon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ export class Argon implements HashDriverContract {
id: `argon2${this.#config.variant}`,
version: this.#config.version,
params: {
t: this.#config.iterations,
m: this.#config.memory,
t: this.#config.iterations,
p: this.#config.parallelism,
},
})
Expand Down
36 changes: 36 additions & 0 deletions tests/drivers/argon2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,42 @@ test.group('argon | verify', () => {
assert.isTrue(await argon.verify(hash, 'password'))
})

test('should verify a precomputed hash with old parameters order', async ({ assert }) => {
// Precomputed hash for "password"
const hash =
'$argon2id$v=19$t=4,m=65536,p=1$oNZeAqWynNAkeJUGcuNMSw$O47kb/ayyV1VWoQLDpI/IkDOYUCF/Ctqzxys4cyEeGc'

const argon = new Argon({
variant: 'id',
iterations: 4,
memory: 65536,
parallelism: 1,
version: 19,
saltSize: 16,
hashLength: 32,
})

assert.isTrue(await argon.verify(hash, 'test-124_arg'))
})

test('should verify a precomputed hash with new parameters order', async ({ assert }) => {
// Precomputed hash for "password"
const hash =
'$argon2id$v=19$m=65536,t=4,p=1$oNZeAqWynNAkeJUGcuNMSw$O47kb/ayyV1VWoQLDpI/IkDOYUCF/Ctqzxys4cyEeGc'

const argon = new Argon({
variant: 'id',
iterations: 4,
memory: 65536,
parallelism: 1,
version: 19,
saltSize: 16,
hashLength: 32,
})

assert.isTrue(await argon.verify(hash, 'test-124_arg'))
})

test('fail verification when value is formatted as phc string', async ({ assert }) => {
const argon = new Argon({
variant: 'id',
Expand Down