Skip to content

Commit

Permalink
SSH2Stream: use randomFillSync when available
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed Jun 30, 2019
1 parent dc59902 commit 391fc6f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -5118,8 +5118,7 @@ function send_(self, payload, cb) {
buf[4] = padLen;
payload.copy(buf, 5);

var padBytes = crypto.randomBytes(padLen);
padBytes.copy(buf, 5 + payload.length);
copyRandPadBytes(buf, 5 + payload.length, padLen);

if (hmac.type !== false && hmac.key) {
mac = crypto.createHmac(SSH_TO_OPENSSL[hmac.type], hmac.key);
Expand Down Expand Up @@ -5200,6 +5199,17 @@ function send_(self, payload, cb) {
return ret;
}

var copyRandPadBytes = (function() {
if (typeof crypto.randomFillSync === 'function') {
return crypto.randomFillSync;
} else {
return function copyRandPadBytes(buf, offset, count) {
var padBytes = crypto.randomBytes(count);
padBytes.copy(buf, offset);
};
}
})();

function randBytes(n, cb) {
crypto.randomBytes(n, function retry(err, buf) {
if (err)
Expand Down

0 comments on commit 391fc6f

Please sign in to comment.