summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/keyderive.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/keyderive.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/keyderive.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/keyderive.js b/packages/meshbay-hub/src/meshbay_hub/static/keyderive.js
index afa5d27..af119c7 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/keyderive.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/keyderive.js
@@ -75,11 +75,12 @@ async function generateKeypairs() {
// is exactly what a GPU is good at, so 600k iterations bought far less than the
// wall-clock time suggested.
//
-// 64 MB / t=3 / p=1 measured at ~320 ms through this WASM build on a desktop, so
-// roughly a second on a modest phone — the most that belongs in a login. Memory
-// is what matters here: at 64 MB per guess, a 24 GB card holds a few hundred in
-// parallel instead of the effectively unbounded number PBKDF2 allows.
-const ARGON2_MEM_KIB = 65536; // 64 MB
+// 128 MB / t=3 / p=1 measured at ~640 ms through this WASM build on a desktop.
+// Memory is the lever, not time: each guess must hold 128 MB, so a 24 GB card
+// fits ~187 in parallel and its bandwidth caps it near 2k guesses/s, against no
+// ceiling at all for PBKDF2. 256 MB would double that again at ~1.3 s, which is
+// too much to ask of a phone for something paid at every sign-in.
+const ARGON2_MEM_KIB = 131072; // 128 MB
const ARGON2_TIME = 3;
const ARGON2_LANES = 1;
@@ -273,7 +274,9 @@ async function loginAndRecover(username, password) {
&& localStorage.getItem(`meshbay_kp_${username}`)) || null;
if (bundleEnc) {
- const keys = await decryptBundle(bundleEnc, password, username);
+ // Reuse the keys just derived — decryptBundle() would run the KDF again,
+ // and at these parameters that is another 0.6 s for nothing.
+ const keys = await decryptBundleWithKey(bundleEnc, result.bundleKey);
result.skEdB64 = keys.skEd;
result.skXB64 = keys.skX;
result.keypairBundleEnc = bundleEnc;