MCPcopy
hub / github.com/vercel/hyper / opensslKeyDeriv

Function opensslKeyDeriv

bin/yarn-standalone.js:4624–4653  ·  view source on GitHub ↗
(cipher, salt, passphrase, count)

Source from the content-addressed store, hash-verified

4622var PKCS5_SALT_LEN = 8;
4623
4624function opensslKeyDeriv(cipher, salt, passphrase, count) {
4625 assert.buffer(salt, 'salt');
4626 assert.buffer(passphrase, 'passphrase');
4627 assert.number(count, 'iteration count');
4628
4629 var clen = CIPHER_LEN[cipher];
4630 assert.object(clen, 'supported cipher');
4631
4632 salt = salt.slice(0, PKCS5_SALT_LEN);
4633
4634 var D, D_prev, bufs;
4635 var material = Buffer.alloc(0);
4636 while (material.length < clen.key + clen.iv) {
4637 bufs = [];
4638 if (D_prev)
4639 bufs.push(D_prev);
4640 bufs.push(passphrase);
4641 bufs.push(salt);
4642 D = Buffer.concat(bufs);
4643 for (var j = 0; j < count; ++j)
4644 D = crypto.createHash('md5').update(D).digest();
4645 material = Buffer.concat([material, D]);
4646 D_prev = D;
4647 }
4648
4649 return ({
4650 key: material.slice(0, clen.key),
4651 iv: material.slice(clen.key, clen.key + clen.iv)
4652 });
4653}
4654
4655/* Count leading zero bits on a buffer */
4656function countZeros(buf) {

Callers

nothing calls this directly

Calls 2

concatMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected