From 0a64aade6249ec8e26f9c326fab600d0c40e30a2 Mon Sep 17 00:00:00 2001 From: Benjamin Hautier Date: Mon, 16 Sep 2024 15:04:19 +0200 Subject: [PATCH 1/2] fix(argond2id):reordering parameters order during serialization to match phc standard --- src/drivers/argon.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/argon.ts b/src/drivers/argon.ts index 4c40d58..a654698 100644 --- a/src/drivers/argon.ts +++ b/src/drivers/argon.ts @@ -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, }, }) From 825118f3ac9f8809897ef1717398a8c15ba12b9d Mon Sep 17 00:00:00 2001 From: Benjamin Hautier Date: Mon, 16 Sep 2024 18:43:30 +0200 Subject: [PATCH 2/2] test(argon2id):adding test to verify that changing parameters order does not break old hashes with old order --- tests/drivers/argon2.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/drivers/argon2.spec.ts b/tests/drivers/argon2.spec.ts index 056937b..25a5e66 100644 --- a/tests/drivers/argon2.spec.ts +++ b/tests/drivers/argon2.spec.ts @@ -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',