diff --git a/lib/crypto/ec.js b/lib/crypto/ec.js index 73e3dcaa..d159151e 100644 --- a/lib/crypto/ec.js +++ b/lib/crypto/ec.js @@ -10,7 +10,7 @@ var elliptic = require('elliptic'); var bn = require('bn.js'); var utils = require('../utils/utils'); -var random = require('./random'); +var crypto = require('./crypto'); var assert = utils.assert; var secp256k1; @@ -67,7 +67,7 @@ ec.generatePrivateKey = function generatePrivateKey() { if (secp256k1) { do { - priv = random.randomBytes(32); + priv = crypto.randomBytes(32); } while (!secp256k1.privateKeyVerify(priv)); } else { key = ec.elliptic.genKeyPair(); @@ -169,8 +169,13 @@ ec.publicKeyTweakAdd = function publicKeyTweakAdd(publicKey, tweak, compressed) */ ec.ecdh = function ecdh(pub, priv) { - if (secp256k1) - return secp256k1.ecdh(pub, priv); + var point; + + if (secp256k1) { + point = secp256k1.ecdhUnsafe(pub, priv, true); + point = ec.curve.decodePoint(point); + return point.getX().toArrayLike(Buffer, 'be', 32); + } priv = ec.elliptic.keyPair({ priv: priv }); pub = ec.elliptic.keyPair({ pub: pub });