-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkdf.js
41 lines (37 loc) · 951 Bytes
/
kdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/
import {
libecc,
} from "./util.js";
/**
* See https://datatracker.ietf.org/doc/html/rfc9106
*
* @param {Uint8Array} passphrase
* @param {Uint8Array} salt, must be of size ecc_kdf_argon2id_SALTIZE
* @param {number} memorySize amount of memory (in kibibytes) to use
* @param {number} iterations number of passes
* @param {number} len intended output length
* @return {Uint8Array} the result or null if the computation didn't complete
*/
export function kdf_argon2id(
passphrase,
salt,
memorySize,
iterations,
len,
) {
let out = new Uint8Array(32);
const r = libecc.ecc_kdf_argon2id(
out,
passphrase, passphrase.length,
salt,
memorySize,
iterations,
out.length,
);
return r === 0 ? out : null;
}