MCPcopy
hub / github.com/Kong/insomnia / opensslKeyDeriv

Function opensslKeyDeriv

packages/insomnia/bin/yarn-standalone.js:4551–4580  ·  view source on GitHub ↗
(cipher, salt, passphrase, count)

Source from the content-addressed store, hash-verified

4549var PKCS5_SALT_LEN = 8;
4550
4551function opensslKeyDeriv(cipher, salt, passphrase, count) {
4552 assert.buffer(salt, 'salt');
4553 assert.buffer(passphrase, 'passphrase');
4554 assert.number(count, 'iteration count');
4555
4556 var clen = CIPHER_LEN[cipher];
4557 assert.object(clen, 'supported cipher');
4558
4559 salt = salt.slice(0, PKCS5_SALT_LEN);
4560
4561 var D, D_prev, bufs;
4562 var material = Buffer.alloc(0);
4563 while (material.length < clen.key + clen.iv) {
4564 bufs = [];
4565 if (D_prev)
4566 bufs.push(D_prev);
4567 bufs.push(passphrase);
4568 bufs.push(salt);
4569 D = Buffer.concat(bufs);
4570 for (var j = 0; j < count; ++j)
4571 D = crypto.createHash('md5').update(D).digest();
4572 material = Buffer.concat([material, D]);
4573 D_prev = D;
4574 }
4575
4576 return ({
4577 key: material.slice(0, clen.key),
4578 iv: material.slice(clen.key, clen.key + clen.iv)
4579 });
4580}
4581
4582/* Count leading zero bits on a buffer */
4583function countZeros(buf) {

Callers

nothing calls this directly

Calls 3

concatMethod · 0.80
updateMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected