diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-07-14 10:52:48 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-07-17 08:49:02 -0700 |
commit | 24f43903b4a2f5aa73a99e6f3d4cc62d559cf94b (patch) | |
tree | 9c32bd08c43de8721e54cd846d816fbe6cdf056e /deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js | |
parent | fa73087fcf4bd14db7791120e688a0a508885b64 (diff) | |
download | android-node-v8-24f43903b4a2f5aa73a99e6f3d4cc62d559cf94b.tar.gz android-node-v8-24f43903b4a2f5aa73a99e6f3d4cc62d559cf94b.tar.bz2 android-node-v8-24f43903b4a2f5aa73a99e6f3d4cc62d559cf94b.zip |
deps: upgrade npm to 5.3.0
PR-URL: https://github.com/nodejs/node/pull/14235
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js')
-rw-r--r-- | deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js b/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js index 74f5e04702..b4d366289b 100644 --- a/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js +++ b/deps/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/dhe.js @@ -10,7 +10,6 @@ var assert = require('assert-plus'); var crypto = require('crypto'); var algs = require('./algs'); var utils = require('./utils'); -var ed; var nacl; var Key = require('./key'); @@ -76,14 +75,11 @@ function DiffieHellman(key) { this._dh.setPublicKey(key.part.Q.data); } else if (key.type === 'curve25519') { - if (ed === undefined) - ed = require('jodid25519'); + if (nacl === undefined) + nacl = require('tweetnacl'); if (this._isPriv) { this._priv = key.part.r.data; - if (this._priv[0] === 0x00) - this._priv = this._priv.slice(1); - this._priv = this._priv.slice(0, 32); } } else { @@ -180,14 +176,17 @@ DiffieHellman.prototype.computeSecret = function (otherpk) { } else if (this._algo === 'curve25519') { pub = otherpk.part.R.data; - if (pub[0] === 0x00) + while (pub[0] === 0x00 && pub.length > 32) pub = pub.slice(1); + assert.strictEqual(pub.length, 32); + assert.strictEqual(this._priv.length, 64); - var secret = ed.dh.computeKey( - this._priv.toString('binary'), - pub.toString('binary')); + var priv = this._priv.slice(0, 32); - return (new Buffer(secret, 'binary')); + var secret = nacl.box.before(new Uint8Array(pub), + new Uint8Array(priv)); + + return (new Buffer(secret)); } throw (new Error('Invalid algorithm: ' + this._algo)); @@ -255,13 +254,15 @@ DiffieHellman.prototype.generateKey = function () { } } else if (this._algo === 'curve25519') { - priv = ed.dh.generateKey(); - pub = ed.dh.publicKey(priv); - this._priv = priv = new Buffer(priv, 'binary'); - pub = new Buffer(pub, 'binary'); + var pair = nacl.box.keyPair(); + priv = new Buffer(pair.secretKey); + pub = new Buffer(pair.publicKey); + priv = Buffer.concat([priv, pub]); + assert.strictEqual(priv.length, 64); + assert.strictEqual(pub.length, 32); parts.push({name: 'R', data: pub}); - parts.push({name: 'r', data: Buffer.concat([priv, pub])}); + parts.push({name: 'r', data: priv}); this._key = new PrivateKey({ type: 'curve25519', parts: parts |