-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { TextEncoder, TextDecoder } from "util"; | ||
|
||
Object.assign(global, { TextDecoder, TextEncoder }); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ByteArray } from "./types"; | ||
import { argon2id } from "@noble/hashes/argon2"; | ||
|
||
const ARGON2ID_ITERATION_COUNT: number = 3; | ||
const ARGON2ID_MEMORY_COST: number = 65536; // 65536 KB = 64 MiB | ||
const ARGON2ID_PARALLELISM: number = 2; | ||
|
||
/** | ||
* Password Processing Function : Derives a password using Argon2id. | ||
* | ||
* @param password The password to derive. | ||
* @param salt PPF salt | ||
* @param outputLength The length of the output key in bytes. | ||
* @returns The derived key. | ||
*/ | ||
function ppf(password: string, salt: ByteArray, outputLength: number = 32): ByteArray { | ||
return argon2id(password, salt, { | ||
t: ARGON2ID_ITERATION_COUNT, | ||
m: ARGON2ID_MEMORY_COST, | ||
p: ARGON2ID_PARALLELISM, | ||
dkLen: outputLength | ||
}); | ||
} | ||
|
||
export { ppf }; |
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,26 @@ | ||
import { ppf } from "../src/ppf"; | ||
import { ByteArray, bytesToHex } from "../src/types"; | ||
|
||
describe("Password Processing Function", () => { | ||
const password: string = "SuperS3cret!"; | ||
const salt: ByteArray = new Uint8Array([ | ||
121, 242, 146, 172, 41, 234, 112, 205, 222, 96, 195, 136, 193, 80, 218, 41, 123, 174, 77, | ||
21, 34, 42, 99, 51, 122, 60, 188, 65, 213, 142, 189, 132 | ||
]); | ||
|
||
it("should compute the Argon2id hash", () => { | ||
const derivedPassword: ByteArray = ppf(password, salt); | ||
|
||
expect(bytesToHex(derivedPassword)).toEqual( | ||
"3482e8e7e70165709a15a690d8a6a3312ae0ea5e645f9be767b7e68aa3bead61" | ||
); | ||
}); | ||
|
||
it("should compute the Argon2id hash (512 bits)", () => { | ||
const derivedPassword: ByteArray = ppf(password, salt, 64); | ||
|
||
expect(bytesToHex(derivedPassword)).toEqual( | ||
"ab2c298ec6e0f1e87d79ba4b43b96daa3e53350d4631983306050507d690053b162c2067b6c6bfd1601cf8b33081464647d5ec817c810af44aa0c68d7b3a40c3" | ||
); | ||
}); | ||
}); |