-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathscrypt.ts
More file actions
77 lines (68 loc) · 1.82 KB
/
scrypt.ts
File metadata and controls
77 lines (68 loc) · 1.82 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import rnqc from 'react-native-quick-crypto';
import * as noble from '@noble/hashes/scrypt.js';
import type { BenchFn } from '../../types/benchmarks';
import { Bench } from 'tinybench';
const TIME_MS = 1000;
// N=256, r=8, p=1 is light and fast enough for mobile benchmarking
// Higher values like 1024 can cause timeouts on slower devices
const N = 256;
const r = 8;
const p = 1;
const keylen = 64;
const scrypt_async: BenchFn = () => {
const bench = new Bench({
name: `scrypt N=${N} r=${r} p=${p} (async)`,
time: TIME_MS,
});
bench
.add('rnqc', async () => {
try {
await new Promise<void>((resolve, reject) => {
rnqc.scrypt(
'password',
'salt',
keylen,
{ N, r, p, maxmem: 32 * 1024 * 1024 },
(err: unknown) => {
if (err) reject(err);
else resolve();
},
);
});
} catch (error) {
console.error('RNQC scrypt error:', error);
throw error;
}
})
.add('@noble/hashes/scrypt', async () => {
await noble.scryptAsync('password', 'salt', { N, r, p, dkLen: keylen });
});
bench.warmupTime = 100;
return bench;
};
const scrypt_sync: BenchFn = () => {
const bench = new Bench({
name: `scrypt N=${N} r=${r} p=${p} (sync)`,
time: TIME_MS,
});
bench
.add('rnqc', () => {
try {
rnqc.scryptSync('password', 'salt', keylen, {
N,
r,
p,
maxmem: 32 * 1024 * 1024,
});
} catch (error) {
console.error('RNQC scryptSync error:', error);
throw error;
}
})
.add('@noble/hashes/scrypt', () => {
noble.scrypt('password', 'salt', { N, r, p, dkLen: keylen });
});
bench.warmupTime = 100;
return bench;
};
export default [scrypt_async, scrypt_sync];