Optimize iterated S2K
This commit is contained in:
parent
a6d7c466e2
commit
cd2bfca519
|
@ -168,13 +168,15 @@ S2K.prototype.produce_key = async function (passphrase, numBytes) {
|
||||||
case 'iterated': {
|
case 'iterated': {
|
||||||
const count = s2k.get_count();
|
const count = s2k.get_count();
|
||||||
const data = util.concatUint8Array([s2k.salt, passphrase]);
|
const data = util.concatUint8Array([s2k.salt, passphrase]);
|
||||||
const datalen = data.length;
|
let datalen = data.length;
|
||||||
const isp = new Uint8Array(prefix.length + count + datalen);
|
const prefixlen = prefix.length;
|
||||||
|
const isp = new Uint8Array(prefixlen + count);
|
||||||
isp.set(prefix);
|
isp.set(prefix);
|
||||||
for (let pos = prefix.length; pos < count; pos += datalen) {
|
isp.set(data, prefixlen);
|
||||||
isp.set(data, pos);
|
for (let pos = prefixlen + datalen; pos < count; pos += datalen, datalen *= 2) {
|
||||||
|
isp.copyWithin(pos, prefixlen, pos);
|
||||||
}
|
}
|
||||||
return crypto.hash.digest(algorithm, isp.subarray(0, prefix.length + count));
|
return crypto.hash.digest(algorithm, isp);
|
||||||
}
|
}
|
||||||
case 'gnu':
|
case 'gnu':
|
||||||
throw new Error("GNU s2k type not supported.");
|
throw new Error("GNU s2k type not supported.");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user