perf(crypto): derive Argon2id via argon2idAsync (unfreeze unlock UI)

deriveKeyBytes now calls NobleArgon2.argon2idAsync instead of the sync
argon2id, so it yields to the event loop periodically and the busy/unlock
spinner keeps animating instead of freezing ~0.65 s during login, register,
and master-pw rotation. Same result (both RFC-9106-verified); all callers
already await deriveKeyBytes so no call-site changes.

- Re-vendored js/argon2.js to export argon2idAsync alongside argon2id
  (re-bundled from @noble/hashes@2.2.0; both variants pass the RFC 9106 §5.3
  vector). 27KB → 29KB.
- Added a sync/async parity test. 63/63 green.
- Closes the last open item of CODE_AUDIT §1.2.

NOTE: argon2.js grew — run BuildAssets to re-embed it before the next
Delphi build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-08 19:41:59 +01:00
parent 9e424efaf4
commit dd86b2bd23
4 changed files with 70 additions and 6 deletions
+14
View File
@@ -83,6 +83,20 @@ test('vendored argon2id matches the RFC 9106 §5.3 test vector', () => {
'0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659');
});
test('argon2idAsync matches argon2id (deriveKeyBytes uses the async variant)', async () => {
// deriveKeyBytes now calls argon2idAsync (yields to the event loop so the
// unlock spinner animates). It must produce the exact same key as the sync
// path — assert parity on the RFC vector.
const args = [new Uint8Array(32).fill(1), new Uint8Array(16).fill(2),
{ t: 3, m: 32, p: 4, dkLen: 32, key: new Uint8Array(8).fill(3),
personalization: new Uint8Array(12).fill(4), version: 0x13 }];
const sync = T.NobleArgon2.argon2id(...args);
const async_ = await T.NobleArgon2.argon2idAsync(...args);
assert.equal(T.bytesToHex(async_), T.bytesToHex(sync));
assert.equal(T.bytesToHex(async_),
'0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659');
});
test('isDecoupledVerifierAlgo: all -v2 markers decouple, legacy does not', () => {
assert.equal(T.isDecoupledVerifierAlgo(T.HASH_ALGO_V2), true);
assert.equal(T.isDecoupledVerifierAlgo(T.HASH_ALGO_ARGON2), true);