diff --git a/lib/bcoin/chachapoly.js b/lib/bcoin/chachapoly.js index d595c6e5..f36b79e7 100644 --- a/lib/bcoin/chachapoly.js +++ b/lib/bcoin/chachapoly.js @@ -110,6 +110,8 @@ ChaCha20.prototype.encrypt = function encrypt(data) { data[i] ^= this.bytes[this.pos++]; } + + return data; }; /** @@ -529,6 +531,8 @@ AEAD.prototype.encrypt = function encrypt(data) { this.chacha20.encrypt(data); this.poly1305.update(data); this.cipherLen += data.length; + + return data; }; /** @@ -543,6 +547,8 @@ AEAD.prototype.decrypt = function decrypt(data) { this.cipherLen += data.length; this.poly1305.update(data); this.chacha20.encrypt(data); + + return data; }; /** diff --git a/lib/bcoin/ec.js b/lib/bcoin/ec.js index 7fa8c20d..d9ebbbca 100644 --- a/lib/bcoin/ec.js +++ b/lib/bcoin/ec.js @@ -86,6 +86,23 @@ ec.publicKeyCreate = function publicKeyCreate(priv, compressed) { return new Buffer(priv); }; +/** + * Create an ecdh. + * @param {Buffer} pub + * @param {Buffer} priv + * @returns {Buffer} + */ + +ec.ecdh = function ecdh(pub, priv) { + if (secp256k1) + return secp256k1.ecdh(pub, priv); + + priv = ec.elliptic.keyPair({ priv: priv }); + pub = ec.elliptic.keyPair({ pub: pub }); + + return priv.derive(pub.getPublic()).toArrayLike(Buffer, 'be', 32); +}; + /** * Generate some random bytes. * @param {Number} size