@byline/admin 2.3.3 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abilities.js +5 -24
- package/dist/index.js +8 -30
- package/dist/lib/assert-admin-actor.js +13 -74
- package/dist/lib/create-command.js +6 -16
- package/dist/modules/admin-account/commands.js +35 -24
- package/dist/modules/admin-account/components/change-password.d.ts +8 -0
- package/dist/modules/admin-account/components/change-password.js +192 -0
- package/dist/modules/admin-account/components/change-password.module.js +8 -0
- package/dist/modules/admin-account/components/change-password_module.css +27 -0
- package/dist/modules/admin-account/components/container.d.ts +29 -0
- package/dist/modules/admin-account/components/container.js +298 -0
- package/dist/modules/admin-account/components/container.module.js +28 -0
- package/dist/modules/admin-account/components/container_module.css +106 -0
- package/dist/modules/admin-account/components/update.d.ts +8 -0
- package/dist/modules/admin-account/components/update.js +207 -0
- package/dist/modules/admin-account/components/update.module.js +8 -0
- package/dist/modules/admin-account/components/update_module.css +27 -0
- package/dist/modules/admin-account/errors.js +14 -45
- package/dist/modules/admin-account/index.js +4 -34
- package/dist/modules/admin-account/schemas.js +25 -59
- package/dist/modules/admin-account/service.js +56 -61
- package/dist/modules/admin-permissions/abilities.js +6 -24
- package/dist/modules/admin-permissions/commands.js +42 -28
- package/dist/modules/admin-permissions/components/inspector.d.ts +4 -0
- package/dist/modules/admin-permissions/components/inspector.js +284 -0
- package/dist/modules/admin-permissions/components/inspector.module.js +56 -0
- package/dist/modules/admin-permissions/components/inspector_module.css +238 -0
- package/dist/modules/admin-permissions/dto.js +3 -16
- package/dist/modules/admin-permissions/errors.js +14 -27
- package/dist/modules/admin-permissions/index.js +6 -26
- package/dist/modules/admin-permissions/repository.js +1 -8
- package/dist/modules/admin-permissions/schemas.js +33 -70
- package/dist/modules/admin-permissions/service.js +88 -92
- package/dist/modules/admin-roles/abilities.js +8 -30
- package/dist/modules/admin-roles/commands.js +89 -55
- package/dist/modules/admin-roles/components/create.d.ts +7 -0
- package/dist/modules/admin-roles/components/create.js +177 -0
- package/dist/modules/admin-roles/components/create.module.js +8 -0
- package/dist/modules/admin-roles/components/create_module.css +27 -0
- package/dist/modules/admin-roles/components/permissions.d.ts +10 -0
- package/dist/modules/admin-roles/components/permissions.js +303 -0
- package/dist/modules/admin-roles/components/permissions.module.js +44 -0
- package/dist/modules/admin-roles/components/permissions_module.css +192 -0
- package/dist/modules/admin-roles/components/update.d.ts +8 -0
- package/dist/modules/admin-roles/components/update.js +166 -0
- package/dist/modules/admin-roles/components/update.module.js +8 -0
- package/dist/modules/admin-roles/components/update_module.css +27 -0
- package/dist/modules/admin-roles/dto.js +3 -16
- package/dist/modules/admin-roles/errors.js +16 -40
- package/dist/modules/admin-roles/index.js +6 -26
- package/dist/modules/admin-roles/repository.js +1 -8
- package/dist/modules/admin-roles/schemas.js +41 -71
- package/dist/modules/admin-roles/service.js +79 -82
- package/dist/modules/admin-users/abilities.js +9 -38
- package/dist/modules/admin-users/commands.js +92 -50
- package/dist/modules/admin-users/components/create.d.ts +8 -0
- package/dist/modules/admin-users/components/create.js +268 -0
- package/dist/modules/admin-users/components/create.module.js +10 -0
- package/dist/modules/admin-users/components/create_module.css +45 -0
- package/dist/modules/admin-users/components/roles.d.ts +11 -0
- package/dist/modules/admin-users/components/roles.js +148 -0
- package/dist/modules/admin-users/components/roles.module.js +18 -0
- package/dist/modules/admin-users/components/roles_module.css +75 -0
- package/dist/modules/admin-users/components/set-password.d.ts +8 -0
- package/dist/modules/admin-users/components/set-password.js +170 -0
- package/dist/modules/admin-users/components/set-password.module.js +9 -0
- package/dist/modules/admin-users/components/set-password_module.css +31 -0
- package/dist/modules/admin-users/components/update.d.ts +8 -0
- package/dist/modules/admin-users/components/update.js +254 -0
- package/dist/modules/admin-users/components/update.module.js +9 -0
- package/dist/modules/admin-users/components/update_module.css +34 -0
- package/dist/modules/admin-users/dto.js +3 -18
- package/dist/modules/admin-users/errors.js +17 -43
- package/dist/modules/admin-users/index.js +7 -27
- package/dist/modules/admin-users/repository.js +1 -8
- package/dist/modules/admin-users/schemas.js +44 -75
- package/dist/modules/admin-users/seed-super-admin.js +9 -34
- package/dist/modules/admin-users/service.js +76 -91
- package/dist/modules/auth/components/sign-in-form.d.ts +12 -0
- package/dist/modules/auth/components/sign-in-form.js +115 -0
- package/dist/modules/auth/components/sign-in-form.module.js +12 -0
- package/dist/modules/auth/components/sign-in-form_module.css +41 -0
- package/dist/modules/auth/index.js +3 -24
- package/dist/modules/auth/jwt-session-provider.js +179 -149
- package/dist/modules/auth/password.js +11 -53
- package/dist/modules/auth/phc.js +21 -54
- package/dist/modules/auth/refresh-tokens-repository.js +1 -8
- package/dist/modules/auth/resolve-actor.js +6 -28
- package/dist/services/admin-services-context.d.ts +16 -0
- package/dist/services/admin-services-context.js +13 -0
- package/dist/services/admin-services-types.d.ts +129 -0
- package/dist/services/admin-services-types.js +1 -0
- package/dist/store.js +1 -8
- package/dist/vendor/noble-argon2/_blake.js +277 -45
- package/dist/vendor/noble-argon2/_md.js +81 -136
- package/dist/vendor/noble-argon2/_u64.js +65 -67
- package/dist/vendor/noble-argon2/argon2.js +181 -342
- package/dist/vendor/noble-argon2/blake2.js +252 -327
- package/dist/vendor/noble-argon2/utils.js +110 -490
- package/dist/vendor/noble-argon2/utils.js.LICENSE.txt +1 -0
- package/package.json +89 -10
- package/src/abilities.ts +32 -0
- package/src/declarations.d.ts +4 -0
- package/src/index.ts +39 -0
- package/src/lib/assert-admin-actor.ts +90 -0
- package/src/lib/create-command.ts +109 -0
- package/src/modules/admin-account/commands.ts +76 -0
- package/src/modules/admin-account/components/change-password.module.css +40 -0
- package/src/modules/admin-account/components/change-password.tsx +232 -0
- package/src/modules/admin-account/components/container.module.css +158 -0
- package/src/modules/admin-account/components/container.tsx +229 -0
- package/src/modules/admin-account/components/update.module.css +40 -0
- package/src/modules/admin-account/components/update.tsx +263 -0
- package/src/modules/admin-account/errors.ts +75 -0
- package/src/modules/admin-account/index.ts +60 -0
- package/src/modules/admin-account/schemas.ts +84 -0
- package/src/modules/admin-account/service.ts +92 -0
- package/src/modules/admin-permissions/abilities.ts +46 -0
- package/src/modules/admin-permissions/commands.ts +103 -0
- package/src/modules/admin-permissions/components/inspector.module.css +326 -0
- package/src/modules/admin-permissions/components/inspector.tsx +298 -0
- package/src/modules/admin-permissions/dto.ts +28 -0
- package/src/modules/admin-permissions/errors.ts +57 -0
- package/src/modules/admin-permissions/index.ts +72 -0
- package/src/modules/admin-permissions/repository.ts +49 -0
- package/src/modules/admin-permissions/schemas.ts +128 -0
- package/src/modules/admin-permissions/service.ts +137 -0
- package/src/modules/admin-roles/abilities.ts +62 -0
- package/src/modules/admin-roles/commands.ts +161 -0
- package/src/modules/admin-roles/components/create.module.css +40 -0
- package/src/modules/admin-roles/components/create.tsx +218 -0
- package/src/modules/admin-roles/components/permissions.module.css +279 -0
- package/src/modules/admin-roles/components/permissions.tsx +396 -0
- package/src/modules/admin-roles/components/update.module.css +40 -0
- package/src/modules/admin-roles/components/update.tsx +218 -0
- package/src/modules/admin-roles/dto.ts +30 -0
- package/src/modules/admin-roles/errors.ts +76 -0
- package/src/modules/admin-roles/index.ts +81 -0
- package/src/modules/admin-roles/repository.ts +96 -0
- package/src/modules/admin-roles/schemas.ts +139 -0
- package/src/modules/admin-roles/service.ts +136 -0
- package/src/modules/admin-users/abilities.ts +76 -0
- package/src/modules/admin-users/commands.ts +157 -0
- package/src/modules/admin-users/components/create.module.css +63 -0
- package/src/modules/admin-users/components/create.tsx +323 -0
- package/src/modules/admin-users/components/roles.module.css +119 -0
- package/src/modules/admin-users/components/roles.tsx +172 -0
- package/src/modules/admin-users/components/set-password.module.css +46 -0
- package/src/modules/admin-users/components/set-password.tsx +199 -0
- package/src/modules/admin-users/components/update.module.css +49 -0
- package/src/modules/admin-users/components/update.tsx +328 -0
- package/src/modules/admin-users/dto.ts +39 -0
- package/src/modules/admin-users/errors.ts +84 -0
- package/src/modules/admin-users/index.ts +91 -0
- package/src/modules/admin-users/repository.ts +161 -0
- package/src/modules/admin-users/schemas.ts +168 -0
- package/src/modules/admin-users/seed-super-admin.ts +102 -0
- package/src/modules/admin-users/service.ts +166 -0
- package/src/modules/auth/components/sign-in-form.module.css +62 -0
- package/src/modules/auth/components/sign-in-form.tsx +132 -0
- package/src/modules/auth/index.ts +31 -0
- package/src/modules/auth/jwt-session-provider.ts +301 -0
- package/src/modules/auth/password.ts +94 -0
- package/src/modules/auth/phc.ts +121 -0
- package/src/modules/auth/refresh-tokens-repository.ts +74 -0
- package/src/modules/auth/resolve-actor.ts +42 -0
- package/src/services/admin-services-context.tsx +52 -0
- package/src/services/admin-services-types.ts +177 -0
- package/src/store.ts +32 -0
- package/src/vendor/noble-argon2/LICENSE +21 -0
- package/src/vendor/noble-argon2/README.md +87 -0
- package/src/vendor/noble-argon2/_blake.ts +58 -0
- package/src/vendor/noble-argon2/_md.ts +223 -0
- package/src/vendor/noble-argon2/_u64.ts +118 -0
- package/src/vendor/noble-argon2/argon2.ts +668 -0
- package/src/vendor/noble-argon2/blake2.ts +583 -0
- package/src/vendor/noble-argon2/utils.ts +849 -0
|
@@ -1,92 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* * JS arrays do slow bound checks, so reading from `A2_BUF` slows it down
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
import { add3H, add3L, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL } from './_u64.js';
|
|
13
|
-
import { blake2b } from './blake2.js';
|
|
14
|
-
import { anumber, clean, kdfInputToBytes, nextTick, swap32IfBE, swap8IfBE, u32, u8, } from './utils.js';
|
|
15
|
-
// RFC 9106 §3.1 type `y`: 0 = Argon2d, 1 = Argon2i, 2 = Argon2id. The numeric values are the
|
|
16
|
-
// spec-bound part here; the object keys are internal labels.
|
|
17
|
-
const AT = { Argond2d: 0, Argon2i: 1, Argon2id: 2 };
|
|
18
|
-
// RFC 9106 sync points constant `SL = 4`, fixed by the design rather than exposed as a tuning knob.
|
|
1
|
+
import { add3H, add3L, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL } from "./_u64.js";
|
|
2
|
+
import { blake2b } from "./blake2.js";
|
|
3
|
+
import { anumber, clean, kdfInputToBytes, nextTick, swap32IfBE, swap8IfBE, u32, u8 } from "./utils.js";
|
|
4
|
+
const AT = {
|
|
5
|
+
Argond2d: 0,
|
|
6
|
+
Argon2i: 1,
|
|
7
|
+
Argon2id: 2
|
|
8
|
+
};
|
|
19
9
|
const ARGON2_SYNC_POINTS = 4;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const abytesOrZero = (buf, errorTitle = '') => {
|
|
23
|
-
if (buf === undefined)
|
|
24
|
-
return Uint8Array.of();
|
|
10
|
+
const abytesOrZero = (buf, errorTitle = '')=>{
|
|
11
|
+
if (void 0 === buf) return Uint8Array.of();
|
|
25
12
|
return kdfInputToBytes(buf, errorTitle);
|
|
26
13
|
};
|
|
27
|
-
// Unsigned `u32 * u32 = { h, l }`, returned as split 64-bit halves.
|
|
28
14
|
function mul(a, b) {
|
|
29
|
-
|
|
30
|
-
const aL = a & 0xffff;
|
|
15
|
+
const aL = 0xffff & a;
|
|
31
16
|
const aH = a >>> 16;
|
|
32
|
-
const bL =
|
|
17
|
+
const bL = 0xffff & b;
|
|
33
18
|
const bH = b >>> 16;
|
|
34
19
|
const ll = Math.imul(aL, bL);
|
|
35
20
|
const hl = Math.imul(aH, bL);
|
|
36
21
|
const lh = Math.imul(aL, bH);
|
|
37
22
|
const hh = Math.imul(aH, bH);
|
|
38
|
-
const carry = (ll >>> 16) + (
|
|
39
|
-
const high =
|
|
40
|
-
const low =
|
|
41
|
-
return {
|
|
23
|
+
const carry = (ll >>> 16) + (0xffff & hl) + lh;
|
|
24
|
+
const high = hh + (hl >>> 16) + (carry >>> 16) | 0;
|
|
25
|
+
const low = carry << 16 | 0xffff & ll;
|
|
26
|
+
return {
|
|
27
|
+
h: high,
|
|
28
|
+
l: low
|
|
29
|
+
};
|
|
42
30
|
}
|
|
43
31
|
function mul2(a, b) {
|
|
44
|
-
// Double the split 64-bit product; carry from `l` is folded back into `h` via `l >>> 31`.
|
|
45
32
|
const { h, l } = mul(a, b);
|
|
46
|
-
return {
|
|
33
|
+
return {
|
|
34
|
+
h: (h << 1 | l >>> 31) & 0xffffffff,
|
|
35
|
+
l: l << 1
|
|
36
|
+
};
|
|
47
37
|
}
|
|
48
|
-
// BlaMka permutation for Argon2
|
|
49
|
-
// `A + B + 2 * trunc(A) * trunc(B)`, where `trunc(...)` means the low 32-bit halves.
|
|
50
38
|
function blamka(Ah, Al, Bh, Bl) {
|
|
51
39
|
const { h: Ch, l: Cl } = mul2(Al, Bl);
|
|
52
|
-
// A + B + (2 * A * B)
|
|
53
40
|
const Rll = add3L(Al, Bl, Cl);
|
|
54
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
h: add3H(Rll, Ah, Bh, Ch),
|
|
43
|
+
l: 0 | Rll
|
|
44
|
+
};
|
|
55
45
|
}
|
|
56
|
-
// Temporary block buffer.
|
|
57
|
-
// 1024-byte block: 256 u32 = 128 interleaved low/high halves = RFC's
|
|
58
|
-
// 8x8 matrix of 16-byte registers.
|
|
59
46
|
const A2_BUF = new Uint32Array(256);
|
|
60
|
-
// Quarter-round over 64-bit word indices into `A2_BUF`; each index maps to adjacent low/high u32s.
|
|
61
47
|
function G(a, b, c, d) {
|
|
62
|
-
let Al = A2_BUF[2 * a], Ah = A2_BUF[2 * a + 1];
|
|
63
|
-
let Bl = A2_BUF[2 * b], Bh = A2_BUF[2 * b + 1];
|
|
64
|
-
let Cl = A2_BUF[2 * c], Ch = A2_BUF[2 * c + 1];
|
|
65
|
-
let Dl = A2_BUF[2 * d], Dh = A2_BUF[2 * d + 1];
|
|
66
|
-
// RFC 9106 Figure 19 GB rotates by 32, 24, 16, and 63 bits after each XOR step.
|
|
48
|
+
let Al = A2_BUF[2 * a], Ah = A2_BUF[2 * a + 1];
|
|
49
|
+
let Bl = A2_BUF[2 * b], Bh = A2_BUF[2 * b + 1];
|
|
50
|
+
let Cl = A2_BUF[2 * c], Ch = A2_BUF[2 * c + 1];
|
|
51
|
+
let Dl = A2_BUF[2 * d], Dh = A2_BUF[2 * d + 1];
|
|
67
52
|
({ h: Ah, l: Al } = blamka(Ah, Al, Bh, Bl));
|
|
68
|
-
({ Dh, Dl } = {
|
|
69
|
-
|
|
53
|
+
({ Dh, Dl } = {
|
|
54
|
+
Dh: Dh ^ Ah,
|
|
55
|
+
Dl: Dl ^ Al
|
|
56
|
+
});
|
|
57
|
+
({ Dh, Dl } = {
|
|
58
|
+
Dh: rotr32H(Dh, Dl),
|
|
59
|
+
Dl: rotr32L(Dh, Dl)
|
|
60
|
+
});
|
|
70
61
|
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
|
|
71
|
-
({ Bh, Bl } = {
|
|
72
|
-
|
|
62
|
+
({ Bh, Bl } = {
|
|
63
|
+
Bh: Bh ^ Ch,
|
|
64
|
+
Bl: Bl ^ Cl
|
|
65
|
+
});
|
|
66
|
+
({ Bh, Bl } = {
|
|
67
|
+
Bh: rotrSH(Bh, Bl, 24),
|
|
68
|
+
Bl: rotrSL(Bh, Bl, 24)
|
|
69
|
+
});
|
|
73
70
|
({ h: Ah, l: Al } = blamka(Ah, Al, Bh, Bl));
|
|
74
|
-
({ Dh, Dl } = {
|
|
75
|
-
|
|
71
|
+
({ Dh, Dl } = {
|
|
72
|
+
Dh: Dh ^ Ah,
|
|
73
|
+
Dl: Dl ^ Al
|
|
74
|
+
});
|
|
75
|
+
({ Dh, Dl } = {
|
|
76
|
+
Dh: rotrSH(Dh, Dl, 16),
|
|
77
|
+
Dl: rotrSL(Dh, Dl, 16)
|
|
78
|
+
});
|
|
76
79
|
({ h: Ch, l: Cl } = blamka(Ch, Cl, Dh, Dl));
|
|
77
|
-
({ Bh, Bl } = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(
|
|
82
|
-
|
|
80
|
+
({ Bh, Bl } = {
|
|
81
|
+
Bh: Bh ^ Ch,
|
|
82
|
+
Bl: Bl ^ Cl
|
|
83
|
+
});
|
|
84
|
+
({ Bh, Bl } = {
|
|
85
|
+
Bh: rotrBH(Bh, Bl, 63),
|
|
86
|
+
Bl: rotrBL(Bh, Bl, 63)
|
|
87
|
+
});
|
|
88
|
+
A2_BUF[2 * a] = Al, A2_BUF[2 * a + 1] = Ah;
|
|
89
|
+
A2_BUF[2 * b] = Bl, A2_BUF[2 * b + 1] = Bh;
|
|
90
|
+
A2_BUF[2 * c] = Cl, A2_BUF[2 * c + 1] = Ch;
|
|
91
|
+
A2_BUF[2 * d] = Dl, A2_BUF[2 * d + 1] = Dh;
|
|
83
92
|
}
|
|
84
|
-
// Argon2 permutation over 16 register indices into `A2_BUF`, not the register values themselves.
|
|
85
|
-
// RFC 9106 Figure 17: these arguments are the 16 `v0..v15` 64-bit word
|
|
86
|
-
// indices inside eight 16-byte inputs, not copied word values.
|
|
87
|
-
// prettier-ignore
|
|
88
93
|
function P(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14, v15) {
|
|
89
|
-
// RFC 9106 Figure 18: first apply GB across rows, then across columns of the 8x8 register matrix.
|
|
90
94
|
G(v00, v04, v08, v12);
|
|
91
95
|
G(v01, v05, v09, v13);
|
|
92
96
|
G(v02, v06, v10, v14);
|
|
@@ -97,83 +101,46 @@ function P(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13,
|
|
|
97
101
|
G(v03, v04, v09, v14);
|
|
98
102
|
}
|
|
99
103
|
function block(x, xPos, yPos, outPos, needXor) {
|
|
100
|
-
for
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
P(i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9, i + 10, i + 11, i + 12, i + 13, i + 14, i + 15);
|
|
106
|
-
}
|
|
107
|
-
// columns (8 strided 16-register groups)
|
|
108
|
-
for (let i = 0; i < 16; i += 2) {
|
|
109
|
-
// prettier-ignore
|
|
110
|
-
P(i, i + 1, i + 16, i + 17, i + 32, i + 33, i + 48, i + 49, i + 64, i + 65, i + 80, i + 81, i + 96, i + 97, i + 112, i + 113);
|
|
111
|
-
}
|
|
112
|
-
// RFC 9106 step 6: passes after the first XOR the old destination block into the new G(X, Y).
|
|
113
|
-
if (needXor)
|
|
114
|
-
for (let i = 0; i < 256; i++)
|
|
115
|
-
x[outPos + i] ^= A2_BUF[i] ^ x[xPos + i] ^ x[yPos + i];
|
|
116
|
-
else
|
|
117
|
-
for (let i = 0; i < 256; i++)
|
|
118
|
-
x[outPos + i] = A2_BUF[i] ^ x[xPos + i] ^ x[yPos + i];
|
|
104
|
+
for(let i = 0; i < 256; i++)A2_BUF[i] = x[xPos + i] ^ x[yPos + i];
|
|
105
|
+
for(let i = 0; i < 128; i += 16)P(i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9, i + 10, i + 11, i + 12, i + 13, i + 14, i + 15);
|
|
106
|
+
for(let i = 0; i < 16; i += 2)P(i, i + 1, i + 16, i + 17, i + 32, i + 33, i + 48, i + 49, i + 64, i + 65, i + 80, i + 81, i + 96, i + 97, i + 112, i + 113);
|
|
107
|
+
if (needXor) for(let i = 0; i < 256; i++)x[outPos + i] ^= A2_BUF[i] ^ x[xPos + i] ^ x[yPos + i];
|
|
108
|
+
else for(let i = 0; i < 256; i++)x[outPos + i] = A2_BUF[i] ^ x[xPos + i] ^ x[yPos + i];
|
|
119
109
|
clean(A2_BUF);
|
|
120
110
|
}
|
|
121
|
-
// Variable-Length Hash Function H'
|
|
122
|
-
// Returns bytes, not words; 1024-byte block callers explicitly reinterpret with `u32(...)`.
|
|
123
111
|
function Hp(A, dkLen) {
|
|
124
112
|
const A8 = u8(A);
|
|
125
113
|
const T = new Uint32Array(1);
|
|
126
114
|
const T8 = u8(T);
|
|
127
|
-
// Argon2 H' prefixes dkLen as LE32; native Uint32Array writes would serialize as BE on s390x.
|
|
128
115
|
T[0] = swap8IfBE(dkLen);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
if (dkLen <= 64) return blake2b.create({
|
|
117
|
+
dkLen
|
|
118
|
+
}).update(T8).update(A8).digest();
|
|
132
119
|
const out = new Uint8Array(dkLen);
|
|
133
120
|
let V = blake2b.create({}).update(T8).update(A8).digest();
|
|
134
121
|
let pos = 0;
|
|
135
|
-
// RFC 9106 Figure 8: each intermediate `V_i` contributes only `W_i`, its first 32 bytes; only
|
|
136
|
-
// `V_{r+1}` is emitted in full at the remaining length.
|
|
137
122
|
out.set(V.subarray(0, 32));
|
|
138
123
|
pos += 32;
|
|
139
|
-
|
|
140
|
-
for (; dkLen - pos > 64; pos += 32) {
|
|
124
|
+
for(; dkLen - pos > 64; pos += 32){
|
|
141
125
|
const Vh = blake2b.create({}).update(V);
|
|
142
126
|
Vh.digestInto(V);
|
|
143
127
|
Vh.destroy();
|
|
144
128
|
out.set(V.subarray(0, 32), pos);
|
|
145
129
|
}
|
|
146
|
-
|
|
147
|
-
|
|
130
|
+
out.set(blake2b(V, {
|
|
131
|
+
dkLen: dkLen - pos
|
|
132
|
+
}), pos);
|
|
148
133
|
clean(V, T);
|
|
149
|
-
// H' is byte-oriented; returning `u32(out)` would silently drop dkLen % 4 tail bytes.
|
|
150
134
|
return out;
|
|
151
135
|
}
|
|
152
|
-
// Used only inside process block!
|
|
153
136
|
function indexAlpha(r, s, laneLen, segmentLen, index, randL, sameLane = false) {
|
|
154
|
-
// RFC 9106 §3.4.2 Figures 12-13: map `J1` / `J2` into the current lane's reference area `W`.
|
|
155
137
|
let area;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
area = index - 1;
|
|
159
|
-
else if (sameLane)
|
|
160
|
-
area = s * segmentLen + index - 1;
|
|
161
|
-
else
|
|
162
|
-
area = s * segmentLen + (index == 0 ? -1 : 0);
|
|
163
|
-
}
|
|
164
|
-
else if (sameLane)
|
|
165
|
-
area = laneLen - segmentLen + index - 1;
|
|
166
|
-
else
|
|
167
|
-
area = laneLen - segmentLen + (index == 0 ? -1 : 0);
|
|
168
|
-
const startPos = r !== 0 && s !== ARGON2_SYNC_POINTS - 1 ? (s + 1) * segmentLen : 0;
|
|
169
|
-
// RFC 9106 Figure 13: `mul(randL, randL).h` is `floor(J_1^2 / 2^32)`, and the outer high-half
|
|
170
|
-
// multiply computes `floor(|W| * x / 2^32)` without floating-point math.
|
|
138
|
+
area = 0 === r ? 0 === s ? index - 1 : sameLane ? s * segmentLen + index - 1 : s * segmentLen + (0 == index ? -1 : 0) : sameLane ? laneLen - segmentLen + index - 1 : laneLen - segmentLen + (0 == index ? -1 : 0);
|
|
139
|
+
const startPos = 0 !== r && s !== ARGON2_SYNC_POINTS - 1 ? (s + 1) * segmentLen : 0;
|
|
171
140
|
const rel = area - 1 - mul(area, mul(randL, randL).h).h;
|
|
172
141
|
return (startPos + rel) % laneLen;
|
|
173
142
|
}
|
|
174
|
-
// Exclusive `2^32` sentinel used by `isU32(...)`, not the inclusive maximum u32 value.
|
|
175
143
|
const maxUint32 = Math.pow(2, 32);
|
|
176
|
-
// Validate safe JS integers in `[0, 2^32 - 1]`.
|
|
177
144
|
function isU32(num) {
|
|
178
145
|
return Number.isSafeInteger(num) && num >= 0 && num < maxUint32;
|
|
179
146
|
}
|
|
@@ -182,194 +149,153 @@ function argon2Opts(opts) {
|
|
|
182
149
|
version: 0x13,
|
|
183
150
|
dkLen: 32,
|
|
184
151
|
maxmem: maxUint32 - 1,
|
|
185
|
-
asyncTick: 10
|
|
152
|
+
asyncTick: 10
|
|
186
153
|
};
|
|
187
|
-
|
|
188
|
-
// destructuring consumes them.
|
|
189
|
-
for (let [k, v] of Object.entries(opts))
|
|
190
|
-
if (v !== undefined)
|
|
191
|
-
merged[k] = v;
|
|
154
|
+
for (let [k, v] of Object.entries(opts))if (void 0 !== v) merged[k] = v;
|
|
192
155
|
const { dkLen, p, m, t, version, onProgress, asyncTick } = merged;
|
|
193
|
-
|
|
194
|
-
if (!isU32(
|
|
195
|
-
|
|
196
|
-
if (!isU32(
|
|
197
|
-
|
|
198
|
-
if (!isU32(m))
|
|
199
|
-
throw new Error('"m" must be 0..2^32');
|
|
200
|
-
if (!isU32(t) || t < 1)
|
|
201
|
-
throw new Error('"t" (iterations) must be 1..2^32');
|
|
202
|
-
if (onProgress !== undefined && typeof onProgress !== 'function')
|
|
203
|
-
throw new Error('"progressCb" must be a function');
|
|
156
|
+
if (!isU32(dkLen) || dkLen < 4) throw new Error('"dkLen" must be 4..');
|
|
157
|
+
if (!isU32(p) || p < 1 || p >= Math.pow(2, 24)) throw new Error('"p" must be 1..2^24');
|
|
158
|
+
if (!isU32(m)) throw new Error('"m" must be 0..2^32');
|
|
159
|
+
if (!isU32(t) || t < 1) throw new Error('"t" (iterations) must be 1..2^32');
|
|
160
|
+
if (void 0 !== onProgress && 'function' != typeof onProgress) throw new Error('"progressCb" must be a function');
|
|
204
161
|
anumber(asyncTick, 'asyncTick');
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
to 2^(32)-1. The actual number of blocks is m', which is m
|
|
208
|
-
rounded down to the nearest multiple of 4*p.
|
|
209
|
-
*/
|
|
210
|
-
if (!isU32(m) || m < 8 * p)
|
|
211
|
-
throw new Error('"m" (memory) must be at least 8*p bytes');
|
|
212
|
-
// Accept legacy `0x10` for compatibility even though RFC 9106 profiles standardize `0x13`.
|
|
213
|
-
if (version !== 0x10 && version !== 0x13)
|
|
214
|
-
throw new Error('"version" must be 0x10 or 0x13, got ' + version);
|
|
162
|
+
if (!isU32(m) || m < 8 * p) throw new Error('"m" (memory) must be at least 8*p bytes');
|
|
163
|
+
if (0x10 !== version && 0x13 !== version) throw new Error('"version" must be 0x10 or 0x13, got ' + version);
|
|
215
164
|
return merged;
|
|
216
165
|
}
|
|
217
166
|
function argon2Init(password, salt, type, opts) {
|
|
218
167
|
password = kdfInputToBytes(password, 'password');
|
|
219
168
|
salt = kdfInputToBytes(salt, 'salt');
|
|
220
|
-
if (!isU32(password.length))
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// hashing; this library intentionally takes the stricter common >=8-byte salt path.
|
|
224
|
-
if (!isU32(salt.length) || salt.length < 8)
|
|
225
|
-
throw new Error('"salt" must be of length 8..4Gb');
|
|
226
|
-
if (!Object.values(AT).includes(type))
|
|
227
|
-
throw new Error('"type" was invalid');
|
|
169
|
+
if (!isU32(password.length)) throw new Error('"password" must be less of length 1..4Gb');
|
|
170
|
+
if (!isU32(salt.length) || salt.length < 8) throw new Error('"salt" must be of length 8..4Gb');
|
|
171
|
+
if (!Object.values(AT).includes(type)) throw new Error('"type" was invalid');
|
|
228
172
|
let { p, dkLen, m, t, version, key, personalization, maxmem, onProgress, asyncTick } = argon2Opts(opts);
|
|
229
|
-
// Validation
|
|
230
173
|
key = abytesOrZero(key, 'key');
|
|
231
174
|
personalization = abytesOrZero(personalization, 'personalization');
|
|
232
|
-
// H_0 = H^(64)(LE32(p) || LE32(T) || LE32(m) || LE32(t) ||
|
|
233
|
-
// LE32(v) || LE32(y) || LE32(length(P)) || P ||
|
|
234
|
-
// LE32(length(S)) || S || LE32(length(K)) || K ||
|
|
235
|
-
// LE32(length(X)) || X)
|
|
236
175
|
const h = blake2b.create();
|
|
237
176
|
const BUF = new Uint32Array(1);
|
|
238
177
|
const BUF8 = u8(BUF);
|
|
239
|
-
for (let item of [
|
|
240
|
-
|
|
178
|
+
for (let item of [
|
|
179
|
+
p,
|
|
180
|
+
dkLen,
|
|
181
|
+
m,
|
|
182
|
+
t,
|
|
183
|
+
version,
|
|
184
|
+
type
|
|
185
|
+
]){
|
|
241
186
|
BUF[0] = swap8IfBE(item);
|
|
242
187
|
h.update(BUF8);
|
|
243
188
|
}
|
|
244
|
-
for (let i of [
|
|
245
|
-
|
|
189
|
+
for (let i of [
|
|
190
|
+
password,
|
|
191
|
+
salt,
|
|
192
|
+
key,
|
|
193
|
+
personalization
|
|
194
|
+
]){
|
|
195
|
+
BUF[0] = swap8IfBE(i.length);
|
|
246
196
|
h.update(BUF8).update(i);
|
|
247
197
|
}
|
|
248
|
-
// Reserve two extra LE32 words after the 64-byte `H_0` so Figures 3-4 can append
|
|
249
|
-
// `LE32(0 or 1) || LE32(i)` in place for the lane-starting blocks.
|
|
250
198
|
const H0 = new Uint32Array(18);
|
|
251
199
|
const H0_8 = u8(H0);
|
|
252
200
|
h.digestInto(H0_8);
|
|
253
|
-
// 256 u32 = 1024 (BLOCK_SIZE), fills A2_BUF on processing
|
|
254
|
-
// Params
|
|
255
201
|
const lanes = p;
|
|
256
|
-
// m' = 4 * p * floor (m / 4p)
|
|
257
202
|
const mP = 4 * p * Math.floor(m / (ARGON2_SYNC_POINTS * p));
|
|
258
|
-
//q = m' / p columns
|
|
259
203
|
const laneLen = Math.floor(mP / p);
|
|
260
204
|
const segmentLen = Math.floor(laneLen / ARGON2_SYNC_POINTS);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
throw new Error('"maxmem" expected <2**32, got ' + maxmem);
|
|
265
|
-
if (memUsed > maxmem)
|
|
266
|
-
throw new Error('"maxmem" limit was hit: memUsed(mP*1024)=' + memUsed + ', maxmem=' + maxmem);
|
|
205
|
+
const memUsed = 1024 * mP;
|
|
206
|
+
if (!isU32(maxmem)) throw new Error('"maxmem" expected <2**32, got ' + maxmem);
|
|
207
|
+
if (memUsed > maxmem) throw new Error('"maxmem" limit was hit: memUsed(mP*1024)=' + memUsed + ', maxmem=' + maxmem);
|
|
267
208
|
const B = new Uint32Array(memUsed / 4);
|
|
268
|
-
|
|
269
|
-
for (let l = 0; l < p; l++) {
|
|
209
|
+
for(let l = 0; l < p; l++){
|
|
270
210
|
const i = 256 * laneLen * l;
|
|
271
|
-
// B[i][0] = H'^(1024)(H_0 || LE32(0) || LE32(i))
|
|
272
211
|
H0[17] = swap8IfBE(l);
|
|
273
212
|
H0[16] = swap8IfBE(0);
|
|
274
213
|
B.set(swap32IfBE(u32(Hp(H0, 1024))), i);
|
|
275
|
-
// B[i][1] = H'^(1024)(H_0 || LE32(1) || LE32(i))
|
|
276
214
|
H0[16] = swap8IfBE(1);
|
|
277
215
|
B.set(swap32IfBE(u32(Hp(H0, 1024))), i + 256);
|
|
278
216
|
}
|
|
279
|
-
let perBlock = ()
|
|
217
|
+
let perBlock = ()=>{};
|
|
280
218
|
if (onProgress) {
|
|
281
|
-
// The first segment of the first pass skips two preinitialized blocks per lane.
|
|
282
219
|
const totalBlock = t * ARGON2_SYNC_POINTS * p * segmentLen - 2 * p;
|
|
283
|
-
// Invoke callback if progress changes from 10.01 to 10.02
|
|
284
|
-
// Allows to draw smooth progress bar on up to 8K screen
|
|
285
220
|
const callbackPer = Math.max(Math.floor(totalBlock / 10000), 1);
|
|
286
221
|
let blockCnt = 0;
|
|
287
|
-
perBlock = ()
|
|
222
|
+
perBlock = ()=>{
|
|
288
223
|
blockCnt++;
|
|
289
|
-
if (onProgress && (!(blockCnt % callbackPer) || blockCnt === totalBlock))
|
|
290
|
-
onProgress(blockCnt / totalBlock);
|
|
224
|
+
if (onProgress && (!(blockCnt % callbackPer) || blockCnt === totalBlock)) onProgress(blockCnt / totalBlock);
|
|
291
225
|
};
|
|
292
226
|
}
|
|
293
227
|
clean(BUF, H0);
|
|
294
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
type,
|
|
230
|
+
mP,
|
|
231
|
+
p,
|
|
232
|
+
t,
|
|
233
|
+
version,
|
|
234
|
+
B,
|
|
235
|
+
laneLen,
|
|
236
|
+
lanes,
|
|
237
|
+
segmentLen,
|
|
238
|
+
dkLen,
|
|
239
|
+
perBlock,
|
|
240
|
+
asyncTick
|
|
241
|
+
};
|
|
295
242
|
}
|
|
296
243
|
function argon2Output(B, p, laneLen, dkLen) {
|
|
297
244
|
const B_final = new Uint32Array(256);
|
|
298
|
-
for
|
|
299
|
-
for (let j = 0; j < 256; j++)
|
|
300
|
-
B_final[j] ^= B[256 * (laneLen * l + laneLen - 1) + j];
|
|
301
|
-
// RFC 9106 steps 7-8 feed the byte string `C` into `H'^T(C)`, so normalize the xor'ed words
|
|
302
|
-
// back to spec byte order before `Hp(...)` reinterprets them as bytes.
|
|
245
|
+
for(let l = 0; l < p; l++)for(let j = 0; j < 256; j++)B_final[j] ^= B[256 * (laneLen * l + laneLen - 1) + j];
|
|
303
246
|
const res = Hp(swap32IfBE(B_final), dkLen);
|
|
304
|
-
// Wipe both the xor scratch and the full working matrix once final digest bytes exist.
|
|
305
|
-
// JS cleanup is still only best-effort, but this local buffer is no longer needed here.
|
|
306
247
|
clean(B, B_final);
|
|
307
248
|
return res;
|
|
308
249
|
}
|
|
309
250
|
function processBlock(B, address, l, r, s, index, laneLen, segmentLen, lanes, offset, prev, dataIndependent, needXor) {
|
|
310
|
-
if (offset % laneLen)
|
|
311
|
-
prev = offset - 1;
|
|
251
|
+
if (offset % laneLen) prev = offset - 1;
|
|
312
252
|
let randL, randH;
|
|
313
253
|
if (dataIndependent) {
|
|
314
254
|
let i128 = index % 128;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
address
|
|
319
|
-
block(address, 256, 2 * 256, 0, false);
|
|
320
|
-
block(address, 0, 2 * 256, 0, false);
|
|
255
|
+
if (0 === i128) {
|
|
256
|
+
address[268]++;
|
|
257
|
+
block(address, 256, 512, 0, false);
|
|
258
|
+
block(address, 0, 512, 0, false);
|
|
321
259
|
}
|
|
322
260
|
randL = address[2 * i128];
|
|
323
261
|
randH = address[2 * i128 + 1];
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
262
|
+
} else {
|
|
326
263
|
const T = 256 * prev;
|
|
327
264
|
randL = B[T];
|
|
328
265
|
randH = B[T + 1];
|
|
329
266
|
}
|
|
330
|
-
|
|
331
|
-
// lane/block per RFC 9106 §3.4.
|
|
332
|
-
const refLane = r === 0 && s === 0 ? l : randH % lanes;
|
|
267
|
+
const refLane = 0 === r && 0 === s ? l : randH % lanes;
|
|
333
268
|
const refPos = indexAlpha(r, s, laneLen, segmentLen, index, randL, refLane == l);
|
|
334
269
|
const refBlock = laneLen * refLane + refPos;
|
|
335
|
-
|
|
336
|
-
block(B, 256 * prev, 256 * refBlock, offset * 256, needXor);
|
|
270
|
+
block(B, 256 * prev, 256 * refBlock, 256 * offset, needXor);
|
|
337
271
|
}
|
|
338
272
|
function argon2(type, password, salt, opts) {
|
|
339
273
|
const { mP, p, t, version, B, laneLen, lanes, segmentLen, dkLen, perBlock } = argon2Init(password, salt, type, opts);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
address[
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// RFC 9106 §3.4.1.3: Argon2id uses Argon2i's data-independent `J1` / `J2` generation only
|
|
354
|
-
// in pass 0, slices 0 and 1; Argon2i uses it in every segment.
|
|
355
|
-
const dataIndependent = type == AT.Argon2i || (type == AT.Argon2id && r === 0 && s < 2);
|
|
356
|
-
for (let l = 0; l < p; l++) {
|
|
357
|
-
address[256 + 2] = l;
|
|
358
|
-
address[256 + 12] = 0;
|
|
274
|
+
const address = new Uint32Array(768);
|
|
275
|
+
address[262] = mP;
|
|
276
|
+
address[264] = t;
|
|
277
|
+
address[266] = type;
|
|
278
|
+
for(let r = 0; r < t; r++){
|
|
279
|
+
const needXor = 0 !== r && 0x13 === version;
|
|
280
|
+
address[256] = r;
|
|
281
|
+
for(let s = 0; s < ARGON2_SYNC_POINTS; s++){
|
|
282
|
+
address[260] = s;
|
|
283
|
+
const dataIndependent = type == AT.Argon2i || type == AT.Argon2id && 0 === r && s < 2;
|
|
284
|
+
for(let l = 0; l < p; l++){
|
|
285
|
+
address[258] = l;
|
|
286
|
+
address[268] = 0;
|
|
359
287
|
let startPos = 0;
|
|
360
|
-
if (
|
|
288
|
+
if (0 === r && 0 === s) {
|
|
361
289
|
startPos = 2;
|
|
362
290
|
if (dataIndependent) {
|
|
363
|
-
address[
|
|
364
|
-
block(address, 256,
|
|
365
|
-
block(address, 0,
|
|
291
|
+
address[268]++;
|
|
292
|
+
block(address, 256, 512, 0, false);
|
|
293
|
+
block(address, 0, 512, 0, false);
|
|
366
294
|
}
|
|
367
295
|
}
|
|
368
|
-
// current block postion
|
|
369
296
|
let offset = l * laneLen + s * segmentLen + startPos;
|
|
370
|
-
// previous block position
|
|
371
297
|
let prev = offset % laneLen ? offset - 1 : offset + laneLen - 1;
|
|
372
|
-
for
|
|
298
|
+
for(let index = startPos; index < segmentLen; index++, offset++, prev++){
|
|
373
299
|
perBlock();
|
|
374
300
|
processBlock(B, address, l, r, s, index, laneLen, segmentLen, lanes, offset, prev, dataIndependent, needXor);
|
|
375
301
|
}
|
|
@@ -379,88 +305,39 @@ function argon2(type, password, salt, opts) {
|
|
|
379
305
|
clean(address);
|
|
380
306
|
return argon2Output(B, p, laneLen, dkLen);
|
|
381
307
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
* @param salt - unique salt value
|
|
386
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
387
|
-
* @returns Derived key bytes.
|
|
388
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
389
|
-
* @example
|
|
390
|
-
* Derive a key with Argon2d.
|
|
391
|
-
* ```ts
|
|
392
|
-
* argon2d('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
393
|
-
* ```
|
|
394
|
-
*/
|
|
395
|
-
export const argon2d = (password, salt, opts) => argon2(AT.Argond2d, password, salt, opts);
|
|
396
|
-
/**
|
|
397
|
-
* Argon2i side-channel-resistant version.
|
|
398
|
-
* @param password - password or input key material
|
|
399
|
-
* @param salt - unique salt value
|
|
400
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
401
|
-
* @returns Derived key bytes.
|
|
402
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
403
|
-
* @example
|
|
404
|
-
* Derive a key with Argon2i.
|
|
405
|
-
* ```ts
|
|
406
|
-
* argon2i('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
export const argon2i = (password, salt, opts) => argon2(AT.Argon2i, password, salt, opts);
|
|
410
|
-
/**
|
|
411
|
-
* Argon2id, combining i+d, the most popular version from RFC 9106.
|
|
412
|
-
* @param password - password or input key material
|
|
413
|
-
* @param salt - unique salt value
|
|
414
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
415
|
-
* @returns Derived key bytes.
|
|
416
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
417
|
-
* @example
|
|
418
|
-
* Derive a key with Argon2id.
|
|
419
|
-
* ```ts
|
|
420
|
-
* argon2id('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
export const argon2id = (password, salt, opts) => argon2(AT.Argon2id, password, salt, opts);
|
|
308
|
+
const argon2d = (password, salt, opts)=>argon2(AT.Argond2d, password, salt, opts);
|
|
309
|
+
const argon2i = (password, salt, opts)=>argon2(AT.Argon2i, password, salt, opts);
|
|
310
|
+
const argon2id = (password, salt, opts)=>argon2(AT.Argon2id, password, salt, opts);
|
|
424
311
|
async function argon2Async(type, password, salt, opts) {
|
|
425
312
|
const { mP, p, t, version, B, laneLen, lanes, segmentLen, dkLen, perBlock, asyncTick } = argon2Init(password, salt, type, opts);
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
address[
|
|
430
|
-
address[256 + 8] = t;
|
|
431
|
-
address[256 + 10] = type;
|
|
313
|
+
const address = new Uint32Array(768);
|
|
314
|
+
address[262] = mP;
|
|
315
|
+
address[264] = t;
|
|
316
|
+
address[266] = type;
|
|
432
317
|
let ts = Date.now();
|
|
433
|
-
for
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const dataIndependent = type == AT.Argon2i || (type == AT.Argon2id && r === 0 && s < 2);
|
|
443
|
-
for (let l = 0; l < p; l++) {
|
|
444
|
-
address[256 + 2] = l;
|
|
445
|
-
address[256 + 12] = 0;
|
|
318
|
+
for(let r = 0; r < t; r++){
|
|
319
|
+
const needXor = 0 !== r && 0x13 === version;
|
|
320
|
+
address[256] = r;
|
|
321
|
+
for(let s = 0; s < ARGON2_SYNC_POINTS; s++){
|
|
322
|
+
address[260] = s;
|
|
323
|
+
const dataIndependent = type == AT.Argon2i || type == AT.Argon2id && 0 === r && s < 2;
|
|
324
|
+
for(let l = 0; l < p; l++){
|
|
325
|
+
address[258] = l;
|
|
326
|
+
address[268] = 0;
|
|
446
327
|
let startPos = 0;
|
|
447
|
-
if (
|
|
328
|
+
if (0 === r && 0 === s) {
|
|
448
329
|
startPos = 2;
|
|
449
330
|
if (dataIndependent) {
|
|
450
|
-
address[
|
|
451
|
-
block(address, 256,
|
|
452
|
-
block(address, 0,
|
|
331
|
+
address[268]++;
|
|
332
|
+
block(address, 256, 512, 0, false);
|
|
333
|
+
block(address, 0, 512, 0, false);
|
|
453
334
|
}
|
|
454
335
|
}
|
|
455
|
-
// current block postion
|
|
456
336
|
let offset = l * laneLen + s * segmentLen + startPos;
|
|
457
|
-
// previous block position
|
|
458
337
|
let prev = offset % laneLen ? offset - 1 : offset + laneLen - 1;
|
|
459
|
-
for
|
|
338
|
+
for(let index = startPos; index < segmentLen; index++, offset++, prev++){
|
|
460
339
|
perBlock();
|
|
461
340
|
processBlock(B, address, l, r, s, index, laneLen, segmentLen, lanes, offset, prev, dataIndependent, needXor);
|
|
462
|
-
// Date.now() is not monotonic. If the clock goes backwards,
|
|
463
|
-
// still yield control.
|
|
464
341
|
const diff = Date.now() - ts;
|
|
465
342
|
if (!(diff >= 0 && diff < asyncTick)) {
|
|
466
343
|
await nextTick();
|
|
@@ -473,45 +350,7 @@ async function argon2Async(type, password, salt, opts) {
|
|
|
473
350
|
clean(address);
|
|
474
351
|
return argon2Output(B, p, laneLen, dkLen);
|
|
475
352
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
481
|
-
* @returns Promise resolving to derived key bytes.
|
|
482
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
483
|
-
* @example
|
|
484
|
-
* Derive a key with Argon2d asynchronously.
|
|
485
|
-
* ```ts
|
|
486
|
-
* await argon2dAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
487
|
-
* ```
|
|
488
|
-
*/
|
|
489
|
-
export const argon2dAsync = (password, salt, opts) => argon2Async(AT.Argond2d, password, salt, opts);
|
|
490
|
-
/**
|
|
491
|
-
* Argon2i async side-channel-resistant version.
|
|
492
|
-
* @param password - password or input key material
|
|
493
|
-
* @param salt - unique salt value
|
|
494
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
495
|
-
* @returns Promise resolving to derived key bytes.
|
|
496
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
497
|
-
* @example
|
|
498
|
-
* Derive a key with Argon2i asynchronously.
|
|
499
|
-
* ```ts
|
|
500
|
-
* await argon2iAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
501
|
-
* ```
|
|
502
|
-
*/
|
|
503
|
-
export const argon2iAsync = (password, salt, opts) => argon2Async(AT.Argon2i, password, salt, opts);
|
|
504
|
-
/**
|
|
505
|
-
* Argon2id async, combining i+d, the most popular version from RFC 9106.
|
|
506
|
-
* @param password - password or input key material
|
|
507
|
-
* @param salt - unique salt value
|
|
508
|
-
* @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
|
|
509
|
-
* @returns Promise resolving to derived key bytes.
|
|
510
|
-
* @throws If the Argon2 input or cost parameters are invalid. {@link Error}
|
|
511
|
-
* @example
|
|
512
|
-
* Derive a key with Argon2id asynchronously.
|
|
513
|
-
* ```ts
|
|
514
|
-
* await argon2idAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
|
|
515
|
-
* ```
|
|
516
|
-
*/
|
|
517
|
-
export const argon2idAsync = (password, salt, opts) => argon2Async(AT.Argon2id, password, salt, opts);
|
|
353
|
+
const argon2dAsync = (password, salt, opts)=>argon2Async(AT.Argond2d, password, salt, opts);
|
|
354
|
+
const argon2iAsync = (password, salt, opts)=>argon2Async(AT.Argon2i, password, salt, opts);
|
|
355
|
+
const argon2idAsync = (password, salt, opts)=>argon2Async(AT.Argon2id, password, salt, opts);
|
|
356
|
+
export { argon2d, argon2dAsync, argon2i, argon2iAsync, argon2id, argon2idAsync };
|