Inline iterated S2K loop
This commit is contained in:
parent
a250ee9f91
commit
4faa84daa0
|
@ -161,15 +161,13 @@ 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]);
|
||||||
let isp = new Array(Math.ceil(count / data.length));
|
const datalen = data.length;
|
||||||
|
const isp = new Uint8Array(prefix.length + count + datalen);
|
||||||
isp = util.concatUint8Array(isp.fill(data));
|
isp.set(prefix);
|
||||||
|
for (let pos = prefix.length; pos < count; pos += datalen) {
|
||||||
if (isp.length > count) {
|
isp.set(data, pos);
|
||||||
isp = isp.subarray(0, count);
|
|
||||||
}
|
}
|
||||||
|
return crypto.hash.digest(algorithm, isp.subarray(0, prefix.length + count));
|
||||||
return crypto.hash.digest(algorithm, util.concatUint8Array([prefix, 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