Files
haproxy-protection/haproxy/js/worker.js
Thomas Lynch a50b35b65d argon2 implementation
- memory and time params customisable as well as "difficulty", default 1 iteration, 6000KB, 3 difficulty.
- updated the noscript bash method to work with argon2
- works in webworkers or main thread, capped at 8 threads (doesn't seem to crash firefox anymore -- we could go higher)
2022-09-24 22:56:55 +10:00

23 lines
624 B
JavaScript

importScripts('/js/argon2.js');
onmessage = async function(e) {
const [userkey, challenge, diffString, argonOpts, id, threads] = e.data;
console.log('Worker thread', id, 'started');
let i = id;
while(true) {
const hash = await argon2.hash({
pass: challenge + i.toString(),
salt: userkey,
...argonOpts,
});
// This throttle seems to really help some browsers not stop the workers abruptly
i % 10 === 0 && await new Promise(res => setTimeout(res, 10));
if (hash.hashHex.startsWith(diffString)) {
console.log('Worker', id, 'found solution');
postMessage([id, i]);
break;
}
i+=threads;
}
}